Service.php
3.65 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
<?php
namespace WebPlugin\Pay\Chinabank;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Reqparams;
use WebPlugin\Pay\Rspparams;
class Service extends PayAbstract
{
var $config ;
function __construct(array $paymentParams)
{
$this->logProjectPrefix = 'chinabank';
$this->config = new Config();
$myConfig = json_decode($paymentParams["pay_params"]) ;
$this->config->merchantAcctId = $myConfig->merchant_id;
$this->config->sp_key = $myConfig->merchant_key;
// $this->config->branchID = $myConfig->merchant_other_code;
}
public function getPayRequestPars(Reqparams $params) {
parent::getPayRequestPars($params);
$baseUrl = $this->getBaseNoticeUrl($params->isTest);
$reqData = array();
$reqData['v_mid'] = $this->config->merchantAcctId; //商户ID
$reqData['v_oid'] = $params->orderCode;
$reqData['v_amount'] = $params->totalFee * 0.01;
$reqData['v_moneytype'] = $this->config->feeType;
$reqData['v_url'] = $baseUrl . $this->config->merchantUrl;
$reqData['v_md5info']= strtoupper(md5($reqData['v_amount'] . $reqData['v_moneytype'] . $reqData['v_oid']. $reqData['v_mid'] . $reqData['v_url']. $this->config->sp_key));
$reqData['remark1'] = $params->orderCode;
$reqData['remark2'] = "[url:=".$baseUrl . $this->config->autoReceiveUrl."]";
$result = array(
'pay_url' => $this->config->payUrl,
'pars' => $reqData,
'reqType' => 'post'
);
return $result;
}
/**
* 解析结果
* (non-PHPdoc)
* @see QCPay_Utils_Abstract::parseResponse()
* @param array $arrResponse
* @return void|QCPay_Utils_Rspparams
*/
function parseResponse(Array $arrResponse){
// {"v_md5all":"8F7E33B3759DC55F0E776120B5C16A55","v_md5info":"e42e938417bd01d8eb69235c1ebe9be3","remark1":"110610002420","v_pmode":null,"remark2":"","v_idx":"5607406315","v_md5":"2E9135262B2729B23B049EBBE80E5183","v_pstatus":"20","v_pstring":null,"v_md5str":"2E9135262B2729B23B049EBBE80E5183","v_md5money":"9330e642e14622f4993ce5a6e9781bbd","v_moneytype":"CNY","v_oid":"110610002420","v_amount":"0.01"}
//把中文进行转码
$arrResponse["v_pmode"] = mb_convert_encoding($arrResponse["v_pmode"], "UTF-8", "GBK");
$arrResponse["v_pstring"] = mb_convert_encoding($arrResponse["v_pstring"], "UTF-8", "GBK");
//定义结果返回变量
$rsp = new Rspparams();
if(!$this->checkResponse($arrResponse)){
//验证不成功
$rsp->payResult = 400;
}
else{
$rsp->bankName = $arrResponse["v_pmode"];
$rsp->orderCode = $arrResponse["v_oid"];
$rsp->payResult = $this->convertResult($arrResponse["v_pstatus"]);
$rsp->payTime = time();
$rsp->totalFee = $arrResponse["v_amount"];
$rsp->resultMsg = $arrResponse["v_pstring"];
//添加支付订单号和交易号
$rsp->payOrderCode = $arrResponse["v_oid"];
$rsp->tradeNo = "";
$rsp->bankBillNo = "";
}
return $rsp;
}
/**
* (non-PHPdoc)
* @see QPay_Utils_Abstract::convertResult()
* @param $resultCode
* @return int|void
*/
protected function convertResult($resultCode)
{
if($resultCode == 20) //20为支付成功,30为支付失败
{
return 200;
}
return $resultCode;
}
/**
* 验证回复的正确性
* @see QPay_Utils_Abstract::verifResponse()
* @param array $arrResponse
* @return bool|void
*/
protected function checkResponse(array $arrResponse)
{
$signText = $arrResponse["v_oid"]. $arrResponse['v_pstatus'] . $arrResponse['v_amount']
. $arrResponse['v_moneytype'] . $this->config->sp_key;
if(strtoupper(md5($signText)) == $arrResponse['v_md5str']){
return true;
}
return false;
}
}