221 lines
6.7 KiB
PHP
221 lines
6.7 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\channel\service\system;
|
||
|
|
||
|
class Guoyanfanglve extends Core
|
||
|
{
|
||
|
# 这几个可以后台设置
|
||
|
protected $host = '';
|
||
|
protected $mid = '';
|
||
|
protected $token = '';
|
||
|
|
||
|
protected $api="";
|
||
|
public function dhcz($param){
|
||
|
$check=array(
|
||
|
'mobile' => 'cardno',
|
||
|
'cash' => 'amount',
|
||
|
);
|
||
|
$this->api='mobile/index.php';
|
||
|
$this->submit($param,$check);
|
||
|
}
|
||
|
|
||
|
# 中石油油卡充值 拼音来吧
|
||
|
public function zsycz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'card' => 'cardno',
|
||
|
'cash' => 'amount',
|
||
|
//'idCard' => 'idcard',
|
||
|
//'realName' => 'card_name',
|
||
|
);
|
||
|
$this->api='mobile/index.php';
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 中石化油卡充值
|
||
|
public function zshcz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'card' => 'cardno',
|
||
|
'cash' => 'amount',
|
||
|
);
|
||
|
$this->api='mobile/index.php';
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 通知处理 主要返回状态 2是成功 3是失败
|
||
|
public function notify($data)
|
||
|
{
|
||
|
$request = $data;
|
||
|
unset($request['sign']);
|
||
|
unset($request['s_order']);
|
||
|
foreach ($request as $k => $v) {
|
||
|
$request[$k] = urlencode($v);
|
||
|
}
|
||
|
$sign = $this->sign($request, 'md5', '&key=' . $this->token);
|
||
|
if ($sign != $data['sign']) {
|
||
|
return false;
|
||
|
}
|
||
|
$result = array();
|
||
|
$result['cash'] = 1;
|
||
|
if(isset($data['query_status'])){
|
||
|
$data['state']=$data['query_status'];
|
||
|
}
|
||
|
if ($data['state'] == 'SUCCESS') {
|
||
|
$result['status'] = 2;
|
||
|
} elseif ($data['state'] == 'CANCEL') {
|
||
|
$result['status'] = 3;
|
||
|
} else {
|
||
|
$result['status'] = 4;
|
||
|
}
|
||
|
$result['yes'] = 'SUCCESS';
|
||
|
|
||
|
if (isset($data['official_sn']) && $data['official_sn']) {
|
||
|
# 流水号
|
||
|
$data['s_nubmer'] = $result['s_nubmer'] = $data['official_sn'];
|
||
|
}
|
||
|
|
||
|
if (isset($data['message']) && $data['message']) {
|
||
|
# 错误信息
|
||
|
$data['msg'] = $result['msg'] = $data['message'];
|
||
|
}
|
||
|
|
||
|
$result['data'] = $data;
|
||
|
|
||
|
return $result;
|
||
|
}
|
||
|
//订单查询
|
||
|
public function query($param)
|
||
|
{
|
||
|
if (empty($param['order'])) {
|
||
|
return 'order';
|
||
|
}
|
||
|
$request['mchid'] = $this->mid;
|
||
|
$request['order_sn'] = $param['order_id'];
|
||
|
$request['act'] = 'refill';
|
||
|
$request['op'] = 'query';
|
||
|
$request['sign'] = $this->_sign($request);
|
||
|
$url = $this->host . 'mobile/index.php';
|
||
|
$response = $this->curl('post', $url, $request);
|
||
|
|
||
|
$log['type'] = 'query_response';
|
||
|
$log['data'] = $response;
|
||
|
$log['config'] = $this->data;
|
||
|
$this->log($log);
|
||
|
|
||
|
$array = $this->json_decode($response, true);
|
||
|
$result = array();
|
||
|
$result['status'] = 4;
|
||
|
if ($array['code']==200&&isset($array['datas'])) {
|
||
|
if ($array['datas']['order_state'] == 40) {
|
||
|
$result['query_status'] = 'SUCCESS';
|
||
|
|
||
|
$result['status'] = 2;
|
||
|
} elseif ($array['datas']['order_state'] == 0) {
|
||
|
$result['query_status'] ='CANCEL';
|
||
|
$result['status'] = 3;
|
||
|
}
|
||
|
if (isset($array['datas']['official_sn']) && $array['datas']['official_sn']) {
|
||
|
# 流水号
|
||
|
// $data['szRtnMsg']
|
||
|
$result['s_number'] = $array['datas']['official_sn'];
|
||
|
}
|
||
|
|
||
|
}
|
||
|
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' => json_encode($array, JSON_UNESCAPED_UNICODE),
|
||
|
'array' => $array,
|
||
|
);
|
||
|
}
|
||
|
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);
|
||
|
}
|
||
|
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['mchid'] = $this->mid;
|
||
|
$request['order_sn'] = $param['order'];
|
||
|
$request['act'] = 'refill';
|
||
|
$request['op'] = 'add';
|
||
|
$request['notifyurl'] = $this->getNotify($param['order'], 1);
|
||
|
$request['sign'] = $this->_sign($request);
|
||
|
$url = $this->host . $this->api;
|
||
|
|
||
|
$response = $this->curl('get', $url, $request);
|
||
|
$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 submit($param, $check)
|
||
|
// {
|
||
|
// $param = $this->param($param, $check);
|
||
|
//
|
||
|
// if (is_string($param) || (is_array($param) && $param['status'] == 1)) {
|
||
|
// return $param;
|
||
|
// }
|
||
|
// $request = $param['detail'];
|
||
|
// $request['act'] = 'refill';
|
||
|
// $request['op'] = 'add';
|
||
|
// $request['mchid'] = $this->mid;
|
||
|
// $request['order_sn'] = $param['order'];
|
||
|
// $request['notifyurl'] = $this->getNotify($param['order'], 1);
|
||
|
//
|
||
|
//// $request['sign'] = $this->sign($request, 'md5', '&key=' . $this->token);
|
||
|
// $request['sign'] = $this->_sign($request);
|
||
|
// $url = $this->host . 'mobile/index.php';
|
||
|
// $response = $this->curl('post', $url, $request);
|
||
|
// $response = $this->response($response);
|
||
|
// //$response['data'] = '';
|
||
|
// //$response['msg'] = 'ok';
|
||
|
// $channel_order_id = '';
|
||
|
// if (isset($response['array']['data'])) {
|
||
|
// $channel_order_id = $response['array']['data'];
|
||
|
// }
|
||
|
// $this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']);
|
||
|
// return $response['msg'];
|
||
|
// }
|
||
|
}
|