186 lines
5.3 KiB
PHP
186 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace app\channel\service\system;
|
|
|
|
/**
|
|
* 服务
|
|
* Class Bodingcheng
|
|
* @package app\channel\service
|
|
*/
|
|
class Kayou extends Core
|
|
{
|
|
# 这几个可以后台设置
|
|
protected $host = 'host';
|
|
protected $mid = 'mid';
|
|
protected $token = 'token';
|
|
protected $api = 'api';
|
|
protected $api_check = 1;
|
|
|
|
|
|
# 中石油充值
|
|
public function zsycz($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'card' => 'gasUserid',
|
|
'cash' => 'cardnum',
|
|
'mobile' => 'gasMobile',
|
|
);
|
|
if (empty($param['mobile'])) {
|
|
$param['mobile'] = 13800138000;
|
|
}
|
|
$this->api = 'kayou/channel/order/oilCardRecharge';
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 中石化油卡充值
|
|
public function zshcz($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'card' => 'gasUserid',
|
|
'cash' => 'cardnum',
|
|
'mobile' => 'gasMobile',
|
|
);
|
|
|
|
if (empty($param['mobile'])) {
|
|
$param['mobile'] = 13800138000;
|
|
}
|
|
|
|
$this->api = 'kayou/channel/order/oilCardRecharge';
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 通知处理 主要返回状态 2是成功 3是失败
|
|
public function notify($data)
|
|
{
|
|
$request = $data;
|
|
$result = array();
|
|
$result['cash'] = 1;
|
|
$result['status'] = 4;
|
|
if (isset($data['result']['orderStatus'])) {
|
|
if ($data['result']['orderStatus'] == 2) {
|
|
$result['status'] = 2;
|
|
} elseif ($data['result']['orderStatus'] == 3) {
|
|
$result['status'] = 3;
|
|
}
|
|
|
|
if (isset($data['result']['code']) && $data['result']['code']) {
|
|
# 流水号
|
|
//$data['s_nubmer'] = $result['s_nubmer'] = $data['result']['code'];
|
|
}
|
|
}
|
|
|
|
$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($order)
|
|
{
|
|
$order = json_decode($order['request'], true);
|
|
$request['appId'] = $this->mid;
|
|
$request['gasUserid'] = $order['gasUserid'];
|
|
$request['gasMobile'] = $order['gasMobile'];
|
|
$request['ordersn'] = $order['ordersn'];
|
|
$request['cardnum'] = $order['cardnum'];
|
|
$request['sign'] = $this->_sign($request, array('appId', 'appSecret', 'gasUserid', 'ordersn', 'cardnum', 'gasMobile'));
|
|
$url = $this->host . 'kayou/channel/order/oilCardQuery';
|
|
$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);
|
|
|
|
$result = array();
|
|
$result['status'] = 4;
|
|
if (isset($array['code']) && $array['code'] == '0') {
|
|
if (isset($data['result']['orderStatus'])) {
|
|
if ($data['result']['orderStatus'] == 2) {
|
|
$result['status'] = 2;
|
|
} elseif ($data['result']['orderStatus'] == 3) {
|
|
$result['status'] = 3;
|
|
}
|
|
|
|
if (isset($data['result']['code']) && $data['result']['code']) {
|
|
# 流水号
|
|
//$data['s_nubmer'] = $result['s_nubmer'] = $data['result']['code'];
|
|
}
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
# 提交数据
|
|
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['ordersn'] = $param['order'];
|
|
$request['sign'] = $this->_sign($request, array('appId', 'appSecret', 'gasUserid', 'ordersn', 'cardnum', 'gasMobile'));
|
|
$url = $this->host . $this->api;
|
|
|
|
$response = $this->curl('post', $url, $request);
|
|
$response = $this->response($response);
|
|
//$response['data'] = '';
|
|
//$response['msg'] = 'ok';
|
|
$channel_order_id = '';
|
|
if (isset($response['array']['result']['code']) && $response['array']['result']['code']) {
|
|
$channel_order_id = $response['array']['result']['code'];
|
|
}
|
|
|
|
$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)
|
|
{
|
|
$request['appSecret'] = $this->token;
|
|
$signature_string = '';
|
|
foreach ($param as $k => $v) {
|
|
if (isset($request[$v]) && $request[$v]) {
|
|
$signature_string .= $request[$v];
|
|
}
|
|
}
|
|
|
|
return md5($signature_string);
|
|
}
|
|
} |