183 lines
4.8 KiB
PHP
183 lines
4.8 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\channel\service\system;
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* Class
|
||
|
* @package app\channel\service
|
||
|
*/
|
||
|
class City extends Core
|
||
|
{
|
||
|
# 这几个可以后台设置
|
||
|
protected $host = '';
|
||
|
protected $mid = '';
|
||
|
protected $token = '';
|
||
|
protected $api = 'purchaser/order/place';
|
||
|
protected $sign = array();
|
||
|
protected $t = 1;
|
||
|
|
||
|
# 电话充值
|
||
|
public function dhcz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'mobile' => 'serveTarget',
|
||
|
'cash' => 'amount',
|
||
|
);
|
||
|
$this->t = 1;
|
||
|
if (isset($param['isp']) && $param['isp']) {
|
||
|
$this->t = $param['isp'];
|
||
|
}
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 通知处理 主要返回状态 2是成功 3是失败
|
||
|
public function notify($data)
|
||
|
{
|
||
|
$request = $data;
|
||
|
/*
|
||
|
$sign = $this->_sign($request, array('status', 'partner_id', 'partner_order_no', 'card_no', 'amount', 'recharge_amount', 'type'));
|
||
|
if ($sign != $data['sign']) {
|
||
|
//return false;
|
||
|
}*/
|
||
|
$result = array();
|
||
|
$result['cash'] = 1;
|
||
|
$result['status'] = 4;
|
||
|
if (isset($data['state'])) {
|
||
|
if ($data['state'] == 10) {
|
||
|
$result['status'] = 2;
|
||
|
} elseif ($data['code'] == -10) {
|
||
|
$result['status'] = 3;
|
||
|
} else {
|
||
|
$result['status'] = 4;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (isset($data['vouchers']) && $data['vouchers']) {
|
||
|
# 流水号
|
||
|
$order = json_decode($data['official_order_no'], true);
|
||
|
if ($order) {
|
||
|
$data['s_nubmer'] = $result['s_nubmer'] = implode(',', $order);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$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($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'];
|
||
|
$request['userSerial'] = $this->mid;
|
||
|
$request['outId'] = $param['order'];
|
||
|
$request['timestamp'] = time();
|
||
|
$request['callbackUrl'] = $this->getNotify($param['order'], 1);
|
||
|
$request['version'] = '3.0';
|
||
|
list($request['goodsId'], $request['skuId']) = $this->getCode($param['cash']);
|
||
|
$request['sign'] = $this->_sign($request);
|
||
|
|
||
|
$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']['order_no'])) {
|
||
|
$channel_order_id = $response['array']['order_no'];
|
||
|
}
|
||
|
|
||
|
$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 ($param as $k => $v) {
|
||
|
$signature_string .= $v . '=' . $request[$v] . '&';
|
||
|
}
|
||
|
|
||
|
$signature_string .= 'key=' . $this->token;
|
||
|
|
||
|
return strtoupper(md5($signature_string));
|
||
|
}
|
||
|
|
||
|
private function getCode($cash)
|
||
|
{
|
||
|
|
||
|
$goodsId = $skuId = '';
|
||
|
if ($this->t == 1) {
|
||
|
$goodsId = 'G221110133725000001';
|
||
|
if ($cash == 50) {
|
||
|
$skuId = '221110133749000161';
|
||
|
} elseif ($cash == 100) {
|
||
|
$skuId = '221110133749000162';
|
||
|
} elseif ($cash == 200) {
|
||
|
$skuId = '221204112943000148';
|
||
|
}
|
||
|
}
|
||
|
if ($this->t == 2) {
|
||
|
$goodsId = 'G221102155629000001';
|
||
|
if ($cash == 100) {
|
||
|
$skuId = '221102155644000054';
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ($this->t == 3) {
|
||
|
$goodsId = 'G221122193933000001';
|
||
|
if ($cash == 100) {
|
||
|
$skuId = '221122193951000030';
|
||
|
} elseif ($cash == 200) {
|
||
|
$skuId = '221122193951000032';
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
return array($goodsId, $skuId);
|
||
|
}
|
||
|
}
|