Service.php
5.25 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
namespace WebPlugin\Pay\Kuaiqian;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Reqparams;
class Service extends PayAbstract
{
var $config ;
function __construct(array $paymentParams)
{
$this->config = new Config();
$myConfig = json_decode($paymentParams["pay_params"]) ;
$this->config->merchantAcctId = $myConfig->merchant_id;
$this->config->sp_key = $myConfig->merchant_key;
}
public function getPayRequestPars(Reqparams $params)
{
$signText = '';
//先添加不可为空的参数
$signText .= "inputCharset=" . $this->config-> inputCharset;
$signText .= "&bgUrl=" . $this->baseNoticeUrl . $this->config->bgUrl;
$signText .= "&version=" . $this->config->version;
$signText .= "&language=" . $this->config->language;
$signText .= "&signType=" . $this->config->signType;
$signText .= "&merchantAcctId=" . $this->config-> merchantAcctId;
$signText .= "&orderId=" . $params->orderCode;
$signText .= "&orderAmount=" . $params->totalFee;
$signText .= "&orderTime=" . date("YmdHis");
$signText .= "&payType=" . $this->config->payType;
$signMsg = strtoupper(md5($signText . "&key=" . $this->config->sp_key));
return array(
'pay_url' => $this->config->pay_url,
'pars' => $signText . "&signMsg=" . $signMsg,
'reqType' => 'get'
);
}
/**
* (non-PHPdoc)
* @see QPay_Utils_Abstract::parseResponse()
* @param array $arrResponse
* @return void|QCPay_Utils_Rspparams
*/
public function parseResponse(array $arrResponse)
{
$rsp = new QCPay_Utils_Rspparams();
if(!$this->checkResponse($arrResponse))
{
//验证不成功
$rsp->payResult = -1;
}
else
{
$rsp->bankName = $arrResponse["bankId"];
$rsp->orderCode = $arrResponse["orderId"];
$rsp->payResult = $this->convertResult($arrResponse["payResult"]);
$rsp->payTime = $this->convertTime($arrResponse["orderTime"]);
$rsp->totalFee = $arrResponse["orderAmount"];
$rsp->resultMsg = "";
//添加支付订单号和交易号
$rsp->payOrderCode = $arrResponse["orderId"];
$rsp->tradeNo = "";
$rsp->bankBillNo = "";
}
return $rsp;
}
/**
* 转化时间
* Enter description here ...
* @param string $payTime
* @return int
*/
private function convertTime($payTime)
{
$strTime = substr($payTime, 0, 4) . '-' . substr($payTime, 4, 2) . '-' . substr($payTime, 6, 2) . ' ' .
substr($payTime, 8, 2) . ':' . substr($payTime, 10, 2) . ':' . substr($payTime, 12, 2);
return strtotime($strTime);
}
/**
* 转换结果
* Enter description here ...
* @param string $resultCode
* @return int|void
*/
protected function convertResult($resultCode)
{
if($resultCode == '10')
{
return 200;
}
return 400;
}
/**
* 验证回复的正确性
* @see QPay_Utils_Abstract::verifResponse()
*/
protected function checkResponse(array $arrResponse)
{
$merchantSignMsgVal = '';
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"merchantAcctId",$arrResponse["merchantAcctId"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"version",$arrResponse["version"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"language",$arrResponse["language"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"signType",$arrResponse["signType"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"payType",$arrResponse["payType"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"bankId",$arrResponse["bankId"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"orderId",$arrResponse["orderId"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"orderTime",$arrResponse["orderTime"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"orderAmount",$arrResponse["orderAmount"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"dealId",$arrResponse["dealId"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"bankDealId",$arrResponse["bankDealId"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"dealTime",$arrResponse["dealTime"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"payAmount",$arrResponse["payAmount"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"fee",$arrResponse["fee"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"ext1",$arrResponse["ext1"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"ext2",$arrResponse["ext2"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"payResult",$arrResponse["payResult"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"errCode",$arrResponse["errCode"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"key",$this->config->sp_key);
return strtoupper(md5($merchantSignMsgVal)) == $arrResponse["signMsg"] ? true :false;
}
private function appendParam($returnStr, $paramId, $paramValue) {
if ($returnStr != "") {
if ($paramValue != "") {
$returnStr .= "&" . $paramId . "=" . $paramValue;
}
} else {
If ($paramValue != "") {
$returnStr = $paramId . "=" . $paramValue;
}
}
return $returnStr;
}
}