180 lines
5.3 KiB
PHP
180 lines
5.3 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\channel\service\system;
|
||
|
|
||
|
/**
|
||
|
* 讯银服务
|
||
|
* Class Bodingcheng
|
||
|
* @package app\channel\service
|
||
|
*/
|
||
|
class Chenmi extends Core
|
||
|
{
|
||
|
# 这几个可以后台设置
|
||
|
protected $host = '';
|
||
|
protected $mid = '';
|
||
|
protected $token = '';
|
||
|
protected $api = '';
|
||
|
|
||
|
# 中石油油卡充值 拼音来吧
|
||
|
public function zsycz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'card' => 'ChargeAccount',
|
||
|
'cash' => 'cash',
|
||
|
);
|
||
|
|
||
|
$this->api = 'Order/InsertV2';
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 中石化油卡充值
|
||
|
public function zshcz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'card' => 'ChargeAccount',
|
||
|
'cash' => 'cash',
|
||
|
);
|
||
|
|
||
|
$this->api = 'Order/InsertV2';
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 通用的充值
|
||
|
public function common($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'account' => 'ChargeAccount',
|
||
|
'cash' => 'cash',
|
||
|
);
|
||
|
|
||
|
$this->api = 'Order/InsertV2';
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 通知处理 主要返回状态 2是成功 3是失败
|
||
|
public function notify($data)
|
||
|
{
|
||
|
//{"s_order":"Q202109255380106740389923","ChargeAccount":"15810090845","ProductCode":"PLM102924","BuyCount":"1","MOrderID":"Q202109255380106740389923","OrderID":"210925151001139000","State":"2","AppKey":"211395015","TimesTamp":"1632553929300","Sign":"287947FE75AE16A172FDB5B6D4D5D56F","ExtendParam":"{\"OfficialDes\":null,\"OfficialOrderID\":null,\"SellPrice\":190000}","ChargeMsg":""}
|
||
|
$request = $data;
|
||
|
$sign = $this->_sign($request, array('AppKey', 'TimesTamp', 'OrderID', 'MOrderID', 'State'));
|
||
|
if ($sign != $data['Sign']) {
|
||
|
return false;
|
||
|
}
|
||
|
$result = array();
|
||
|
$result['cash'] = 1;
|
||
|
if ($data['State'] == 2) {
|
||
|
$result['status'] = 2;
|
||
|
} elseif ($data['State'] == 3) {
|
||
|
$result['status'] = 3;
|
||
|
} else {
|
||
|
$result['status'] = 4;
|
||
|
}
|
||
|
|
||
|
if (isset($data['ExtendParam']) && is_string($data['ExtendParam']) && strstr($data['ExtendParam'], '{')) {
|
||
|
$data['ExtendParam'] = json_decode($data['ExtendParam'], true);
|
||
|
}
|
||
|
|
||
|
if (isset($data['ExtendParam']['OfficialOrderID']) && $data['ExtendParam']['OfficialOrderID']) {
|
||
|
# 错误信息
|
||
|
$msg = $data['msg'] = $result['msg'] = $data['ExtendParam']['OfficialOrderID'];
|
||
|
|
||
|
# 流水号
|
||
|
if (strstr($data['msg'], '订单号:')) {
|
||
|
$temp = explode('订单号:', $data['msg']);
|
||
|
$data['s_nubmer'] = $result['s_nubmer'] = $temp[1];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$result['yes'] = '{"Code":0}';
|
||
|
|
||
|
$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'] == '999') {
|
||
|
# 正确
|
||
|
$msg = 'ok';
|
||
|
} else {
|
||
|
# 错误
|
||
|
$msg = isset($array['Msg']) ? $array['Msg'] : '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'];
|
||
|
unset($request['cash']);
|
||
|
$request['BuyCount'] = 1;
|
||
|
$request['AppKey'] = $this->mid;
|
||
|
$request['ProductCode'] = $this->getGid($param['cash']);
|
||
|
$request['MOrderID'] = $param['order'];
|
||
|
$request['CustomerIP'] = '8.140.175.72';
|
||
|
$request['TimesTamp'] = time();
|
||
|
$request['CallBackUrl'] = $this->getNotify($param['order'], 1);
|
||
|
|
||
|
$request['Sign'] = $this->_sign($request, array('AppKey', 'BuyCount', 'CallBackUrl', 'ChargeAccount', 'CustomerIP', 'MOrderID', 'MemberAmountCode', 'ProductCode', 'TimesTamp'));
|
||
|
$url = $this->host . $this->api;
|
||
|
|
||
|
$response = $this->curl('post', $url, $request);
|
||
|
$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, $param)
|
||
|
{
|
||
|
//ksort($request);
|
||
|
$signature_string = '';
|
||
|
foreach ($param as $k => $v) {
|
||
|
if (isset($request[$v]) && $request[$v]) {
|
||
|
$signature_string .= $request[$v];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//$signature_string = substr($signature_string, 0, -1);
|
||
|
|
||
|
$signature_string .= $this->token;
|
||
|
return strtoupper(md5($signature_string));
|
||
|
}
|
||
|
}
|