175 lines
4.7 KiB
PHP
175 lines
4.7 KiB
PHP
<?php
|
||
|
||
namespace app\channel\service\system;
|
||
|
||
/**
|
||
* 服务
|
||
* Class Bodingcheng
|
||
* @package app\channel\service
|
||
*/
|
||
class Liuyiliu extends Core
|
||
{
|
||
# 这几个可以后台设置
|
||
protected $host = 'host';
|
||
protected $mid = 'mid';
|
||
protected $token = 'token';
|
||
protected $api = 'api';
|
||
|
||
# 电话充值
|
||
public function dhcz($param)
|
||
{
|
||
$check = array
|
||
(
|
||
'mobile' => 'mobile',
|
||
'cash' => 'spec',
|
||
);
|
||
$this->api = '/v1/openapi/order/phoneCharge';
|
||
return $this->submit($param, $check);
|
||
}
|
||
|
||
# 中石油充值
|
||
public function zsycz($param)
|
||
{
|
||
$check = array
|
||
(
|
||
'card' => 'account',
|
||
'cash' => 'spec',
|
||
'cardType' => 'cardType',
|
||
);
|
||
$param['cardType'] = 'ZSY';
|
||
$this->api = '/v1/openapi/order/gasCard';
|
||
return $this->submit($param, $check);
|
||
}
|
||
|
||
# 中石化油卡充值
|
||
public function zshcz($param, $type = 2)
|
||
{
|
||
$check = array
|
||
(
|
||
'card' => 'account',
|
||
'cash' => 'spec',
|
||
'cardType' => 'cardType',
|
||
);
|
||
$param['cardType'] = 'ZSH';
|
||
$this->api = '/v1/openapi/order/gasCard';
|
||
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) {
|
||
$result['status'] = 3;
|
||
} else {
|
||
$result['status'] = 4;
|
||
}
|
||
|
||
if (isset($data['orderVoucher']) && $data['orderVoucher']) {
|
||
# 流水号
|
||
$data['s_nubmer'] = $result['s_nubmer'] = $data['orderVoucher'];
|
||
}
|
||
|
||
$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['status']) && $array['status'] == '0') {
|
||
# 正确
|
||
$msg = 'ok';
|
||
} else {
|
||
# 错误
|
||
$msg = isset($array['message']) ? $array['message'] : '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'];
|
||
$temp = explode('|', $this->mid);
|
||
$request['merchantId'] = $temp[0];
|
||
$request['businessId'] = $temp[1];
|
||
$request['bizCode'] = $param['order'];
|
||
$request['callbackUrl'] = $this->getNotify($param['order'], 1);
|
||
|
||
$header['businessId'] = $request['businessId'];
|
||
$header['nonce'] = substr(sha1(microtime()), rand(10, 15));
|
||
$header['timestamp'] = $this->msectime();
|
||
$header['signType'] = 'MD5';
|
||
$header['sign'] = strtoupper($this->_sign($header, $request));
|
||
|
||
$url = $this->host . $this->api;
|
||
$response = $this->curl('post', $url, $request, true, $header);
|
||
print_r($request);
|
||
print_r($header);
|
||
print_r($response);die;
|
||
$response = $this->response($response);
|
||
//$response['data'] = '';
|
||
//$response['msg'] = 'ok';
|
||
$channel_order_id = '';
|
||
if (isset($response['array']['data']['orderCode'])) {
|
||
$channel_order_id = $response['array']['data']['orderCode'];
|
||
}
|
||
|
||
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']);
|
||
return $response['msg'];
|
||
}
|
||
|
||
private function _sign($header, $request)
|
||
{
|
||
ksort($header);
|
||
$signature_string = '';
|
||
foreach ($header as $k => $v) {
|
||
$signature_string .= $k . '=' . $v . '&';
|
||
}
|
||
|
||
$json = json_encode($request, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
|
||
|
||
$signature_string = substr($signature_string, 0, -1);
|
||
|
||
$signature_string .= $json . $this->token;
|
||
return md5($signature_string);
|
||
}
|
||
|
||
private function msectime()
|
||
{
|
||
list($s1, $s2) = explode(' ', microtime());
|
||
return (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
|
||
}
|
||
} |