
- 添加 LinSuoKa 类实现临时锁卡功能 - 优化卡密订单关联逻辑,处理状态为 4 的订单- 新增 redis 记录订单详情,用于限单和退款处理 - 修改 Qiling 类中的签名生成逻辑 - 更新 Test 控制器中的 test_ts 方法,增加对不同订单表的处理
232 lines
7.4 KiB
PHP
232 lines
7.4 KiB
PHP
<?php
|
|
|
|
namespace app\channel\service\system;
|
|
|
|
#模板
|
|
class Muck extends Core
|
|
{
|
|
protected $host = ''; // 主机,不设置,后台
|
|
protected $mid = ''; // 商户id
|
|
protected $token = ''; // 密钥
|
|
protected $api = '';
|
|
|
|
# cardbuy为通用写法
|
|
public function cardbuy($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'account' => 'buyerAcc',
|
|
'cash'=>'price',
|
|
'num'=>'num'
|
|
);
|
|
if(!isset($param['num']))$param['num']=1;
|
|
$this->api='api/order';
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 通知处理 主要返回状态 2是成功 3是失败
|
|
public function notify($data)
|
|
{
|
|
$result = array();
|
|
$result['cash'] = 1;
|
|
$result['status'] = 4;
|
|
#以上基本不要变
|
|
|
|
$result['status']= $data['status'];
|
|
|
|
|
|
|
|
|
|
|
|
if(isset($data['kami'])&&$data['kami']){
|
|
$result['kami']=$data['kami'];
|
|
}
|
|
$result['yes'] = 'ok'; //响应给上游的数据
|
|
|
|
$result['data'] = $data;
|
|
|
|
return $result;
|
|
}
|
|
public function query($order){
|
|
$request['merchantId'] = $this->mid;
|
|
$request['orderId'] = $order['merchant_order_id'];
|
|
$request_array = json_decode($order['request']);
|
|
$request['productId'] = $request_array->productId ?? 1;
|
|
$request['sign'] = $this->_sign($request,array('orderId','merchantId','productId'));
|
|
$url = $this->host . 'api/query';
|
|
$response = $this->curl('post', $url, $request);
|
|
|
|
#记录日志
|
|
$log['type'] = 'query_response';
|
|
$log['data'] = $response;
|
|
$log['config'] = $this->data;
|
|
$this->log($log);
|
|
#记录借宿
|
|
|
|
$array = $this->json_decode($response,true);
|
|
|
|
$result = array();
|
|
$result['status'] = 4;
|
|
if ($array['code']=='200' ) {
|
|
// $result['status'] = 2;
|
|
if($array['data']['orderState'] ==1){
|
|
$result['status'] = 2;
|
|
}elseif ($array['data']['orderState'] == 2){
|
|
$result['status'] = 3;
|
|
}
|
|
|
|
}
|
|
if(isset($array['data']['cardList'])){
|
|
$result['status'] = 7;
|
|
$cardpwd = $this->decrypt($array['data']['cardList']['cardPwd']);
|
|
$result['kami']=array(
|
|
'cardno' => $array['data']['cardList']['cardNo'] ?? '',
|
|
'cardpwd' => $cardpwd??['data']['cardList']['cardPwd']??'',
|
|
'expired' => null,
|
|
);
|
|
}
|
|
return $result;
|
|
}
|
|
# 数据响应格式处理
|
|
public function response($data)
|
|
{
|
|
$log['type'] = 'response';
|
|
$log['data'] = $data;
|
|
$log['config'] = $this->data;
|
|
$this->log($log);
|
|
|
|
#以上不要做任何变动
|
|
|
|
|
|
|
|
$array = $this->json_decode($data); //响应数据为json
|
|
#如果响应为XML格式
|
|
// $array = (array) simplexml_load_string($data);
|
|
|
|
if (!$array) {
|
|
$msg = 'error';
|
|
} elseif (isset($array['code']) && $array['code']=='200') { //修改判断逻辑为确定提交成功即可
|
|
# 正确
|
|
$msg = 'ok';
|
|
if($array['data'] ){
|
|
if(is_string($array['data']))$cardLists = $this->json_decode($array['data']);
|
|
else $cardLists = $array['data'];
|
|
|
|
// var_dump($cardLists);die;
|
|
$cardList = $cardLists['cardList'][0]??null;
|
|
if($cardList){
|
|
$cardpwd = $this->decrypt($cardList['cardPwd']);
|
|
$array['kami'] = array
|
|
(
|
|
'cardno' => $cardList['cardNo'],
|
|
'cardpwd' => $cardpwd??$cardList['cardPwd']??'',
|
|
'expired' => null,
|
|
// 'value' => $array['data']['count_money'],
|
|
);
|
|
$msg = 'yescard';
|
|
}
|
|
|
|
// var_dump($array);die;die
|
|
|
|
|
|
}
|
|
// var_dump($array);die;
|
|
|
|
#如有其他判断以下
|
|
|
|
} else {
|
|
# 错误
|
|
$msg = $array['msg'] ?? 'error'; //前面message根据响应内容改成对应的错误提示
|
|
}
|
|
|
|
return array
|
|
(
|
|
'msg' => $msg,
|
|
'data' => $array,
|
|
'array' => $array,
|
|
);
|
|
}
|
|
|
|
# 查询余额接口
|
|
public function account($day)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
# 提交数据
|
|
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']; //上面替换剩下的
|
|
#结束初步
|
|
|
|
$request['merchantId']=$this->mid;
|
|
|
|
$request['notifyUrl']=$this->getNotify($param['order'], 1); //回调方法默认不用改
|
|
$request['orderId']=$param['merchant_order']; //我方系统订单号
|
|
$request['buyerNick']=$request['buyerAcc'] = 'abc';
|
|
|
|
$request['productId']=$this->getGid($param['cash']); //此方法为根据面值获取产品id,如无需可注释
|
|
if($request['productId'] == -1)unset($request['productId']);
|
|
$request['payment'] = $request['totalFee']=$param['cash'] * $request['num'];
|
|
// if (isset($_SERVER['SERVER_ADDR'])) {
|
|
// $request['buyerIp'] = $_SERVER['SERVER_ADDR'];
|
|
// } elseif (isset($_SERVER['LOCAL_ADDR'])) {
|
|
// $request['buyerIp'] = $_SERVER['LOCAL_ADDR'];
|
|
// } else {
|
|
// $request['buyerIp'] = '127.0.0.1';
|
|
// }
|
|
|
|
$request['sign'] = $this->_sign($request,array('orderId','merchantId','buyerAcc','buyerNick','price','num','productId','totalFee','payment','notifyUrl'));
|
|
$url = $this->host . $this->api; //组装地址
|
|
|
|
|
|
|
|
|
|
$response = http_post($url,$request); //如果上面不可用,可以用这个方法, thinkadmin自带方法;
|
|
// $response = '{"code":"200","msg":"操作成功","data":"{\"cardList\":[{\"cardNo\":\"MUCK99760123637103268\",\"cardPwd\":\"rtR5Ul1AaRHhjUx18klJ9Q==\"}],\"orderId\":\"4351076030923116612\",\"orderState\":1}"}';
|
|
$response = $this->response($response);
|
|
$channel_order_id = '';
|
|
|
|
#如果出现响应有上游订单号,可以如下
|
|
// if (isset($response["array"]['data']['order_id'])) {
|
|
// $channel_order_id = $response["array"]['data']['order_id'];
|
|
// }
|
|
|
|
$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)
|
|
{
|
|
// unset($request['cash']);
|
|
$signature_string = '';
|
|
foreach ($param as $k => $v) {
|
|
if (isset($request[$v]) && $request[$v]) {
|
|
$signature_string .= $v.'='.$request[$v].'&';
|
|
}
|
|
}
|
|
// var_dump($signature_string.'merchantKey='.$this->token);die;
|
|
|
|
return md5($signature_string.'merchantKey='.$this->token);
|
|
}
|
|
|
|
public function decrypt($content, $charset = 'UTF-8') {
|
|
// 将Base64编码的内容解码
|
|
$decodeBytes = base64_decode($content);
|
|
|
|
|
|
$iv = str_repeat("\0", 16);
|
|
|
|
// 解密数据
|
|
$decryptText = openssl_decrypt($decodeBytes, 'AES-128-CBC', $this->token, OPENSSL_RAW_DATA, $iv);
|
|
|
|
// 转换为指定字符集并返回
|
|
return mb_convert_encoding($decryptText, $charset, 'UTF-8');
|
|
}
|
|
} |