Service.php
5.91 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
150
151
152
153
154
155
156
<?php
namespace WebPlugin\Pay\Kqshenzhou;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Reqparams;
use WebPlugin\Pay\Rspparams;
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)
{
$signMsgVal = '';
$signMsgVal=$this->appendParam($signMsgVal,"inputCharset",$this->config->inputCharset);
$signMsgVal=$this->appendParam($signMsgVal,"bgUrl", $this->baseNoticeUrl . $this->config->bgUrl);
$signMsgVal=$this->appendParam($signMsgVal,"pageUrl",$this->config->pageUrl);
$signMsgVal=$this->appendParam($signMsgVal,"version",$this->config->version);
$signMsgVal=$this->appendParam($signMsgVal,"language",$this->config->language);
$signMsgVal=$this->appendParam($signMsgVal,"signType",$this->config->signType);
$signMsgVal=$this->appendParam($signMsgVal,"merchantAcctId",$this->config->merchantAcctId);
$signMsgVal=$this->appendParam($signMsgVal,"payerName","");
$signMsgVal=$this->appendParam($signMsgVal,"payerContactType","");
$signMsgVal=$this->appendParam($signMsgVal,"payerContact","");
$signMsgVal=$this->appendParam($signMsgVal,"orderId",$params->orderCode);
$signMsgVal=$this->appendParam($signMsgVal,"orderAmount",$params->totalFee);
$signMsgVal=$this->appendParam($signMsgVal,"payType",$this->config->payType);
$signMsgVal=$this->appendParam($signMsgVal,"fullAmountFlag",$this->config->fullAmountFlag);
$signMsgVal=$this->appendParam($signMsgVal,"orderTime", date("YmdHis"));
$signMsgVal=$this->appendParam($signMsgVal,"productName",urlencode($params->goodsName));
$signMsgVal=$this->appendParam($signMsgVal,"productNum","");
$signMsgVal=$this->appendParam($signMsgVal,"productId","");
$signMsgVal=$this->appendParam($signMsgVal,"productDesc",urlencode(""));
$signMsgVal=$this->appendParam($signMsgVal,"ext1","");
$signMsgVal=$this->appendParam($signMsgVal,"ext2","");
$signMsgVal=$this->appendParam($signMsgVal,"key",$this->config->sp_key);
$signMsg= strtoupper(md5($signMsgVal));
$result = array(
'pay_url' => $this->config->pay_url,
'pars' => $signMsgVal . "&signMsg=" . $signMsg,
'reqType' => 'get'
);
return $result;
}
public function parseResponse(array $arrResponse)
{
$rsp = new Rspparams();
if(!$this->checkResponse($arrResponse))
{
//验证不成功
$rsp->payResult = -1;
}
else
{
$rsp->bankName = $this->getPaytypeName($arrResponse["payType"]) ;
$rsp->bargainorId = $arrResponse["merchantAcctId"];
$rsp->orderId = $arrResponse["orderId"];
$rsp->payResult = $this->convertResult($arrResponse["payResult"]);
$rsp->payTime = $arrResponse["billOrderTime"];
$rsp->totalFee = $arrResponse["payAmount"];
}
return $rsp;
}
/**
* 获取支付方式名称
* @return string
*/
private function getPaytypeName()
{
$res = "";
switch($res)
{
case "00":
return "神州行卡密支付和快钱账户支付";
case "41":
return "快钱账户支付";
case "42":
return "神州行卡密支付和快钱账户支付";
case "52":
return "神州行卡密支付";
}
}
/**
* @param $resultCode
* @return int|void
*/
protected function convertResult($resultCode)
{
return $resultCode == "10" ? 0 : 1;
}
/**
* 验证回复的正确性
* @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,"payType", $arrResponse["payType"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"cardNumber", $arrResponse["cardNumber"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"cardPwd", $arrResponse["cardPwd"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"orderId", $arrResponse["orderId"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"orderAmount", $arrResponse["orderAmount"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"dealId", $arrResponse["dealId"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"orderTime", $arrResponse["orderTime"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"ext1", $arrResponse["ext1"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"ext2", $arrResponse["ext2"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"payAmount", $arrResponse["payAmount"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"billOrderTime", $arrResponse["billOrderTime"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"payResult", $arrResponse["payResult"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"signType", $arrResponse["signType"]);
$merchantSignMsgVal=$this->appendParam($merchantSignMsgVal,"key", $this->config->sp_key);
if( strtoupper(md5($merchantSignMsgVal)) == $arrResponse["signMsg"] )
{
return true;
}
return false;
}
private function appendParam($returnStr, $paramId, $paramValue) {
if ($returnStr != "") {
if ($paramValue != "") {
$returnStr .= "&" . $paramId . "=" . $paramValue;
}
} else {
If ($paramValue != "") {
$returnStr = $paramId . "=" . $paramValue;
}
}
return $returnStr;
}
}