174 lines
4.6 KiB
PHP
174 lines
4.6 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\channel\service\system;
|
||
|
|
||
|
/**
|
||
|
* 欢度
|
||
|
* Class Huandu
|
||
|
* @package app\channel\service
|
||
|
*/
|
||
|
class Huifen extends Core
|
||
|
{
|
||
|
# 这几个可以后台设置
|
||
|
protected $host = '';
|
||
|
protected $mid = '';
|
||
|
protected $token = '';
|
||
|
protected $api = '';
|
||
|
protected $sign = array();
|
||
|
|
||
|
# 通用的充值
|
||
|
public function common($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'mobile' => 'accountNo',
|
||
|
'cash' => 'cash',
|
||
|
);
|
||
|
$param['productQty'] = 1;
|
||
|
$this->api = 'product-order/api/procuder/order/submit';
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 电话充值
|
||
|
public function dhcz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'mobile' => 'accountNo',
|
||
|
'cash' => 'cash',
|
||
|
);
|
||
|
$param['productQty'] = 1;
|
||
|
$this->api = 'product-order/api/procuder/order/submit';
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 通知处理 主要返回状态 2是成功 3是失败
|
||
|
public function notify($data)
|
||
|
{
|
||
|
$request = $data;
|
||
|
$result = array();
|
||
|
$result['cash'] = 1;
|
||
|
if ($data['orderStatus'] == '20') {
|
||
|
$result['status'] = 2;
|
||
|
} elseif ($data['orderStatus'] == '40') {
|
||
|
$result['status'] = 3;
|
||
|
} else {
|
||
|
$result['status'] = 4;
|
||
|
}
|
||
|
if (isset($data['operatorSerialNo']) && $data['operatorSerialNo']) {
|
||
|
# 流水号
|
||
|
if (strstr($data['operatorSerialNo'], '订单号:')) {
|
||
|
$temp = explode('订单号:', $data['operatorSerialNo']);
|
||
|
} else {
|
||
|
$temp[1] = $data['operatorSerialNo'];
|
||
|
}
|
||
|
|
||
|
$data['s_nubmer'] = $result['s_nubmer'] = $temp[1];
|
||
|
}
|
||
|
|
||
|
$result['yes'] = 'success';
|
||
|
|
||
|
$result['data'] = $data;
|
||
|
|
||
|
return $result;
|
||
|
}
|
||
|
|
||
|
# 数据响应格式处理
|
||
|
public function response($data)
|
||
|
{
|
||
|
$log['type'] = 'response';
|
||
|
$log['data'] = $data;
|
||
|
$log['config'] = $this->data;
|
||
|
$this->log($log);
|
||
|
|
||
|
$array = $this->json_decode($data);
|
||
|
|
||
|
if (!$array) {
|
||
|
$msg = 'error';
|
||
|
} elseif (isset($array['code']) && $array['code'] == '200') {
|
||
|
# 正确
|
||
|
$msg = 'ok';
|
||
|
} else {
|
||
|
# 错误
|
||
|
$msg = isset($array['message']) ? $array['message'] : 'error';
|
||
|
}
|
||
|
|
||
|
return array
|
||
|
(
|
||
|
'msg' => $msg,
|
||
|
'data' => $data,
|
||
|
'array' => $array,
|
||
|
);
|
||
|
}
|
||
|
|
||
|
# 查询接口
|
||
|
public function query($param)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
# 提交数据
|
||
|
private function submit($param, $check)
|
||
|
{
|
||
|
$param = $this->param($param, $check);
|
||
|
if (is_string($param) || (is_array($param) && $param['status'] == 1)) {
|
||
|
return $param;
|
||
|
}
|
||
|
$request = $param['detail'];
|
||
|
if (isset($request['cash'])) {
|
||
|
unset($request['cash']);
|
||
|
}
|
||
|
$request['partnerNo'] = $this->mid;
|
||
|
$request['orderNo'] = $param['order'];
|
||
|
$request['productQty'] = 1;
|
||
|
$request['notify'] = $this->getNotify($param['order'], 1);
|
||
|
//$request['productNo'] = $this->getGid($param['cash']);
|
||
|
$request['productNo'] = $this->getCode($param['cash']);
|
||
|
|
||
|
$request['sign'] = $this->_sign($request);
|
||
|
|
||
|
$url = $this->host . $this->api;
|
||
|
$response = $this->curl('post', $url, $request, true);
|
||
|
|
||
|
$response = $this->response($response);
|
||
|
//$response['data'] = '';
|
||
|
//$response['msg'] = 'ok';
|
||
|
$channel_order_id = '';
|
||
|
if (isset($response['array']['orderId'])) {
|
||
|
$channel_order_id = $response['array']['orderId'];
|
||
|
}
|
||
|
|
||
|
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']);
|
||
|
return $response['msg'];
|
||
|
}
|
||
|
|
||
|
private function _sign($request)
|
||
|
{
|
||
|
ksort($request);
|
||
|
$signature_string = '';
|
||
|
foreach ($request as $k => $v) {
|
||
|
$signature_string .= $k . '=' . $v . '&';
|
||
|
}
|
||
|
|
||
|
//$signature_string = substr($signature_string, 0, -1);
|
||
|
|
||
|
$signature_string .= 'secretKey=' . $this->token;
|
||
|
|
||
|
return strtoupper(md5($signature_string));
|
||
|
}
|
||
|
|
||
|
private function getCode($cash)
|
||
|
{
|
||
|
if ($cash == 10) {
|
||
|
return 'huafei_success';
|
||
|
} elseif ($cash == 50) {
|
||
|
return 'pos_ydmc_50';
|
||
|
} elseif ($cash == 100) {
|
||
|
return 'pos_ydmc_100';
|
||
|
} elseif ($cash == 200) {
|
||
|
return 'pos_ydmc_200';
|
||
|
}
|
||
|
|
||
|
return 11;
|
||
|
}
|
||
|
}
|