129 lines
3.5 KiB
PHP
129 lines
3.5 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\channel\service\system;
|
||
|
|
||
|
/**
|
||
|
* 抖音
|
||
|
* Class Common
|
||
|
* @package app\channel\service
|
||
|
*/
|
||
|
class Yunjiu extends Core
|
||
|
{
|
||
|
# 这几个可以后台设置
|
||
|
protected $host = 'host';
|
||
|
protected $mid = 'mid';
|
||
|
protected $token = 'token';
|
||
|
protected $api = 'api';
|
||
|
|
||
|
# 通用的充值
|
||
|
public function common($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'account' => 'account',
|
||
|
'cash' => 'orderMoney',
|
||
|
);
|
||
|
$this->api = 'api/order/createDyOrder';
|
||
|
$this->sign = array('orderNo', 'orderMoney', 'merchNo');
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 通知处理 主要返回状态 2是成功 3是失败
|
||
|
public function notify($data)
|
||
|
{
|
||
|
$request = $data;
|
||
|
$result = array();
|
||
|
$result['cash'] = 1;
|
||
|
if ($data['orderStatus'] == 2) {
|
||
|
$result['status'] = 2;
|
||
|
} elseif ($data['orderStatus'] == 3 || $data['orderStatus'] == 4 || $data['orderStatus'] == 99) {
|
||
|
$result['status'] = 3;
|
||
|
} else {
|
||
|
$result['status'] = 4;
|
||
|
}
|
||
|
if (isset($data['memo']) && $data['memo']) {
|
||
|
# 流水号
|
||
|
//$data['s_nubmer'] = $result['s_nubmer'] = $data['memo'];
|
||
|
}
|
||
|
|
||
|
$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'] == '200') {
|
||
|
# 正确
|
||
|
$msg = 'ok';
|
||
|
} else {
|
||
|
# 错误
|
||
|
$msg = isset($array['msg']) ? $array['msg'] : 'error';
|
||
|
}
|
||
|
|
||
|
return array
|
||
|
(
|
||
|
'msg' => $msg,
|
||
|
'data' => $data,
|
||
|
'array' => $array,
|
||
|
);
|
||
|
}
|
||
|
|
||
|
# 主动查询接口
|
||
|
public function query($order)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
# 提交数据
|
||
|
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'];
|
||
|
$temp = explode('|', $this->mid);
|
||
|
$request['merchNo'] = $temp[0];
|
||
|
$request['orderMoney'] = $request['orderMoney']*100;
|
||
|
$request['notifyTime'] = $temp[1];
|
||
|
$request['orderNo'] = $param['order'];
|
||
|
$request['payType'] = 'weixin';
|
||
|
//$request['prodCode'] = $this->getGid($param['cash']);;
|
||
|
$request['notifyUrl'] = $this->getNotify($param['order'], 1);
|
||
|
$request['sign'] = $this->_sign($request, $this->sign);
|
||
|
|
||
|
$url = $this->host . $this->api;
|
||
|
$response = $this->curl('post', $url, $request, true);
|
||
|
$response = $this->response($response);
|
||
|
$channel_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)
|
||
|
{
|
||
|
//ksort($request);
|
||
|
$signature_string = '';
|
||
|
foreach ($param as $k => $v) {
|
||
|
if (isset($request[$v])) {
|
||
|
$signature_string .= $request[$v];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$signature_string .= $this->token;
|
||
|
return strtoupper(md5($signature_string));
|
||
|
}
|
||
|
}
|