@@ -12,10 +12,10 @@ discard block |
||
12 | 12 | use zhangv\wechat\cache\JsonFileCacheProvider; |
13 | 13 | |
14 | 14 | class WechatPay { |
15 | - const TRADETYPE_JSAPI = 'JSAPI',TRADETYPE_NATIVE = 'NATIVE',TRADETYPE_APP = 'APP',TRADETYPE_MWEB = 'MWEB'; |
|
15 | + const TRADETYPE_JSAPI = 'JSAPI', TRADETYPE_NATIVE = 'NATIVE', TRADETYPE_APP = 'APP', TRADETYPE_MWEB = 'MWEB'; |
|
16 | 16 | const SIGNTYPE_MD5 = 'MD5', SIGNTYPE_HMACSHA256 = 'HMAC-SHA256'; |
17 | - const CHECKNAME_FORCECHECK = 'FORCE_CHECK',CHECKNAME_NOCHECK = 'NO_CHECK'; |
|
18 | - const ACCOUNTTYPE_BASIC = 'Basic',ACCOUNTTYPE_OPERATION = 'Operation',ACCOUNTTYPE_FEES = 'Fees'; |
|
17 | + const CHECKNAME_FORCECHECK = 'FORCE_CHECK', CHECKNAME_NOCHECK = 'NO_CHECK'; |
|
18 | + const ACCOUNTTYPE_BASIC = 'Basic', ACCOUNTTYPE_OPERATION = 'Operation', ACCOUNTTYPE_FEES = 'Fees'; |
|
19 | 19 | const API_ENDPOINT = 'https://api.mch.weixin.qq.com/'; |
20 | 20 | /** 支付 */ |
21 | 21 | const URL_UNIFIEDORDER = 'pay/unifiedorder'; |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | const URL_GETPUBLICKEY = 'https://fraud.mch.weixin.qq.com/risk/getpublickey'; |
49 | 49 | public static $BANKCODE = ['工商银行' => '1002', '农业银行' => '1005', '中国银行' => '1026', '建设银行' => '1003', '招商银行' => '1001', |
50 | 50 | '邮储银行' => '1066', '交通银行' => '1020', '浦发银行' => '1004', '民生银行' => '1006', '兴业银行' => '1009', '平安银行' => '1010', |
51 | - '中信银行' => '1021', '华夏银行' => '1025', '广发银行' => '1027', '光大银行' => '1022', '北京银行' => '1032', '宁波银行' => '1056',]; |
|
51 | + '中信银行' => '1021', '华夏银行' => '1025', '广发银行' => '1027', '光大银行' => '1022', '北京银行' => '1032', '宁波银行' => '1056', ]; |
|
52 | 52 | |
53 | 53 | public $getSignKeyUrl = "sandboxnew/pay/getsignkey"; |
54 | 54 | public $sandbox = false; |
@@ -91,34 +91,34 @@ discard block |
||
91 | 91 | $this->cacheProvider = new JsonFileCacheProvider(); |
92 | 92 | } |
93 | 93 | |
94 | - public function setWechatOAuth($wechatOAuth){ |
|
94 | + public function setWechatOAuth($wechatOAuth) { |
|
95 | 95 | $this->wechatOAuth = $wechatOAuth; |
96 | 96 | } |
97 | 97 | |
98 | - public function getWechatOAuth(){ |
|
99 | - if(!$this->wechatOAuth){ |
|
100 | - $this->wechatOAuth = new WechatOAuth($this->config['app_id'],$this->config['app_secret']); |
|
98 | + public function getWechatOAuth() { |
|
99 | + if (!$this->wechatOAuth) { |
|
100 | + $this->wechatOAuth = new WechatOAuth($this->config['app_id'], $this->config['app_secret']); |
|
101 | 101 | } |
102 | 102 | return $this->wechatOAuth; |
103 | 103 | } |
104 | 104 | |
105 | - public function setConfig($config){ |
|
105 | + public function setConfig($config) { |
|
106 | 106 | $this->config = $config; |
107 | 107 | } |
108 | 108 | |
109 | - public function getConfig(){ |
|
109 | + public function getConfig() { |
|
110 | 110 | return $this->config; |
111 | 111 | } |
112 | 112 | |
113 | - public function setHttpClient($httpClient){ |
|
113 | + public function setHttpClient($httpClient) { |
|
114 | 114 | $this->httpClient = $httpClient; |
115 | 115 | } |
116 | 116 | |
117 | - public function setCacheProvider($cacheProvider){ |
|
117 | + public function setCacheProvider($cacheProvider) { |
|
118 | 118 | $this->cacheProvider = $cacheProvider; |
119 | 119 | } |
120 | 120 | |
121 | - public function getCacheProvider(){ |
|
121 | + public function getCacheProvider() { |
|
122 | 122 | return $this->cacheProvider; |
123 | 123 | } |
124 | 124 | |
@@ -134,16 +134,16 @@ discard block |
||
134 | 134 | * @return string |
135 | 135 | * @throws \Exception |
136 | 136 | */ |
137 | - public function getPrepayId($body,$out_trade_no,$total_fee,$openid,$spbill_create_ip = null,$ext = null) { |
|
138 | - $data = ($ext && is_array($ext))?$ext:array(); |
|
137 | + public function getPrepayId($body, $out_trade_no, $total_fee, $openid, $spbill_create_ip = null, $ext = null) { |
|
138 | + $data = ($ext && is_array($ext)) ? $ext : array(); |
|
139 | 139 | $data["body"] = $body; |
140 | 140 | $data["out_trade_no"] = $out_trade_no; |
141 | 141 | $data["total_fee"] = $total_fee; |
142 | - $data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["REMOTE_ADDR"]; |
|
142 | + $data["spbill_create_ip"] = $spbill_create_ip ?: $_SERVER["REMOTE_ADDR"]; |
|
143 | 143 | $data["notify_url"] = $this->config["notify_url"]; |
144 | 144 | $data["trade_type"] = WechatPay::TRADETYPE_JSAPI; |
145 | - if(!$openid) throw new Exception('openid is required when trade_type is JSAPI'); |
|
146 | - $data["openid"] = $openid; |
|
145 | + if (!$openid) throw new Exception('openid is required when trade_type is JSAPI'); |
|
146 | + $data["openid"] = $openid; |
|
147 | 147 | $result = $this->unifiedOrder($data); |
148 | 148 | return $result["prepay_id"]; |
149 | 149 | } |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @param $ext array |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - public function getPrepayIdAPP($body,$out_trade_no,$total_fee,$spbill_create_ip,$ext = null) { |
|
162 | - $data = ($ext && is_array($ext))?$ext:array(); |
|
161 | + public function getPrepayIdAPP($body, $out_trade_no, $total_fee, $spbill_create_ip, $ext = null) { |
|
162 | + $data = ($ext && is_array($ext)) ? $ext : array(); |
|
163 | 163 | $data["body"] = $body; |
164 | 164 | $data["out_trade_no"] = $out_trade_no; |
165 | 165 | $data["total_fee"] = $total_fee; |
@@ -182,15 +182,15 @@ discard block |
||
182 | 182 | * @return string |
183 | 183 | * @throws Exception |
184 | 184 | */ |
185 | - public function getCodeUrl($body,$out_trade_no,$total_fee,$product_id,$spbill_create_ip = null,$ext = null){ |
|
186 | - $data = ($ext && is_array($ext))?$ext:array(); |
|
185 | + public function getCodeUrl($body, $out_trade_no, $total_fee, $product_id, $spbill_create_ip = null, $ext = null) { |
|
186 | + $data = ($ext && is_array($ext)) ? $ext : array(); |
|
187 | 187 | $data["body"] = $body; |
188 | 188 | $data["out_trade_no"] = $out_trade_no; |
189 | 189 | $data["total_fee"] = $total_fee; |
190 | - $data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["SERVER_ADDR"]; |
|
190 | + $data["spbill_create_ip"] = $spbill_create_ip ?: $_SERVER["SERVER_ADDR"]; |
|
191 | 191 | $data["notify_url"] = $this->config["notify_url"]; |
192 | 192 | $data["trade_type"] = self::TRADETYPE_NATIVE; |
193 | - if(!$product_id) throw new Exception('product_id is required when trade_type is NATIVE'); |
|
193 | + if (!$product_id) throw new Exception('product_id is required when trade_type is NATIVE'); |
|
194 | 194 | $data["product_id"] = $product_id; |
195 | 195 | $result = $this->unifiedOrder($data); |
196 | 196 | return $result["code_url"]; |
@@ -206,15 +206,15 @@ discard block |
||
206 | 206 | * @return string |
207 | 207 | * @throws Exception |
208 | 208 | */ |
209 | - public function getMwebUrl($body,$out_trade_no,$total_fee,$ext = null){ |
|
210 | - $data = ($ext && is_array($ext))?$ext:array(); |
|
209 | + public function getMwebUrl($body, $out_trade_no, $total_fee, $ext = null) { |
|
210 | + $data = ($ext && is_array($ext)) ? $ext : array(); |
|
211 | 211 | $data["body"] = $body; |
212 | 212 | $data["out_trade_no"] = $out_trade_no; |
213 | 213 | $data["total_fee"] = $total_fee; |
214 | - $data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:''; |
|
214 | + $data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : ''; |
|
215 | 215 | $data["notify_url"] = $this->config["notify_url"]; |
216 | 216 | $data["trade_type"] = self::TRADETYPE_MWEB; |
217 | - if(!isset($this->config['h5_scene_info'])) throw new Exception('h5_scene_info should be configured'); |
|
217 | + if (!isset($this->config['h5_scene_info'])) throw new Exception('h5_scene_info should be configured'); |
|
218 | 218 | $data["scene_info"] = json_encode($this->config['h5_scene_info']); |
219 | 219 | $result = $this->unifiedOrder($data); |
220 | 220 | return $result["mweb_url"]; |
@@ -230,25 +230,25 @@ discard block |
||
230 | 230 | public function unifiedOrder($params) { |
231 | 231 | $data = array(); |
232 | 232 | $data["appid"] = $this->config["app_id"]; |
233 | - $data["device_info"] = (isset($params['device_info'])&&trim($params['device_info'])!='')?$params['device_info']:null; |
|
233 | + $data["device_info"] = (isset($params['device_info']) && trim($params['device_info']) != '') ? $params['device_info'] : null; |
|
234 | 234 | $data["body"] = $params['body']; |
235 | - $data["detail"] = isset($params['detail'])?$params['detail']:null;//optional |
|
236 | - $data["attach"] = isset($params['attach'])?$params['attach']:null;//optional |
|
237 | - $data["out_trade_no"] = isset($params['out_trade_no'])?$params['out_trade_no']:null; |
|
238 | - $data["fee_type"] = isset($params['fee_type'])?$params['fee_type']:'CNY'; |
|
235 | + $data["detail"] = isset($params['detail']) ? $params['detail'] : null; //optional |
|
236 | + $data["attach"] = isset($params['attach']) ? $params['attach'] : null; //optional |
|
237 | + $data["out_trade_no"] = isset($params['out_trade_no']) ? $params['out_trade_no'] : null; |
|
238 | + $data["fee_type"] = isset($params['fee_type']) ? $params['fee_type'] : 'CNY'; |
|
239 | 239 | $data["total_fee"] = $params['total_fee']; |
240 | 240 | $data["spbill_create_ip"] = $params['spbill_create_ip']; |
241 | - $data["time_start"] = isset($params['time_start'])?$params['time_start']:null;//optional |
|
242 | - $data["time_expire"] = isset($params['time_expire'])?$params['time_expire']:null;//optional |
|
243 | - $data["goods_tag"] = isset($params['goods_tag'])?$params['goods_tag']:null; |
|
241 | + $data["time_start"] = isset($params['time_start']) ? $params['time_start'] : null; //optional |
|
242 | + $data["time_expire"] = isset($params['time_expire']) ? $params['time_expire'] : null; //optional |
|
243 | + $data["goods_tag"] = isset($params['goods_tag']) ? $params['goods_tag'] : null; |
|
244 | 244 | $data["notify_url"] = $this->config["notify_url"]; |
245 | 245 | $data["trade_type"] = $params['trade_type']; |
246 | - if($params['trade_type'] == WechatPay::TRADETYPE_NATIVE){ |
|
247 | - if(!isset($params['product_id'])) throw new Exception('product_id is required when trade_type is NATIVE'); |
|
246 | + if ($params['trade_type'] == WechatPay::TRADETYPE_NATIVE) { |
|
247 | + if (!isset($params['product_id'])) throw new Exception('product_id is required when trade_type is NATIVE'); |
|
248 | 248 | $data["product_id"] = $params['product_id']; |
249 | 249 | } |
250 | - if($params['trade_type'] == WechatPay::TRADETYPE_JSAPI){ |
|
251 | - if(!isset($params['openid'])) throw new Exception('openid is required when trade_type is JSAPI'); |
|
250 | + if ($params['trade_type'] == WechatPay::TRADETYPE_JSAPI) { |
|
251 | + if (!isset($params['openid'])) throw new Exception('openid is required when trade_type is JSAPI'); |
|
252 | 252 | $data["openid"] = $params['openid']; |
253 | 253 | } |
254 | 254 | $result = $this->post(self::URL_UNIFIEDORDER, $data); |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | * @param $transaction_id string 微信订单号 |
262 | 262 | * @return array |
263 | 263 | */ |
264 | - public function queryOrderByTransactionId($transaction_id){ |
|
264 | + public function queryOrderByTransactionId($transaction_id) { |
|
265 | 265 | $data = array(); |
266 | 266 | $data["appid"] = $this->config["app_id"]; |
267 | 267 | $data["transaction_id"] = $transaction_id; |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | * @param $out_trade_no string 商户订单号 |
276 | 276 | * @return array |
277 | 277 | */ |
278 | - public function queryOrderByOutTradeNo($out_trade_no){ |
|
278 | + public function queryOrderByOutTradeNo($out_trade_no) { |
|
279 | 279 | $data = array(); |
280 | 280 | $data["appid"] = $this->config["app_id"]; |
281 | 281 | $data["out_trade_no"] = $out_trade_no; |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | * @param $offset int 偏移 |
291 | 291 | * @return array |
292 | 292 | */ |
293 | - public function queryRefundByTransactionId($transaction_id,$offset = 0){ |
|
293 | + public function queryRefundByTransactionId($transaction_id, $offset = 0) { |
|
294 | 294 | $data = array(); |
295 | 295 | $data["appid"] = $this->config["app_id"]; |
296 | 296 | $data["transaction_id"] = $transaction_id; |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | * @param $offset int 偏移 |
307 | 307 | * @return array |
308 | 308 | */ |
309 | - public function queryRefundByOutTradeNo($out_trade_no,$offset = 0){ |
|
309 | + public function queryRefundByOutTradeNo($out_trade_no, $offset = 0) { |
|
310 | 310 | $data = array(); |
311 | 311 | $data["appid"] = $this->config["app_id"]; |
312 | 312 | $data["out_trade_no"] = $out_trade_no; |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | * @param $offset int 偏移 |
323 | 323 | * @return array |
324 | 324 | */ |
325 | - public function queryRefundByRefundId($refund_id,$offset = 0){ |
|
325 | + public function queryRefundByRefundId($refund_id, $offset = 0) { |
|
326 | 326 | $data = array(); |
327 | 327 | $data["appid"] = $this->config["app_id"]; |
328 | 328 | $data["refund_id"] = $refund_id; |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | * @param $offset int 偏移 |
339 | 339 | * @return array |
340 | 340 | */ |
341 | - public function queryRefundByOutRefundNo($out_refund_no,$offset = 0){ |
|
341 | + public function queryRefundByOutRefundNo($out_refund_no, $offset = 0) { |
|
342 | 342 | $data = array(); |
343 | 343 | $data["appid"] = $this->config["app_id"]; |
344 | 344 | $data["out_refund_no"] = $out_refund_no; |
@@ -353,11 +353,11 @@ discard block |
||
353 | 353 | * @param $out_trade_no string 商户订单号 |
354 | 354 | * @return array |
355 | 355 | */ |
356 | - public function closeOrder($out_trade_no){ |
|
356 | + public function closeOrder($out_trade_no) { |
|
357 | 357 | $data = array(); |
358 | 358 | $data["appid"] = $this->config["app_id"]; |
359 | 359 | $data["out_trade_no"] = $out_trade_no; |
360 | - $result = $this->post(self::URL_CLOSEORDER, $data,false); |
|
360 | + $result = $this->post(self::URL_CLOSEORDER, $data, false); |
|
361 | 361 | return $result; |
362 | 362 | } |
363 | 363 | |
@@ -372,14 +372,14 @@ discard block |
||
372 | 372 | * @param $ext array 扩展数组 |
373 | 373 | * @return array |
374 | 374 | */ |
375 | - public function refundByOutTradeNo($out_trade_no,$out_refund_no,$total_fee,$refund_fee,$ext = array()){ |
|
376 | - $data = ($ext && is_array($ext))?$ext:array(); |
|
375 | + public function refundByOutTradeNo($out_trade_no, $out_refund_no, $total_fee, $refund_fee, $ext = array()) { |
|
376 | + $data = ($ext && is_array($ext)) ? $ext : array(); |
|
377 | 377 | $data["appid"] = $this->config["app_id"]; |
378 | 378 | $data["out_trade_no"] = $out_trade_no; |
379 | 379 | $data["out_refund_no"] = $out_refund_no; |
380 | 380 | $data["total_fee"] = $total_fee; |
381 | 381 | $data["refund_fee"] = $refund_fee; |
382 | - $result = $this->post(self::URL_REFUND, $data,true); |
|
382 | + $result = $this->post(self::URL_REFUND, $data, true); |
|
383 | 383 | return $result; |
384 | 384 | } |
385 | 385 | |
@@ -394,14 +394,14 @@ discard block |
||
394 | 394 | * @param $ext array 扩展数组 |
395 | 395 | * @return array |
396 | 396 | */ |
397 | - public function refundByTransactionId($transaction_id,$out_refund_no,$total_fee,$refund_fee,$ext = array()){ |
|
398 | - $data = ($ext && is_array($ext))?$ext:array(); |
|
397 | + public function refundByTransactionId($transaction_id, $out_refund_no, $total_fee, $refund_fee, $ext = array()) { |
|
398 | + $data = ($ext && is_array($ext)) ? $ext : array(); |
|
399 | 399 | $data["appid"] = $this->config["app_id"]; |
400 | 400 | $data["transaction_id"] = $transaction_id; |
401 | 401 | $data["out_refund_no"] = $out_refund_no; |
402 | 402 | $data["total_fee"] = $total_fee; |
403 | 403 | $data["refund_fee"] = $refund_fee; |
404 | - $result = $this->post(self::URL_REFUND, $data,true); |
|
404 | + $result = $this->post(self::URL_REFUND, $data, true); |
|
405 | 405 | return $result; |
406 | 406 | } |
407 | 407 | |
@@ -411,11 +411,11 @@ discard block |
||
411 | 411 | * @param $out_trade_no string 商户订单号 |
412 | 412 | * @return array |
413 | 413 | */ |
414 | - public function reverseByOutTradeNo($out_trade_no){ |
|
414 | + public function reverseByOutTradeNo($out_trade_no) { |
|
415 | 415 | $data = array(); |
416 | 416 | $data["appid"] = $this->config["app_id"]; |
417 | 417 | $data["out_trade_no"] = $out_trade_no; |
418 | - $result = $this->post(self::URL_REVERSE, $data,true); |
|
418 | + $result = $this->post(self::URL_REVERSE, $data, true); |
|
419 | 419 | return $result; |
420 | 420 | } |
421 | 421 | |
@@ -425,11 +425,11 @@ discard block |
||
425 | 425 | * @param $transaction_id string 微信订单号 |
426 | 426 | * @return array |
427 | 427 | */ |
428 | - public function reverseByTransactionId($transaction_id){ |
|
428 | + public function reverseByTransactionId($transaction_id) { |
|
429 | 429 | $data = array(); |
430 | 430 | $data["appid"] = $this->config["app_id"]; |
431 | 431 | $data["transaction_id"] = $transaction_id; |
432 | - $result = $this->post(self::URL_REVERSE, $data,true); |
|
432 | + $result = $this->post(self::URL_REVERSE, $data, true); |
|
433 | 433 | return $result; |
434 | 434 | } |
435 | 435 | |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | * @param $bill_type string 类型 ALL|SUCCESS |
441 | 441 | * @return array |
442 | 442 | */ |
443 | - public function downloadBill($bill_date,$bill_type = 'ALL'){ |
|
443 | + public function downloadBill($bill_date, $bill_type = 'ALL') { |
|
444 | 444 | $data = array(); |
445 | 445 | $data["appid"] = $this->config["app_id"]; |
446 | 446 | $data["bill_date"] = $bill_date; |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | * @param $tar_type string 压缩账单 |
458 | 458 | * @return array |
459 | 459 | */ |
460 | - public function downloadFundFlow($bill_date,$account_type = self::ACCOUNTTYPE_BASIC,$tar_type = 'GZIP'){ |
|
460 | + public function downloadFundFlow($bill_date, $account_type = self::ACCOUNTTYPE_BASIC, $tar_type = 'GZIP') { |
|
461 | 461 | $data = array(); |
462 | 462 | $data["appid"] = $this->config["app_id"]; |
463 | 463 | $data["bill_date"] = $bill_date; |
@@ -484,14 +484,14 @@ discard block |
||
484 | 484 | * @return array |
485 | 485 | * @throws Exception |
486 | 486 | */ |
487 | - public function sendRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark,$scene_id = '',$riskinfo = '',$consume_mch_id = ''){ |
|
487 | + public function sendRedPack($mch_billno, $send_name, $re_openid, $total_amount, $total_num, $wishing, $act_name, $remark, $scene_id = '', $riskinfo = '', $consume_mch_id = '') { |
|
488 | 488 | $data = array(); |
489 | 489 | $data["wxappid"] = $this->config["app_id"]; |
490 | 490 | $data["mch_billno"] = $mch_billno; |
491 | 491 | $data["send_name"] = $send_name; |
492 | 492 | $data["re_openid"] = $re_openid; |
493 | 493 | $data["total_amount"] = $total_amount; |
494 | - if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000"); |
|
494 | + if ($total_amount > 20000 && trim($scene_id) == '') throw new Exception("scene_id is required when total_amount beyond 20000"); |
|
495 | 495 | $data["total_num"] = $total_num; |
496 | 496 | $data["wishing"] = $wishing; |
497 | 497 | $data["act_name"] = $act_name; |
@@ -520,14 +520,14 @@ discard block |
||
520 | 520 | * @return array |
521 | 521 | * @throws Exception |
522 | 522 | */ |
523 | - public function sendGroupRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark,$scene_id = '',$riskinfo = '',$consume_mch_id = ''){ |
|
523 | + public function sendGroupRedPack($mch_billno, $send_name, $re_openid, $total_amount, $total_num, $wishing, $act_name, $remark, $scene_id = '', $riskinfo = '', $consume_mch_id = '') { |
|
524 | 524 | $data = array(); |
525 | - $data["wxappid"] = $this->config["app_id"];//NOTE: WXappid |
|
525 | + $data["wxappid"] = $this->config["app_id"]; //NOTE: WXappid |
|
526 | 526 | $data["mch_billno"] = $mch_billno; |
527 | 527 | $data["send_name"] = $send_name; |
528 | 528 | $data["re_openid"] = $re_openid; |
529 | 529 | $data["total_amount"] = $total_amount; |
530 | - if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)"); |
|
530 | + if ($total_amount > 20000 && trim($scene_id) == '') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)"); |
|
531 | 531 | $data["total_num"] = $total_num; |
532 | 532 | $data["amt_type"] = 'ALL_RAND'; //红包金额设置方式 ALL_RAND—全部随机 |
533 | 533 | $data["wishing"] = $wishing; |
@@ -547,7 +547,7 @@ discard block |
||
547 | 547 | * @throws Exception |
548 | 548 | * @ref https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_6&index=5 |
549 | 549 | */ |
550 | - public function getHbInfo($mch_billno){ |
|
550 | + public function getHbInfo($mch_billno) { |
|
551 | 551 | $data = array(); |
552 | 552 | $data["mch_billno"] = $mch_billno; |
553 | 553 | $data["appid"] = $this->config["app_id"]; |
@@ -565,14 +565,14 @@ discard block |
||
565 | 565 | * @param int $limit 条数 |
566 | 566 | * @return array |
567 | 567 | */ |
568 | - public function batchQueryComment($begin_time,$end_time,$offset = 0,$limit = 200){ |
|
568 | + public function batchQueryComment($begin_time, $end_time, $offset = 0, $limit = 200) { |
|
569 | 569 | $data = array(); |
570 | 570 | $data["appid"] = $this->config["app_id"]; |
571 | 571 | $data["begin_time"] = $begin_time; |
572 | 572 | $data["end_time"] = $end_time; |
573 | 573 | $data["offset"] = $offset; |
574 | 574 | $data["limit"] = $limit; |
575 | - $data["sign"] = $this->sign($data,WechatPay::SIGNTYPE_HMACSHA256); |
|
575 | + $data["sign"] = $this->sign($data, WechatPay::SIGNTYPE_HMACSHA256); |
|
576 | 576 | $result = $this->post(self::URL_BATCHQUERYCOMMENT, $data, true); //cert is required |
577 | 577 | return $result; |
578 | 578 | } |
@@ -585,21 +585,21 @@ discard block |
||
585 | 585 | */ |
586 | 586 | public function getPackage($prepay_id, $trade_type = WechatPay::TRADETYPE_JSAPI) { |
587 | 587 | $data = array(); |
588 | - if ($trade_type == WechatPay::TRADETYPE_JSAPI){ |
|
588 | + if ($trade_type == WechatPay::TRADETYPE_JSAPI) { |
|
589 | 589 | $data["package"] = "prepay_id=$prepay_id"; |
590 | 590 | $data["timeStamp"] = time(); |
591 | 591 | $data["nonceStr"] = $this->getNonceStr(); |
592 | 592 | $data["appId"] = $this->config["app_id"]; |
593 | 593 | $data["signType"] = "MD5"; |
594 | 594 | $data["paySign"] = $this->sign($data); |
595 | - } else if ($trade_type == WechatPay::TRADETYPE_APP){ |
|
595 | + }else if ($trade_type == WechatPay::TRADETYPE_APP) { |
|
596 | 596 | $data["package"] = "Sign=WXPay"; |
597 | 597 | $data['prepayid'] = $prepay_id; |
598 | 598 | $data['partnerid'] = $this->config["mch_id"]; |
599 | 599 | $data["timestamp"] = time(); |
600 | 600 | $data["noncestr"] = $this->getNonceStr(); |
601 | 601 | $data["appid"] = $this->config["app_id"]; |
602 | - $data["sign"] = $this->sign($data); |
|
602 | + $data["sign"] = $this->sign($data); |
|
603 | 603 | } |
604 | 604 | return $data; |
605 | 605 | } |
@@ -615,15 +615,15 @@ discard block |
||
615 | 615 | * @param array $ext |
616 | 616 | * @return array |
617 | 617 | */ |
618 | - public function microPay($body,$out_trade_no,$total_fee,$spbill_create_ip,$auth_code,$ext = array()){ |
|
619 | - $data = (!empty($ext) && is_array($ext))?$ext:array(); |
|
618 | + public function microPay($body, $out_trade_no, $total_fee, $spbill_create_ip, $auth_code, $ext = array()) { |
|
619 | + $data = (!empty($ext) && is_array($ext)) ? $ext : array(); |
|
620 | 620 | $data["appid"] = $this->config["app_id"]; |
621 | 621 | $data["body"] = $body; |
622 | 622 | $data["out_trade_no"] = $out_trade_no; |
623 | 623 | $data["total_fee"] = $total_fee; |
624 | 624 | $data["spbill_create_ip"] = $spbill_create_ip; |
625 | 625 | $data["auth_code"] = $auth_code; |
626 | - $result = $this->post(self::URL_MICROPAY,$data,false); |
|
626 | + $result = $this->post(self::URL_MICROPAY, $data, false); |
|
627 | 627 | return $result; |
628 | 628 | } |
629 | 629 | |
@@ -634,11 +634,11 @@ discard block |
||
634 | 634 | * @return null |
635 | 635 | * @throws Exception |
636 | 636 | */ |
637 | - public function onPaidNotify($notify_data,callable $callback = null){ |
|
638 | - if(!is_array($notify_data)) $notify_data = $this->xml2array($notify_data); |
|
639 | - if(!$this->validateSign($notify_data)) throw new Exception('Invalid paid notify data'); |
|
640 | - if($callback && is_callable($callback)){ |
|
641 | - return call_user_func_array( $callback , [$notify_data] ); |
|
637 | + public function onPaidNotify($notify_data, callable $callback = null) { |
|
638 | + if (!is_array($notify_data)) $notify_data = $this->xml2array($notify_data); |
|
639 | + if (!$this->validateSign($notify_data)) throw new Exception('Invalid paid notify data'); |
|
640 | + if ($callback && is_callable($callback)) { |
|
641 | + return call_user_func_array($callback, [$notify_data]); |
|
642 | 642 | } |
643 | 643 | } |
644 | 644 | |
@@ -649,11 +649,11 @@ discard block |
||
649 | 649 | * @return mixed |
650 | 650 | * @throws Exception |
651 | 651 | */ |
652 | - public function onRefundedNotify($notify_data,callable $callback = null){ |
|
653 | - if(!is_array($notify_data)) $notify_data = $this->xml2array($notify_data); |
|
654 | - if(!$this->validateSign($notify_data)) throw new Exception('Invalid refund notify data'); |
|
655 | - if($callback && is_callable($callback)){ |
|
656 | - return call_user_func_array( $callback ,[$notify_data] ); |
|
652 | + public function onRefundedNotify($notify_data, callable $callback = null) { |
|
653 | + if (!is_array($notify_data)) $notify_data = $this->xml2array($notify_data); |
|
654 | + if (!$this->validateSign($notify_data)) throw new Exception('Invalid refund notify data'); |
|
655 | + if ($callback && is_callable($callback)) { |
|
656 | + return call_user_func_array($callback, [$notify_data]); |
|
657 | 657 | } |
658 | 658 | } |
659 | 659 | |
@@ -679,13 +679,13 @@ discard block |
||
679 | 679 | * @param bool $print |
680 | 680 | * @return string |
681 | 681 | */ |
682 | - public function responseNotify($print = true,$data = [],$return_code="SUCCESS", $return_msg= 'OK') { |
|
682 | + public function responseNotify($print = true, $data = [], $return_code = "SUCCESS", $return_msg = 'OK') { |
|
683 | 683 | $data["return_code"] = $return_code; |
684 | 684 | if ($return_msg) { |
685 | 685 | $data["return_msg"] = $return_msg; |
686 | 686 | } |
687 | 687 | $xml = $this->array2xml($data); |
688 | - if($print === true) print $xml; |
|
688 | + if ($print === true) print $xml; |
|
689 | 689 | else return $xml; |
690 | 690 | } |
691 | 691 | |
@@ -705,8 +705,8 @@ discard block |
||
705 | 705 | * @param string $err_code_des |
706 | 706 | * @return array |
707 | 707 | */ |
708 | - public function report($interface_url,$execution_time,$return_code,$result_code,$user_ip,$out_trade_no = null,$time = null,$device_info = null, |
|
709 | - $return_msg = null,$err_code = null,$err_code_des = null){ |
|
708 | + public function report($interface_url, $execution_time, $return_code, $result_code, $user_ip, $out_trade_no = null, $time = null, $device_info = null, |
|
709 | + $return_msg = null, $err_code = null, $err_code_des = null) { |
|
710 | 710 | $data = array(); |
711 | 711 | $data["appid"] = $this->config["app_id"]; |
712 | 712 | $data["interface_url"] = $interface_url; |
@@ -714,12 +714,12 @@ discard block |
||
714 | 714 | $data["return_code"] = $return_code; |
715 | 715 | $data["result_code"] = $result_code; |
716 | 716 | $data["user_ip"] = $user_ip; |
717 | - if($out_trade_no) $data["out_trade_no"] = $out_trade_no; |
|
718 | - if($time) $data["time"] = $time; |
|
719 | - if($device_info) $data["device_info"] = $device_info; |
|
720 | - if($return_msg) $data["return_msg"] = $return_msg; |
|
721 | - if($err_code) $data["err_code"] = $err_code; |
|
722 | - if($err_code_des) $data["err_code_des"] = $err_code_des; |
|
717 | + if ($out_trade_no) $data["out_trade_no"] = $out_trade_no; |
|
718 | + if ($time) $data["time"] = $time; |
|
719 | + if ($device_info) $data["device_info"] = $device_info; |
|
720 | + if ($return_msg) $data["return_msg"] = $return_msg; |
|
721 | + if ($err_code) $data["err_code"] = $err_code; |
|
722 | + if ($err_code_des) $data["err_code_des"] = $err_code_des; |
|
723 | 723 | return $this->post(self::URL_REPORT, $data, false); |
724 | 724 | } |
725 | 725 | |
@@ -729,11 +729,11 @@ discard block |
||
729 | 729 | * @param $longurl |
730 | 730 | * @return string |
731 | 731 | */ |
732 | - public function shortUrl($longurl){ |
|
732 | + public function shortUrl($longurl) { |
|
733 | 733 | $data = array(); |
734 | 734 | $data["appid"] = $this->config["app_id"]; |
735 | 735 | $data["long_url"] = $longurl; |
736 | - $result = $this->post(self::URL_SHORTURL,$data,false); |
|
736 | + $result = $this->post(self::URL_SHORTURL, $data, false); |
|
737 | 737 | return $result['short_url']; |
738 | 738 | } |
739 | 739 | |
@@ -743,11 +743,11 @@ discard block |
||
743 | 743 | * @param $auth_code |
744 | 744 | * @return mixed |
745 | 745 | */ |
746 | - public function authCodeToOpenId($auth_code){ |
|
746 | + public function authCodeToOpenId($auth_code) { |
|
747 | 747 | $data = array(); |
748 | 748 | $data["appid"] = $this->config["app_id"]; |
749 | 749 | $data["auth_code"] = $auth_code; |
750 | - $result = $this->post(self::URL_AUTHCODETOOPENID,$data,false); |
|
750 | + $result = $this->post(self::URL_AUTHCODETOOPENID, $data, false); |
|
751 | 751 | return $result['openid']; |
752 | 752 | } |
753 | 753 | |
@@ -764,19 +764,19 @@ discard block |
||
764 | 764 | * @return array |
765 | 765 | * @throws Exception |
766 | 766 | */ |
767 | - public function transferWallet($partner_trade_no,$openid,$amount,$desc,$spbill_create_ip = null,$re_user_name = null,$check_name = WechatPay::CHECKNAME_FORCECHECK){ |
|
767 | + public function transferWallet($partner_trade_no, $openid, $amount, $desc, $spbill_create_ip = null, $re_user_name = null, $check_name = WechatPay::CHECKNAME_FORCECHECK) { |
|
768 | 768 | $data = array(); |
769 | - if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required'); |
|
769 | + if ($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required'); |
|
770 | 770 | $data["mch_appid"] = $this->config["app_id"]; |
771 | 771 | $data["mchid"] = $this->config["mch_id"]; |
772 | 772 | $data["partner_trade_no"] = $partner_trade_no; |
773 | 773 | $data["openid"] = $openid; |
774 | 774 | $data["amount"] = $amount; |
775 | 775 | $data["desc"] = $desc; |
776 | - $data['spbill_create_ip'] = $spbill_create_ip?:$_SERVER['SERVER_ADDR']; |
|
776 | + $data['spbill_create_ip'] = $spbill_create_ip ?: $_SERVER['SERVER_ADDR']; |
|
777 | 777 | $data["check_name"] = $check_name; |
778 | 778 | $data["re_user_name"] = $re_user_name; |
779 | - $result = $this->post(self::URL_TRANSFER_WALLET,$data,true); |
|
779 | + $result = $this->post(self::URL_TRANSFER_WALLET, $data, true); |
|
780 | 780 | return $result; |
781 | 781 | } |
782 | 782 | |
@@ -786,12 +786,12 @@ discard block |
||
786 | 786 | * @param $partner_trade_no |
787 | 787 | * @return array |
788 | 788 | */ |
789 | - public function queryTransferWallet($partner_trade_no){ |
|
789 | + public function queryTransferWallet($partner_trade_no) { |
|
790 | 790 | $data = array(); |
791 | 791 | $data["appid"] = $this->config["app_id"]; |
792 | 792 | $data["mch_id"] = $this->config["mch_id"]; |
793 | 793 | $data["partner_trade_no"] = $partner_trade_no; |
794 | - $result = $this->post(self::URL_QUERY_TRANSFER_WALLET,$data,true); |
|
794 | + $result = $this->post(self::URL_QUERY_TRANSFER_WALLET, $data, true); |
|
795 | 795 | return $result; |
796 | 796 | } |
797 | 797 | |
@@ -807,8 +807,8 @@ discard block |
||
807 | 807 | * @return array |
808 | 808 | * @throws Exception |
809 | 809 | */ |
810 | - public function transferBankCard($partner_trade_no,$bank_no,$true_name,$bank_code,$amount,$desc){ |
|
811 | - if(!in_array($bank_code,array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code: $bank_code"); |
|
810 | + public function transferBankCard($partner_trade_no, $bank_no, $true_name, $bank_code, $amount, $desc) { |
|
811 | + if (!in_array($bank_code, array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code: $bank_code"); |
|
812 | 812 | $data = array(); |
813 | 813 | $data["partner_trade_no"] = $partner_trade_no; |
814 | 814 | $enc_bank_no = $this->rsaEncrypt($bank_no); |
@@ -818,7 +818,7 @@ discard block |
||
818 | 818 | $data["bank_code"] = $bank_code; |
819 | 819 | $data["desc"] = $desc; |
820 | 820 | $data["amount"] = $amount; |
821 | - $result = $this->post(self::URL_TRANSFER_BANKCARD,$data,true); |
|
821 | + $result = $this->post(self::URL_TRANSFER_BANKCARD, $data, true); |
|
822 | 822 | return $result; |
823 | 823 | } |
824 | 824 | |
@@ -828,12 +828,12 @@ discard block |
||
828 | 828 | * @param $partner_trade_no |
829 | 829 | * @return array |
830 | 830 | */ |
831 | - public function queryTransferBankCard($partner_trade_no){ |
|
831 | + public function queryTransferBankCard($partner_trade_no) { |
|
832 | 832 | $data = array(); |
833 | 833 | $data["appid"] = $this->config["app_id"]; |
834 | 834 | $data["mch_id"] = $this->config["mch_id"]; |
835 | 835 | $data["partner_trade_no"] = $partner_trade_no; |
836 | - $result = $this->post(self::URL_QUERY_TRANSFER_WALLET,$data,true); |
|
836 | + $result = $this->post(self::URL_QUERY_TRANSFER_WALLET, $data, true); |
|
837 | 837 | return $result; |
838 | 838 | } |
839 | 839 | |
@@ -847,14 +847,14 @@ discard block |
||
847 | 847 | * @param array $ext |
848 | 848 | * @return array |
849 | 849 | */ |
850 | - public function sendCoupon($coupon_stock_id,$open_id,$partner_trade_no,$op_user_id = '',$ext = array()){ |
|
851 | - $data = (!empty($ext) && is_array($ext))?$ext:array(); |
|
850 | + public function sendCoupon($coupon_stock_id, $open_id, $partner_trade_no, $op_user_id = '', $ext = array()) { |
|
851 | + $data = (!empty($ext) && is_array($ext)) ? $ext : array(); |
|
852 | 852 | $data["partner_trade_no"] = $partner_trade_no; |
853 | 853 | $data["coupon_stock_id"] = $coupon_stock_id; |
854 | 854 | $data["openid_count"] = 1; |
855 | 855 | $data["open_id"] = $open_id; |
856 | 856 | $data["op_user_id"] = $op_user_id; |
857 | - $result = $this->post(self::URL_SEND_COUPON,$data,true); |
|
857 | + $result = $this->post(self::URL_SEND_COUPON, $data, true); |
|
858 | 858 | return $result; |
859 | 859 | } |
860 | 860 | |
@@ -865,11 +865,11 @@ discard block |
||
865 | 865 | * @param string $op_user_id |
866 | 866 | * @return array |
867 | 867 | */ |
868 | - public function queryCouponStock($coupon_stock_id,$op_user_id = ''){ |
|
868 | + public function queryCouponStock($coupon_stock_id, $op_user_id = '') { |
|
869 | 869 | $data = array(); |
870 | 870 | $data["coupon_stock_id"] = $coupon_stock_id; |
871 | 871 | $data["op_user_id"] = $op_user_id; |
872 | - $result = $this->post(self::URL_QUERY_COUPON_STOCK,$data,false); |
|
872 | + $result = $this->post(self::URL_QUERY_COUPON_STOCK, $data, false); |
|
873 | 873 | return $result; |
874 | 874 | } |
875 | 875 | |
@@ -883,13 +883,13 @@ discard block |
||
883 | 883 | * @param array $ext |
884 | 884 | * @return array |
885 | 885 | */ |
886 | - public function queryCouponsInfo($coupon_id,$open_id,$stock_id,$op_user_id = '',$ext = array()){ |
|
887 | - $data = (!empty($ext) && is_array($ext))?$ext:array(); |
|
886 | + public function queryCouponsInfo($coupon_id, $open_id, $stock_id, $op_user_id = '', $ext = array()) { |
|
887 | + $data = (!empty($ext) && is_array($ext)) ? $ext : array(); |
|
888 | 888 | $data["coupon_id"] = $coupon_id; |
889 | 889 | $data["stock_id"] = $stock_id; |
890 | 890 | $data["open_id"] = $open_id; |
891 | 891 | $data["op_user_id"] = $op_user_id; |
892 | - $result = $this->post(self::URL_QUERY_COUPON_INFO,$data,false); |
|
892 | + $result = $this->post(self::URL_QUERY_COUPON_INFO, $data, false); |
|
893 | 893 | return $result; |
894 | 894 | } |
895 | 895 | |
@@ -900,11 +900,11 @@ discard block |
||
900 | 900 | * @return string |
901 | 901 | * @throws Exception |
902 | 902 | */ |
903 | - public function getPublicKey($refresh = false){ |
|
904 | - if(!$this->publicKey) { |
|
903 | + public function getPublicKey($refresh = false) { |
|
904 | + if (!$this->publicKey) { |
|
905 | 905 | if (!$refresh && file_exists($this->config["rsa_pubkey_path"])) { |
906 | 906 | $this->publicKey = file_get_contents($this->config["rsa_pubkey_path"]); |
907 | - }else{ |
|
907 | + }else { |
|
908 | 908 | $data = array(); |
909 | 909 | $data["mch_id"] = $this->config["mch_id"]; |
910 | 910 | $data["sign_type"] = $this->config["sign_type"]; |
@@ -919,24 +919,24 @@ discard block |
||
919 | 919 | return $this->publicKey; |
920 | 920 | } |
921 | 921 | |
922 | - public function setPublicKey($publicKey){ |
|
922 | + public function setPublicKey($publicKey) { |
|
923 | 923 | $this->publicKey = $publicKey; |
924 | 924 | } |
925 | 925 | |
926 | - private function convertPKCS1toPKCS8($pkcs1){ |
|
926 | + private function convertPKCS1toPKCS8($pkcs1) { |
|
927 | 927 | $start_key = $pkcs1; |
928 | 928 | $start_key = str_replace('-----BEGIN RSA PUBLIC KEY-----', '', $start_key); |
929 | 929 | $start_key = trim(str_replace('-----END RSA PUBLIC KEY-----', '', $start_key)); |
930 | - $key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' . str_replace("\n", '', $start_key); |
|
931 | - $key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($key, 64, "\n", true) . "\n-----END PUBLIC KEY-----"; |
|
930 | + $key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A'.str_replace("\n", '', $start_key); |
|
931 | + $key = "-----BEGIN PUBLIC KEY-----\n".wordwrap($key, 64, "\n", true)."\n-----END PUBLIC KEY-----"; |
|
932 | 932 | return $key; |
933 | 933 | } |
934 | 934 | |
935 | - public function rsaEncrypt($data,$pubkey = null){ |
|
936 | - if(!$pubkey) $pubkey = $this->getPublicKey(); |
|
935 | + public function rsaEncrypt($data, $pubkey = null) { |
|
936 | + if (!$pubkey) $pubkey = $this->getPublicKey(); |
|
937 | 937 | $encrypted = null; |
938 | 938 | $pubkey = openssl_get_publickey($pubkey); |
939 | - if (@openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING)) |
|
939 | + if (@openssl_public_encrypt($data, $encrypted, $pubkey, OPENSSL_PKCS1_OAEP_PADDING)) |
|
940 | 940 | $data = base64_encode($encrypted); |
941 | 941 | else |
942 | 942 | throw new Exception('Unable to encrypt data'); |
@@ -948,10 +948,10 @@ discard block |
||
948 | 948 | * @ref https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=23_1 |
949 | 949 | * @return array |
950 | 950 | */ |
951 | - public function getSignKey(){ |
|
951 | + public function getSignKey() { |
|
952 | 952 | $data = array(); |
953 | 953 | $data["mch_id"] = $this->config["mch_id"]; |
954 | - $result = $this->post($this->getSignKeyUrl,$data,false); |
|
954 | + $result = $this->post($this->getSignKeyUrl, $data, false); |
|
955 | 955 | return $result['sandbox_signkey']; |
956 | 956 | } |
957 | 957 | |
@@ -961,8 +961,8 @@ discard block |
||
961 | 961 | * @param string $ticket |
962 | 962 | * @return array |
963 | 963 | */ |
964 | - public function getSignPackage($url, $ticket = null){ |
|
965 | - if(!$ticket) $ticket = $this->getTicket(); |
|
964 | + public function getSignPackage($url, $ticket = null) { |
|
965 | + if (!$ticket) $ticket = $this->getTicket(); |
|
966 | 966 | $timestamp = time(); |
967 | 967 | $nonceStr = $this->getNonceStr(); |
968 | 968 | $rawString = "jsapi_ticket=$ticket&noncestr=$nonceStr×tamp=$timestamp&url=$url"; |
@@ -984,29 +984,29 @@ discard block |
||
984 | 984 | * @param boolean $cache |
985 | 985 | * @return string |
986 | 986 | */ |
987 | - public function getTicket($cache = true){ |
|
987 | + public function getTicket($cache = true) { |
|
988 | 988 | $ticket = null; |
989 | 989 | $cacheKey = 'jsapi_ticket'; |
990 | - if($cache === true){ |
|
990 | + if ($cache === true) { |
|
991 | 991 | $data = $this->cacheProvider->get($cacheKey); |
992 | 992 | if ($data && $data->expires_at > time()) { |
993 | 993 | $ticket = $data->ticket; |
994 | 994 | } |
995 | 995 | } |
996 | - if(!$ticket){ |
|
996 | + if (!$ticket) { |
|
997 | 997 | $data = $this->getWechatOAuth()->getTicket(); |
998 | - if($cache === true){ |
|
999 | - $this->cacheProvider->set($cacheKey,$data,time() + $data->expires_in); |
|
998 | + if ($cache === true) { |
|
999 | + $this->cacheProvider->set($cacheKey, $data, time() + $data->expires_in); |
|
1000 | 1000 | } |
1001 | 1001 | $ticket = $data->ticket; |
1002 | 1002 | } |
1003 | 1003 | return $ticket; |
1004 | 1004 | } |
1005 | 1005 | |
1006 | - private function post($url, $data,$cert = true) { |
|
1007 | - if(!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"]; |
|
1008 | - if(!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr(); |
|
1009 | - if(!isset($data['sign'])) $data['sign'] = $this->sign($data); |
|
1006 | + private function post($url, $data, $cert = true) { |
|
1007 | + if (!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"]; |
|
1008 | + if (!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr(); |
|
1009 | + if (!isset($data['sign'])) $data['sign'] = $this->sign($data); |
|
1010 | 1010 | $this->requestXML = $this->responseXML = null; |
1011 | 1011 | $this->requestArray = $this->responseArray = null; |
1012 | 1012 | |
@@ -1018,23 +1018,23 @@ discard block |
||
1018 | 1018 | CURLOPT_RETURNTRANSFER => true, |
1019 | 1019 | CURLOPT_TIMEOUT => 10 |
1020 | 1020 | ]; |
1021 | - if($cert == true){ |
|
1021 | + if ($cert == true) { |
|
1022 | 1022 | $opts[CURLOPT_SSLCERTTYPE] = 'PEM'; |
1023 | 1023 | $opts[CURLOPT_SSLCERT] = $this->config['ssl_cert_path']; |
1024 | 1024 | $opts[CURLOPT_SSLKEYTYPE] = 'PEM'; |
1025 | 1025 | $opts[CURLOPT_SSLKEY] = $this->config['ssl_key_path']; |
1026 | 1026 | } |
1027 | 1027 | $processResponse = true; |
1028 | - if(in_array($url,[self::URL_DOWNLOADBILL,self::URL_DOWNLOAD_FUND_FLOW,self::URL_BATCHQUERYCOMMENT])){ |
|
1028 | + if (in_array($url, [self::URL_DOWNLOADBILL, self::URL_DOWNLOAD_FUND_FLOW, self::URL_BATCHQUERYCOMMENT])) { |
|
1029 | 1029 | $processResponse = false; |
1030 | 1030 | } |
1031 | - if($this->sandbox === true) $url = "sandboxnew/{$url}"; |
|
1031 | + if ($this->sandbox === true) $url = "sandboxnew/{$url}"; |
|
1032 | 1032 | |
1033 | - $content = $this->httpClient->post(self::API_ENDPOINT . $url,$this->requestXML,[],$opts); |
|
1034 | - if(!$content) throw new Exception("Empty response with {$this->requestXML}"); |
|
1033 | + $content = $this->httpClient->post(self::API_ENDPOINT.$url, $this->requestXML, [], $opts); |
|
1034 | + if (!$content) throw new Exception("Empty response with {$this->requestXML}"); |
|
1035 | 1035 | |
1036 | 1036 | $this->responseXML = $content; |
1037 | - if($processResponse) |
|
1037 | + if ($processResponse) |
|
1038 | 1038 | return $this->processResponseXML($this->responseXML); |
1039 | 1039 | else return $this->responseXML; |
1040 | 1040 | |
@@ -1045,51 +1045,51 @@ discard block |
||
1045 | 1045 | * @return array |
1046 | 1046 | * @throws Exception |
1047 | 1047 | */ |
1048 | - private function processResponseXML($responseXML){ |
|
1048 | + private function processResponseXML($responseXML) { |
|
1049 | 1049 | $result = $this->xml2array($responseXML); |
1050 | 1050 | $this->responseArray = $result; |
1051 | - if(empty($result['return_code'])){ |
|
1051 | + if (empty($result['return_code'])) { |
|
1052 | 1052 | throw new Exception("No return code presents in {$this->responseXML}"); |
1053 | 1053 | } |
1054 | 1054 | $this->returnCode = $result["return_code"]; |
1055 | - $this->returnMsg = isset($result['return_msg'])?$result['return_msg']:''; |
|
1055 | + $this->returnMsg = isset($result['return_msg']) ? $result['return_msg'] : ''; |
|
1056 | 1056 | |
1057 | 1057 | if ($this->returnCode == "SUCCESS") { |
1058 | - if(isset($result['result_code']) && $result['result_code'] == "FAIL"){ |
|
1058 | + if (isset($result['result_code']) && $result['result_code'] == "FAIL") { |
|
1059 | 1059 | $this->resultCode = $result['result_code']; |
1060 | 1060 | $this->errCode = $result['err_code']; |
1061 | 1061 | $this->errCodeDes = $result['err_code_des']; |
1062 | 1062 | throw new Exception("[$this->errCode]$this->errCodeDes"); |
1063 | - }else{ |
|
1063 | + }else { |
|
1064 | 1064 | return $result; |
1065 | 1065 | } |
1066 | - } else if($this->returnCode == 'FAIL'){ |
|
1066 | + }else if ($this->returnCode == 'FAIL') { |
|
1067 | 1067 | throw new Exception($this->returnMsg); |
1068 | 1068 | } |
1069 | 1069 | } |
1070 | 1070 | |
1071 | - public function sign($data,$sign_type = WechatPay::SIGNTYPE_MD5) { |
|
1071 | + public function sign($data, $sign_type = WechatPay::SIGNTYPE_MD5) { |
|
1072 | 1072 | ksort($data); |
1073 | 1073 | $string1 = ""; |
1074 | 1074 | foreach ($data as $k => $v) { |
1075 | - if ($v && trim($v)!='') { |
|
1075 | + if ($v && trim($v) != '') { |
|
1076 | 1076 | $string1 .= "$k=$v&"; |
1077 | 1077 | } |
1078 | 1078 | } |
1079 | - $stringSignTemp = $string1 . "key=" . $this->config["api_key"]; |
|
1080 | - if($sign_type == WechatPay::SIGNTYPE_MD5){ |
|
1079 | + $stringSignTemp = $string1."key=".$this->config["api_key"]; |
|
1080 | + if ($sign_type == WechatPay::SIGNTYPE_MD5) { |
|
1081 | 1081 | $sign = strtoupper(md5($stringSignTemp)); |
1082 | - }elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){ |
|
1083 | - $sign = strtoupper(hash_hmac('sha256',$stringSignTemp,$this->config["api_key"])); |
|
1082 | + }elseif ($sign_type == WechatPay::SIGNTYPE_HMACSHA256) { |
|
1083 | + $sign = strtoupper(hash_hmac('sha256', $stringSignTemp, $this->config["api_key"])); |
|
1084 | 1084 | }else throw new Exception("Not supported sign type - $sign_type"); |
1085 | 1085 | return $sign; |
1086 | 1086 | } |
1087 | 1087 | |
1088 | 1088 | private function array2xml($array) { |
1089 | - $xml = "<xml>" . PHP_EOL; |
|
1089 | + $xml = "<xml>".PHP_EOL; |
|
1090 | 1090 | foreach ($array as $k => $v) { |
1091 | - if($v && trim($v)!='') |
|
1092 | - $xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL; |
|
1091 | + if ($v && trim($v) != '') |
|
1092 | + $xml .= "<$k><![CDATA[$v]]></$k>".PHP_EOL; |
|
1093 | 1093 | } |
1094 | 1094 | $xml .= "</xml>"; |
1095 | 1095 | return $xml; |
@@ -1098,14 +1098,14 @@ discard block |
||
1098 | 1098 | private function xml2array($xml) { |
1099 | 1099 | $array = []; |
1100 | 1100 | $tmp = (array) simplexml_load_string($xml); |
1101 | - foreach ( $tmp as $k => $v) { |
|
1101 | + foreach ($tmp as $k => $v) { |
|
1102 | 1102 | $array[$k] = (string) $v; |
1103 | 1103 | } |
1104 | 1104 | return $array; |
1105 | 1105 | } |
1106 | 1106 | |
1107 | 1107 | private function getNonceStr() { |
1108 | - return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"),0,32); |
|
1108 | + return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"), 0, 32); |
|
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | } |
1112 | 1112 | \ No newline at end of file |
@@ -142,7 +142,9 @@ discard block |
||
142 | 142 | $data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["REMOTE_ADDR"]; |
143 | 143 | $data["notify_url"] = $this->config["notify_url"]; |
144 | 144 | $data["trade_type"] = WechatPay::TRADETYPE_JSAPI; |
145 | - if(!$openid) throw new Exception('openid is required when trade_type is JSAPI'); |
|
145 | + if(!$openid) { |
|
146 | + throw new Exception('openid is required when trade_type is JSAPI'); |
|
147 | + } |
|
146 | 148 | $data["openid"] = $openid; |
147 | 149 | $result = $this->unifiedOrder($data); |
148 | 150 | return $result["prepay_id"]; |
@@ -190,7 +192,9 @@ discard block |
||
190 | 192 | $data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["SERVER_ADDR"]; |
191 | 193 | $data["notify_url"] = $this->config["notify_url"]; |
192 | 194 | $data["trade_type"] = self::TRADETYPE_NATIVE; |
193 | - if(!$product_id) throw new Exception('product_id is required when trade_type is NATIVE'); |
|
195 | + if(!$product_id) { |
|
196 | + throw new Exception('product_id is required when trade_type is NATIVE'); |
|
197 | + } |
|
194 | 198 | $data["product_id"] = $product_id; |
195 | 199 | $result = $this->unifiedOrder($data); |
196 | 200 | return $result["code_url"]; |
@@ -214,7 +218,9 @@ discard block |
||
214 | 218 | $data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:''; |
215 | 219 | $data["notify_url"] = $this->config["notify_url"]; |
216 | 220 | $data["trade_type"] = self::TRADETYPE_MWEB; |
217 | - if(!isset($this->config['h5_scene_info'])) throw new Exception('h5_scene_info should be configured'); |
|
221 | + if(!isset($this->config['h5_scene_info'])) { |
|
222 | + throw new Exception('h5_scene_info should be configured'); |
|
223 | + } |
|
218 | 224 | $data["scene_info"] = json_encode($this->config['h5_scene_info']); |
219 | 225 | $result = $this->unifiedOrder($data); |
220 | 226 | return $result["mweb_url"]; |
@@ -244,11 +250,15 @@ discard block |
||
244 | 250 | $data["notify_url"] = $this->config["notify_url"]; |
245 | 251 | $data["trade_type"] = $params['trade_type']; |
246 | 252 | if($params['trade_type'] == WechatPay::TRADETYPE_NATIVE){ |
247 | - if(!isset($params['product_id'])) throw new Exception('product_id is required when trade_type is NATIVE'); |
|
253 | + if(!isset($params['product_id'])) { |
|
254 | + throw new Exception('product_id is required when trade_type is NATIVE'); |
|
255 | + } |
|
248 | 256 | $data["product_id"] = $params['product_id']; |
249 | 257 | } |
250 | 258 | if($params['trade_type'] == WechatPay::TRADETYPE_JSAPI){ |
251 | - if(!isset($params['openid'])) throw new Exception('openid is required when trade_type is JSAPI'); |
|
259 | + if(!isset($params['openid'])) { |
|
260 | + throw new Exception('openid is required when trade_type is JSAPI'); |
|
261 | + } |
|
252 | 262 | $data["openid"] = $params['openid']; |
253 | 263 | } |
254 | 264 | $result = $this->post(self::URL_UNIFIEDORDER, $data); |
@@ -491,7 +501,9 @@ discard block |
||
491 | 501 | $data["send_name"] = $send_name; |
492 | 502 | $data["re_openid"] = $re_openid; |
493 | 503 | $data["total_amount"] = $total_amount; |
494 | - if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000"); |
|
504 | + if($total_amount > 20000 && trim($scene_id)=='') { |
|
505 | + throw new Exception("scene_id is required when total_amount beyond 20000"); |
|
506 | + } |
|
495 | 507 | $data["total_num"] = $total_num; |
496 | 508 | $data["wishing"] = $wishing; |
497 | 509 | $data["act_name"] = $act_name; |
@@ -527,7 +539,9 @@ discard block |
||
527 | 539 | $data["send_name"] = $send_name; |
528 | 540 | $data["re_openid"] = $re_openid; |
529 | 541 | $data["total_amount"] = $total_amount; |
530 | - if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)"); |
|
542 | + if($total_amount > 20000 && trim($scene_id)=='') { |
|
543 | + throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)"); |
|
544 | + } |
|
531 | 545 | $data["total_num"] = $total_num; |
532 | 546 | $data["amt_type"] = 'ALL_RAND'; //红包金额设置方式 ALL_RAND—全部随机 |
533 | 547 | $data["wishing"] = $wishing; |
@@ -635,8 +649,12 @@ discard block |
||
635 | 649 | * @throws Exception |
636 | 650 | */ |
637 | 651 | public function onPaidNotify($notify_data,callable $callback = null){ |
638 | - if(!is_array($notify_data)) $notify_data = $this->xml2array($notify_data); |
|
639 | - if(!$this->validateSign($notify_data)) throw new Exception('Invalid paid notify data'); |
|
652 | + if(!is_array($notify_data)) { |
|
653 | + $notify_data = $this->xml2array($notify_data); |
|
654 | + } |
|
655 | + if(!$this->validateSign($notify_data)) { |
|
656 | + throw new Exception('Invalid paid notify data'); |
|
657 | + } |
|
640 | 658 | if($callback && is_callable($callback)){ |
641 | 659 | return call_user_func_array( $callback , [$notify_data] ); |
642 | 660 | } |
@@ -650,8 +668,12 @@ discard block |
||
650 | 668 | * @throws Exception |
651 | 669 | */ |
652 | 670 | public function onRefundedNotify($notify_data,callable $callback = null){ |
653 | - if(!is_array($notify_data)) $notify_data = $this->xml2array($notify_data); |
|
654 | - if(!$this->validateSign($notify_data)) throw new Exception('Invalid refund notify data'); |
|
671 | + if(!is_array($notify_data)) { |
|
672 | + $notify_data = $this->xml2array($notify_data); |
|
673 | + } |
|
674 | + if(!$this->validateSign($notify_data)) { |
|
675 | + throw new Exception('Invalid refund notify data'); |
|
676 | + } |
|
655 | 677 | if($callback && is_callable($callback)){ |
656 | 678 | return call_user_func_array( $callback ,[$notify_data] ); |
657 | 679 | } |
@@ -685,8 +707,11 @@ discard block |
||
685 | 707 | $data["return_msg"] = $return_msg; |
686 | 708 | } |
687 | 709 | $xml = $this->array2xml($data); |
688 | - if($print === true) print $xml; |
|
689 | - else return $xml; |
|
710 | + if($print === true) { |
|
711 | + print $xml; |
|
712 | + } else { |
|
713 | + return $xml; |
|
714 | + } |
|
690 | 715 | } |
691 | 716 | |
692 | 717 | /** |
@@ -714,12 +739,24 @@ discard block |
||
714 | 739 | $data["return_code"] = $return_code; |
715 | 740 | $data["result_code"] = $result_code; |
716 | 741 | $data["user_ip"] = $user_ip; |
717 | - if($out_trade_no) $data["out_trade_no"] = $out_trade_no; |
|
718 | - if($time) $data["time"] = $time; |
|
719 | - if($device_info) $data["device_info"] = $device_info; |
|
720 | - if($return_msg) $data["return_msg"] = $return_msg; |
|
721 | - if($err_code) $data["err_code"] = $err_code; |
|
722 | - if($err_code_des) $data["err_code_des"] = $err_code_des; |
|
742 | + if($out_trade_no) { |
|
743 | + $data["out_trade_no"] = $out_trade_no; |
|
744 | + } |
|
745 | + if($time) { |
|
746 | + $data["time"] = $time; |
|
747 | + } |
|
748 | + if($device_info) { |
|
749 | + $data["device_info"] = $device_info; |
|
750 | + } |
|
751 | + if($return_msg) { |
|
752 | + $data["return_msg"] = $return_msg; |
|
753 | + } |
|
754 | + if($err_code) { |
|
755 | + $data["err_code"] = $err_code; |
|
756 | + } |
|
757 | + if($err_code_des) { |
|
758 | + $data["err_code_des"] = $err_code_des; |
|
759 | + } |
|
723 | 760 | return $this->post(self::URL_REPORT, $data, false); |
724 | 761 | } |
725 | 762 | |
@@ -766,7 +803,9 @@ discard block |
||
766 | 803 | */ |
767 | 804 | public function transferWallet($partner_trade_no,$openid,$amount,$desc,$spbill_create_ip = null,$re_user_name = null,$check_name = WechatPay::CHECKNAME_FORCECHECK){ |
768 | 805 | $data = array(); |
769 | - if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required'); |
|
806 | + if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) { |
|
807 | + throw new Exception('Real name is required'); |
|
808 | + } |
|
770 | 809 | $data["mch_appid"] = $this->config["app_id"]; |
771 | 810 | $data["mchid"] = $this->config["mch_id"]; |
772 | 811 | $data["partner_trade_no"] = $partner_trade_no; |
@@ -808,7 +847,9 @@ discard block |
||
808 | 847 | * @throws Exception |
809 | 848 | */ |
810 | 849 | public function transferBankCard($partner_trade_no,$bank_no,$true_name,$bank_code,$amount,$desc){ |
811 | - if(!in_array($bank_code,array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code: $bank_code"); |
|
850 | + if(!in_array($bank_code,array_values(self::$BANKCODE))) { |
|
851 | + throw new Exception("Unsupported bank code: $bank_code"); |
|
852 | + } |
|
812 | 853 | $data = array(); |
813 | 854 | $data["partner_trade_no"] = $partner_trade_no; |
814 | 855 | $enc_bank_no = $this->rsaEncrypt($bank_no); |
@@ -904,7 +945,7 @@ discard block |
||
904 | 945 | if(!$this->publicKey) { |
905 | 946 | if (!$refresh && file_exists($this->config["rsa_pubkey_path"])) { |
906 | 947 | $this->publicKey = file_get_contents($this->config["rsa_pubkey_path"]); |
907 | - }else{ |
|
948 | + } else{ |
|
908 | 949 | $data = array(); |
909 | 950 | $data["mch_id"] = $this->config["mch_id"]; |
910 | 951 | $data["sign_type"] = $this->config["sign_type"]; |
@@ -933,13 +974,16 @@ discard block |
||
933 | 974 | } |
934 | 975 | |
935 | 976 | public function rsaEncrypt($data,$pubkey = null){ |
936 | - if(!$pubkey) $pubkey = $this->getPublicKey(); |
|
977 | + if(!$pubkey) { |
|
978 | + $pubkey = $this->getPublicKey(); |
|
979 | + } |
|
937 | 980 | $encrypted = null; |
938 | 981 | $pubkey = openssl_get_publickey($pubkey); |
939 | - if (@openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING)) |
|
940 | - $data = base64_encode($encrypted); |
|
941 | - else |
|
942 | - throw new Exception('Unable to encrypt data'); |
|
982 | + if (@openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING)) { |
|
983 | + $data = base64_encode($encrypted); |
|
984 | + } else { |
|
985 | + throw new Exception('Unable to encrypt data'); |
|
986 | + } |
|
943 | 987 | return $data; |
944 | 988 | } |
945 | 989 | |
@@ -962,7 +1006,9 @@ discard block |
||
962 | 1006 | * @return array |
963 | 1007 | */ |
964 | 1008 | public function getSignPackage($url, $ticket = null){ |
965 | - if(!$ticket) $ticket = $this->getTicket(); |
|
1009 | + if(!$ticket) { |
|
1010 | + $ticket = $this->getTicket(); |
|
1011 | + } |
|
966 | 1012 | $timestamp = time(); |
967 | 1013 | $nonceStr = $this->getNonceStr(); |
968 | 1014 | $rawString = "jsapi_ticket=$ticket&noncestr=$nonceStr×tamp=$timestamp&url=$url"; |
@@ -1004,9 +1050,15 @@ discard block |
||
1004 | 1050 | } |
1005 | 1051 | |
1006 | 1052 | private function post($url, $data,$cert = true) { |
1007 | - if(!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"]; |
|
1008 | - if(!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr(); |
|
1009 | - if(!isset($data['sign'])) $data['sign'] = $this->sign($data); |
|
1053 | + if(!isset($data['mch_id']) && !isset($data['mchid'])) { |
|
1054 | + $data["mch_id"] = $this->config["mch_id"]; |
|
1055 | + } |
|
1056 | + if(!isset($data['nonce_str'])) { |
|
1057 | + $data["nonce_str"] = $this->getNonceStr(); |
|
1058 | + } |
|
1059 | + if(!isset($data['sign'])) { |
|
1060 | + $data['sign'] = $this->sign($data); |
|
1061 | + } |
|
1010 | 1062 | $this->requestXML = $this->responseXML = null; |
1011 | 1063 | $this->requestArray = $this->responseArray = null; |
1012 | 1064 | |
@@ -1028,15 +1080,21 @@ discard block |
||
1028 | 1080 | if(in_array($url,[self::URL_DOWNLOADBILL,self::URL_DOWNLOAD_FUND_FLOW,self::URL_BATCHQUERYCOMMENT])){ |
1029 | 1081 | $processResponse = false; |
1030 | 1082 | } |
1031 | - if($this->sandbox === true) $url = "sandboxnew/{$url}"; |
|
1083 | + if($this->sandbox === true) { |
|
1084 | + $url = "sandboxnew/{$url}"; |
|
1085 | + } |
|
1032 | 1086 | |
1033 | 1087 | $content = $this->httpClient->post(self::API_ENDPOINT . $url,$this->requestXML,[],$opts); |
1034 | - if(!$content) throw new Exception("Empty response with {$this->requestXML}"); |
|
1088 | + if(!$content) { |
|
1089 | + throw new Exception("Empty response with {$this->requestXML}"); |
|
1090 | + } |
|
1035 | 1091 | |
1036 | 1092 | $this->responseXML = $content; |
1037 | - if($processResponse) |
|
1038 | - return $this->processResponseXML($this->responseXML); |
|
1039 | - else return $this->responseXML; |
|
1093 | + if($processResponse) { |
|
1094 | + return $this->processResponseXML($this->responseXML); |
|
1095 | + } else { |
|
1096 | + return $this->responseXML; |
|
1097 | + } |
|
1040 | 1098 | |
1041 | 1099 | } |
1042 | 1100 | |
@@ -1060,7 +1118,7 @@ discard block |
||
1060 | 1118 | $this->errCode = $result['err_code']; |
1061 | 1119 | $this->errCodeDes = $result['err_code_des']; |
1062 | 1120 | throw new Exception("[$this->errCode]$this->errCodeDes"); |
1063 | - }else{ |
|
1121 | + } else{ |
|
1064 | 1122 | return $result; |
1065 | 1123 | } |
1066 | 1124 | } else if($this->returnCode == 'FAIL'){ |
@@ -1079,17 +1137,20 @@ discard block |
||
1079 | 1137 | $stringSignTemp = $string1 . "key=" . $this->config["api_key"]; |
1080 | 1138 | if($sign_type == WechatPay::SIGNTYPE_MD5){ |
1081 | 1139 | $sign = strtoupper(md5($stringSignTemp)); |
1082 | - }elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){ |
|
1140 | + } elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){ |
|
1083 | 1141 | $sign = strtoupper(hash_hmac('sha256',$stringSignTemp,$this->config["api_key"])); |
1084 | - }else throw new Exception("Not supported sign type - $sign_type"); |
|
1142 | + } else { |
|
1143 | + throw new Exception("Not supported sign type - $sign_type"); |
|
1144 | + } |
|
1085 | 1145 | return $sign; |
1086 | 1146 | } |
1087 | 1147 | |
1088 | 1148 | private function array2xml($array) { |
1089 | 1149 | $xml = "<xml>" . PHP_EOL; |
1090 | 1150 | foreach ($array as $k => $v) { |
1091 | - if($v && trim($v)!='') |
|
1092 | - $xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL; |
|
1151 | + if($v && trim($v)!='') { |
|
1152 | + $xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL; |
|
1153 | + } |
|
1093 | 1154 | } |
1094 | 1155 | $xml .= "</xml>"; |
1095 | 1156 | return $xml; |