Completed
Push — master ( d444bc...935144 )
by Wei
07:33
created
demo/pay-h5.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 //h5支付
4
-require_once __DIR__ . "/autoload.php";
4
+require_once __DIR__."/autoload.php";
5 5
 use zhangv\wechat\WechatPay;
6 6
 
7 7
 $cfg = include './config.php';
Please login to merge, or discard this patch.
demo/paidnotify.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,15 +1,15 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-require_once __DIR__ . "/autoload.php";
3
+require_once __DIR__."/autoload.php";
4 4
 use zhangv\wechat\WechatPay;
5 5
 
6 6
 $xml = file_get_contents("php://input");
7 7
 
8 8
 $cfg = require './config.php';
9 9
 $payment = new WechatPay($cfg);
10
-$payment->onPaidNotify($xml,function($notifydata) use ($payment){
10
+$payment->onPaidNotify($xml, function($notifydata) use ($payment){
11 11
 	//do stuff
12 12
 	print_r($notifydata);
13
-	$payment->responseNotify('SUCCESS','OK');
13
+	$payment->responseNotify('SUCCESS', 'OK');
14 14
 });
15 15
 
Please login to merge, or discard this patch.
src/WechatPay.php 1 patch
Spacing   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -8,10 +8,10 @@  discard block
 block discarded – undo
8 8
 use \Exception;
9 9
 
10 10
 class WechatPay {
11
-	const TRADETYPE_JSAPI = 'JSAPI',TRADETYPE_NATIVE = 'NATIVE',TRADETYPE_APP = 'APP',TRADETYPE_MWEB = 'MWEB';
11
+	const TRADETYPE_JSAPI = 'JSAPI', TRADETYPE_NATIVE = 'NATIVE', TRADETYPE_APP = 'APP', TRADETYPE_MWEB = 'MWEB';
12 12
 	const SIGNTYPE_MD5 = 'MD5', SIGNTYPE_HMACSHA256 = 'HMAC-SHA256';
13
-	const CHECKNAME_FORCECHECK = 'FORCE_CHECK',CHECKNAME_NOCHECK = 'NO_CHECK';
14
-	const ACCOUNTTYPE_BASIC = 'Basic',ACCOUNTTYPE_OPERATION = 'Operation',ACCOUNTTYPE_FEES = 'Fees';
13
+	const CHECKNAME_FORCECHECK = 'FORCE_CHECK', CHECKNAME_NOCHECK = 'NO_CHECK';
14
+	const ACCOUNTTYPE_BASIC = 'Basic', ACCOUNTTYPE_OPERATION = 'Operation', ACCOUNTTYPE_FEES = 'Fees';
15 15
 	/** 支付 */
16 16
 	const URL_UNIFIEDORDER = "https://api.mch.weixin.qq.com/pay/unifiedorder";
17 17
 	const URL_ORDERQUERY = "https://api.mch.weixin.qq.com/pay/orderquery";
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	const URL_GETPUBLICKEY = 'https://fraud.mch.weixin.qq.com/risk/getpublickey';
44 44
 	public static $BANKCODE = ['工商银行' => '1002', '农业银行' => '1005', '中国银行' => '1026', '建设银行' => '1003', '招商银行' => '1001',
45 45
 		'邮储银行' => '1066', '交通银行' => '1020', '浦发银行' => '1004', '民生银行' => '1006', '兴业银行' => '1009', '平安银行' => '1010',
46
-		'中信银行' => '1021', '华夏银行' => '1025', '广发银行' => '1027', '光大银行' => '1022', '北京银行' => '1032', '宁波银行' => '1056',];
46
+		'中信银行' => '1021', '华夏银行' => '1025', '广发银行' => '1027', '光大银行' => '1022', '北京银行' => '1032', '宁波银行' => '1056', ];
47 47
 
48 48
 	public $getSignKeyUrl = "https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey";
49 49
 	public $sandbox = false;
@@ -81,18 +81,18 @@  discard block
 block discarded – undo
81 81
 		$this->httpClient = new HttpClient(5);
82 82
 	}
83 83
 
84
-	public function getWechatOAuth(){
85
-		if(!$this->wechatOAuth){
86
-			$this->wechatOAuth = new WechatOAuth($this->config['app_id'],$this->config['app_secret']);
84
+	public function getWechatOAuth() {
85
+		if (!$this->wechatOAuth) {
86
+			$this->wechatOAuth = new WechatOAuth($this->config['app_id'], $this->config['app_secret']);
87 87
 		}
88 88
 		return $this->wechatOAuth;
89 89
 	}
90 90
 
91
-	public function setConfig($config){
91
+	public function setConfig($config) {
92 92
 		$this->config = $config;
93 93
 	}
94 94
 
95
-	public function setHttpClient($httpClient){
95
+	public function setHttpClient($httpClient) {
96 96
 		$this->httpClient = $httpClient;
97 97
 	}
98 98
 
@@ -108,16 +108,16 @@  discard block
 block discarded – undo
108 108
 	 * @return string
109 109
 	 * @throws \Exception
110 110
 	 */
111
-	public function getPrepayId($body,$out_trade_no,$total_fee,$openid,$spbill_create_ip = null,$ext = null) {
112
-		$data = ($ext && is_array($ext))?$ext:array();
111
+	public function getPrepayId($body, $out_trade_no, $total_fee, $openid, $spbill_create_ip = null, $ext = null) {
112
+		$data = ($ext && is_array($ext)) ? $ext : array();
113 113
 		$data["body"]         = $body;
114 114
 		$data["out_trade_no"] = $out_trade_no;
115 115
 		$data["total_fee"]    = $total_fee;
116
-		$data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["REMOTE_ADDR"];
116
+		$data["spbill_create_ip"] = $spbill_create_ip ?: $_SERVER["REMOTE_ADDR"];
117 117
 		$data["notify_url"]   = $this->config["notify_url"];
118 118
 		$data["trade_type"]   = WechatPay::TRADETYPE_JSAPI;
119
-		if(!$openid) throw new Exception('openid is required when trade_type is JSAPI');
120
-		$data["openid"]   = $openid;
119
+		if (!$openid) throw new Exception('openid is required when trade_type is JSAPI');
120
+		$data["openid"] = $openid;
121 121
 		$result = $this->unifiedOrder($data);
122 122
 		return $result["prepay_id"];
123 123
 	}
@@ -132,8 +132,8 @@  discard block
 block discarded – undo
132 132
 	 * @param $ext array
133 133
 	 * @return string
134 134
 	 */
135
-	public function getPrepayIdAPP($body,$out_trade_no,$total_fee,$spbill_create_ip,$ext = null) {
136
-		$data = ($ext && is_array($ext))?$ext:array();
135
+	public function getPrepayIdAPP($body, $out_trade_no, $total_fee, $spbill_create_ip, $ext = null) {
136
+		$data = ($ext && is_array($ext)) ? $ext : array();
137 137
 		$data["body"]         = $body;
138 138
 		$data["out_trade_no"] = $out_trade_no;
139 139
 		$data["total_fee"]    = $total_fee;
@@ -156,15 +156,15 @@  discard block
 block discarded – undo
156 156
 	 * @return string
157 157
 	 * @throws Exception
158 158
 	 */
159
-	public function getCodeUrl($body,$out_trade_no,$total_fee,$product_id,$spbill_create_ip = null,$ext = null){
160
-		$data = ($ext && is_array($ext))?$ext:array();
159
+	public function getCodeUrl($body, $out_trade_no, $total_fee, $product_id, $spbill_create_ip = null, $ext = null) {
160
+		$data = ($ext && is_array($ext)) ? $ext : array();
161 161
 		$data["body"]         = $body;
162 162
 		$data["out_trade_no"] = $out_trade_no;
163 163
 		$data["total_fee"]    = $total_fee;
164
-		$data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["SERVER_ADDR"];
164
+		$data["spbill_create_ip"] = $spbill_create_ip ?: $_SERVER["SERVER_ADDR"];
165 165
 		$data["notify_url"]   = $this->config["notify_url"];
166 166
 		$data["trade_type"]   = self::TRADETYPE_NATIVE;
167
-		if(!$product_id) throw new Exception('product_id is required when trade_type is NATIVE');
167
+		if (!$product_id) throw new Exception('product_id is required when trade_type is NATIVE');
168 168
 		$data["product_id"]   = $product_id;
169 169
 		$result = $this->unifiedOrder($data);
170 170
 		return $result["code_url"];
@@ -180,15 +180,15 @@  discard block
 block discarded – undo
180 180
 	 * @return string
181 181
 	 * @throws Exception
182 182
 	 */
183
-	public function getMwebUrl($body,$out_trade_no,$total_fee,$ext = null){
184
-		$data = ($ext && is_array($ext))?$ext:array();
183
+	public function getMwebUrl($body, $out_trade_no, $total_fee, $ext = null) {
184
+		$data = ($ext && is_array($ext)) ? $ext : array();
185 185
 		$data["body"]         = $body;
186 186
 		$data["out_trade_no"] = $out_trade_no;
187 187
 		$data["total_fee"]    = $total_fee;
188
-		$data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:'';
188
+		$data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : '';
189 189
 		$data["notify_url"]   = $this->config["notify_url"];
190 190
 		$data["trade_type"]   = self::TRADETYPE_MWEB;
191
-		if(!isset($this->config['h5_scene_info'])) throw new Exception('h5_scene_info should be configured');
191
+		if (!isset($this->config['h5_scene_info'])) throw new Exception('h5_scene_info should be configured');
192 192
 		$data["scene_info"]   = json_encode($this->config['h5_scene_info']);
193 193
 		$result = $this->unifiedOrder($data);
194 194
 		return $result["mweb_url"];
@@ -204,25 +204,25 @@  discard block
 block discarded – undo
204 204
 	public function unifiedOrder($params) {
205 205
 		$data = array();
206 206
 		$data["appid"] = $this->config["app_id"];
207
-		$data["device_info"] = (isset($params['device_info'])&&trim($params['device_info'])!='')?$params['device_info']:null;
207
+		$data["device_info"] = (isset($params['device_info']) && trim($params['device_info']) != '') ? $params['device_info'] : null;
208 208
 		$data["body"] = $params['body'];
209
-		$data["detail"] = isset($params['detail'])?$params['detail']:null;//optional
210
-		$data["attach"] = isset($params['attach'])?$params['attach']:null;//optional
211
-		$data["out_trade_no"] = isset($params['out_trade_no'])?$params['out_trade_no']:null;
212
-		$data["fee_type"] = isset($params['fee_type'])?$params['fee_type']:'CNY';
209
+		$data["detail"] = isset($params['detail']) ? $params['detail'] : null; //optional
210
+		$data["attach"] = isset($params['attach']) ? $params['attach'] : null; //optional
211
+		$data["out_trade_no"] = isset($params['out_trade_no']) ? $params['out_trade_no'] : null;
212
+		$data["fee_type"] = isset($params['fee_type']) ? $params['fee_type'] : 'CNY';
213 213
 		$data["total_fee"]    = $params['total_fee'];
214 214
 		$data["spbill_create_ip"] = $params['spbill_create_ip'];
215
-		$data["time_start"] = isset($params['time_start'])?$params['time_start']:null;//optional
216
-		$data["time_expire"] = isset($params['time_expire'])?$params['time_expire']:null;//optional
217
-		$data["goods_tag"] = isset($params['goods_tag'])?$params['goods_tag']:null;
215
+		$data["time_start"] = isset($params['time_start']) ? $params['time_start'] : null; //optional
216
+		$data["time_expire"] = isset($params['time_expire']) ? $params['time_expire'] : null; //optional
217
+		$data["goods_tag"] = isset($params['goods_tag']) ? $params['goods_tag'] : null;
218 218
 		$data["notify_url"] = $this->config["notify_url"];
219 219
 		$data["trade_type"] = $params['trade_type'];
220
-		if($params['trade_type'] == WechatPay::TRADETYPE_NATIVE){
221
-			if(!isset($params['product_id'])) throw new Exception('product_id is required when trade_type is NATIVE');
220
+		if ($params['trade_type'] == WechatPay::TRADETYPE_NATIVE) {
221
+			if (!isset($params['product_id'])) throw new Exception('product_id is required when trade_type is NATIVE');
222 222
 			$data["product_id"] = $params['product_id'];
223 223
 		}
224
-		if($params['trade_type'] == WechatPay::TRADETYPE_JSAPI){
225
-			if(!isset($params['openid'])) throw new Exception('openid is required when trade_type is JSAPI');
224
+		if ($params['trade_type'] == WechatPay::TRADETYPE_JSAPI) {
225
+			if (!isset($params['openid'])) throw new Exception('openid is required when trade_type is JSAPI');
226 226
 			$data["openid"] = $params['openid'];
227 227
 		}
228 228
 		$result = $this->post(self::URL_UNIFIEDORDER, $data);
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 	 * @param $transaction_id string 微信订单号
236 236
 	 * @return array
237 237
 	 */
238
-	public function queryOrderByTransactionId($transaction_id){
238
+	public function queryOrderByTransactionId($transaction_id) {
239 239
 		$data = array();
240 240
 		$data["appid"] = $this->config["app_id"];
241 241
 		$data["transaction_id"] = $transaction_id;
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 	 * @param $out_trade_no string 商户订单号
250 250
 	 * @return array
251 251
 	 */
252
-	public function queryOrderByOutTradeNo($out_trade_no){
252
+	public function queryOrderByOutTradeNo($out_trade_no) {
253 253
 		$data = array();
254 254
 		$data["appid"] = $this->config["app_id"];
255 255
 		$data["out_trade_no"] = $out_trade_no;
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
 	 * @param $offset int 偏移
265 265
 	 * @return array
266 266
 	 */
267
-	public function queryRefundByTransactionId($transaction_id,$offset = 0){
267
+	public function queryRefundByTransactionId($transaction_id, $offset = 0) {
268 268
 		$data = array();
269 269
 		$data["appid"] = $this->config["app_id"];
270 270
 		$data["transaction_id"] = $transaction_id;
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 	 * @param $offset int 偏移
281 281
 	 * @return array
282 282
 	 */
283
-	public function queryRefundByOutTradeNo($out_trade_no,$offset = 0){
283
+	public function queryRefundByOutTradeNo($out_trade_no, $offset = 0) {
284 284
 		$data = array();
285 285
 		$data["appid"] = $this->config["app_id"];
286 286
 		$data["out_trade_no"] = $out_trade_no;
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
 	 * @param $offset int 偏移
297 297
 	 * @return array
298 298
 	 */
299
-	public function queryRefundByRefundId($refund_id,$offset = 0){
299
+	public function queryRefundByRefundId($refund_id, $offset = 0) {
300 300
 		$data = array();
301 301
 		$data["appid"] = $this->config["app_id"];
302 302
 		$data["refund_id"] = $refund_id;
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
 	 * @param $offset int 偏移
313 313
 	 * @return array
314 314
 	 */
315
-	public function queryRefundByOutRefundNo($out_refund_no,$offset = 0){
315
+	public function queryRefundByOutRefundNo($out_refund_no, $offset = 0) {
316 316
 		$data = array();
317 317
 		$data["appid"] = $this->config["app_id"];
318 318
 		$data["out_refund_no"] = $out_refund_no;
@@ -327,11 +327,11 @@  discard block
 block discarded – undo
327 327
 	 * @param $out_trade_no string 商户订单号
328 328
 	 * @return array
329 329
 	 */
330
-	public function closeOrder($out_trade_no){
330
+	public function closeOrder($out_trade_no) {
331 331
 		$data = array();
332 332
 		$data["appid"] = $this->config["app_id"];
333 333
 		$data["out_trade_no"] = $out_trade_no;
334
-		$result = $this->post(self::URL_CLOSEORDER, $data,false);
334
+		$result = $this->post(self::URL_CLOSEORDER, $data, false);
335 335
 		return $result;
336 336
 	}
337 337
 
@@ -346,14 +346,14 @@  discard block
 block discarded – undo
346 346
 	 * @param $ext array 扩展数组
347 347
 	 * @return array
348 348
 	 */
349
-	public function refundByOutTradeNo($out_trade_no,$out_refund_no,$total_fee,$refund_fee,$ext = array()){
350
-		$data = ($ext && is_array($ext))?$ext:array();
349
+	public function refundByOutTradeNo($out_trade_no, $out_refund_no, $total_fee, $refund_fee, $ext = array()) {
350
+		$data = ($ext && is_array($ext)) ? $ext : array();
351 351
 		$data["appid"] = $this->config["app_id"];
352 352
 		$data["out_trade_no"] = $out_trade_no;
353 353
 		$data["out_refund_no"] = $out_refund_no;
354 354
 		$data["total_fee"] = $total_fee;
355 355
 		$data["refund_fee"] = $refund_fee;
356
-		$result = $this->post(self::URL_REFUND, $data,true);
356
+		$result = $this->post(self::URL_REFUND, $data, true);
357 357
 		return $result;
358 358
 	}
359 359
 
@@ -368,14 +368,14 @@  discard block
 block discarded – undo
368 368
 	 * @param $ext array 扩展数组
369 369
 	 * @return array
370 370
 	 */
371
-	public function refundByTransactionId($transaction_id,$out_refund_no,$total_fee,$refund_fee,$ext = array()){
372
-		$data = ($ext && is_array($ext))?$ext:array();
371
+	public function refundByTransactionId($transaction_id, $out_refund_no, $total_fee, $refund_fee, $ext = array()) {
372
+		$data = ($ext && is_array($ext)) ? $ext : array();
373 373
 		$data["appid"] = $this->config["app_id"];
374 374
 		$data["transaction_id"] = $transaction_id;
375 375
 		$data["out_refund_no"] = $out_refund_no;
376 376
 		$data["total_fee"] = $total_fee;
377 377
 		$data["refund_fee"] = $refund_fee;
378
-		$result = $this->post(self::URL_REFUND, $data,true);
378
+		$result = $this->post(self::URL_REFUND, $data, true);
379 379
 		return $result;
380 380
 	}
381 381
 
@@ -385,11 +385,11 @@  discard block
 block discarded – undo
385 385
 	 * @param $out_trade_no string 商户订单号
386 386
 	 * @return array
387 387
 	 */
388
-	public function reverseByOutTradeNo($out_trade_no){
388
+	public function reverseByOutTradeNo($out_trade_no) {
389 389
 		$data = array();
390 390
 		$data["appid"] = $this->config["app_id"];
391 391
 		$data["out_trade_no"] = $out_trade_no;
392
-		$result = $this->post(self::URL_REVERSE, $data,true);
392
+		$result = $this->post(self::URL_REVERSE, $data, true);
393 393
 		return $result;
394 394
 	}
395 395
 
@@ -399,11 +399,11 @@  discard block
 block discarded – undo
399 399
 	 * @param $transaction_id string 微信订单号
400 400
 	 * @return array
401 401
 	 */
402
-	public function reverseByTransactionId($transaction_id){
402
+	public function reverseByTransactionId($transaction_id) {
403 403
 		$data = array();
404 404
 		$data["appid"] = $this->config["app_id"];
405 405
 		$data["transaction_id"] = $transaction_id;
406
-		$result = $this->post(self::URL_REVERSE, $data,true);
406
+		$result = $this->post(self::URL_REVERSE, $data, true);
407 407
 		return $result;
408 408
 	}
409 409
 
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
 	 * @param $bill_type string 类型 ALL|SUCCESS
415 415
 	 * @return array
416 416
 	 */
417
-	public function downloadBill($bill_date,$bill_type = 'ALL'){
417
+	public function downloadBill($bill_date, $bill_type = 'ALL') {
418 418
 		$data = array();
419 419
 		$data["appid"] = $this->config["app_id"];
420 420
 		$data["bill_date"] = $bill_date;
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
 	 * @param $tar_type string 压缩账单
432 432
 	 * @return array
433 433
 	 */
434
-	public function downloadFundFlow($bill_date,$account_type = self::ACCOUNTTYPE_BASIC,$tar_type = 'GZIP'){
434
+	public function downloadFundFlow($bill_date, $account_type = self::ACCOUNTTYPE_BASIC, $tar_type = 'GZIP') {
435 435
 		$data = array();
436 436
 		$data["appid"] = $this->config["app_id"];
437 437
 		$data["bill_date"] = $bill_date;
@@ -458,14 +458,14 @@  discard block
 block discarded – undo
458 458
 	 * @return array
459 459
 	 * @throws Exception
460 460
 	 */
461
-	public function sendRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark,$scene_id = '',$riskinfo = '',$consume_mch_id = ''){
461
+	public function sendRedPack($mch_billno, $send_name, $re_openid, $total_amount, $total_num, $wishing, $act_name, $remark, $scene_id = '', $riskinfo = '', $consume_mch_id = '') {
462 462
 		$data = array();
463 463
 		$data["wxappid"] = $this->config["app_id"];
464 464
 		$data["mch_billno"] = $mch_billno;
465 465
 		$data["send_name"] = $send_name;
466 466
 		$data["re_openid"] = $re_openid;
467 467
 		$data["total_amount"] = $total_amount;
468
-		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000");
468
+		if ($total_amount > 20000 && trim($scene_id) == '') throw new Exception("scene_id is required when total_amount beyond 20000");
469 469
 		$data["total_num"] = $total_num;
470 470
 		$data["wishing"] = $wishing;
471 471
 		$data["act_name"] = $act_name;
@@ -494,14 +494,14 @@  discard block
 block discarded – undo
494 494
 	 * @return array
495 495
 	 * @throws Exception
496 496
 	 */
497
-	public function sendGroupRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark,$scene_id = '',$riskinfo = '',$consume_mch_id = ''){
497
+	public function sendGroupRedPack($mch_billno, $send_name, $re_openid, $total_amount, $total_num, $wishing, $act_name, $remark, $scene_id = '', $riskinfo = '', $consume_mch_id = '') {
498 498
 		$data = array();
499
-		$data["wxappid"] = $this->config["app_id"];//NOTE: WXappid
499
+		$data["wxappid"] = $this->config["app_id"]; //NOTE: WXappid
500 500
 		$data["mch_billno"] = $mch_billno;
501 501
 		$data["send_name"] = $send_name;
502 502
 		$data["re_openid"] = $re_openid;
503 503
 		$data["total_amount"] = $total_amount;
504
-		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
504
+		if ($total_amount > 20000 && trim($scene_id) == '') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
505 505
 		$data["total_num"] = $total_num;
506 506
 		$data["amt_type"] = 'ALL_RAND'; //红包金额设置方式 ALL_RAND—全部随机
507 507
 		$data["wishing"] = $wishing;
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
 	 * @throws Exception
522 522
 	 * @ref https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_6&index=5
523 523
 	 */
524
-	public function getHbInfo($mch_billno){
524
+	public function getHbInfo($mch_billno) {
525 525
 		$data = array();
526 526
 		$data["mch_billno"] = $mch_billno;
527 527
 		$data["appid"] = $this->config["app_id"];
@@ -538,14 +538,14 @@  discard block
 block discarded – undo
538 538
 	 * @param int $limit 条数
539 539
 	 * @return array
540 540
 	 */
541
-	public function batchQueryComment($begin_time,$end_time,$offset = 0,$limit = 200){
541
+	public function batchQueryComment($begin_time, $end_time, $offset = 0, $limit = 200) {
542 542
 		$data = array();
543 543
 		$data["appid"] = $this->config["app_id"];
544 544
 		$data["begin_time"] = $begin_time;
545 545
 		$data["end_time"] = $end_time;
546 546
 		$data["offset"] = $offset;
547 547
 		$data["limit"] = $limit;
548
-		$data["sign"] = $this->sign($data,WechatPay::SIGNTYPE_HMACSHA256);
548
+		$data["sign"] = $this->sign($data, WechatPay::SIGNTYPE_HMACSHA256);
549 549
 		$result = $this->post(self::URL_BATCHQUERYCOMMENT, $data, true); //cert is required
550 550
 		return $result;
551 551
 	}
@@ -558,21 +558,21 @@  discard block
 block discarded – undo
558 558
 	 */
559 559
 	public function getPackage($prepay_id, $trade_type = WechatPay::TRADETYPE_JSAPI) {
560 560
 		$data = array();
561
-		if ($trade_type == WechatPay::TRADETYPE_JSAPI){
561
+		if ($trade_type == WechatPay::TRADETYPE_JSAPI) {
562 562
 			$data["package"]   = "prepay_id=$prepay_id";
563 563
 			$data["timeStamp"] = time();
564 564
 			$data["nonceStr"]  = $this->getNonceStr();
565 565
 			$data["appId"] = $this->config["app_id"];
566 566
 			$data["signType"]  = "MD5";
567 567
 			$data["paySign"]   = $this->sign($data);
568
-		} else if ($trade_type == WechatPay::TRADETYPE_APP){
568
+		}else if ($trade_type == WechatPay::TRADETYPE_APP) {
569 569
 			$data["package"]   = "Sign=WXPay";
570 570
 			$data['prepayid'] = $prepay_id;
571 571
 			$data['partnerid'] = $this->config["mch_id"];
572 572
 			$data["timestamp"] = time();
573 573
 			$data["noncestr"]  = $this->getNonceStr();
574 574
 			$data["appid"] = $this->config["app_id"];
575
-			$data["sign"]   = $this->sign($data);
575
+			$data["sign"] = $this->sign($data);
576 576
 		}
577 577
 		return $data;
578 578
 	}
@@ -588,15 +588,15 @@  discard block
 block discarded – undo
588 588
 	 * @param array $ext
589 589
 	 * @return array
590 590
 	 */
591
-	public function microPay($body,$out_trade_no,$total_fee,$spbill_create_ip,$auth_code,$ext = array()){
592
-		$data = (!empty($ext) && is_array($ext))?$ext:array();
591
+	public function microPay($body, $out_trade_no, $total_fee, $spbill_create_ip, $auth_code, $ext = array()) {
592
+		$data = (!empty($ext) && is_array($ext)) ? $ext : array();
593 593
 		$data["appid"] = $this->config["app_id"];
594 594
 		$data["body"]         = $body;
595 595
 		$data["out_trade_no"] = $out_trade_no;
596 596
 		$data["total_fee"]    = $total_fee;
597 597
 		$data["spbill_create_ip"] = $spbill_create_ip;
598 598
 		$data["auth_code"] = $auth_code;
599
-		$result = $this->post(self::URL_MICROPAY,$data,false);
599
+		$result = $this->post(self::URL_MICROPAY, $data, false);
600 600
 		return $result;
601 601
 	}
602 602
 
@@ -607,17 +607,17 @@  discard block
 block discarded – undo
607 607
 	 * @return null
608 608
 	 * @throws Exception
609 609
 	 */
610
-	public function onPaidNotify($notify_data,callable $callback = null){
611
-		if(!is_array($notify_data)){
610
+	public function onPaidNotify($notify_data, callable $callback = null) {
611
+		if (!is_array($notify_data)) {
612 612
 			$notify_data = $this->xml2array($notify_data);
613 613
 		}
614
-		if($this->validateSign($notify_data)){
615
-			if($callback && is_callable($callback)){
616
-				return call_user_func_array( $callback , [$notify_data] );
617
-			}else{
614
+		if ($this->validateSign($notify_data)) {
615
+			if ($callback && is_callable($callback)) {
616
+				return call_user_func_array($callback, [$notify_data]);
617
+			}else {
618 618
 				$this->responseNotify();
619 619
 			}
620
-		}else{
620
+		}else {
621 621
 			throw new Exception('Invalid paid notify data');
622 622
 		}
623 623
 	}
@@ -629,17 +629,17 @@  discard block
 block discarded – undo
629 629
 	 * @return mixed
630 630
 	 * @throws Exception
631 631
 	 */
632
-	public function onRefundedNotify($notify_data,callable $callback = null){
633
-		if(!is_array($notify_data)){
632
+	public function onRefundedNotify($notify_data, callable $callback = null) {
633
+		if (!is_array($notify_data)) {
634 634
 			$notify_data = $this->xml2array($notify_data);
635 635
 		}
636
-		if($this->validateSign($notify_data)){
637
-			if($callback && is_callable($callback)){
638
-				return call_user_func_array( $callback , $notify_data );
639
-			}else{
636
+		if ($this->validateSign($notify_data)) {
637
+			if ($callback && is_callable($callback)) {
638
+				return call_user_func_array($callback, $notify_data);
639
+			}else {
640 640
 				$this->responseNotify();
641 641
 			}
642
-		}else{
642
+		}else {
643 643
 			throw new Exception('Invalid refunded notify data');
644 644
 		}
645 645
 	}
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
 	 * @param $return_code string 返回状态码 SUCCESS/FAIL
664 664
 	 * @param $return_msg string 返回信息
665 665
 	 */
666
-	public function responseNotify($return_code="SUCCESS", $return_msg= 'OK') {
666
+	public function responseNotify($return_code = "SUCCESS", $return_msg = 'OK') {
667 667
 		$data = array();
668 668
 		$data["return_code"] = $return_code;
669 669
 		if ($return_msg) {
@@ -689,8 +689,8 @@  discard block
 block discarded – undo
689 689
 	 * @param string $err_code_des
690 690
 	 * @return array
691 691
 	 */
692
-	public function report($interface_url,$execution_time,$return_code,$result_code,$user_ip,$out_trade_no = null,$time = null,$device_info = null,
693
-	                       $return_msg = null,$err_code = null,$err_code_des = null){
692
+	public function report($interface_url, $execution_time, $return_code, $result_code, $user_ip, $out_trade_no = null, $time = null, $device_info = null,
693
+	                       $return_msg = null, $err_code = null, $err_code_des = null) {
694 694
 		$data = array();
695 695
 		$data["appid"] = $this->config["app_id"];
696 696
 		$data["interface_url"] = $interface_url;
@@ -698,12 +698,12 @@  discard block
 block discarded – undo
698 698
 		$data["return_code"] = $return_code;
699 699
 		$data["result_code"] = $result_code;
700 700
 		$data["user_ip"] = $user_ip;
701
-		if($out_trade_no) $data["out_trade_no"] = $out_trade_no;
702
-		if($time) $data["time"] = $time;
703
-		if($device_info) $data["device_info"] = $device_info;
704
-		if($return_msg) $data["return_msg"] = $return_msg;
705
-		if($err_code) $data["err_code"] = $err_code;
706
-		if($err_code_des) $data["err_code_des"] = $err_code_des;
701
+		if ($out_trade_no) $data["out_trade_no"] = $out_trade_no;
702
+		if ($time) $data["time"] = $time;
703
+		if ($device_info) $data["device_info"] = $device_info;
704
+		if ($return_msg) $data["return_msg"] = $return_msg;
705
+		if ($err_code) $data["err_code"] = $err_code;
706
+		if ($err_code_des) $data["err_code_des"] = $err_code_des;
707 707
 		$result = $this->post(self::URL_REPORT, $data, false);
708 708
 		return $result;
709 709
 	}
@@ -714,11 +714,11 @@  discard block
 block discarded – undo
714 714
 	 * @param $longurl
715 715
 	 * @return string
716 716
 	 */
717
-	public function shortUrl($longurl){
717
+	public function shortUrl($longurl) {
718 718
 		$data = array();
719 719
 		$data["appid"] = $this->config["app_id"];
720 720
 		$data["long_url"] = $longurl;
721
-		$result = $this->post(self::URL_SHORTURL,$data,false);
721
+		$result = $this->post(self::URL_SHORTURL, $data, false);
722 722
 		return $result['short_url'];
723 723
 	}
724 724
 
@@ -728,11 +728,11 @@  discard block
 block discarded – undo
728 728
 	 * @param $auth_code
729 729
 	 * @return mixed
730 730
 	 */
731
-	public function authCodeToOpenId($auth_code){
731
+	public function authCodeToOpenId($auth_code) {
732 732
 		$data = array();
733 733
 		$data["appid"] = $this->config["app_id"];
734 734
 		$data["auth_code"] = $auth_code;
735
-		$result = $this->post(self::URL_AUTHCODETOOPENID,$data,false);
735
+		$result = $this->post(self::URL_AUTHCODETOOPENID, $data, false);
736 736
 		return $result['openid'];
737 737
 	}
738 738
 
@@ -749,19 +749,19 @@  discard block
 block discarded – undo
749 749
 	 * @return array
750 750
 	 * @throws Exception
751 751
 	 */
752
-	public function transferWallet($partner_trade_no,$openid,$amount,$desc,$spbill_create_ip = null,$re_user_name = null,$check_name = WechatPay::CHECKNAME_FORCECHECK){
752
+	public function transferWallet($partner_trade_no, $openid, $amount, $desc, $spbill_create_ip = null, $re_user_name = null, $check_name = WechatPay::CHECKNAME_FORCECHECK) {
753 753
 		$data = array();
754
-		if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required');
754
+		if ($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required');
755 755
 		$data["mch_appid"] = $this->config["app_id"];
756 756
 		$data["mchid"] = $this->config["mch_id"];
757 757
 		$data["partner_trade_no"] = $partner_trade_no;
758 758
 		$data["openid"] = $openid;
759 759
 		$data["amount"] = $amount;
760 760
 		$data["desc"] = $desc;
761
-		$data['spbill_create_ip'] = $spbill_create_ip?:$_SERVER['SERVER_ADDR'];
761
+		$data['spbill_create_ip'] = $spbill_create_ip ?: $_SERVER['SERVER_ADDR'];
762 762
 		$data["check_name"] = $check_name;
763 763
 		$data["re_user_name"] = $re_user_name;
764
-		$result = $this->post(self::URL_TRANSFER_WALLET,$data,true);
764
+		$result = $this->post(self::URL_TRANSFER_WALLET, $data, true);
765 765
 		return $result;
766 766
 	}
767 767
 
@@ -771,12 +771,12 @@  discard block
 block discarded – undo
771 771
 	 * @param $partner_trade_no
772 772
 	 * @return array
773 773
 	 */
774
-	public function queryTransferWallet($partner_trade_no){
774
+	public function queryTransferWallet($partner_trade_no) {
775 775
 		$data = array();
776 776
 		$data["appid"] = $this->config["app_id"];
777 777
 		$data["mch_id"] = $this->config["mch_id"];
778 778
 		$data["partner_trade_no"] = $partner_trade_no;
779
-		$result = $this->post(self::URL_QUERY_TRANSFER_WALLET,$data,true);
779
+		$result = $this->post(self::URL_QUERY_TRANSFER_WALLET, $data, true);
780 780
 		return $result;
781 781
 	}
782 782
 
@@ -792,8 +792,8 @@  discard block
 block discarded – undo
792 792
 	 * @return array
793 793
 	 * @throws Exception
794 794
 	 */
795
-	public function transferBankCard($partner_trade_no,$bank_no,$true_name,$bank_code,$amount,$desc){
796
-		if(!in_array($bank_code,array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code: $bank_code");
795
+	public function transferBankCard($partner_trade_no, $bank_no, $true_name, $bank_code, $amount, $desc) {
796
+		if (!in_array($bank_code, array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code: $bank_code");
797 797
 		$data = array();
798 798
 		$data["partner_trade_no"] = $partner_trade_no;
799 799
 		$enc_bank_no = $this->rsaEncrypt($bank_no);
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
 		$data["bank_code"] = $bank_code;
804 804
 		$data["desc"] = $desc;
805 805
 		$data["amount"] = $amount;
806
-		$result = $this->post(self::URL_TRANSFER_BANKCARD,$data,true);
806
+		$result = $this->post(self::URL_TRANSFER_BANKCARD, $data, true);
807 807
 		return $result;
808 808
 	}
809 809
 
@@ -813,12 +813,12 @@  discard block
 block discarded – undo
813 813
 	 * @param $partner_trade_no
814 814
 	 * @return array
815 815
 	 */
816
-	public function queryTransferBankCard($partner_trade_no){
816
+	public function queryTransferBankCard($partner_trade_no) {
817 817
 		$data = array();
818 818
 		$data["appid"] = $this->config["app_id"];
819 819
 		$data["mch_id"] = $this->config["mch_id"];
820 820
 		$data["partner_trade_no"] = $partner_trade_no;
821
-		$result = $this->post(self::URL_QUERY_TRANSFER_WALLET,$data,true);
821
+		$result = $this->post(self::URL_QUERY_TRANSFER_WALLET, $data, true);
822 822
 		return $result;
823 823
 	}
824 824
 
@@ -832,14 +832,14 @@  discard block
 block discarded – undo
832 832
 	 * @param array $ext
833 833
 	 * @return array
834 834
 	 */
835
-	public function sendCoupon($coupon_stock_id,$open_id,$partner_trade_no,$op_user_id = '',$ext = array()){
836
-		$data = (!empty($ext) && is_array($ext))?$ext:array();
835
+	public function sendCoupon($coupon_stock_id, $open_id, $partner_trade_no, $op_user_id = '', $ext = array()) {
836
+		$data = (!empty($ext) && is_array($ext)) ? $ext : array();
837 837
 		$data["partner_trade_no"] = $partner_trade_no;
838 838
 		$data["coupon_stock_id"] = $coupon_stock_id;
839 839
 		$data["openid_count"] = 1;
840 840
 		$data["open_id"] = $open_id;
841 841
 		$data["op_user_id"] = $op_user_id;
842
-		$result = $this->post(self::URL_SEND_COUPON,$data,true);
842
+		$result = $this->post(self::URL_SEND_COUPON, $data, true);
843 843
 		return $result;
844 844
 	}
845 845
 
@@ -850,11 +850,11 @@  discard block
 block discarded – undo
850 850
 	 * @param string $op_user_id
851 851
 	 * @return array
852 852
 	 */
853
-	public function queryCouponStock($coupon_stock_id,$op_user_id = ''){
853
+	public function queryCouponStock($coupon_stock_id, $op_user_id = '') {
854 854
 		$data = array();
855 855
 		$data["coupon_stock_id"] = $coupon_stock_id;
856 856
 		$data["op_user_id"] = $op_user_id;
857
-		$result = $this->post(self::URL_QUERY_COUPON_STOCK,$data,false);
857
+		$result = $this->post(self::URL_QUERY_COUPON_STOCK, $data, false);
858 858
 		return $result;
859 859
 	}
860 860
 
@@ -868,13 +868,13 @@  discard block
 block discarded – undo
868 868
 	 * @param array $ext
869 869
 	 * @return array
870 870
 	 */
871
-	public function queryCouponsInfo($coupon_id,$open_id,$stock_id,$op_user_id = '',$ext = array()){
872
-		$data = (!empty($ext) && is_array($ext))?$ext:array();
871
+	public function queryCouponsInfo($coupon_id, $open_id, $stock_id, $op_user_id = '', $ext = array()) {
872
+		$data = (!empty($ext) && is_array($ext)) ? $ext : array();
873 873
 		$data["coupon_id"] = $coupon_id;
874 874
 		$data["stock_id"] = $stock_id;
875 875
 		$data["open_id"] = $open_id;
876 876
 		$data["op_user_id"] = $op_user_id;
877
-		$result = $this->post(self::URL_QUERY_COUPON_INFO,$data,false);
877
+		$result = $this->post(self::URL_QUERY_COUPON_INFO, $data, false);
878 878
 		return $result;
879 879
 	}
880 880
 
@@ -885,7 +885,7 @@  discard block
 block discarded – undo
885 885
 	 * @return string
886 886
 	 * @throws Exception
887 887
 	 */
888
-	public function getPublicKey($refresh = false){
888
+	public function getPublicKey($refresh = false) {
889 889
 		if (!$refresh && file_exists($this->config["rsa_pubkey_path"])) {
890 890
 			$pubkey = file_get_contents($this->config["rsa_pubkey_path"]);
891 891
 			return $pubkey;
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
 		$data = array();
894 894
 		$data["mch_id"] = $this->config["mch_id"];
895 895
 		$data["sign_type"] = $this->config["sign_type"];
896
-		$result = $this->post(self::URL_GETPUBLICKEY,$data,true);
896
+		$result = $this->post(self::URL_GETPUBLICKEY, $data, true);
897 897
 		$pubkey = $result['pub_key'];
898 898
 		$pubkey = $this->convertPKCS1toPKCS8($pubkey);
899 899
 		$fp = fopen($this->config["rsa_pubkey_path"], "w");
@@ -906,20 +906,20 @@  discard block
 block discarded – undo
906 906
 		}
907 907
 	}
908 908
 
909
-	private function convertPKCS1toPKCS8($pkcs1){
909
+	private function convertPKCS1toPKCS8($pkcs1) {
910 910
 		$start_key = $pkcs1;
911 911
 		$start_key = str_replace('-----BEGIN RSA PUBLIC KEY-----', '', $start_key);
912 912
 		$start_key = trim(str_replace('-----END RSA PUBLIC KEY-----', '', $start_key));
913
-		$key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' . str_replace("\n", '', $start_key);
914
-		$key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($key, 64, "\n", true) . "\n-----END PUBLIC KEY-----";
913
+		$key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A'.str_replace("\n", '', $start_key);
914
+		$key = "-----BEGIN PUBLIC KEY-----\n".wordwrap($key, 64, "\n", true)."\n-----END PUBLIC KEY-----";
915 915
 		return $key;
916 916
 	}
917 917
 
918
-	private function rsaEncrypt($data){
918
+	private function rsaEncrypt($data) {
919 919
 		$pubkey = $this->getPublicKey();
920 920
 		$encrypted = null;
921 921
 		$pubkey = openssl_get_publickey($pubkey);
922
-		if (openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING))
922
+		if (openssl_public_encrypt($data, $encrypted, $pubkey, OPENSSL_PKCS1_OAEP_PADDING))
923 923
 			$data = base64_encode($encrypted);
924 924
 		else
925 925
 			throw new Exception('Unable to encrypt data');
@@ -931,10 +931,10 @@  discard block
 block discarded – undo
931 931
 	 * @ref https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=23_1
932 932
 	 * @return array
933 933
 	 */
934
-	public function getSignKey(){
934
+	public function getSignKey() {
935 935
 		$data = array();
936 936
 		$data["mch_id"] = $this->config["mch_id"];
937
-		$result = $this->post($this->getSignKeyUrl,$data,false);
937
+		$result = $this->post($this->getSignKeyUrl, $data, false);
938 938
 		return $result['sandbox_signkey'];
939 939
 	}
940 940
 
@@ -942,7 +942,7 @@  discard block
 block discarded – undo
942 942
 	 * 获取JSAPI所需要的页面参数
943 943
 	 * @return array
944 944
 	 */
945
-	public function getSignPackage($url){
945
+	public function getSignPackage($url) {
946 946
 		$jsapiTicket = $this->getJSAPITicket();
947 947
 		$timestamp = time();
948 948
 		$nonceStr = $this->getNonceStr();
@@ -964,8 +964,8 @@  discard block
 block discarded – undo
964 964
 	 * 获取JSAPI Ticket
965 965
 	 * @return string
966 966
 	 */
967
-	public function getJSAPITicket(){
968
-		if(isset($this->config['jsapi_ticket']) && file_exists($this->config['jsapi_ticket'])){
967
+	public function getJSAPITicket() {
968
+		if (isset($this->config['jsapi_ticket']) && file_exists($this->config['jsapi_ticket'])) {
969 969
 			$data = json_decode(file_get_contents($this->config['jsapi_ticket']));
970 970
 			if (!$data || $data->expire_time < time()) {
971 971
 				$data = $this->getWechatOAuth()->getTicket();
@@ -978,10 +978,10 @@  discard block
 block discarded – undo
978 978
 		}
979 979
 	}
980 980
 
981
-	private function post($url, $data,$cert = true) {
982
-		if(!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"];
983
-		if(!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr();
984
-		if(!isset($data['sign'])) $data['sign'] = $this->sign($data);
981
+	private function post($url, $data, $cert = true) {
982
+		if (!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"];
983
+		if (!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr();
984
+		if (!isset($data['sign'])) $data['sign'] = $this->sign($data);
985 985
 		$this->requestXML = $this->responseXML = null;
986 986
 		$this->requestArray = $this->responseArray = null;
987 987
 
@@ -993,53 +993,53 @@  discard block
 block discarded – undo
993 993
 			CURLOPT_RETURNTRANSFER => true,
994 994
 			CURLOPT_TIMEOUT => 10
995 995
 		];
996
-		if($cert == true){
996
+		if ($cert == true) {
997 997
 			$opts[CURLOPT_SSLCERTTYPE] = 'PEM';
998 998
 			$opts[CURLOPT_SSLCERT] = $this->config['ssl_cert_path'];
999 999
 			$opts[CURLOPT_SSLKEYTYPE] = 'PEM';
1000 1000
 			$opts[CURLOPT_SSLKEY] = $this->config['ssl_key_path'];
1001 1001
 		}
1002 1002
 		$processResponse = true;
1003
-		if(in_array($url,[self::URL_DOWNLOADBILL,self::URL_DOWNLOAD_FUND_FLOW])){
1003
+		if (in_array($url, [self::URL_DOWNLOADBILL, self::URL_DOWNLOAD_FUND_FLOW])) {
1004 1004
 			$processResponse = false;
1005 1005
 		}
1006
-		if($this->sandbox === true){
1006
+		if ($this->sandbox === true) {
1007 1007
 			$host = "https://api.mch.weixin.qq.com";
1008
-			$url = str_replace($host,'',$url);
1008
+			$url = str_replace($host, '', $url);
1009 1009
 			$url = "{$host}/sandboxnew{$url}";
1010 1010
 		}
1011
-		$content = $this->httpClient->post($url,$this->requestXML,[],$opts);
1012
-		if(!$content) throw new Exception("Empty response with {$this->requestXML}");
1011
+		$content = $this->httpClient->post($url, $this->requestXML, [], $opts);
1012
+		if (!$content) throw new Exception("Empty response with {$this->requestXML}");
1013 1013
 
1014 1014
 		$this->responseXML = $content;
1015
-		if($processResponse)
1015
+		if ($processResponse)
1016 1016
 			return $this->processResponseXML($this->responseXML);
1017 1017
 		else return $this->responseXML;
1018 1018
 
1019 1019
 	}
1020 1020
 
1021
-	private function processResponseXML($responseXML){
1021
+	private function processResponseXML($responseXML) {
1022 1022
 		$result = $this->xml2array($responseXML);
1023 1023
 		$this->responseArray = $result;
1024
-		if(empty($result['return_code'])){
1024
+		if (empty($result['return_code'])) {
1025 1025
 			throw new Exception("No return code presents in {$this->responseXML}");
1026 1026
 		}
1027 1027
 		$this->returnCode = $result["return_code"];
1028
-		$this->returnMsg = isset($result['return_msg'])?$result['return_msg']:'';
1028
+		$this->returnMsg = isset($result['return_msg']) ? $result['return_msg'] : '';
1029 1029
 
1030 1030
 		if ($this->returnCode == "SUCCESS") {
1031
-			if(isset($result['result_code']) && $result['result_code'] == "FAIL"){
1031
+			if (isset($result['result_code']) && $result['result_code'] == "FAIL") {
1032 1032
 				$this->resultCode = $result['result_code'];
1033 1033
 				$this->errCode = $result['err_code'];
1034 1034
 				$this->errCodeDes = $result['err_code_des'];
1035 1035
 				throw new Exception("[$this->errCode]$this->errCodeDes");
1036
-			}else{
1036
+			}else {
1037 1037
 				return $result;
1038 1038
 			}
1039
-		} else {
1040
-			if($result["return_code"] == "FAIL"){
1039
+		}else {
1040
+			if ($result["return_code"] == "FAIL") {
1041 1041
 				throw new Exception($this->returnMsg);
1042
-			}else{
1042
+			}else {
1043 1043
 				$this->resultCode = $result['result_code'];
1044 1044
 				$this->errCode = $result['err_code'];
1045 1045
 				$this->errCodeDes = $result['err_code_des'];
@@ -1048,28 +1048,28 @@  discard block
 block discarded – undo
1048 1048
 		}
1049 1049
 	}
1050 1050
 
1051
-	public function sign($data,$sign_type = WechatPay::SIGNTYPE_MD5) {
1051
+	public function sign($data, $sign_type = WechatPay::SIGNTYPE_MD5) {
1052 1052
 		ksort($data);
1053 1053
 		$string1 = "";
1054 1054
 		foreach ($data as $k => $v) {
1055
-			if ($v && trim($v)!='') {
1055
+			if ($v && trim($v) != '') {
1056 1056
 				$string1 .= "$k=$v&";
1057 1057
 			}
1058 1058
 		}
1059
-		$stringSignTemp = $string1 . "key=" . $this->config["api_key"];
1060
-		if($sign_type == WechatPay::SIGNTYPE_MD5){
1059
+		$stringSignTemp = $string1."key=".$this->config["api_key"];
1060
+		if ($sign_type == WechatPay::SIGNTYPE_MD5) {
1061 1061
 			$sign = strtoupper(md5($stringSignTemp));
1062
-		}elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){
1063
-			$sign = strtoupper(hash_hmac('sha256',$stringSignTemp,$this->config["api_key"]));
1062
+		}elseif ($sign_type == WechatPay::SIGNTYPE_HMACSHA256) {
1063
+			$sign = strtoupper(hash_hmac('sha256', $stringSignTemp, $this->config["api_key"]));
1064 1064
 		}else throw new Exception("Not supported sign type - $sign_type");
1065 1065
 		return $sign;
1066 1066
 	}
1067 1067
 
1068 1068
 	private function array2xml($array) {
1069
-		$xml = "<xml>" . PHP_EOL;
1069
+		$xml = "<xml>".PHP_EOL;
1070 1070
 		foreach ($array as $k => $v) {
1071
-			if($v && trim($v)!='')
1072
-				$xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL;
1071
+			if ($v && trim($v) != '')
1072
+				$xml .= "<$k><![CDATA[$v]]></$k>".PHP_EOL;
1073 1073
 		}
1074 1074
 		$xml .= "</xml>";
1075 1075
 		return $xml;
@@ -1078,19 +1078,19 @@  discard block
 block discarded – undo
1078 1078
 	private function xml2array($xml) {
1079 1079
 		$array = array();
1080 1080
 		$tmp = array();
1081
-		try{
1081
+		try {
1082 1082
 			$tmp = (array) simplexml_load_string($xml);
1083
-		}catch(Exception $e){
1083
+		} catch (Exception $e) {
1084 1084
 			throw $e;
1085 1085
 		}
1086
-		foreach ( $tmp as $k => $v) {
1086
+		foreach ($tmp as $k => $v) {
1087 1087
 			$array[$k] = (string) $v;
1088 1088
 		}
1089 1089
 		return $array;
1090 1090
 	}
1091 1091
 
1092 1092
 	private function getNonceStr() {
1093
-		return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"),0,32);
1093
+		return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"), 0, 32);
1094 1094
 	}
1095 1095
 
1096 1096
 }
1097 1097
\ No newline at end of file
Please login to merge, or discard this patch.