212 lines
5.5 KiB
PHP
Raw Normal View History

2024-09-29 15:43:18 +08:00
<?php
namespace app\channel\service\system;
/**
* 服务
* Class Tiancheng
* @package app\channel\service
*/
class Xiaoniu extends Core
{
# 这几个可以后台设置
protected $host = '';
protected $mid = '';
protected $token = '';
protected $api = '';
# 电话充值
public function common($param)
{
$check = array
(
'account' => 'account',
'cash' => 'faceAmount',
);
$this->order_type = 'DB';
return $this->submit($param, $check);
}
# 电话充值
public function dhcz($param)
{
$check = array
(
'mobile' => 'account',
'cash' => 'faceAmount',
);
$this->order_type = 'YD';
if (isset($param['isp']) && $param['isp']) {
if ($param['isp'] == 1) {
$this->order_type = 'YD';
} elseif ($param['isp'] == 2) {
$this->order_type = 'LT';
} elseif ($param['isp'] == 3) {
$this->order_type = 'DX';
}
}
return $this->submit($param, $check);
}
# 抖音充值
public function dy($param)
{
$check = array
(
'account' => 'account',
'cash' => 'faceAmount',
);
$this->order_type = 'DB';
return $this->submit($param, $check);
}
# 抖音充值
public function kb($param)
{
$check = array
(
'account' => 'account',
'cash' => 'faceAmount',
);
$this->order_type = 'KB';
return $this->submit($param, $check);
}
# 中石化油卡充值
public function zshcz($param)
{
$check = array
(
'card' => 'account',
'cash' => 'faceAmount',
);
$this->order_type = 'Sinopec';
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
unset($request['sign']);
unset($request['s_order']);
$sign = $this->_sign($request);
if ($sign != $data['sign']) {
//return false;
}
$result = array();
$result['cash'] = 1;
if ($data['status'] == 1) {
$result['status'] = 2;
} elseif ($data['status'] == 2) {
$result['status'] = 3;
} else {
$result['status'] = 4;
}
if (isset($data['content']) && $data['content']) {
# 流水号
if (strstr($data['content'], ':')) {
$temp = explode(':', $data['content']);
if (strstr($temp[1], '')) {
$x = explode('', $temp[1]);
$data['s_nubmer'] = $result['s_nubmer'] = $x[0];
} else {
$data['s_nubmer'] = $result['s_nubmer'] = $temp[1];
}
} else {
$data['s_nubmer'] = $result['s_nubmer'] = $data['content'];
}
}
$result['yes'] = 'success';
$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'] == '0') {
# 正确
$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'];
$request['mId'] = $this->mid;
$request['mOrderNo'] = $param['order'];
$request['timestamp'] = date('YmdHis');
$request['subclassType'] = $this->order_type;
$request['notifyUrl'] = $this->getNotify($param['order'], 1);
if ($this->order_type == 'Sinopec') {
$request['mobile'] = $this->getMobile($request['account']);
}
$request['sign'] = $this->_sign($request);
$url = $this->host . 'api/order/recharge';
$response = $this->curl('post', $url, $request);
$response = $this->response($response);
$channel_order_id = '';
if (isset($response['array']['orderNo'])) {
$channel_order_id = $response['array']['orderNo'];
}
$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) {
if ($v) {
//$v = urlencode($v);
$signature_string .= $k . '=' . $v . '&';
}
}
$signature_string .= 'key=' . $this->token;
return md5($signature_string);
}
}