REAPI/app/channel/service/system/Gengchen.php
2024-09-30 09:10:47 +08:00

261 lines
7.0 KiB
PHP

<?php
namespace app\channel\service\system;
/**
* 庚辰数据服务 v4
* Class Gengchen
* @package app\channel\service
*/
class Gengchen extends Core
{
# 这几个可以后台设置
protected $host = '';
protected $mid = '';
protected $token = '';
protected $method = '';
# 电话充值 拼音来吧
public function dhcz($param)
{
$param['product'] = 'dhcz';
return $this->submit_param($param);
}
#移动充值
public function ydcz($param)
{
$param['product'] = 'ydcz';
return $this->submit_param($param);
}
#联通充值
public function ltcz($param)
{
$param['product'] = 'ltcz';
return $this->submit_param($param);
}
#电信充值
public function dxcz($param)
{
$param['product'] = 'dxcz';
return $this->submit_param($param);
}
#提交统一参数
public function submit_param($param)
{
$check = array
(
'mobile' => 'mobile',
'cash' => 'cash',
'product' => 'product',
);
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
unset($request['signature']);
// $request = $this->getParam($request, $this->token, 2);
// if ($request['signature'] != $data['signature']) {
// return false;
// }
$result = array();
$result['cash'] = 1;
if ($data['status'] == 2) {
$result['status'] = 2;
} elseif ($data['status'] == 3) {
$result['status'] = 3;
} else {
$result['status'] = 4;
}
/*
if (isset($this->data['product_key']) && strstr($this->data['product_key'], '_tc') && isset($data['vnum']) && $data['vnum']) {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $data['vnum'];
}
*/
if (isset($data['s_nubmer']) && $data['s_nubmer']) {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $data['s_nubmer'];
}
if (isset($data['msg']) && $data['msg']) {
# 错误信息
$data['msg'] = $result['msg'] = $data['msg'];
}
// $result['data'] = $data;
$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'] == 1) {
# 正确
$msg = 'ok';
} else {
# 错误
$msg = isset($array['info']) ? $array['info'] : 'error';
}
return array
(
'msg' => $msg,
'data' => $data,
'array' => $array,
);
}
# 查询接口
public function query($order)
{
$time=time();
$request=array(
'appid'=>$this->mid,
'version'=>'v4',
'product'=>'query',
'merchant_order_id'=>$order->order_id,
'nonce'=>$time.rand(0,9),
'time'=>$time,
);
$request['sign']=$this->_sign($request);
#
$url = $this->host . 'handle/order';
$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['data']['status']) && $array['code'] == 1 ) {
if($array['status'] == '2'){
// $result['nFlag'] = 2;
$result['status'] = 2;
}elseif ($array['status'] == '3'){
// $result['nFlag'] = 3;
$result['status'] = 3;
}
if (isset($array['number']) && $array['number']) {
# 流水号
// $data['szRtnMsg']
$result['number'] = $array['data']['number'];
}
}
return $result;
}
# 查询余额接口
public function account($day)
{
$request['day'] = $day;
$request['appid'] = $this->mid;
$request['version'] = 'v4';
$request['product'] = 'query';
list($msec, $sec) = explode(' ', microtime());
$msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
$request['time'] = $msectime;
$request['nonce'] = substr(sha1(microtime()), rand(10, 15));
$request['sign'] = $this->_sign($request);
$url = $this->host . 'handle/accountByDay';
$response = $this->curl('post', $url, $request,true);
$response = $this->response($response);
return $response['array']['data'];
}
# 提交数据
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['appid'] = $this->mid;
$request['order'] = $param['order'];
$request['version'] = 'v4';
list($msec, $sec) = explode(' ', microtime());
$msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
$request['time'] = $msectime;
$request['nonce'] = substr(sha1(microtime()), rand(10, 15));
$request['notify'] = $this->getNotify($param['order'], 1);
$request['sign'] = $this->_sign($request);
$url = $this->host . 'handle/submit';
$response = $this->curl('post', $url, $request ,true);
$response = $this->response($response);
//$response['data'] = '{}';
//$response['msg'] = 'ok';
$channel_order_id = '';
if(isset($response['array']['data']['order']) && !empty($response['array']['data']['order'])) {
$channel_order_id = $response['array']['data']['order'];
}
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account'],);
return $response['msg'];
}
public function _sign($request)
{
ksort($request);
$signature_string = '';
foreach ($request as $k => $v) {
if (strstr($v, 'http') && !str_contains($v, '%')) {
$v = urlencode($v);
}
$signature_string .= $k . '=' . $v . '&';
}
$token = sha1($request['appid'] . '|' . $this->token);
$signature_string .=$token;
return sha1($signature_string);
}
}