223 lines
5.9 KiB
PHP
223 lines
5.9 KiB
PHP
<?php
|
|
|
|
namespace app\channel\service\system;
|
|
|
|
/**
|
|
* 服务
|
|
* Class Bodingcheng
|
|
* @package app\channel\service
|
|
*/
|
|
class Youhe extends Core
|
|
{
|
|
# 这几个可以后台设置
|
|
protected $host = 'host';
|
|
protected $mid = 'mid';
|
|
protected $token = 'token';
|
|
protected $api = 'api';
|
|
protected $t = 1;
|
|
|
|
# 通用的充值
|
|
public function common($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'account' => 'szPhoneNum',
|
|
'cash' => 'nMoney',
|
|
'nSortType' => 'nSortType',
|
|
);
|
|
$param['nSortType'] = '1031';
|
|
$this->t = 2;
|
|
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 手机充值
|
|
public function dhcz($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'mobile' => 'szPhoneNum',
|
|
'cash' => 'nMoney',
|
|
'nSortType' => 'nSortType',
|
|
);
|
|
$param['nSortType'] = 0;
|
|
if (isset($param['isp']) && $param['isp']) {
|
|
if ($param['isp'] == 1) {
|
|
$param['nSortType'] = 1;
|
|
} elseif ($param['isp'] == 2) {
|
|
$param['nSortType'] = 2;
|
|
} elseif ($param['isp'] == 3) {
|
|
$param['nSortType'] = 3;
|
|
}
|
|
}
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 中石油充值
|
|
public function zsycz($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'card' => 'szPhoneNum',
|
|
'cash' => 'nMoney',
|
|
'nSortType' => 'nSortType',
|
|
'mobile' => 'thirdphone',
|
|
'idCard' => 'idCard',
|
|
'realName' => 'realName',
|
|
);
|
|
$param['nSortType'] = 105;
|
|
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 中石化油卡充值
|
|
public function zshcz($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'card' => 'szPhoneNum',
|
|
'cash' => 'nMoney',
|
|
'nSortType' => 'nSortType',
|
|
);
|
|
$param['nSortType'] = 104;
|
|
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 通知处理 主要返回状态 2是成功 3是失败
|
|
public function notify($data)
|
|
{
|
|
$request = $data;
|
|
$sign = $this->_sign($request, array('szAgentId', 'szOrderId', 'szPhoneNum', 'nDemo', 'fSalePrice', 'nFlag'));
|
|
if ($sign != $data['szVerifyString']) {
|
|
return false;
|
|
}
|
|
$result = array();
|
|
$result['cash'] = 1;
|
|
if ($data['nFlag'] == '2') {
|
|
$result['status'] = 2;
|
|
} elseif ($data['nFlag'] == '3') {
|
|
$result['status'] = 3;
|
|
} else {
|
|
$result['status'] = 4;
|
|
}
|
|
|
|
if (isset($data['szRtnMsg']) && $data['szRtnMsg']) {
|
|
# 流水号
|
|
$data['s_nubmer'] = $result['s_nubmer'] = $data['szRtnMsg'];
|
|
}
|
|
|
|
$result['yes'] = 'ok';
|
|
|
|
$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['nRtn']) && $array['nRtn'] == '0') {
|
|
# 正确
|
|
$msg = 'ok';
|
|
} else {
|
|
# 错误
|
|
$msg = isset($array['szRtnCode']) ? $array['szRtnCode'] : '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;
|
|
}
|
|
if (!strstr($this->host, 'plat')) {
|
|
$this->api = 'plat/api/old/submitorder';
|
|
} else {
|
|
$this->api = '';
|
|
}
|
|
|
|
$request = $param['detail'];
|
|
$request['szAgentId'] = $this->mid;
|
|
$request['szOrderId'] = $param['order'];
|
|
$request['nProductClass'] = 1;
|
|
$request['nProductType'] = 1;
|
|
$request['szTimeStamp'] = date('Y-m-d H:i:s');
|
|
|
|
if ($this->t == 2) {
|
|
$request['szProductId'] = $this->getGid($param['cash']);
|
|
}
|
|
/*
|
|
$request['szProductId'] = $this->getCode($param['cash'], $request['nSortType']);
|
|
if (!$request['szProductId']) {
|
|
return 'order';
|
|
}
|
|
*/
|
|
$request['szVerifyString'] = $this->_sign($request, array('szAgentId', 'szOrderId', 'szPhoneNum', 'nMoney', 'nSortType', 'nProductClass', 'nProductType', 'szTimeStamp'));
|
|
$request['szNotifyUrl'] = $this->getNotify($param['order'], 1);
|
|
$url = $this->host . $this->api;
|
|
|
|
$response = $this->curl('post', $url, $request);
|
|
$response = $this->response($response);
|
|
//$response['data'] = '';
|
|
//$response['msg'] = 'ok';
|
|
$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 getCode($cash, $type)
|
|
{
|
|
if ($type == 2) {
|
|
if ($cash == 20) {
|
|
return 20051;
|
|
} elseif ($cash == 30) {
|
|
return 20052;
|
|
} elseif ($cash == 50) {
|
|
return 20053;
|
|
} elseif ($cash == 100) {
|
|
return 20054;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private function _sign($request, $param)
|
|
{
|
|
//ksort($request);
|
|
$signature_string = '';
|
|
foreach ($param as $k => $v) {
|
|
if (isset($request[$v])) {
|
|
$signature_string .= $v . '=' . $request[$v] . '&';
|
|
}
|
|
}
|
|
|
|
$signature_string .= 'szKey=' . $this->token;
|
|
return md5($signature_string);
|
|
}
|
|
} |