Service.php
4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
namespace WebPlugin\Pay\Allinpay;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Reqparams;
use WebPlugin\Pay\Rspparams;
use WebPlugin\UdpLog;
class Service extends PayAbstract
{
public $config;
public function __construct(array $paymentParams)
{
$this->logProjectPrefix = 'allinpay';
$this->config = new Config();
$myConfig = json_decode($paymentParams["pay_params"]);
$this->config->merchantId = $myConfig->merchant_id;
$this->config->merchantKey = $myConfig->merchant_key;
}
/**
* @param Reqparams $params
* @return array
*/
public function getPayRequestPars(Reqparams $params)
{
$baseUrl = $this->getBaseNoticeUrl($params->isTest);
$loseTime = intval(($params->orderTime + 7200 - time()) / 60);
$reqData = array(
'inputCharset' => $this->config->input_charset,
'pickupUrl' => $baseUrl . $this->config->return_url,
'receiveUrl' => $baseUrl . $this->config->notify_url,
'version' => $this->config->version,
'language' => 1,
'signType' => $this->config->sign_type,
'merchantId' => $this->config->merchantId,
'orderNo' => $params->orderCode,
'orderAmount' => $params->totalFee,
'orderCurrency' => 0, //币种,0为人民币
'orderDatetime' => date('YmdHis', $params->orderTime),
'orderExpireDatetime' => $loseTime,
'payType' => $this->config->payType
);
$paramsArr = array();
foreach ($reqData as $k => $v) {
$paramsArr[] = $k . '=' . $v;
}
$reqData['signMsg'] = strtoupper(md5(implode('&', $paramsArr) . '&key=' . $this->config->merchantKey));
return array(
'pay_url' => $this->config->pay_url,
'pars' => $reqData,
'reqType' => 'post'
);
}
/**
* 回复解析(non-PHPdoc)
* @param array $arrResponse
* @return void|Rspparams
*/
public function parseResponse(array $arrResponse)
{
UdpLog::info("【{$this->logProjectPrefix}-通联支付】,function:parseResponse,参数", $arrResponse);
$rsp = new Rspparams();
if (!$this->checkResponse($arrResponse)) {
$rsp->payResult = -1;
} else {
$rsp->bankName = "";
$rsp->orderCode = $arrResponse["orderNo"];
$rsp->payResult = $this->convertResult($arrResponse["payResult"]);
$rsp->payTime = $arrResponse["payDatetime"];
$rsp->totalFee = $arrResponse["payAmount"] / 100;
$rsp->resultMsg = $arrResponse["payResult"];
//添加支付订单号和交易号
$rsp->payOrderCode = $arrResponse["orderNo"];
$rsp->tradeNo = "";
$rsp->bankBillNo = "";
}
UdpLog::info("【{$this->logProjectPrefix}-通联支付】,function:parseResponse,回调参数处理结果", $arrResponse);
return $rsp;
}
protected function convertResult($resultCode)
{
if ($resultCode == 1) {
return 200;
}
return 400;
}
/**
* 验证回复的正确性
* @see QPay_Utils_Abstract::verifResponse()
* @param array $arrResponse
* @return bool|void
*/
protected function checkResponse(array $arrResponse)
{
$strParams = 'merchantId=' . $arrResponse['merchantId'];
$paramKey = array('version', 'language', 'signType', 'payType', 'issuerId', 'paymentOrderId', 'orderNo', 'orderDatetime', 'orderAmount', 'payDatetime', 'payAmount', 'ext1', 'ext2', 'payResult', 'errorCode', 'returnDatetime');
foreach ($paramKey as $k) {
if (isset($arrResponse[$k]) && $arrResponse[$k] != "") {
$strParams .= '&' . $k . '=' . $arrResponse[$k];
}
}
$signMsg = strtoupper(md5($strParams . '&key=' . $this->config->merchantKey));
return $signMsg == $arrResponse['signMsg'] ? true : false;
}
}