210 lines
5.6 KiB
PHP
210 lines
5.6 KiB
PHP
<?php
|
|
|
|
namespace app\channel\service\system;
|
|
|
|
/**
|
|
* cheyouma服务
|
|
* Class Bodingcheng
|
|
* @package app\channel\service
|
|
*/
|
|
class Shenyou extends Core
|
|
{
|
|
# 这几个可以后台设置
|
|
protected $host = 'host';
|
|
protected $mid = 'mid';
|
|
protected $token = 'token';
|
|
protected $api = 'api';
|
|
protected $item_type = false;
|
|
|
|
# 中石油油卡充值 拼音来吧
|
|
public function zsycz($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'card' => 'phone',
|
|
'cash' => 'cash',
|
|
);
|
|
$this->api = 'app/agent/order';
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 中石化油卡充值
|
|
public function zshcz($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'card' => 'phone',
|
|
'cash' => 'cash',
|
|
);
|
|
$this->api = 'app/agent/order';
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 中石油油卡充值 拼音来吧
|
|
public function dhcz($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'mobile' => 'phone',
|
|
'cash' => 'cash',
|
|
);
|
|
$this->api = 'app/agent/order';
|
|
$this->item_type = 1;
|
|
if (isset($param['isp']) && $param['isp']) {
|
|
$this->item_type = $param['isp'];
|
|
}
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 通知处理 主要返回状态 2是成功 3是失败
|
|
public function notify($data)
|
|
{
|
|
$request = $data;
|
|
/*
|
|
$sign = $this->_sign($request);
|
|
if ($sign != $data['RecordKey']) {
|
|
return false;
|
|
}*/
|
|
$result = array();
|
|
$result['cash'] = 1;
|
|
if ($data['status'] == 3) {
|
|
$result['status'] = 2;
|
|
} elseif ($data['status'] == 4) {
|
|
$result['status'] = 3;
|
|
} else {
|
|
$result['status'] = 4;
|
|
}
|
|
|
|
/*
|
|
if (isset($data['exchangeTraded']) && $data['exchangeTraded']) {
|
|
# 流水号
|
|
if (strstr($data['exchangeTraded'], '订单号:')) {
|
|
$temp = explode('订单号:', $data['exchangeTraded']);
|
|
} else {
|
|
$temp[1] = $data['exchangeTraded'];
|
|
}
|
|
|
|
$data['s_number'] = $result['s_number'] = $temp[1];
|
|
}
|
|
*/
|
|
|
|
$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' => $array,
|
|
'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['agentProductId'] = $this->getGid($param['cash']);
|
|
if ($request['agentProductId'] == '-1') {
|
|
$request['agentProductId'] = $this->getCode($param['cash']);
|
|
}
|
|
if (!$request['agentProductId']) {
|
|
return 'order';
|
|
}
|
|
$request['phone'] = $param['detail']['phone'];
|
|
$request['appid'] = $this->mid;
|
|
$request['inOrderNumber'] = $param['order'];
|
|
$request['num'] = 1;
|
|
$request['timestamp'] = date('YmdHis');
|
|
$request['notifyUrl'] = urlencode($this->getNotify($param['order'], 1));
|
|
$request['sign'] = $this->_sign($request);
|
|
$url = $this->host . $this->api;
|
|
$response = $this->curl('post', $url, $request, true);
|
|
$response = $this->response($response);
|
|
|
|
$channel_order_id = '';
|
|
if (isset($response['array']['InOrderNumber'])) {
|
|
$channel_order_id = $response['array']['InOrderNumber'];
|
|
}
|
|
|
|
$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)
|
|
{
|
|
ksort($request);
|
|
$signature_string = '';
|
|
foreach ($request as $k => $v) {
|
|
$signature_string .= $k . '=' . $v . '&';
|
|
}
|
|
|
|
//$signature_string = substr($signature_string, 0, -1);
|
|
|
|
$signature_string .= 'key=' . $this->token;
|
|
|
|
return md5($signature_string);
|
|
}
|
|
|
|
private function getCode($cash) {
|
|
if ($this->item_type == 1) {
|
|
if ($cash == 50) {
|
|
return '171';
|
|
} elseif ($cash == 100) {
|
|
return '169';
|
|
} elseif ($cash == 200) {
|
|
return '170';
|
|
}
|
|
} elseif ($this->item_type == 2) {
|
|
if ($cash == 50) {
|
|
return '172';
|
|
} elseif ($cash == 100) {
|
|
return '173';
|
|
} elseif ($cash == 200) {
|
|
return '174';
|
|
}
|
|
} elseif ($this->item_type == 3) {
|
|
if ($cash == 50) {
|
|
return '175';
|
|
} elseif ($cash == 100) {
|
|
return '176';
|
|
} elseif ($cash == 200) {
|
|
return '177';
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} |