157 lines
4.2 KiB
PHP
157 lines
4.2 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\channel\service\system;
|
||
|
|
||
|
/**
|
||
|
* 服务
|
||
|
* Class Bodingcheng
|
||
|
* @package app\channel\service
|
||
|
*/
|
||
|
class Fee extends Core
|
||
|
{
|
||
|
# 这几个可以后台设置
|
||
|
protected $host = '';
|
||
|
protected $mid = '';
|
||
|
protected $token = '';
|
||
|
protected $api = '';
|
||
|
protected $product_type = '';
|
||
|
protected $sign = array();
|
||
|
|
||
|
# 抖音
|
||
|
public function dycz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'account' => 'mobile',
|
||
|
'cash' => 'packcode',
|
||
|
'flowtype' => 'flowtype',
|
||
|
);
|
||
|
$param['flowtype'] = 'douyin_dyb';
|
||
|
$this->api = 'fee/api/charge.do';
|
||
|
$this->sign = array('userid', 'orderid', 'secretkey', 'echo', 'timestamp');
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 电话充值
|
||
|
public function dhcz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'mobile' => 'mobile',
|
||
|
'cash' => 'packcode',
|
||
|
'flowtype' => 'flowtype',
|
||
|
);
|
||
|
$param['flowtype'] = 'fee_quick';//fee_quick,fee_slow
|
||
|
$this->api = 'fee/api/charge.do';
|
||
|
$this->sign = array('userid', 'orderid', 'secretkey', 'echo', 'timestamp');
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 通知处理 主要返回状态 2是成功 3是失败
|
||
|
public function notify($data)
|
||
|
{
|
||
|
$request = $data;
|
||
|
/*
|
||
|
$request['secretkey'] = $this->token;
|
||
|
$sign = $this->_sign($request, array('userid', 'ordernum', 'timestamp'));
|
||
|
if ($sign != $data['sign']) {
|
||
|
return false;
|
||
|
}
|
||
|
*/
|
||
|
$result = array();
|
||
|
$result['cash'] = 1;
|
||
|
if ($data['state'] == 2) {
|
||
|
$result['status'] = 2;
|
||
|
} elseif ($data['state'] == 3) {
|
||
|
$result['status'] = 3;
|
||
|
} else {
|
||
|
$result['status'] = 4;
|
||
|
}
|
||
|
if (isset($data['serialno']) && $data['serialno']) {
|
||
|
# 流水号
|
||
|
$data['s_nubmer'] = $result['s_nubmer'] = $data['serialno'];
|
||
|
}
|
||
|
|
||
|
$result['yes'] = '{"code":"0000","desc":""}';
|
||
|
|
||
|
$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'] == '0000') {
|
||
|
# 正确
|
||
|
$msg = 'ok';
|
||
|
} else {
|
||
|
# 错误
|
||
|
$msg = isset($array['desc']) ? $array['desc'] : '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['userid'] = $this->mid;
|
||
|
$request['orderid'] = $param['order'];
|
||
|
$request['echo'] = time();
|
||
|
$request['timestamp'] = date('YmdHis');
|
||
|
$request['version'] = '1.0';
|
||
|
$request['callback_url'] = $this->getNotify($param['order'], 1);
|
||
|
$request['secretkey'] = $this->token;
|
||
|
$request['chargeSign'] = $this->_sign($request, $this->sign);
|
||
|
unset($request['secretkey']);
|
||
|
|
||
|
$url = $this->host . $this->api;
|
||
|
$response = $this->curl('post', $url, $request, true);
|
||
|
|
||
|
$response = $this->response($response);
|
||
|
//$response['data'] = '';
|
||
|
//$response['msg'] = 'ok';
|
||
|
$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)
|
||
|
{
|
||
|
$signature_string = '';
|
||
|
foreach ($param as $k => $v) {
|
||
|
if (isset($request[$v]) && $request[$v]) {
|
||
|
$signature_string .= $request[$v];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return md5($signature_string);
|
||
|
}
|
||
|
}
|