153 lines
4.2 KiB
PHP
153 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace app\channel\service\system;
|
|
|
|
/**
|
|
* 服务
|
|
* Class Bodingcheng
|
|
* @package app\channel\service
|
|
*/
|
|
class Xinda extends Core
|
|
{
|
|
# 这几个可以后台设置
|
|
protected $host = 'host';
|
|
protected $mid = 'mid';
|
|
protected $token = 'token';
|
|
protected $api = 'api';
|
|
protected $itemId = 'OIL';
|
|
|
|
# 中石油充值
|
|
public function zsycz($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'card' => 'oil_cardno',
|
|
'cash' => 'charge_money',
|
|
'oil_cardtype' => 'oil_cardtype',
|
|
//'mobile' => 'recv_phone',
|
|
);
|
|
$param['oil_cardtype'] = 61;
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 中石化油卡充值
|
|
public function zshcz($param, $type = 1)
|
|
{
|
|
$check = array
|
|
(
|
|
'card' => 'oil_cardno',
|
|
'cash' => 'charge_money',
|
|
'oil_cardtype' => 'oil_cardtype',
|
|
);
|
|
$param['oil_cardtype'] = 60;
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 通知处理 主要返回状态 2是成功 3是失败
|
|
public function notify($data)
|
|
{
|
|
$request = $data;
|
|
$sign = $this->_sign($request, array('merchant_id', 'merchant_orderid', 'charge_status'));
|
|
if ($sign != $data['sign']) {
|
|
//return false;
|
|
}
|
|
$result = array();
|
|
$result['cash'] = 1;
|
|
if ($data['charge_status'] == 'SUCC') {
|
|
$result['status'] = 2;
|
|
} elseif ($data['charge_status'] == 'FAIL') {
|
|
$result['status'] = 3;
|
|
} else {
|
|
$result['status'] = 4;
|
|
}
|
|
|
|
if (isset($data['audited_voucher']) && $data['audited_voucher']) {
|
|
# 流水号
|
|
$data['s_nubmer'] = $result['s_nubmer'] = $data['audited_voucher'];
|
|
}
|
|
|
|
$result['yes'] = 'succ';
|
|
|
|
$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);
|
|
parse_str($data, $array);
|
|
if (!$array) {
|
|
$msg = 'error';
|
|
} elseif (isset($array['result_code']) && $array['result_code'] == '0000') {
|
|
# 正确
|
|
$msg = 'ok';
|
|
} else {
|
|
# 错误
|
|
$msg = isset($array['result_desc']) ? $array['result_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;
|
|
}
|
|
$this->api = 'oilorder';
|
|
$request = $param['detail'];
|
|
$request['merchant_id'] = $this->mid;
|
|
$request['merchant_orderid'] = $param['order'];
|
|
$request['recv_phone'] = '13800138000';
|
|
$request['back_url'] = $this->getNotify($param['order'], 1);
|
|
|
|
$request['sign'] = $this->_sign($request, array('merchant_id', 'merchant_orderid', 'oil_cardtype', 'oil_cardno', 'charge_money', 'recv_phone', 'back_url'));
|
|
|
|
$request['back_url'] = urlencode($request['back_url']);
|
|
$url = $this->host . $this->api;
|
|
|
|
$response = $this->curl('get', $url, $request);
|
|
$response = $this->response($response);
|
|
//$response['data'] = '';
|
|
//$response['msg'] = 'ok';
|
|
$channel_order_id = '';
|
|
if (isset($response['array']['order_id'])) {
|
|
$channel_order_id = $response['array']['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)
|
|
{
|
|
//ksort($request);
|
|
$signature_string = '';
|
|
foreach ($param as $k => $v) {
|
|
$signature_string .= $request[$v];
|
|
}
|
|
|
|
$signature_string .= $this->token;
|
|
return md5($signature_string);
|
|
}
|
|
} |