
- 添加 LinSuoKa 类实现临时锁卡功能 - 优化卡密订单关联逻辑,处理状态为 4 的订单- 新增 redis 记录订单详情,用于限单和退款处理 - 修改 Qiling 类中的签名生成逻辑 - 更新 Test 控制器中的 test_ts 方法,增加对不同订单表的处理
293 lines
8.1 KiB
PHP
293 lines
8.1 KiB
PHP
<?php
|
|
|
|
namespace app\channel\service\system;
|
|
|
|
#模板
|
|
class kuaijiaofei extends Core
|
|
{
|
|
protected $host = ''; // 主机,不设置,后台
|
|
protected $mid = ''; // 商户id
|
|
protected $token = ''; // 密钥
|
|
protected $api = '';
|
|
//话费直充
|
|
public function dhcz($param){
|
|
|
|
$check = array
|
|
(
|
|
'mobile' => 'rechargeAccount',
|
|
'cash'=>'faceValue',
|
|
);
|
|
|
|
|
|
$this->api='submitRechargeOrder';
|
|
|
|
|
|
return $this->submit($param, $check);
|
|
}
|
|
#dhcz 三网他,ydcz/dxcz/ltcz各个运营商类目,不识别
|
|
|
|
public function ydcz($param)
|
|
{
|
|
#需呀定义运营商
|
|
|
|
return $this->dhcz($param);
|
|
}
|
|
public function ydcz_lt_mnp($param)
|
|
{
|
|
#需呀定义运营商
|
|
|
|
return $this->dhcz($param);
|
|
}
|
|
|
|
public function common($param)
|
|
{
|
|
return $this->dhcz($param);
|
|
|
|
}
|
|
public function dxcz($param)
|
|
{
|
|
return $this->dhcz($param);
|
|
}
|
|
public function ltcz($param)
|
|
{
|
|
return $this->dhcz($param);
|
|
}
|
|
|
|
# 通知处理 主要返回状态 2是成功 3是失败
|
|
public function notify($data)
|
|
{
|
|
$result = array();
|
|
$result['cash'] = 1;
|
|
$result['status'] = 4;
|
|
#以上基本不要变
|
|
|
|
if ($data['code'] == 201) {
|
|
$result['status'] = 2;
|
|
} elseif($data['code'] == 202 || $data['code'] == 203 || $data['code'] == 204){
|
|
$result['status'] = 3;
|
|
}
|
|
|
|
|
|
if (isset($data['supplyCert']) && $data['supplyCert']) {
|
|
# 流水号
|
|
$data['s_number'] = $result['s_number'] = $data['supplyCert'];
|
|
}
|
|
|
|
|
|
|
|
if (isset($data['msg']) && $data['msg']) {
|
|
$data['msg'] = $result['msg'] = $data['msg'];
|
|
}
|
|
$result['yes'] = 'ok'; //响应给上游的数据
|
|
|
|
$result['data'] = $data;
|
|
|
|
return $result;
|
|
}
|
|
public function query($order){
|
|
$request['memberId'] = $this->mid;
|
|
if(isset($order['channel_order_id']) && $order['channel_order_id']){
|
|
$request['rechargeOrderId'] = $order['channel_order_id'];
|
|
}else{
|
|
$request['memberOrderId'] = $order['order_id'];
|
|
}
|
|
$request['requestDate'] = date('Y-m-d H:i:s');
|
|
$request['sign'] = $this->_sign($request,array('memberId','rechargeOrderId','memberOrderId','requestDate'));
|
|
$url = $this->host . 'queryRechargeOrder';
|
|
$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['code']=='ok' ) {
|
|
// if($array['status'] ==1){
|
|
// $result['query_status'] = 200;
|
|
// $result['status'] = 2;
|
|
// }else {
|
|
// $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['code']) && $array['code']=='100') {
|
|
# 正确
|
|
$msg = 'ok';
|
|
|
|
} else {
|
|
# 错误
|
|
$msg = $array['msg'] ?? 'error'; //前面message根据响应内容改成对应的错误提示
|
|
}
|
|
|
|
return array
|
|
(
|
|
'msg' => $msg,
|
|
'data' => $data,
|
|
'array' => $array,
|
|
);
|
|
}
|
|
|
|
# 查询余额接口
|
|
public function account($day)
|
|
{
|
|
$request['memberId'] = $this->mid;
|
|
$request['requestDate']=date('Y-m-d H:i:s');
|
|
$request['sign'] = $this->_sign($request,array('memberId','requestDate'));
|
|
$url = $this->host . 'queryRechargeMember';
|
|
$response = $this->curl('post', $url, $request);
|
|
// $response = $this->response($response);
|
|
$log['type'] = 'response';
|
|
$log['data'] = $response;
|
|
$log['config'] = $this->data;
|
|
$this->log($log);
|
|
|
|
#以上不要做任何变动
|
|
|
|
|
|
|
|
$array = $this->json_decode($response); //响应数据为json
|
|
|
|
if(is_array($array) && isset($array['result']) && isset($array['result']['money']) ){
|
|
$array['account'] = $array['result']['money']; //此处为余额
|
|
}
|
|
|
|
return $array;
|
|
}
|
|
|
|
# 库存查询
|
|
public function stock($gid)
|
|
{
|
|
try {
|
|
$request = [
|
|
'memberId' => $this->mid,
|
|
'requestDate' => date('Y-m-d H:i:s'),
|
|
'productId' => $gid,
|
|
];
|
|
$request['sign'] = $this->_sign($request, ['memberId', 'productId', 'requestDate']);
|
|
$url = $this->host . 'queryProductSupply';
|
|
$response = $this->curl('post', $url, $request);
|
|
|
|
if (empty($response)) {
|
|
return false;
|
|
}
|
|
|
|
$array = json_decode($response, true);
|
|
if (!is_array($array) || !isset($array['status']) || $array['status'] !== 1 || !isset($array['result']['items'])) {
|
|
return false;
|
|
}
|
|
|
|
$items = $array['result']['items'];
|
|
$stocks = [];
|
|
$prices = [];
|
|
|
|
foreach ($items as $index => $item) {
|
|
if ($index >= 3) break;
|
|
$stocks[] = $item['num'] ?? 0;
|
|
$prices[] = $item['discount'] ?? 0;
|
|
}
|
|
|
|
if (count($stocks) < 3) {
|
|
return false;
|
|
}
|
|
|
|
if ($stocks[0] > 3) {
|
|
return ['stock' => $stocks[0], 'price' => $prices[0]];
|
|
} elseif ($stocks[1] > 5) {
|
|
return ['stock' => $stocks[1], 'price' => $prices[1]];
|
|
} elseif ($stocks[2] > 5) {
|
|
return ['stock' => $stocks[2], 'price' => $prices[2]];
|
|
}
|
|
|
|
return false;
|
|
|
|
} catch (\Exception $e) {
|
|
// 记录日志或处理异常
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
# 提交数据
|
|
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['memberId']=$this->mid;
|
|
|
|
|
|
$request['memberOrderId']=$param['order']; //我方系统订单号
|
|
$request['productId']=$this->getGid($param['cash']); //此方法为根据面值获取产品id,如无需可注释
|
|
// unset($request['cash']);
|
|
$request['waitingTime']=300;
|
|
$stockArray = $this->stock($request['productId']);
|
|
if($stockArray){
|
|
$request['tradeMoney']=($stockArray['price']/100)*$param['cash'];
|
|
}
|
|
|
|
$request['sign'] = $this->_sign($request,array('memberId','productId','memberOrderId','rechargeAccount','faceValue'));
|
|
$url = $this->host . $this->api; //组装地址
|
|
|
|
|
|
$response = $this->curl('post', $url, $request);
|
|
$response = $this->response($response);
|
|
$channel_order_id = '';
|
|
|
|
#如果出现响应有上游订单号,可以如下
|
|
if (isset($response["array"]['rechargeOrderId'])) {
|
|
$channel_order_id = $response["array"]['rechargeOrderId'];
|
|
}
|
|
|
|
if (isset($response['array']['tradeMoney']) && $response['array']['tradeMoney']) {
|
|
#动态成本
|
|
$response['channel_cost'] = $response['array']['tradeMoney'];
|
|
}
|
|
|
|
$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];
|
|
}
|
|
}
|
|
|
|
return md5($signature_string.'signkey='.$this->token);
|
|
}
|
|
} |