Merge branch 'temp'
Showing
21 changed files
with
661 additions
and
194 deletions
@@ -10,25 +10,25 @@ use WebPlugin\PhpLog; | @@ -10,25 +10,25 @@ use WebPlugin\PhpLog; | ||
10 | 10 | ||
11 | class Service extends PayAbstract | 11 | class Service extends PayAbstract |
12 | { | 12 | { |
13 | - public $config; | 13 | + public $config; |
14 | private $log; | 14 | private $log; |
15 | - | ||
16 | - public function __construct(array $paymentParams) | ||
17 | - { | ||
18 | - $this->logProjectPrefix = 'alibank'; | ||
19 | - $this->config = new Config(); | ||
20 | - $myConfig = json_decode($paymentParams["pay_params"]) ; | ||
21 | - $this->config->partner = $myConfig->merchant_id; | ||
22 | - $this->config->alipay_key = $myConfig->merchant_key; | ||
23 | - $this->config->sellerMail = $myConfig->merchant_other_code; | 15 | + |
16 | + public function __construct(array $paymentParams) | ||
17 | + { | ||
18 | + $this->logProjectPrefix = 'alibank'; | ||
19 | + $this->config = new Config(); | ||
20 | + $myConfig = json_decode($paymentParams["pay_params"]); | ||
21 | + $this->config->partner = $myConfig->merchant_id; | ||
22 | + $this->config->alipay_key = $myConfig->merchant_key; | ||
23 | + $this->config->sellerMail = $myConfig->merchant_other_code; | ||
24 | 24 | ||
25 | $this->log = new PhpLog($this->config->logDir, "PRC", $this->config->logLevel); | 25 | $this->log = new PhpLog($this->config->logDir, "PRC", $this->config->logLevel); |
26 | - } | ||
27 | - | ||
28 | - /** | ||
29 | - * 获取时间戳 | ||
30 | - */ | ||
31 | - private function getTimestamp() | 26 | + } |
27 | + | ||
28 | + /** | ||
29 | + * 获取时间戳 | ||
30 | + */ | ||
31 | + private function getTimestamp() | ||
32 | { | 32 | { |
33 | $url = "https://mapi.alipay.com/gateway.do?service=query_timestamp&partner=" . trim(strtolower($this->config->partner)) . "&_input_charset=" . trim(strtolower($this->config->input_charset)); | 33 | $url = "https://mapi.alipay.com/gateway.do?service=query_timestamp&partner=" . trim(strtolower($this->config->partner)) . "&_input_charset=" . trim(strtolower($this->config->input_charset)); |
34 | 34 | ||
@@ -38,173 +38,178 @@ class Service extends PayAbstract | @@ -38,173 +38,178 @@ class Service extends PayAbstract | ||
38 | $encrypt_key = $itemEncrypt_key->item(0)->nodeValue; | 38 | $encrypt_key = $itemEncrypt_key->item(0)->nodeValue; |
39 | 39 | ||
40 | return $encrypt_key; | 40 | return $encrypt_key; |
41 | - } | ||
42 | - | ||
43 | - public function getPayRequestPars(Reqparams $params) | ||
44 | - { | ||
45 | - $baseUrl = $this->getBaseNoticeUrl($params->isTest); | ||
46 | - $loseTime = intval(($params->orderTime + 7200 -time())/60); | ||
47 | - // $loseTime = intval((strtotime(date("Y-m-d 10:00:00", strtotime("+1 day")))-time())/60); | ||
48 | - | ||
49 | - $parameter = array( | ||
50 | - 'service' => $this->config->service, | ||
51 | - 'partner' => $this->config->partner, | ||
52 | - '_input_charset' => $this->config->input_charset, | ||
53 | - 'notify_url' => $baseUrl . $this->config->notify_url, | ||
54 | - 'return_url' => $baseUrl . $this->config->return_url, | ||
55 | - /* 业务参数 */ | ||
56 | - 'subject' => $params->goodsName, | ||
57 | - 'out_trade_no' => $params->orderCode.'_'.$params->paymentParameter, | ||
58 | - 'total_fee' => $params->totalFee / 100, //单位为元 | ||
59 | - 'payment_type' => $this->config->payment_type, | ||
60 | - 'defaultbank' => $params->paymentParameter, | ||
61 | - 'seller_email' => $this->config->sellerMail, | 41 | + } |
42 | + | ||
43 | + public function getPayRequestPars(Reqparams $params) | ||
44 | + { | ||
45 | + $baseUrl = $this->getBaseNoticeUrl($params->isTest); | ||
46 | + $loseTime = intval(($params->orderTime + 7200 - time()) / 60); | ||
47 | + // $loseTime = intval((strtotime(date("Y-m-d 10:00:00", strtotime("+1 day")))-time())/60); | ||
48 | + | ||
49 | + $parameter = array( | ||
50 | + 'service' => $this->config->service, | ||
51 | + 'partner' => $this->config->partner, | ||
52 | + '_input_charset' => $this->config->input_charset, | ||
53 | + 'notify_url' => $baseUrl . $this->config->notify_url, | ||
54 | + 'return_url' => $baseUrl . $this->config->return_url, | ||
55 | + /* 业务参数 */ | ||
56 | + 'subject' => $params->goodsName, | ||
57 | + 'out_trade_no' => $params->orderCode . '_' . $params->paymentParameter, | ||
58 | + 'total_fee' => $params->totalFee / 100, //单位为元 | ||
59 | + 'payment_type' => $this->config->payment_type, | ||
60 | + 'defaultbank' => $params->paymentParameter, | ||
61 | + 'seller_email' => $this->config->sellerMail, | ||
62 | // 'it_b_pay' => $loseTime . 'm' | 62 | // 'it_b_pay' => $loseTime . 'm' |
63 | - ); | ||
64 | - if($this->config->anti_fishing['timestamp_enable']) { | ||
65 | - $anti_phishing_key = $this->getTimestamp(); | ||
66 | - if(!empty($anti_phishing_key)) { | ||
67 | - $parameter['anti_phishing_key'] = $anti_phishing_key; | ||
68 | - } | ||
69 | - } | ||
70 | - if($this->config->anti_fishing['ip_enable']) { | ||
71 | - $parameter['exter_invoke_ip'] = $params->spbill_create_ip; | ||
72 | - } | 63 | + ); |
64 | + if ($this->config->anti_fishing['timestamp_enable']) { | ||
65 | + $anti_phishing_key = $this->getTimestamp(); | ||
66 | + if (!empty($anti_phishing_key)) { | ||
67 | + $parameter['anti_phishing_key'] = $anti_phishing_key; | ||
68 | + } | ||
69 | + } | ||
70 | + if ($this->config->anti_fishing['ip_enable']) { | ||
71 | + $parameter['exter_invoke_ip'] = $params->spbill_create_ip; | ||
72 | + } | ||
73 | 73 | ||
74 | // 除去数组中的空值和签名参数 | 74 | // 除去数组中的空值和签名参数 |
75 | $para_filter = array(); | 75 | $para_filter = array(); |
76 | foreach ($parameter AS $k => $v) { | 76 | foreach ($parameter AS $k => $v) { |
77 | - if($k == "sign" || $k == "sign_type" || $v == "") { | 77 | + if ($k == "sign" || $k == "sign_type" || $v == "") { |
78 | continue; | 78 | continue; |
79 | } else { | 79 | } else { |
80 | $para_filter[$k] = $parameter[$k]; | 80 | $para_filter[$k] = $parameter[$k]; |
81 | } | 81 | } |
82 | } | 82 | } |
83 | - | ||
84 | - ksort($para_filter); | ||
85 | - reset($para_filter); | ||
86 | - | ||
87 | - $param = ''; | ||
88 | - $sign = ''; | ||
89 | - foreach ($para_filter AS $key => $val) { | ||
90 | - $param .= "$key=" .urlencode($val). "&"; | ||
91 | - $sign .= "$key=$val&"; | ||
92 | - } | ||
93 | - $param = substr($param, 0, -1); | ||
94 | - $sign = substr($sign, 0, -1); | 83 | + |
84 | + ksort($para_filter); | ||
85 | + reset($para_filter); | ||
86 | + | ||
87 | + $param = ''; | ||
88 | + $sign = ''; | ||
89 | + foreach ($para_filter AS $key => $val) { | ||
90 | + $param .= "$key=" . urlencode($val) . "&"; | ||
91 | + $sign .= "$key=$val&"; | ||
92 | + } | ||
93 | + $param = substr($param, 0, -1); | ||
94 | + $sign = substr($sign, 0, -1); | ||
95 | //如果存在转义字符,那么去掉转义 | 95 | //如果存在转义字符,那么去掉转义 |
96 | - if(get_magic_quotes_gpc()){$sign = stripslashes($sign);} | 96 | + if (get_magic_quotes_gpc()) { |
97 | + $sign = stripslashes($sign); | ||
98 | + } | ||
97 | $sign .= $this->config->alipay_key; | 99 | $sign .= $this->config->alipay_key; |
98 | - | ||
99 | - $result = array( | 100 | + |
101 | + $result = array( | ||
100 | 'pay_url' => $this->config->pay_url, | 102 | 'pay_url' => $this->config->pay_url, |
101 | - 'pars' => $param . "&sign=" . md5($sign). "&sign_type=" . $this->config-> sign_type, | 103 | + 'pars' => $param . "&sign=" . md5($sign) . "&sign_type=" . $this->config->sign_type, |
102 | 'reqType' => 'get' | 104 | 'reqType' => 'get' |
103 | - ); | ||
104 | - | ||
105 | - return $result; | ||
106 | - } | ||
107 | - | ||
108 | - public function parseResponse(array $arrResponse) | ||
109 | - { | ||
110 | - /* 返回示例 | ||
111 | - * http://www.yohobuy.com/pay/notice/alipayreturn?buyer_email=tds%40smartunite.com&buyer_id=2088302294447308&exterface=create_direct_pay_by_user&is_success=T¬ify_id=RqPnCoPT3K9%252Fvwbh3I7xtEV5W65QRToFQ5fPrXsVxt12e%252FExCtC1XNiKnuRwupLaVLAR¬ify_time=2011-06-11+07%3A48%3A10¬ify_type=trade_status_sync&out_trade_no=1061003000&payment_type=1&seller_email=shop%40yoho.cn&seller_id=2088001550230585&subject=YOHO%E5%95%86%E5%93%81&total_fee=0.01&trade_no=2011061199833830&trade_status=TRADE_SUCCESS&sign=ca1c49f58d17eaa57aac308d0ac64434&sign_type=MD5 | ||
112 | - */ | 105 | + ); |
106 | + | ||
107 | + return $result; | ||
108 | + } | ||
109 | + | ||
110 | + public function parseResponse(array $arrResponse) | ||
111 | + { | ||
112 | + /* 返回示例 | ||
113 | + * http://www.yohobuy.com/pay/notice/alipayreturn?buyer_email=tds%40smartunite.com&buyer_id=2088302294447308&exterface=create_direct_pay_by_user&is_success=T¬ify_id=RqPnCoPT3K9%252Fvwbh3I7xtEV5W65QRToFQ5fPrXsVxt12e%252FExCtC1XNiKnuRwupLaVLAR¬ify_time=2011-06-11+07%3A48%3A10¬ify_type=trade_status_sync&out_trade_no=1061003000&payment_type=1&seller_email=shop%40yoho.cn&seller_id=2088001550230585&subject=YOHO%E5%95%86%E5%93%81&total_fee=0.01&trade_no=2011061199833830&trade_status=TRADE_SUCCESS&sign=ca1c49f58d17eaa57aac308d0ac64434&sign_type=MD5 | ||
114 | + */ | ||
113 | $this->log->LogInfo("===开始解析支付宝银行的回调参数==="); | 115 | $this->log->LogInfo("===开始解析支付宝银行的回调参数==="); |
114 | $this->log->logInfo("-----回调参数为---"); | 116 | $this->log->logInfo("-----回调参数为---"); |
115 | $this->log->logInfo(var_export($arrResponse), true); | 117 | $this->log->logInfo(var_export($arrResponse), true); |
116 | 118 | ||
117 | - if(isset($arrResponse['q'])){ | ||
118 | - unset($arrResponse['q']); | ||
119 | - } | ||
120 | - $rsp = new Rspparams(); | ||
121 | - if(!$this->checkResponse($arrResponse)) | ||
122 | - { | ||
123 | - $this->log->LogInfo("验证支付宝银行的回调参数失败"); | ||
124 | - //验证不成功 | ||
125 | - $rsp->payResult = -1; | ||
126 | - } | ||
127 | - else | ||
128 | - { | ||
129 | - $rsp->bankName = ""; | ||
130 | - $outTradeNo = $arrResponse["out_trade_no"]; | 119 | + if (isset($arrResponse['q'])) { |
120 | + unset($arrResponse['q']); | ||
121 | + } | ||
122 | + $rsp = new Rspparams(); | ||
123 | + if (!$this->checkResponse($arrResponse)) { | ||
124 | + $this->log->LogInfo("---验证支付宝银行的回调参数失败---"); | ||
125 | + | ||
126 | + //验证不成功 | ||
127 | + $rsp->payResult = -1; | ||
128 | + } else { | ||
129 | + $this->log->LogInfo("---验证支付宝银行的回调参数成功---"); | ||
130 | + | ||
131 | + $rsp->bankName = ""; | ||
132 | + $outTradeNo = $arrResponse["out_trade_no"]; | ||
131 | // if(strlen($outTradeNo) > 9) { | 133 | // if(strlen($outTradeNo) > 9) { |
132 | // $outTradeNo = substr($outTradeNo, 2); | 134 | // $outTradeNo = substr($outTradeNo, 2); |
133 | // } | 135 | // } |
134 | - //支付订单处理 | ||
135 | - $orderCodeArr = explode('_',$outTradeNo); | ||
136 | - if(count($orderCodeArr) == 2){ | ||
137 | - $rsp->orderCode = $orderCodeArr[0]; | ||
138 | - $rsp->bankName = $orderCodeArr[1]; | ||
139 | - }else{ | ||
140 | - $rsp->orderCode = $outTradeNo; | ||
141 | - $rsp->bankName = ""; | ||
142 | - } | ||
143 | - $rsp->payResult = $this->convertResult($arrResponse["trade_status"]); | ||
144 | - $rsp->payTime = isset($arrResponse["gmt_payment"]) ? $arrResponse["gmt_payment"] : time(); | ||
145 | - $rsp->totalFee = $arrResponse["total_fee"]; | ||
146 | - $rsp->resultMsg = $arrResponse["notify_type"]; | ||
147 | - //添加支付订单号和交易号和银行的流水号 | ||
148 | - $rsp->payOrderCode = $outTradeNo; | ||
149 | - $rsp->tradeNo = $arrResponse['trade_no']; | ||
150 | - $rsp->bankBillNo = $arrResponse['bank_seq_no'] ? $arrResponse['bank_seq_no'] : ""; | ||
151 | - } | ||
152 | - return $rsp; | ||
153 | - } | ||
154 | - | ||
155 | - protected function convertResult($resultCode) | ||
156 | - { | ||
157 | - if($resultCode == "TRADE_SUCCESS") | ||
158 | - { | ||
159 | - return 200; | ||
160 | - } | ||
161 | - return 400; | ||
162 | - } | ||
163 | - | ||
164 | - /** | ||
165 | - * 除去数组中的空值和签名参数 | ||
166 | - * @param $para 签名参数组 | ||
167 | - * return 去掉空值与签名参数后的新签名参数组 | ||
168 | - */ | ||
169 | - private function paraFilter($para) { | ||
170 | - $para_filter = array(); | ||
171 | - foreach ($para as $key=>$val) { | ||
172 | - if($key == "sign" || $key == "sign_type" || $val == "")continue; | ||
173 | - else $para_filter[$key] = $para[$key]; | ||
174 | - } | ||
175 | - return $para_filter; | ||
176 | - } | ||
177 | - | ||
178 | - /** | ||
179 | - * 对数组排序 | ||
180 | - * @param $para 排序前的数组 | ||
181 | - * return 排序后的数组 | ||
182 | - */ | ||
183 | - private function argSort($para) { | ||
184 | - ksort($para); | ||
185 | - reset($para); | ||
186 | - return $para; | ||
187 | - } | ||
188 | - | ||
189 | - /** | ||
190 | - * 验证回复的正确性 | ||
191 | - * @see QPay_Utils_Abstract::verifResponse() | ||
192 | - */ | ||
193 | - protected function checkResponse(array $arrResponse) | ||
194 | - { | ||
195 | - ksort($arrResponse); | ||
196 | - reset($arrResponse); | ||
197 | - $sign = ''; | ||
198 | - foreach ($arrResponse AS $key=>$val) | ||
199 | - { | ||
200 | - if ($key != 'sign' && $key != 'sign_type' && $key != 'code') | ||
201 | - { | ||
202 | - $sign .= "$key=$val&"; | ||
203 | - } | ||
204 | - } | ||
205 | - $sign = substr($sign, 0, -1) . $this->config->alipay_key; | ||
206 | - | ||
207 | - return md5($sign) != $arrResponse['sign'] ? false : true; | ||
208 | - | ||
209 | - } | 136 | + //支付订单处理 |
137 | + $orderCodeArr = explode('_', $outTradeNo); | ||
138 | + if (count($orderCodeArr) == 2) { | ||
139 | + $rsp->orderCode = $orderCodeArr[0]; | ||
140 | + $rsp->bankName = $orderCodeArr[1]; | ||
141 | + } else { | ||
142 | + $rsp->orderCode = $outTradeNo; | ||
143 | + $rsp->bankName = ""; | ||
144 | + } | ||
145 | + $rsp->payResult = $this->convertResult($arrResponse["trade_status"]); | ||
146 | + $rsp->payTime = isset($arrResponse["gmt_payment"]) ? $arrResponse["gmt_payment"] : time(); | ||
147 | + $rsp->totalFee = $arrResponse["total_fee"]; | ||
148 | + $rsp->resultMsg = $arrResponse["notify_type"]; | ||
149 | + //添加支付订单号和交易号和银行的流水号 | ||
150 | + $rsp->payOrderCode = $outTradeNo; | ||
151 | + $rsp->tradeNo = $arrResponse['trade_no']; | ||
152 | + $rsp->bankBillNo = $arrResponse['bank_seq_no'] ? $arrResponse['bank_seq_no'] : ""; | ||
153 | + | ||
154 | + $this->log->LogInfo('----支付宝银行回调处理结果为----'); | ||
155 | + $this->log->LogInfo(var_export($rsp, true)); | ||
156 | + } | ||
157 | + | ||
158 | + return $rsp; | ||
159 | + } | ||
160 | + | ||
161 | + protected function convertResult($resultCode) | ||
162 | + { | ||
163 | + if ($resultCode == "TRADE_SUCCESS") { | ||
164 | + return 200; | ||
165 | + } | ||
166 | + return 400; | ||
167 | + } | ||
168 | + | ||
169 | + /** | ||
170 | + * 除去数组中的空值和签名参数 | ||
171 | + * @param $para 签名参数组 | ||
172 | + * return 去掉空值与签名参数后的新签名参数组 | ||
173 | + */ | ||
174 | + private function paraFilter($para) | ||
175 | + { | ||
176 | + $para_filter = array(); | ||
177 | + foreach ($para as $key => $val) { | ||
178 | + if ($key == "sign" || $key == "sign_type" || $val == "") continue; | ||
179 | + else $para_filter[$key] = $para[$key]; | ||
180 | + } | ||
181 | + return $para_filter; | ||
182 | + } | ||
183 | + | ||
184 | + /** | ||
185 | + * 对数组排序 | ||
186 | + * @param $para 排序前的数组 | ||
187 | + * return 排序后的数组 | ||
188 | + */ | ||
189 | + private function argSort($para) | ||
190 | + { | ||
191 | + ksort($para); | ||
192 | + reset($para); | ||
193 | + return $para; | ||
194 | + } | ||
195 | + | ||
196 | + /** | ||
197 | + * 验证回复的正确性 | ||
198 | + * @see QPay_Utils_Abstract::verifResponse() | ||
199 | + */ | ||
200 | + protected function checkResponse(array $arrResponse) | ||
201 | + { | ||
202 | + ksort($arrResponse); | ||
203 | + reset($arrResponse); | ||
204 | + $sign = ''; | ||
205 | + foreach ($arrResponse AS $key => $val) { | ||
206 | + if ($key != 'sign' && $key != 'sign_type' && $key != 'code') { | ||
207 | + $sign .= "$key=$val&"; | ||
208 | + } | ||
209 | + } | ||
210 | + $sign = substr($sign, 0, -1) . $this->config->alipay_key; | ||
211 | + | ||
212 | + return md5($sign) != $arrResponse['sign'] ? false : true; | ||
213 | + | ||
214 | + } | ||
210 | } | 215 | } |
1 | +<?php | ||
2 | + | ||
3 | +namespace WebPlugin\Pay\Alimobilemini; | ||
4 | + | ||
5 | +/** | ||
6 | + * 手机支付配置文件 | ||
7 | + * @author tongds | ||
8 | + * | ||
9 | + */ | ||
10 | +class Config | ||
11 | +{ | ||
12 | + var $partner = '2088701661478015'; | ||
13 | + | ||
14 | + /** | ||
15 | + * @var string 日志目录 | ||
16 | + */ | ||
17 | + var $logDir = '/Data/logs/pc_pay/alimobilemini'; | ||
18 | + | ||
19 | + /** | ||
20 | + * @var string 日志等级 | ||
21 | + */ | ||
22 | + var $logLevel = 2; // 记录信息日志 | ||
23 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace WebPlugin\Pay\Alimobilemini; | ||
4 | + | ||
5 | +use WebPlugin\Pay\PayAbstract; | ||
6 | +use WebPlugin\Pay\Rspparams; | ||
7 | +use WebPlugin\PhpLog; | ||
8 | + | ||
9 | +/** | ||
10 | + * 手机支付返回 | ||
11 | + * @author tongds | ||
12 | + * | ||
13 | + */ | ||
14 | +class Service extends PayAbstract | ||
15 | +{ | ||
16 | + public $config; | ||
17 | + private $log; | ||
18 | + | ||
19 | + private $utils; | ||
20 | + | ||
21 | + public function __construct(array $paymentParams) | ||
22 | + { | ||
23 | + $this->logProjectPrefix = 'alimobilemini'; | ||
24 | + $this->utils = new Utils(); | ||
25 | + $this->config = new Config(); | ||
26 | + | ||
27 | + $this->log = new PhpLog($this->config->logDir, 'PRC', $this->config->logLevel); | ||
28 | + } | ||
29 | + | ||
30 | + | ||
31 | + /** | ||
32 | + * 处理支付宝极简支付的结果 | ||
33 | + * | ||
34 | + * @param array $arrResponse | ||
35 | + * @return Rspparams | ||
36 | + */ | ||
37 | + public function parseResponse(array $arrResponse) | ||
38 | + { | ||
39 | + $rsp = new Rspparams(); | ||
40 | +// ksort($arrResponse); | ||
41 | +// ##组织代签名字符串################# | ||
42 | +// $sign=$arrResponse['sign']; | ||
43 | +// foreach($arrResponse as $a =>$v) | ||
44 | +// { | ||
45 | +// if(in_array($a,array('sign','sign_type')) || $v=="") continue; | ||
46 | +// $data[]=$a.'='.$v; | ||
47 | +// } | ||
48 | + | ||
49 | +// $datastr=implode("&", $data); | ||
50 | +// ################################## | ||
51 | + | ||
52 | + $isVerify = $this->utils->getSignVeryfy($arrResponse); | ||
53 | + if ($isVerify) { | ||
54 | + //验证成功 | ||
55 | + $rsp->bankName = ""; | ||
56 | + $rsp->orderCode = $arrResponse['out_trade_no']; | ||
57 | + $rsp->payResult = $this->convertResult($arrResponse['trade_status']); | ||
58 | + $rsp->payTime = $arrResponse["gmt_create"]; | ||
59 | + $rsp->totalFee = $arrResponse["total_fee"]; | ||
60 | + $rsp->resultMsg = $arrResponse["trade_no"]; | ||
61 | + //添加支付订单号和交易号 | ||
62 | + $rsp->payOrderCode = $arrResponse['out_trade_no']; | ||
63 | + $rsp->tradeNo = $arrResponse['trade_no']; | ||
64 | + $rsp->bankBillNo = ""; | ||
65 | + | ||
66 | + $this->log->logInfo(var_export($arrResponse, true)); | ||
67 | + $this->log->logInfo('======alimobilemini成功==='); | ||
68 | + } else { | ||
69 | + //不成功 | ||
70 | + $rsp->payResult = -1; | ||
71 | + $this->log->logInfo(var_export($arrResponse, true)); | ||
72 | + $this->log->logInfo('======alimobilemini失败===订单号----->' . $arrResponse['out_trade_no']); | ||
73 | + } | ||
74 | + | ||
75 | + return $rsp; | ||
76 | + } | ||
77 | + | ||
78 | + /** | ||
79 | + * 转换结果 | ||
80 | + * | ||
81 | + * @param string $resultCode 返回码 | ||
82 | + * @return int | ||
83 | + */ | ||
84 | + protected function convertResult($resultCode) | ||
85 | + { | ||
86 | + if ($resultCode == "TRADE_SUCCESS" || $resultCode == "TRADE_FINISHED") { | ||
87 | + return 200; | ||
88 | + } | ||
89 | + | ||
90 | + return -1; | ||
91 | + } | ||
92 | + | ||
93 | + | ||
94 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace WebPlugin\Pay\Alimobilemini; | ||
4 | + | ||
5 | +use WebPlugin\Pay\PayAbstract; | ||
6 | + | ||
7 | +/** | ||
8 | + * 支付宝手机极简支付工具类 | ||
9 | + * @author Smile | ||
10 | + * | ||
11 | + */ | ||
12 | +class Utils extends PayAbstract | ||
13 | +{ | ||
14 | + /** | ||
15 | + * 构造函数 | ||
16 | + */ | ||
17 | + public function __construct() | ||
18 | + { | ||
19 | + } | ||
20 | + | ||
21 | + | ||
22 | + /**RSA签名 | ||
23 | + * $data待签名数据 | ||
24 | + * 签名用商户私钥,必须是没有经过pkcs8转换的私钥 | ||
25 | + * 最后的签名,需要用base64编码 | ||
26 | + * return Sign签名 | ||
27 | + */ | ||
28 | + function sign($data) | ||
29 | + { | ||
30 | + | ||
31 | + //转换为openssl密钥,必须是没有经过pkcs8转换的私钥 | ||
32 | + $res = openssl_get_privatekey($this->priKey); | ||
33 | + | ||
34 | + //调用openssl内置签名方法,生成签名$sign | ||
35 | + openssl_sign($data, $sign, $res); | ||
36 | + | ||
37 | + //释放资源 | ||
38 | + openssl_free_key($res); | ||
39 | + | ||
40 | + //base64编码 | ||
41 | + $sign = base64_encode($sign); | ||
42 | + | ||
43 | + return $sign; | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + * RSA验签 | ||
48 | + * 验签用支付宝公钥 | ||
49 | + * | ||
50 | + * return 验签是否通过 bool值 | ||
51 | + * @param array $data 待签名数据 | ||
52 | + * @param string $sign 需要验签的签名 | ||
53 | + * @return bool 验签是否通过 bool值 | ||
54 | + */ | ||
55 | + function verify($data, $sign) | ||
56 | + { | ||
57 | + $pubKeyPath = dirname(__FILE__) . '/key/alipay_public_key.pem'; | ||
58 | + //转换为openssl格式密钥 | ||
59 | + $pubKey = file_get_contents($pubKeyPath); | ||
60 | + $res = openssl_get_publickey($pubKey); | ||
61 | + if ($res == false) { | ||
62 | + while ($text = openssl_error_string()) | ||
63 | + echo "$text \n"; | ||
64 | + } | ||
65 | + //调用openssl内置方法验签,返回bool值 | ||
66 | + $result = (bool)openssl_verify($data, base64_decode($sign), $res); | ||
67 | + | ||
68 | + //释放资源 | ||
69 | + openssl_free_key($res); | ||
70 | + | ||
71 | + //返回资源是否成功 | ||
72 | + return $result; | ||
73 | + } | ||
74 | + | ||
75 | + /** | ||
76 | + * 获取返回时的签名验证结果 | ||
77 | + * | ||
78 | + * @param $para_temp 通知返回来的参数数组 | ||
79 | + * @return string $sign 返回的签名结果 | ||
80 | + */ | ||
81 | + function getSignVeryfy($para_temp) | ||
82 | + { | ||
83 | + //支付宝公钥路径 | ||
84 | + $pubKeyPath = dirname(__FILE__) . '/key/alipay_public_key.pem'; | ||
85 | + //签名类型:RSA | ||
86 | + $sign_type = $para_temp['sign_type']; | ||
87 | + | ||
88 | + //签名 | ||
89 | + $sign = $para_temp['sign']; | ||
90 | + | ||
91 | + //除去待签名参数数组中的空值和签名参数 | ||
92 | + $para_filter = self::paraFilter($para_temp); | ||
93 | + | ||
94 | + //对待签名参数数组排序 | ||
95 | + $para_sort = self::argSort($para_filter); | ||
96 | + | ||
97 | + //把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串 | ||
98 | + $prestr = self::createLinkstring($para_sort); | ||
99 | + | ||
100 | + switch (strtoupper($sign_type)) { | ||
101 | + case "RSA" : | ||
102 | + $isSgin = self::rsaVerify($prestr, $pubKeyPath, $sign); | ||
103 | + break; | ||
104 | + default : | ||
105 | + $isSgin = false; | ||
106 | + } | ||
107 | + | ||
108 | + return $isSgin; | ||
109 | + } | ||
110 | + | ||
111 | + /** | ||
112 | + * 除去数组中的空值和签名参数 | ||
113 | + * @param array $para 签名参数组 | ||
114 | + * @return array 去掉空值与签名参数后的新签名参数组 | ||
115 | + */ | ||
116 | + function paraFilter($para) | ||
117 | + { | ||
118 | + $para_filter = array(); | ||
119 | + while (list ($key, $val) = each($para)) { | ||
120 | + if ($key == "sign" || $key == "sign_type" || $val == "") { | ||
121 | + continue; | ||
122 | + } else { | ||
123 | + $para_filter[$key] = $para[$key]; | ||
124 | + } | ||
125 | + } | ||
126 | + | ||
127 | + return $para_filter; | ||
128 | + } | ||
129 | + | ||
130 | + /** | ||
131 | + * 对数组排序 | ||
132 | + * @param array $para 排序前的数组 | ||
133 | + * @return array 排序后的数组 | ||
134 | + */ | ||
135 | + function argSort($para) | ||
136 | + { | ||
137 | + ksort($para); | ||
138 | + reset($para); | ||
139 | + | ||
140 | + return $para; | ||
141 | + } | ||
142 | + | ||
143 | + /** | ||
144 | + * 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串 | ||
145 | + * @param array $para 需要拼接的数组 | ||
146 | + * @return string 拼接完成以后的字符串 | ||
147 | + */ | ||
148 | + function createLinkstring($para) | ||
149 | + { | ||
150 | + $arg = ""; | ||
151 | + while (list ($key, $val) = each($para)) { | ||
152 | + $arg .= $key . "=" . $val . "&"; | ||
153 | + } | ||
154 | + //去掉最后一个&字符 | ||
155 | + $arg = substr($arg, 0, count($arg) - 2); | ||
156 | + | ||
157 | + //如果存在转义字符,那么去掉转义 | ||
158 | + if (get_magic_quotes_gpc()) { | ||
159 | + $arg = stripslashes($arg); | ||
160 | + } | ||
161 | + | ||
162 | + return $arg; | ||
163 | + } | ||
164 | + | ||
165 | + /** | ||
166 | + * RSA验签 | ||
167 | + * @param array $data 待签名数据 | ||
168 | + * @param string $ali_public_key_path 支付宝的公钥文件路径 | ||
169 | + * @param string $sign 要校对的的签名结果 | ||
170 | + * @return bool 验证结果 | ||
171 | + */ | ||
172 | + function rsaVerify($data, $ali_public_key_path, $sign) | ||
173 | + { | ||
174 | + $pubKey = file_get_contents($ali_public_key_path); | ||
175 | + $res = openssl_get_publickey($pubKey); | ||
176 | + $result = (bool)openssl_verify($data, base64_decode($sign), $res); | ||
177 | + openssl_free_key($res); | ||
178 | + | ||
179 | + return $result; | ||
180 | + } | ||
181 | + | ||
182 | +} |
1 | +-----BEGIN RSA PRIVATE KEY----- | ||
2 | +MIICXAIBAAKBgQDNtQee4Q7qVyjIkrLfIKcOajn4IGQyALkSclFdCrYcZ3WhFWdH | ||
3 | ++cjt/CGW8KuxX4CJWZO0LECA9avJFsipqZ339jz4nWma5yMoLpEFu55J2sJE3Mv1 | ||
4 | +USe+3/egRfOmHGWa3GHAPjglyux10ZStLkUoMSrNZxSeDKnaAaYLYxmB+wIDAQAB | ||
5 | +AoGAdqF3Ap5iPq0DPSC0/U7UaNDEG596iQe3s7avy4uY2KqlwL8aL/0SboTgTi7/ | ||
6 | +pSwhcZRyRQ7cKEMFzdNQ59+E1Gm1XqbZIKAb8D16JtcVrPBdKBCb5DOizW/6nKUk | ||
7 | +djo2FjuSB6nZCy5pZoyxjHkvOKZ0I+YfjYiNZGCCcRnYQmkCQQDqI7VsiywgqXUC | ||
8 | +anKzo/U8+exVofhe8Lrcd9pPeolaA9L9amCpW7VOBSlwnSuD7xX77/9XLUo3Ry1n | ||
9 | +PewANsQ/AkEA4Om+p5ZjR32v4nJkuE5LEMtDIei1Hhz4tdsBq/xIfY/wNy5Z8Kmo | ||
10 | +vpn0D1xF4qN99E7pp7SjRx/lW6VSn/4jRQJBAMXEO63fL/q2p7rOpuvNhYtnnpQG | ||
11 | +J4Ap3evy4FdZrUJ3EHQ0skjayZ2JBqO0XdkmzW7sHMVJ3/IpENSvnPPhTokCQBw5 | ||
12 | +ONOO66Zs/0VLVZhLOuBAoYv/x7qfqBYqBWuvnOkkxuAl0OOCZsqERzwmOB7YpVWj | ||
13 | +EW8aG+Mw/Xcip9ur6IECQDLwM0wvlCGyQaOClhlzlWPq0pgEpnnJMwkfyXbx03Cb | ||
14 | +DyXYdx6FDfqcCKlHcfHevuCVczR4aT4/rUClJB39AqU= | ||
15 | +-----END RSA PRIVATE KEY----- |
@@ -100,6 +100,10 @@ class Service extends PayAbstract | @@ -100,6 +100,10 @@ class Service extends PayAbstract | ||
100 | 'pars' => $param . "&sign=" . md5($sign) . "&sign_type=" . $this->config->sign_type, | 100 | 'pars' => $param . "&sign=" . md5($sign) . "&sign_type=" . $this->config->sign_type, |
101 | 'reqType' => 'get' | 101 | 'reqType' => 'get' |
102 | ); | 102 | ); |
103 | + | ||
104 | + $this->log->LogInfo('----支付宝回调处理结果为----'); | ||
105 | + $this->log->LogInfo(var_export($result, true)); | ||
106 | + | ||
103 | return $result; | 107 | return $result; |
104 | } | 108 | } |
105 | 109 | ||
@@ -117,9 +121,11 @@ class Service extends PayAbstract | @@ -117,9 +121,11 @@ class Service extends PayAbstract | ||
117 | } | 121 | } |
118 | $rsp = new Rspparams(); | 122 | $rsp = new Rspparams(); |
119 | if (!$this->checkResponse($arrResponse)) { | 123 | if (!$this->checkResponse($arrResponse)) { |
124 | + $this->log->logInfo("-----支付宝回调参数验证签名失败---"); | ||
120 | //验证不成功 | 125 | //验证不成功 |
121 | $rsp->payResult = -1; | 126 | $rsp->payResult = -1; |
122 | } else { | 127 | } else { |
128 | + $this->log->logInfo("-----支付宝回调参数验证签名成功---"); | ||
123 | $rsp->bankName = ""; | 129 | $rsp->bankName = ""; |
124 | $outTradeNo = $arrResponse["out_trade_no"]; | 130 | $outTradeNo = $arrResponse["out_trade_no"]; |
125 | $rsp->orderCode = $outTradeNo; | 131 | $rsp->orderCode = $outTradeNo; |
@@ -5,10 +5,12 @@ namespace WebPlugin\Pay\Allinpay; | @@ -5,10 +5,12 @@ namespace WebPlugin\Pay\Allinpay; | ||
5 | use WebPlugin\Pay\PayAbstract; | 5 | use WebPlugin\Pay\PayAbstract; |
6 | use WebPlugin\Pay\Reqparams; | 6 | use WebPlugin\Pay\Reqparams; |
7 | use WebPlugin\Pay\Rspparams; | 7 | use WebPlugin\Pay\Rspparams; |
8 | +use WebPlugin\PhpLog; | ||
8 | 9 | ||
9 | class Service extends PayAbstract | 10 | class Service extends PayAbstract |
10 | { | 11 | { |
11 | - var $config; | 12 | + public $config; |
13 | + private $log; | ||
12 | 14 | ||
13 | public function __construct(array $paymentParams) | 15 | public function __construct(array $paymentParams) |
14 | { | 16 | { |
@@ -17,6 +19,8 @@ class Service extends PayAbstract | @@ -17,6 +19,8 @@ class Service extends PayAbstract | ||
17 | $myConfig = json_decode($paymentParams["pay_params"]); | 19 | $myConfig = json_decode($paymentParams["pay_params"]); |
18 | $this->config->merchantId = $myConfig->merchant_id; | 20 | $this->config->merchantId = $myConfig->merchant_id; |
19 | $this->config->merchantKey = $myConfig->merchant_key; | 21 | $this->config->merchantKey = $myConfig->merchant_key; |
22 | + | ||
23 | + $this->log = new PhpLog($this->config->logDir, 'PRC', $this->config->logLevel); | ||
20 | } | 24 | } |
21 | 25 | ||
22 | /** | 26 | /** |
@@ -63,10 +67,18 @@ class Service extends PayAbstract | @@ -63,10 +67,18 @@ class Service extends PayAbstract | ||
63 | */ | 67 | */ |
64 | public function parseResponse(array $arrResponse) | 68 | public function parseResponse(array $arrResponse) |
65 | { | 69 | { |
70 | + $this->log->LogInfo("===开始处理通联支付的回调参数==="); | ||
71 | + $this->log->logInfo("-----回调参数为---"); | ||
72 | + $this->log->logInfo(var_export($arrResponse, true)); | ||
73 | + | ||
66 | $rsp = new Rspparams(); | 74 | $rsp = new Rspparams(); |
67 | if (!$this->checkResponse($arrResponse)) { | 75 | if (!$this->checkResponse($arrResponse)) { |
76 | + $this->log->logInfo("-----验证通联支付回调参数失败---"); | ||
77 | + | ||
68 | $rsp->payResult = -1; | 78 | $rsp->payResult = -1; |
69 | } else { | 79 | } else { |
80 | + $this->log->logInfo("-----验证通联支付回调参数成功---"); | ||
81 | + | ||
70 | $rsp->bankName = ""; | 82 | $rsp->bankName = ""; |
71 | $rsp->orderCode = $arrResponse["orderNo"]; | 83 | $rsp->orderCode = $arrResponse["orderNo"]; |
72 | $rsp->payResult = $this->convertResult($arrResponse["payResult"]); | 84 | $rsp->payResult = $this->convertResult($arrResponse["payResult"]); |
@@ -112,7 +112,7 @@ class Config | @@ -112,7 +112,7 @@ class Config | ||
112 | /** | 112 | /** |
113 | * @var string 日志目录 | 113 | * @var string 日志目录 |
114 | */ | 114 | */ |
115 | - var $logDir = '/tmp/logs/shengpay'; | 115 | + var $logDir = '/Data/logs/pc_pay/shengpay'; |
116 | 116 | ||
117 | /** | 117 | /** |
118 | * @var string 日志等级 | 118 | * @var string 日志等级 |
@@ -108,15 +108,19 @@ class Service extends PayAbstract | @@ -108,15 +108,19 @@ class Service extends PayAbstract | ||
108 | */ | 108 | */ |
109 | function parseResponse(Array $arrResponse) | 109 | function parseResponse(Array $arrResponse) |
110 | { | 110 | { |
111 | - $this->log->LogInfo("===开始处理盛付通的请求参数==="); | ||
112 | - $this->log->logInfo("-----请求参数为---"); | 111 | + $this->log->LogInfo("===开始处理盛付通的回调参数==="); |
112 | + $this->log->logInfo("-----回调参数为---"); | ||
113 | $this->log->logInfo(var_export($arrResponse, true)); | 113 | $this->log->logInfo(var_export($arrResponse, true)); |
114 | 114 | ||
115 | $rsp = new Rspparams(); | 115 | $rsp = new Rspparams(); |
116 | if (!$this->checkResponse($arrResponse)) { | 116 | if (!$this->checkResponse($arrResponse)) { |
117 | + $this->log->logInfo("-----验证盛付通回调参数失败---"); | ||
118 | + | ||
117 | //验证不成功 | 119 | //验证不成功 |
118 | $rsp->payResult = -1; | 120 | $rsp->payResult = -1; |
119 | } else { | 121 | } else { |
122 | + $this->log->logInfo("-----验证盛付通回调参数成功---"); | ||
123 | + | ||
120 | $rsp->bankName = ""; | 124 | $rsp->bankName = ""; |
121 | $rsp->orderCode = $arrResponse["OrderNo"]; | 125 | $rsp->orderCode = $arrResponse["OrderNo"]; |
122 | $rsp->payResult = $this->convertResult($arrResponse["Status"]); | 126 | $rsp->payResult = $this->convertResult($arrResponse["Status"]); |
@@ -35,20 +35,22 @@ class Service extends PayAbstract | @@ -35,20 +35,22 @@ class Service extends PayAbstract | ||
35 | */ | 35 | */ |
36 | public function parseResponse(array $package) | 36 | public function parseResponse(array $package) |
37 | { | 37 | { |
38 | + $this->log->logInfo("===开始解析银联支付的回调参数==="); | ||
39 | + $this->log->logInfo("===回调参数为==="); | ||
38 | $this->log->LogInfo(var_export($package, true)); | 40 | $this->log->LogInfo(var_export($package, true)); |
39 | 41 | ||
40 | $verify = false; | 42 | $verify = false; |
41 | $responseData = new Rspparams(); | 43 | $responseData = new Rspparams(); |
42 | 44 | ||
43 | if (!isset($package['respCode']) || $package['respCode'] !== '00') { | 45 | if (!isset($package['respCode']) || $package['respCode'] !== '00') { |
44 | - $this->log->LogInfo('支付返回码有误'); | 46 | + $this->log->LogInfo('银联支付返回码有误'); |
45 | $responseData->payResult = -1; | 47 | $responseData->payResult = -1; |
46 | return $responseData; | 48 | return $responseData; |
47 | } | 49 | } |
48 | 50 | ||
49 | if (isset($package['signature'])) { // TODO isset($package['signature']) && verify($package)验证签名待做 | 51 | if (isset($package['signature'])) { // TODO isset($package['signature']) && verify($package)验证签名待做 |
50 | $verify = true; | 52 | $verify = true; |
51 | - $this->log->LogInfo('验签成功'); | 53 | + $this->log->LogInfo('银联支付验签成功'); |
52 | } | 54 | } |
53 | 55 | ||
54 | if ($verify) { | 56 | if ($verify) { |
@@ -67,6 +69,7 @@ class Service extends PayAbstract | @@ -67,6 +69,7 @@ class Service extends PayAbstract | ||
67 | $responseData->payResult = -1; | 69 | $responseData->payResult = -1; |
68 | } | 70 | } |
69 | 71 | ||
72 | + $this->log->logInfo("===银联支付的回调参数处理结果为==="); | ||
70 | $this->log->LogInfo(var_export($responseData, true)); | 73 | $this->log->LogInfo(var_export($responseData, true)); |
71 | 74 | ||
72 | return $responseData; | 75 | return $responseData; |
@@ -53,10 +53,10 @@ const SDK_FRONT_NOTIFY_URL = 'http://www.yohobuy.com/pay/notice/unionpaywebretur | @@ -53,10 +53,10 @@ const SDK_FRONT_NOTIFY_URL = 'http://www.yohobuy.com/pay/notice/unionpaywebretur | ||
53 | const SDK_BACK_NOTIFY_URL = 'http://www.yohobuy.com/pay/notice/unionpaywebnotice'; | 53 | const SDK_BACK_NOTIFY_URL = 'http://www.yohobuy.com/pay/notice/unionpaywebnotice'; |
54 | 54 | ||
55 | //文件下载目录 | 55 | //文件下载目录 |
56 | -const SDK_FILE_DOWN_PATH = '/tmp/unionpay/files/'; | 56 | +const SDK_FILE_DOWN_PATH = '/Data/logs/pc_pay/unionpay/files/'; |
57 | 57 | ||
58 | //日志 目录 | 58 | //日志 目录 |
59 | -const SDK_LOG_FILE_PATH = '/tmp/logs/unionpay/'; | 59 | +const SDK_LOG_FILE_PATH = '/Data/logs/pc_pay/unionpay/'; |
60 | 60 | ||
61 | //日志级别 | 61 | //日志级别 |
62 | const SDK_LOG_LEVEL = 2; // 记录信息日志 | 62 | const SDK_LOG_LEVEL = 2; // 记录信息日志 |
@@ -49,10 +49,10 @@ const SDK_FRONT_NOTIFY_URL = 'http://www.yohobuy.com/pay/notice/unionpaywebretur | @@ -49,10 +49,10 @@ const SDK_FRONT_NOTIFY_URL = 'http://www.yohobuy.com/pay/notice/unionpaywebretur | ||
49 | const SDK_BACK_NOTIFY_URL = 'http://www.yohobuy.com/pay/notice/unionpaywebnotice'; | 49 | const SDK_BACK_NOTIFY_URL = 'http://www.yohobuy.com/pay/notice/unionpaywebnotice'; |
50 | 50 | ||
51 | //文件下载目录 | 51 | //文件下载目录 |
52 | -const SDK_FILE_DOWN_PATH = '/tmp/unionpay/files/'; | 52 | +const SDK_FILE_DOWN_PATH = '/Data/logs/pc_pay/unionpay/files/'; |
53 | 53 | ||
54 | //日志 目录 | 54 | //日志 目录 |
55 | -const SDK_LOG_FILE_PATH = '/tmp/logs/unionpay/'; | 55 | +const SDK_LOG_FILE_PATH = '/Data/logs/pc_pay/unionpay/'; |
56 | 56 | ||
57 | //日志级别 | 57 | //日志级别 |
58 | const SDK_LOG_LEVEL = 2; | 58 | const SDK_LOG_LEVEL = 2; |
@@ -21,10 +21,11 @@ class Service extends PayAbstract | @@ -21,10 +21,11 @@ class Service extends PayAbstract | ||
21 | private $payCurl; | 21 | private $payCurl; |
22 | private $log; | 22 | private $log; |
23 | 23 | ||
24 | - public function __construct(array $paymentParams) { | 24 | + public function __construct(array $paymentParams) |
25 | + { | ||
25 | $this->logProjectPrefix = 'wechatpay'; | 26 | $this->logProjectPrefix = 'wechatpay'; |
26 | $this->config = new Config(); | 27 | $this->config = new Config(); |
27 | - $environParam = 'pay_'.APPLICATION_ENV.'_url'; | 28 | + $environParam = 'pay_' . APPLICATION_ENV . '_url'; |
28 | $this->payCurl = $this->config->$environParam; | 29 | $this->payCurl = $this->config->$environParam; |
29 | $this->appKey = $this->config->app_key; | 30 | $this->appKey = $this->config->app_key; |
30 | $this->privateKey = $this->config->private_key; | 31 | $this->privateKey = $this->config->private_key; |
@@ -33,7 +34,8 @@ class Service extends PayAbstract | @@ -33,7 +34,8 @@ class Service extends PayAbstract | ||
33 | $this->log = new PhpLog($this->config->logDir, 'PRC', $this->config->logLevel); | 34 | $this->log = new PhpLog($this->config->logDir, 'PRC', $this->config->logLevel); |
34 | } | 35 | } |
35 | 36 | ||
36 | - public function getPayRequestPars(Reqparams $params) { | 37 | + public function getPayRequestPars(Reqparams $params) |
38 | + { | ||
37 | $this->orderCode = $params->orderCode; | 39 | $this->orderCode = $params->orderCode; |
38 | $result = array( | 40 | $result = array( |
39 | 'pay_url' => $this->config->payment_url, | 41 | 'pay_url' => $this->config->payment_url, |
@@ -49,7 +51,8 @@ class Service extends PayAbstract | @@ -49,7 +51,8 @@ class Service extends PayAbstract | ||
49 | * @return string | 51 | * @return string |
50 | * @internal param array $orderCode | 52 | * @internal param array $orderCode |
51 | */ | 53 | */ |
52 | - public function pay(array $orderInfo) { | 54 | + public function pay(array $orderInfo) |
55 | + { | ||
53 | $this->log->LogInfo("===开始处理微信扫码支付的请求参数==="); | 56 | $this->log->LogInfo("===开始处理微信扫码支付的请求参数==="); |
54 | $this->log->logInfo("-----请求参数为---"); | 57 | $this->log->logInfo("-----请求参数为---"); |
55 | $this->log->logInfo(var_export($orderInfo, true)); | 58 | $this->log->logInfo(var_export($orderInfo, true)); |
@@ -74,7 +77,7 @@ class Service extends PayAbstract | @@ -74,7 +77,7 @@ class Service extends PayAbstract | ||
74 | ); | 77 | ); |
75 | $pars = ''; | 78 | $pars = ''; |
76 | foreach ($parameter as $p_key => $p_val) { | 79 | foreach ($parameter as $p_key => $p_val) { |
77 | - $pars.=$p_key . '=' . urlencode($p_val) . '&'; | 80 | + $pars .= $p_key . '=' . urlencode($p_val) . '&'; |
78 | } | 81 | } |
79 | $payUrlInfo = array( | 82 | $payUrlInfo = array( |
80 | 'pay_url' => $this->payCurl, | 83 | 'pay_url' => $this->payCurl, |
@@ -90,7 +93,8 @@ class Service extends PayAbstract | @@ -90,7 +93,8 @@ class Service extends PayAbstract | ||
90 | return array('pay_url' => $payUrl); | 93 | return array('pay_url' => $payUrl); |
91 | } | 94 | } |
92 | 95 | ||
93 | - public function parseResponse(array $data) { | 96 | + public function parseResponse(array $data) |
97 | + { | ||
94 | /* 返回示例 | 98 | /* 返回示例 |
95 | * http://www.yohobuy.com/pay/notice/wechatqrcodereturn?ordercode=93465435 | 99 | * http://www.yohobuy.com/pay/notice/wechatqrcodereturn?ordercode=93465435 |
96 | */ | 100 | */ |
@@ -108,7 +112,7 @@ class Service extends PayAbstract | @@ -108,7 +112,7 @@ class Service extends PayAbstract | ||
108 | 112 | ||
109 | $rsp = new Rspparams(); | 113 | $rsp = new Rspparams(); |
110 | // 支付成功 | 114 | // 支付成功 |
111 | - if(isset($result['trade_state']) && $result['trade_state'] === 'SUCCESS'){ | 115 | + if (isset($result['trade_state']) && $result['trade_state'] === 'SUCCESS') { |
112 | $rsp->payResult = 200; | 116 | $rsp->payResult = 200; |
113 | $rsp->bankName = "WX"; | 117 | $rsp->bankName = "WX"; |
114 | $rsp->orderCode = $data['orderCode']; | 118 | $rsp->orderCode = $data['orderCode']; |
@@ -119,7 +123,8 @@ class Service extends PayAbstract | @@ -119,7 +123,8 @@ class Service extends PayAbstract | ||
119 | $rsp->payOrderCode = $data["orderCode"]; | 123 | $rsp->payOrderCode = $data["orderCode"]; |
120 | $rsp->tradeNo = $result["out_trade_no"]; | 124 | $rsp->tradeNo = $result["out_trade_no"]; |
121 | $rsp->bankBillNo = $result['bank_type']; | 125 | $rsp->bankBillNo = $result['bank_type']; |
122 | - }else{ | 126 | + } else { |
127 | + $this->log->logInfo("===微信扫码支付失败==="); | ||
123 | $rsp->payResult = -1; | 128 | $rsp->payResult = -1; |
124 | } | 129 | } |
125 | 130 |
@@ -14,6 +14,7 @@ use WebPlugin\Pay\weixin\lib\WxPayConfig; | @@ -14,6 +14,7 @@ use WebPlugin\Pay\weixin\lib\WxPayConfig; | ||
14 | use WebPlugin\Pay\weixin\lib\WxPayNativePay; | 14 | use WebPlugin\Pay\weixin\lib\WxPayNativePay; |
15 | use WebPlugin\Pay\weixin\lib\WxPayOrderQuery; | 15 | use WebPlugin\Pay\weixin\lib\WxPayOrderQuery; |
16 | use WebPlugin\Pay\weixin\lib\WxPayUnifiedOrder; | 16 | use WebPlugin\Pay\weixin\lib\WxPayUnifiedOrder; |
17 | +use WebPlugin\PhpLog; | ||
17 | 18 | ||
18 | /** | 19 | /** |
19 | * 支付有关方法 | 20 | * 支付有关方法 |
@@ -25,6 +26,22 @@ use WebPlugin\Pay\weixin\lib\WxPayUnifiedOrder; | @@ -25,6 +26,22 @@ use WebPlugin\Pay\weixin\lib\WxPayUnifiedOrder; | ||
25 | */ | 26 | */ |
26 | class PayModel | 27 | class PayModel |
27 | { | 28 | { |
29 | + // 日志等级,2表示记录信息等级的日志 | ||
30 | + const LOG_LEVEL = 2; | ||
31 | + // 支付方式有关接口调用日志 | ||
32 | + const PAYMENT_LIST_LOG = '/Data/logs/pc_pay/payment_list'; | ||
33 | + // 向ERP提交订单状态有关接口调用日志和更新订单状态有关接口调用日志 | ||
34 | + const ORDER_STATUS_LOG = '/Data/logs/pc_pay/order_status'; | ||
35 | + // 获取或者更新订单支付银行的接口调用日志 | ||
36 | + const ORDER_BANK_LOG = '/Data/logs/pc_pay/order_bank'; | ||
37 | + // 根据用户UID获取订单数有关接口调用日志 | ||
38 | + const ORDER_COUNT_LOG = '/Data/logs/pc_pay/order_count'; | ||
39 | + // 发送短信有关接口调用日志 | ||
40 | + const SEND_MESSAGE_LOG = '/Data/logs/pc_pay/send_message'; | ||
41 | + | ||
42 | + // 是否老用户订单数判断值 | ||
43 | + const OLD_USER_LIMIT = 1; | ||
44 | + | ||
28 | /** | 45 | /** |
29 | * 获取支付方式选择页面有关信息 | 46 | * 获取支付方式选择页面有关信息 |
30 | * | 47 | * |
@@ -94,8 +111,14 @@ class PayModel | @@ -94,8 +111,14 @@ class PayModel | ||
94 | // 用户ID | 111 | // 用户ID |
95 | $result['uid'] = $uid; | 112 | $result['uid'] = $uid; |
96 | 113 | ||
114 | + // 初始化日志 | ||
115 | + $log = new PhpLog(self::PAYMENT_LIST_LOG, 'PRC', self::LOG_LEVEL); | ||
97 | // 获取支付途径列表 | 116 | // 获取支付途径列表 |
117 | + $log->LogInfo('===开始调用支付方式列表接口,接口方法为web.SpaceOrders.getPaymentList==='); | ||
98 | $payTypes = PayData::getPaymentList(); | 118 | $payTypes = PayData::getPaymentList(); |
119 | + $log->LogInfo('===结束调用支付方式列表接口,返回结果为==='); | ||
120 | + $log->LogInfo(var_export($payTypes, true)); | ||
121 | + | ||
99 | $defaultPayType = 0; | 122 | $defaultPayType = 0; |
100 | $types = array(); | 123 | $types = array(); |
101 | if (isset($payTypes['data']) && !empty($payTypes['data'])) { | 124 | if (isset($payTypes['data']) && !empty($payTypes['data'])) { |
@@ -125,16 +148,37 @@ class PayModel | @@ -125,16 +148,37 @@ class PayModel | ||
125 | 148 | ||
126 | // 无需付款 | 149 | // 无需付款 |
127 | if (isset($order["payment_amount"]) && $order["payment_amount"] == 0) { | 150 | if (isset($order["payment_amount"]) && $order["payment_amount"] == 0) { |
151 | + // 初始化日志 | ||
152 | + $log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL); | ||
153 | + $log->LogInfo('===[' . $orderCode . ']==='); | ||
154 | + | ||
128 | // ERP提交订单状态 | 155 | // ERP提交订单状态 |
129 | - PayData::submitOrderStatus($orderCode, 0, '', '', 0, '', '', ''); | 156 | + $log->LogInfo('===开始调用ERP提交订单状态接口,接口方法为web.SpaceOrders.submitOrderStatus==='); |
157 | + $log->LogInfo('===请求参数为orderCode=' . $orderCode . '==='); | ||
158 | + $erpReturn = PayData::submitOrderStatus($orderCode, 0, '', '', 0, '', '', ''); | ||
159 | + $log->LogInfo('===结束调用ERP提交订单状态接口,返回结果为==='); | ||
160 | + $log->LogInfo(var_export($erpReturn, true)); | ||
161 | + | ||
130 | // 更新订单的状态 | 162 | // 更新订单的状态 |
131 | - PayData::updateOrderStatus($order['order_id'], $uid, 0, 'Y', ''); | 163 | + $log->LogInfo('===开始调用更新订单状态接口,接口方法为web.SpaceOrders.updatePaymentStatus==='); |
164 | + $log->LogInfo('===请求参数为orderId=' . $order['order_id'] . 'uid=' . $uid . '==='); | ||
165 | + $updateOrderStatus = PayData::updateOrderStatus($order['order_id'], $uid, 0, 'Y', ''); | ||
166 | + $log->LogInfo('===结束调用更新订单状态接口,返回结果为==='); | ||
167 | + $log->LogInfo(var_export($updateOrderStatus, true)); | ||
168 | + | ||
132 | $result['notNeedPay'] = true; | 169 | $result['notNeedPay'] = true; |
133 | break; | 170 | break; |
134 | } | 171 | } |
135 | 172 | ||
136 | // 记录支付方式 | 173 | // 记录支付方式 |
174 | + // 初始化日志 | ||
175 | + $log = new PhpLog(self::ORDER_BANK_LOG, 'PRC', self::LOG_LEVEL); | ||
176 | + $log->LogInfo('===开始调用记录支付方式接口,接口方法为web.SpaceOrders.getOrderPayBank==='); | ||
177 | + $log->LogInfo('===请求参数为orderCode=' . $orderCode . '==='); | ||
137 | $bankRecord = PayData::getBankByOrder($orderCode); | 178 | $bankRecord = PayData::getBankByOrder($orderCode); |
179 | + $log->LogInfo('===结束调用记录支付方式接口,返回结果为==='); | ||
180 | + $log->LogInfo(var_export($bankRecord, true)); | ||
181 | + | ||
138 | if (isset($bankRecord['data']['bankCode']) && !empty($bankRecord['data']['bankCode'])) { | 182 | if (isset($bankRecord['data']['bankCode']) && !empty($bankRecord['data']['bankCode'])) { |
139 | $payRecord = $bankRecord['data']['bankCode']; | 183 | $payRecord = $bankRecord['data']['bankCode']; |
140 | } else { | 184 | } else { |
@@ -158,11 +202,17 @@ class PayModel | @@ -158,11 +202,17 @@ class PayModel | ||
158 | 202 | ||
159 | // 是否是老用户(用于订单统计) | 203 | // 是否是老用户(用于订单统计) |
160 | $orderCount = 0; | 204 | $orderCount = 0; |
205 | + // 初始化日志 | ||
206 | + $log = new PhpLog(self::ORDER_COUNT_LOG, 'PRC', self::LOG_LEVEL); | ||
207 | + $log->LogInfo('===开始调用查询用户订单数接口,接口方法为web.SpaceOrders.getOrderCountByUid==='); | ||
161 | $orders = PayData::getOrderCountByUid($uid); | 208 | $orders = PayData::getOrderCountByUid($uid); |
209 | + $log->LogInfo('===结束调用查询用户订单数接口,返回结果为==='); | ||
210 | + $log->LogInfo(var_export($orders, true)); | ||
211 | + | ||
162 | if (isset($orders['data']) && !empty($orders['data'])) { | 212 | if (isset($orders['data']) && !empty($orders['data'])) { |
163 | $orderCount = $orders['data']['total']; | 213 | $orderCount = $orders['data']['total']; |
164 | } | 214 | } |
165 | - $result['isOldUser'] = (intval($orderCount) > 1) ? true : false; | 215 | + $result['isOldUser'] = (intval($orderCount) > self::OLD_USER_LIMIT) ? true : false; |
166 | // 订单数(用于订单统计) | 216 | // 订单数(用于订单统计) |
167 | $result['orderCount'] = $orderCount; | 217 | $result['orderCount'] = $orderCount; |
168 | $result['is_advance'] = $order['attribute'] == 5 ? 'Y' : 'N'; | 218 | $result['is_advance'] = $order['attribute'] == 5 ? 'Y' : 'N'; |
@@ -424,6 +474,11 @@ class PayModel | @@ -424,6 +474,11 @@ class PayModel | ||
424 | break; | 474 | break; |
425 | } | 475 | } |
426 | 476 | ||
477 | + // 初始化日志 | ||
478 | + $log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL); | ||
479 | + $log->LogInfo('========[' . $orderCode . ']========'); | ||
480 | + $log->LogInfo('========开始查询微信扫码支付状态========'); | ||
481 | + | ||
427 | // 组装微信支付的订单号 | 482 | // 组装微信支付的订单号 |
428 | $tradeNo = 'YOHOBuy_' . $orderCode; | 483 | $tradeNo = 'YOHOBuy_' . $orderCode; |
429 | $input = new WxPayOrderQuery(); | 484 | $input = new WxPayOrderQuery(); |
@@ -431,6 +486,7 @@ class PayModel | @@ -431,6 +486,7 @@ class PayModel | ||
431 | $payResult = WxPayApi::orderQuery($input); | 486 | $payResult = WxPayApi::orderQuery($input); |
432 | 487 | ||
433 | if (isset($payResult['trade_state']) && $payResult['trade_state'] === 'SUCCESS') { | 488 | if (isset($payResult['trade_state']) && $payResult['trade_state'] === 'SUCCESS') { |
489 | + $log->LogInfo('========微信扫码支付成功========'); | ||
434 | $result = array( | 490 | $result = array( |
435 | 'code' => '200', | 491 | 'code' => '200', |
436 | 'message' => 'success' | 492 | 'message' => 'success' |
@@ -457,8 +513,18 @@ class PayModel | @@ -457,8 +513,18 @@ class PayModel | ||
457 | ); | 513 | ); |
458 | 514 | ||
459 | do { | 515 | do { |
516 | + // 初始化日志 | ||
517 | + $log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL); | ||
518 | + $log->LogInfo('========[' . $payResult->orderCode . ']========'); | ||
519 | + $log->LogInfo(var_export($payResult, true)); | ||
520 | + | ||
521 | + $log->LogInfo('===开始调用获取订单详情方式接口,接口方法为app.SpaceOrders.detail==='); | ||
460 | $orderInfo = OrderData::getOrderDetail($uid, $payResult->orderCode); | 522 | $orderInfo = OrderData::getOrderDetail($uid, $payResult->orderCode); |
523 | + $log->LogInfo('===结束调用获取订单详情方式接口,返回结果为==='); | ||
524 | + $log->LogInfo(var_export($orderInfo, true)); | ||
525 | + | ||
461 | if (!isset($orderInfo['data']) || empty($orderInfo['data'])) { | 526 | if (!isset($orderInfo['data']) || empty($orderInfo['data'])) { |
527 | + $log->LogInfo('===订单支付失败,未获取到订单详情信息==='); | ||
462 | break; | 528 | break; |
463 | } | 529 | } |
464 | 530 | ||
@@ -470,7 +536,14 @@ class PayModel | @@ -470,7 +536,14 @@ class PayModel | ||
470 | // 订单已取消 | 536 | // 订单已取消 |
471 | if ($orderData['is_cancel'] === 'Y' && $paymentStatus === 'N') { | 537 | if ($orderData['is_cancel'] === 'Y' && $paymentStatus === 'N') { |
472 | // 给用户发送短信 | 538 | // 给用户发送短信 |
473 | - PayData::sendMessage($orderData['mobile'], 'error_sms', '支付成功,但订单已取消,订单号为' . $orderCode); | 539 | + // 初始化日志 |
540 | + $log = new PhpLog(self::SEND_MESSAGE_LOG, 'PRC', self::LOG_LEVEL); | ||
541 | + $log->LogInfo('===[' . $orderCode . ']==='); | ||
542 | + $log->LogInfo('===开始调用订单取消时给用户发短信接口,接口方法为app.message.sendMsg==='); | ||
543 | + $messageReturn = PayData::sendMessage($orderData['mobile'], 'error_sms', '支付成功,但订单已取消,订单号为' . $orderCode); | ||
544 | + $log->LogInfo('===结束调用给用户发短信接口,返回结果为==='); | ||
545 | + $log->LogInfo(var_export($messageReturn, true)); | ||
546 | + | ||
474 | $result['code'] = 417; | 547 | $result['code'] = 417; |
475 | $result['message'] = '支付成功,但订单已取消,需联系客服'; | 548 | $result['message'] = '支付成功,但订单已取消,需联系客服'; |
476 | break; | 549 | break; |
@@ -478,6 +551,8 @@ class PayModel | @@ -478,6 +551,8 @@ class PayModel | ||
478 | 551 | ||
479 | // 支付金额与订单金额不一致 | 552 | // 支付金额与订单金额不一致 |
480 | if (round($amount, 2) != round($payResult->totalFee, 2)) { | 553 | if (round($amount, 2) != round($payResult->totalFee, 2)) { |
554 | + $log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL); | ||
555 | + $log->LogInfo('===订单支付失败,支付金额与订单金额不一致==='); | ||
481 | $result['code'] = 415; | 556 | $result['code'] = 415; |
482 | $result['message'] = '支付金额与订单金额不一致'; | 557 | $result['message'] = '支付金额与订单金额不一致'; |
483 | break; | 558 | break; |
@@ -489,10 +564,25 @@ class PayModel | @@ -489,10 +564,25 @@ class PayModel | ||
489 | $bankBillNo = $payResult->bankBillNo ? $payResult->bankBillNo : ""; | 564 | $bankBillNo = $payResult->bankBillNo ? $payResult->bankBillNo : ""; |
490 | $bankName = $payResult->bankName; | 565 | $bankName = $payResult->bankName; |
491 | $bankCode = $payResult->bankCode; | 566 | $bankCode = $payResult->bankCode; |
567 | + | ||
568 | + // 初始化日志 | ||
569 | + $log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL); | ||
570 | + $log->LogInfo('===[' . $orderCode . ']==='); | ||
571 | + | ||
572 | + $log->LogInfo('===开始调用ERP提交订单状态接口,接口方法为web.SpaceOrders.submitOrderStatus==='); | ||
573 | + $log->LogInfo('===请求参数为orderCode=' . $orderCode . '==='); | ||
492 | // ERP提交订单状态 | 574 | // ERP提交订单状态 |
493 | - PayData::submitOrderStatus($orderCode, $payment, $bankName, $bankCode, $amount, $payOrderCode, $tradeNo, $bankBillNo); | 575 | + $erpReturn = PayData::submitOrderStatus($orderCode, $payment, $bankName, $bankCode, $amount, $payOrderCode, $tradeNo, $bankBillNo); |
576 | + $log->LogInfo('===结束调用ERP提交订单状态接口,返回结果为==='); | ||
577 | + $log->LogInfo(var_export($erpReturn, true)); | ||
578 | + | ||
579 | + $log->LogInfo('===开始调用更新订单状态接口,接口方法为web.SpaceOrders.updatePaymentStatus==='); | ||
580 | + $log->LogInfo('===请求参数为orderId=' . $orderData['order_id'] . 'uid=' . $uid . '==='); | ||
494 | // 更新订单的状态 | 581 | // 更新订单的状态 |
495 | - PayData::updateOrderStatus($orderData['order_id'], $uid, $payment, 'Y', $bankCode); | 582 | + $updateOrderStatus = PayData::updateOrderStatus($orderData['order_id'], $uid, $payment, 'Y', $bankCode); |
583 | + $log->LogInfo('===结束调用更新订单状态接口,返回结果为==='); | ||
584 | + $log->LogInfo(var_export($updateOrderStatus, true)); | ||
585 | + $log->LogInfo('===订单支付成功,请等待发货==='); | ||
496 | 586 | ||
497 | $result['code'] = 200; | 587 | $result['code'] = 200; |
498 | $result['message'] = '支付成功,请等待发货'; | 588 | $result['message'] = '支付成功,请等待发货'; |
@@ -200,8 +200,6 @@ class NoticeController extends WebAction | @@ -200,8 +200,6 @@ class NoticeController extends WebAction | ||
200 | */ | 200 | */ |
201 | public function shengpayreturnAction() | 201 | public function shengpayreturnAction() |
202 | { | 202 | { |
203 | -// $strData = '{"Amount":"0.01","PayAmount":"0.01","OrderNo":"1070021504","serialno":"B000110726001873577","Status":"01","MerchantNo":"408258","PayChannel":"04","Discount":"1","SignType":"2","PayTime":"20110726162126","CurrencyType":"RMB","ProductNo":"","ProductDesc":"","Remark1":"","Remark2":"","ExInfo":"bankid:SDTBNK","Branch":"SHB","MAC":"8ABC0FBAA3EE3202F16A915B42571B58"}'; | ||
204 | - // $pars = json_decode($strData, true); | ||
205 | $payment = PayModel::getPaymentById(11); | 203 | $payment = PayModel::getPaymentById(11); |
206 | $payService = PayFactory::factory($payment); | 204 | $payService = PayFactory::factory($payment); |
207 | $res = $payService->parseResponse($_POST); | 205 | $res = $payService->parseResponse($_POST); |
@@ -299,6 +297,25 @@ class NoticeController extends WebAction | @@ -299,6 +297,25 @@ class NoticeController extends WebAction | ||
299 | $this->payResultProc($res, 25); | 297 | $this->payResultProc($res, 25); |
300 | echo "OK"; | 298 | echo "OK"; |
301 | } | 299 | } |
300 | + | ||
301 | + exit(); | ||
302 | + } | ||
303 | + | ||
304 | + /** | ||
305 | + * 支付宝手机支付(极简)的返回 | ||
306 | + */ | ||
307 | + public function alimobilenoticeminiAction() | ||
308 | + { | ||
309 | + $payment = PayModel::getPaymentById(20); | ||
310 | + $payService = PayFactory::factory($payment); | ||
311 | + $res = $payService->parseResponse($_POST); //支付宝通知使用的 | ||
312 | + if ($res->payResult != -1) { | ||
313 | + $this->payResultProc($res, 20); | ||
314 | + echo "OK"; | ||
315 | + } else { | ||
316 | + echo 'faile'; | ||
317 | + } | ||
318 | + | ||
302 | exit(); | 319 | exit(); |
303 | } | 320 | } |
304 | 321 |
-
Please register or login to post a comment