2024-09-29 15:43:18 +08:00

218 lines
5.2 KiB
PHP

<?php
namespace app\channel\service\system;
/**
* 迅猫科技
* Class Bodingcheng
* @package app\channel\service
*/
class Xunmao extends Core
{
# 这几个可以后台设置
protected $host = '';
protected $mid = '';
protected $token = '';
protected $card = array();
protected $order_id = '';
protected $api = '';
protected $sign = array();
# 电话充值
public function dhcz($param)
{
$check = array
(
'mobile' => 'phone',
'cash' => 'amount',
);
// $this->sign = array('amount','appid', 'orderNo', 'phone', 'amount', 'notifyUrl');
$this->api = 'open/recharge';
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
$result = array();
$result['cash'] = 1;
$result['status'] = 4;
if(isset($data['nFlag']) ){
if ($data['nFlag'] == 3) {
$result['status'] = 2;
} else if($data['nFlag'] == 2) {
$result['status'] = 3;
}
}else{
if ($data['status'] == 3) {
$result['status'] = 2;
} else if($data['status'] == 2) {
$result['status'] = 3;
}
}
// if (isset($data['szRtnMsg']) && $data['szRtnMsg']) {
// # 流水号
// $data['s_nubmer'] = $result['s_nubmer'] = $data['szRtnMsg'];
// }
$result['yes'] = 'success';
$result['data'] = $data;
return $result;
}
#查询
public function query($order)
{
$request['appid'] = $this->mid;
$request['orderNo'] = $order['order_id'];
$request['phone'] = $order['account'];
$request['orderId'] = $order['channel_order_id'];
$request['sign'] = $this->_sign($request);
$url = $this->host . 'open/query';
$response = $this->curl('post', $url, $request,true);
$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 (isset($array['code']) && isset($array['data']['status']) && $array['data']['status'] != 0) {
if($array['data']['status'] == '3'){
$result['nFlag'] = 3;
$result['status'] = 2;
}elseif ($array['data']['status']== '2'){
$result['nFlag'] = 2;
$result['status'] = 3;
}
// if (isset($array['szRtnMsg']) && $array['szRtnMsg']) {
// # 流水号
//// $data['szRtnMsg']
// $result['szRtnMsg'] = $array['szRtnMsg'];
// }
}
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'] == '0') {
# 正确
$msg = 'ok';
} else {
# 错误
$msg = $array['desc'] ?? 'error';
}
return array
(
'msg' => $msg,
'data' => $data,
'array' => $array,
);
}
private function submit($param, $check)
{
$param = $this->param($param, $check);
if (is_string($param) || (is_array($param) && $param['status'] == 1)) {
return $param;
}
#TODO 以下修改
$request = $param['detail'];
$request['appid'] = $this->mid;
$request['orderNo'] = $param['order'];
// $request['szProductId'] = $this->getGid($param['cash']);
$request['notifyUrl'] = $this->getNotify($param['order'], 1);
ksort($request);
$request['sign'] = $this->_sign($request);
$url = $this->host . $this->api;
// var_dump($request);die;
$response = $this->curl('post', $url, $request,true);
// $response = $this->http_send('POST', $url, $request,true);
$response = $this->response($response);
$channel_order_id = '';
if (isset($response['array']['data']['orderId'])) {
#警告类型
$channel_order_id = $response['array']['data']['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 . '&';
}
// var_dump($signature_string);die;
$signature_string = substr($signature_string, 0, -1);
$signature_string .= '&secret='.$this->token;
return md5($signature_string);
}
# 订单查询
# 查询余额接口
# 查询接口
# 提交数据
}