
- 添加 LinSuoKa 类实现临时锁卡功能 - 优化卡密订单关联逻辑,处理状态为 4 的订单- 新增 redis 记录订单详情,用于限单和退款处理 - 修改 Qiling 类中的签名生成逻辑 - 更新 Test 控制器中的 test_ts 方法,增加对不同订单表的处理
236 lines
6.9 KiB
PHP
236 lines
6.9 KiB
PHP
<?php
|
|
|
|
namespace app\channel\service\system;
|
|
|
|
#70充 -- https://docs.qq.com/doc/DZW5jTWdHZFVIYnZp?_t=1639711707120
|
|
class Qiling extends Core
|
|
{
|
|
protected $host = ''; // 主机,不设置,后台
|
|
protected $mid = ''; // 商户id
|
|
protected $token = ''; // 密钥
|
|
protected $api = '';
|
|
//话费直充
|
|
public function dhcz($param){
|
|
$check = array
|
|
(
|
|
'mobile' => 'szPhoneNum',
|
|
'cash'=>'nMoney',
|
|
'nSortType'=>'nSortType'
|
|
);
|
|
|
|
|
|
$this->api='plat/api/old/submitorder';
|
|
# 判断运营商的方法
|
|
|
|
#写法:
|
|
if(!isset($param['nSortType'])){
|
|
|
|
if (isset($param['isp']) && $param['isp']) {
|
|
$param['nSortType'] = $param['isp'];
|
|
}else{
|
|
$isp = $this->isp($param['mobile']);
|
|
$param['nSortType'] = $isp;
|
|
}
|
|
}
|
|
|
|
#isp 1移动,2联通,3电信
|
|
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
public function ydcz($param)
|
|
{
|
|
#需呀定义运营商
|
|
$param['nSortType'] = 1;
|
|
|
|
return $this->dhcz($param);
|
|
}
|
|
public function dxcz($param)
|
|
{
|
|
$param['nSortType'] = 3;
|
|
|
|
return $this->dhcz($param);
|
|
}
|
|
public function ltcz($param)
|
|
{
|
|
$param['nSortType'] = 2;
|
|
|
|
return $this->dhcz($param);
|
|
}
|
|
|
|
|
|
|
|
|
|
# 通知处理 主要返回状态 2是成功 3是失败
|
|
public function notify($data)
|
|
{
|
|
$result = array();
|
|
$result['cash'] = 1;
|
|
$result['status'] = 4;
|
|
#以上基本不要变
|
|
|
|
if(isset($data['query_status'])){
|
|
if ($data['query_status'] == 200) {
|
|
$result['status'] = 2;
|
|
} else if($data['query_status'] == 500) {
|
|
$result['status'] = 3;
|
|
}else {
|
|
$result['status'] = 4;
|
|
}
|
|
}else{
|
|
if ($data['nFlag'] == 2) {
|
|
$result['status'] = 2;
|
|
} else if($data['nFlag'] == 3) {
|
|
$result['status'] = 3;
|
|
}else {
|
|
$result['status'] = 4;
|
|
}
|
|
}
|
|
if (isset($data['szRtnMsg']) && $data['szRtnMsg']) {
|
|
# 流水号
|
|
$data['s_number'] = $result['s_number'] = $data['szRtnMsg'];
|
|
}
|
|
$result['yes'] = 'ok'; //响应给上游的数据
|
|
|
|
$result['data'] = $data;
|
|
|
|
return $result;
|
|
}
|
|
public function query($order){
|
|
$request['szAgentId'] = $this->mid;
|
|
$request['szOrderId'] = $order['order_id'];
|
|
$request['szVerifyString'] = $this->_sign($request, array('szAgentId','szOrderId'));
|
|
$url = $this->host . 'plat/api/old/queryorder';
|
|
$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);
|
|
|
|
$result = array();
|
|
$result['status'] = 4;
|
|
|
|
if($array['nRtn'] ==5012){
|
|
$result['query_status'] = 200;
|
|
|
|
$result['status'] = 2;
|
|
}elseif ($array['nRtn'] == 5013){
|
|
$result['query_status'] = 500;
|
|
$result['status'] = 3;
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
if (!$array) {
|
|
$msg = 'error';
|
|
} elseif (isset($array['nRtn']) && ($array['nRtn']=='0' || $array['nRtn']=='3003')) { //修改判断逻辑为确定提交成功即可
|
|
# 正确
|
|
$msg = 'ok';
|
|
|
|
} else {
|
|
# 错误
|
|
$msg = $array['szRtnCode'] ?? 'error'; //前面message根据响应内容改成对应的错误提示
|
|
}
|
|
|
|
return array
|
|
(
|
|
'msg' => $msg,
|
|
'data' => $data,
|
|
'array' => $array,
|
|
);
|
|
}
|
|
|
|
# 查询余额接口
|
|
public function account($day)
|
|
{
|
|
$request['szAgentId'] = $this->mid;
|
|
$request['szVerifyString'] = $this->_sign($request, array('szAgentId'));
|
|
$url = $this->host . 'plat/api/old/queryBalance';
|
|
// var_dump($request);die;
|
|
$response = $this->curl('post', $url, $request);
|
|
$response = $this->response($response);
|
|
|
|
$datas = $response['array'];
|
|
// var_dump($datas);die;
|
|
if(is_array($datas) && isset($datas['fBalance']) ){
|
|
$datas['account'] = $datas['fBalance']; //此处为余额
|
|
}
|
|
|
|
return $datas;
|
|
}
|
|
|
|
|
|
# 提交数据
|
|
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['szAgentId']=$this->mid;
|
|
$request['szOrderId']=$param['order']; //我方系统订单号
|
|
$request['nProductClass']=1;
|
|
$request['nProductType']=1;
|
|
$request['szProductId']=$this->getGid($param['cash']); //此方法为根据面值获取产品id,如无需可注释
|
|
if($request['szProductId'] == -1)unset($request['szProductId']);
|
|
$request['szTimeStamp']=date('Y-m-d H:i:s');
|
|
$request['szVerifyString'] = $this->_sign($request, array('szAgentId','szOrderId','szPhoneNum','nMoney','nSortType','nProductClass','nProductType','szTimeStamp'));
|
|
$request['szNotifyUrl']=$this->getNotify($param['order'], 1); //回调方法默认不用改
|
|
|
|
$url = $this->host . $this->api; //组装地址
|
|
|
|
|
|
$response = $this->curl('post', $url, $request);
|
|
$response = $this->response($response);
|
|
$channel_order_id = '';
|
|
|
|
#如果出现响应有上游订单号,可以如下
|
|
if (isset($response["array"]['szOrderId'])) {
|
|
$channel_order_id = $response["array"]['szOrderId'];
|
|
}
|
|
if (isset($response['array']['fSalePrice']) && $response['array']['fSalePrice']) {
|
|
#动态成本
|
|
$response['channel_cost'] = $response['array']['fSalePrice'];
|
|
}
|
|
|
|
$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)
|
|
{
|
|
$signature_string = '';
|
|
foreach ($param as $k => $v) {
|
|
if (isset($request[$v]) && $request[$v]) {
|
|
$signature_string .= $v . '=' . $request[$v] . '&';
|
|
}
|
|
}
|
|
|
|
$signature_string .= 'szKey=' . $this->token;
|
|
|
|
return strtolower(md5($signature_string));
|
|
}
|
|
} |