
- 优化美城支付查询逻辑,增加对 query_status 的判断 - 调整请求方式从 POST 改为 GET- 更新订单状态查询逻辑,解决未返回 query_status 的问题
257 lines
6.8 KiB
PHP
257 lines
6.8 KiB
PHP
<?php
|
|
|
|
namespace app\channel\service\system;
|
|
|
|
/**
|
|
* 话费服务
|
|
* Class Common
|
|
* @package app\channel\service
|
|
*/
|
|
class Meicheng extends Core
|
|
{
|
|
# 这几个可以后台设置
|
|
protected $host = 'host';
|
|
protected $mid = 'mid';
|
|
protected $token = 'token';
|
|
protected $api = 'api';
|
|
|
|
# 电话充值
|
|
public function dhcz($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'mobile' => 'mobile',
|
|
'cash' => 'price',
|
|
'paytype' => 'paytype',
|
|
);
|
|
$this->api = 'onlinepay.do';
|
|
|
|
if (isset($param['isp']) && $param['isp']) {
|
|
$isp = $param['isp'];
|
|
} else {
|
|
$isp = $this->isp($param['mobile']);
|
|
}
|
|
$paytype = '';
|
|
if ($isp == 1) {
|
|
$paytype = 'yd';
|
|
}
|
|
if ($isp == 2) {
|
|
$paytype = 'lt';
|
|
}
|
|
if ($isp == 3) {
|
|
$paytype = 'dx';
|
|
}
|
|
$param['paytype'] = $paytype;
|
|
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
public function ydcz($param)
|
|
{
|
|
$param['paytype'] = 'yd';
|
|
return $this->hf_submit($param);
|
|
}
|
|
public function ltcz($param)
|
|
{
|
|
$param['paytype'] = 'lt';
|
|
return $this->hf_submit($param);
|
|
}
|
|
public function dxcz($param)
|
|
{
|
|
$param['paytype'] = 'dx';
|
|
return $this->hf_submit($param);
|
|
}
|
|
|
|
public function dxcz_lt_mnp($param)
|
|
{
|
|
$param['paytype'] = 'dx';
|
|
return $this->hf_submit($param);
|
|
}
|
|
|
|
public function hf_submit($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'mobile' => 'mobile',
|
|
'cash' => 'price',
|
|
'paytype' => 'paytype',
|
|
's_num'=>'num'
|
|
);
|
|
$param['s_num'] = 1;
|
|
$this->api = 'onlinepay.do';
|
|
|
|
return $this->submit($param, $check);
|
|
|
|
}
|
|
|
|
# 查询余额接口
|
|
public function account()
|
|
{
|
|
// $request['day'] = $day;
|
|
$request['userid'] = $this->mid;
|
|
$request['sign'] = $this->_sign($request, array('userid'));
|
|
$url = $this->host . 'searchbalance.do';
|
|
$response = $this->curl('get', $url, $request);
|
|
// var_dump($response);die;
|
|
$log['type'] = 'account_response';
|
|
$log['data'] = $response;
|
|
$log['config'] = $this->data;
|
|
$this->log($log);
|
|
|
|
$array = (array) simplexml_load_string($response);
|
|
|
|
if (!$array) {
|
|
return false;
|
|
} elseif (isset($array['resultno']) && $array['resultno'] == '1') {
|
|
$array['account'] = $array['balance'];
|
|
# 正确
|
|
return $array;
|
|
} else {
|
|
# 错误
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
# 通知处理 主要返回状态 2是成功 3是失败
|
|
public function notify($data)
|
|
{
|
|
$request = $data;
|
|
unset($request['sign']);
|
|
unset($request['s_order']);
|
|
$sign = strtoupper($this->_sign($request, array('userid', 'orderid', 'sporderid', 'merchantsubmittime', 'resultno')));
|
|
if(!isset($data['query_status']) ){
|
|
if ($sign != $data['sign']) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
$result = array();
|
|
$result['cash'] = 1;
|
|
if ($data['resultno'] == 1) {
|
|
$result['status'] = 2;
|
|
} elseif ($data['resultno'] == 9) {
|
|
$result['status'] = 3;
|
|
} else {
|
|
$result['status'] = 4;
|
|
}
|
|
if (isset($data['remark1']) && $data['remark1']) {
|
|
# 流水号
|
|
$data['s_number'] = $result['s_number'] = $data['remark1'];
|
|
}
|
|
|
|
$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 = (array) simplexml_load_string($data);
|
|
|
|
if (!$array) {
|
|
$msg = 'error';
|
|
} elseif (isset($array['resultno']) && $array['resultno'] == '0') {
|
|
# 正确
|
|
$msg = 'ok';
|
|
} else {
|
|
# 错误
|
|
$msg = 'error';
|
|
}
|
|
|
|
return array
|
|
(
|
|
'msg' => $msg,
|
|
'data' => $array,
|
|
'array' => $array,
|
|
);
|
|
}
|
|
|
|
# 查询接口
|
|
public function query($param)
|
|
{
|
|
$request['userid'] = $this->mid;
|
|
$request['sporderid'] = $param['order_id'];
|
|
|
|
$request['sign'] = $this->_sign($request, array('userid', 'sporderid'));
|
|
$url = $this->host . 'searchpay.do';
|
|
$response = $this->curl('get', $url, $request);
|
|
|
|
$log['type'] = 'query_response';
|
|
$log['data'] = $response;
|
|
$log['config'] = $this->data;
|
|
$this->log($log);
|
|
|
|
$array = (array) simplexml_load_string($response);
|
|
|
|
$result = array();
|
|
$result = $array;
|
|
$result['status'] = 4;
|
|
$result['query_status'] = 1;
|
|
if (isset($array['resultno']) ) {
|
|
if($array['resultno'] == '1'){
|
|
$result['status'] = 2;
|
|
}elseif ($array['resultno'] == '9'){
|
|
$result['status'] = 3;
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
# 提交数据
|
|
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['num'] = $request['num']??1;
|
|
$request['productid'] = '';
|
|
|
|
$request['userid'] = $this->mid;
|
|
$request['sporderid'] = $param['order'];
|
|
$request['spordertime'] = date('YmdHis');
|
|
$request['back_url'] = $this->getNotify($param['order'], 1);
|
|
|
|
$request['productid'] = $this->getGid($param['cash']);
|
|
|
|
$request['sign'] = $this->_sign($request, array('userid', 'productid', 'price', 'num', 'mobile', 'spordertime', 'sporderid'));
|
|
$url = $this->host . $this->api;
|
|
$response = $this->curl('get', $url, $request);
|
|
$response = $this->response($response);
|
|
$channel_order_id = '';
|
|
if (isset($response['array']['orderid'])) {
|
|
$channel_order_id = $response['array']['orderid'];
|
|
}
|
|
|
|
$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) {
|
|
if (isset($request[$v])) {
|
|
$signature_string .= $v . '=' . $request[$v] . '&';
|
|
}
|
|
}
|
|
|
|
$signature_string .= 'key=' . $this->token;
|
|
|
|
return md5($signature_string);
|
|
}
|
|
} |