Completed
Push — master ( ec4bbc...f977bb )
by Wei
06:04
created
src/WechatPay.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -655,7 +655,7 @@
 block discarded – undo
655 655
 	 * @return array
656 656
 	 */
657 657
 	public function report($interface_url,$execution_time,$return_code,$result_code,$user_ip,$out_trade_no = null,$time = null,$device_info = null,
658
-	                       $return_msg = null,$err_code = null,$err_code_des = null){
658
+						   $return_msg = null,$err_code = null,$err_code_des = null){
659 659
 		$data = array();
660 660
 		$data["appid"] = $this->config["app_id"];
661 661
 		$data["interface_url"] = $interface_url;
Please login to merge, or discard this patch.
Braces   +72 added lines, -28 removed lines patch added patch discarded remove patch
@@ -187,11 +187,15 @@  discard block
 block discarded – undo
187 187
 		$data["notify_url"] = $this->config["notify_url"];
188 188
 		$data["trade_type"] = $params['trade_type'];
189 189
 		if($params['trade_type'] == WechatPay::TRADETYPE_NATIVE){
190
-			if(!isset($params['product_id'])) throw new Exception('product_id is required when trade_type is NATIVE');
190
+			if(!isset($params['product_id'])) {
191
+				throw new Exception('product_id is required when trade_type is NATIVE');
192
+			}
191 193
 			$data["product_id"] = $params['product_id'];
192 194
 		}
193 195
 		if($params['trade_type'] == WechatPay::TRADETYPE_JSAPI){
194
-			if(!isset($params['openid'])) throw new Exception('openid is required when trade_type is JSAPI');
196
+			if(!isset($params['openid'])) {
197
+				throw new Exception('openid is required when trade_type is JSAPI');
198
+			}
195 199
 			$data["openid"] = $params['openid'];
196 200
 		}
197 201
 		$result = $this->post(self::URL_UNIFIEDORDER, $data);
@@ -411,8 +415,12 @@  discard block
 block discarded – undo
411 415
 	 * @throws Exception
412 416
 	 */
413 417
 	public function onPaidNotify($notify_data,callable $callback = null){
414
-		if(!is_array($notify_data)) $notify_data = $this->xml2array($notify_data);
415
-		if(!$this->validateSign($notify_data)) throw new Exception('Invalid paid notify data');
418
+		if(!is_array($notify_data)) {
419
+			$notify_data = $this->xml2array($notify_data);
420
+		}
421
+		if(!$this->validateSign($notify_data)) {
422
+			throw new Exception('Invalid paid notify data');
423
+		}
416 424
 		if($callback && is_callable($callback)){
417 425
 			return call_user_func_array( $callback , [$notify_data] );
418 426
 		}
@@ -426,8 +434,12 @@  discard block
 block discarded – undo
426 434
 	 * @throws Exception
427 435
 	 */
428 436
 	public function onRefundedNotify($notify_data,callable $callback = null){
429
-		if(!is_array($notify_data)) $notify_data = $this->xml2array($notify_data);
430
-		if(!$this->validateSign($notify_data)) throw new Exception('Invalid refund notify data');
437
+		if(!is_array($notify_data)) {
438
+			$notify_data = $this->xml2array($notify_data);
439
+		}
440
+		if(!$this->validateSign($notify_data)) {
441
+			throw new Exception('Invalid refund notify data');
442
+		}
431 443
 		if($callback && is_callable($callback)){
432 444
 			return call_user_func_array( $callback ,[$notify_data] );
433 445
 		}
@@ -461,8 +473,11 @@  discard block
 block discarded – undo
461 473
 			$data["return_msg"] = $return_msg;
462 474
 		}
463 475
 		$xml = $this->array2xml($data);
464
-		if($print === true) print $xml;
465
-		else return $xml;
476
+		if($print === true) {
477
+			print $xml;
478
+		} else {
479
+			return $xml;
480
+		}
466 481
 	}
467 482
 
468 483
 	/**
@@ -490,12 +505,24 @@  discard block
 block discarded – undo
490 505
 		$data["return_code"] = $return_code;
491 506
 		$data["result_code"] = $result_code;
492 507
 		$data["user_ip"] = $user_ip;
493
-		if($out_trade_no) $data["out_trade_no"] = $out_trade_no;
494
-		if($time) $data["time"] = $time;
495
-		if($device_info) $data["device_info"] = $device_info;
496
-		if($return_msg) $data["return_msg"] = $return_msg;
497
-		if($err_code) $data["err_code"] = $err_code;
498
-		if($err_code_des) $data["err_code_des"] = $err_code_des;
508
+		if($out_trade_no) {
509
+			$data["out_trade_no"] = $out_trade_no;
510
+		}
511
+		if($time) {
512
+			$data["time"] = $time;
513
+		}
514
+		if($device_info) {
515
+			$data["device_info"] = $device_info;
516
+		}
517
+		if($return_msg) {
518
+			$data["return_msg"] = $return_msg;
519
+		}
520
+		if($err_code) {
521
+			$data["err_code"] = $err_code;
522
+		}
523
+		if($err_code_des) {
524
+			$data["err_code_des"] = $err_code_des;
525
+		}
499 526
 		return $this->post(self::URL_REPORT, $data, false);
500 527
 	}
501 528
 
@@ -532,7 +559,9 @@  discard block
 block discarded – undo
532 559
 	 * @return array
533 560
 	 */
534 561
 	public function getSignPackage($url, $ticket = null){
535
-		if(!$ticket) $ticket = $this->getTicket();
562
+		if(!$ticket) {
563
+			$ticket = $this->getTicket();
564
+		}
536 565
 		$timestamp = time();
537 566
 		$nonceStr = $this->getNonceStr();
538 567
 		$rawString = "jsapi_ticket=$ticket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
@@ -574,9 +603,15 @@  discard block
 block discarded – undo
574 603
 	}
575 604
 
576 605
 	protected function post($url, $data,$cert = true) {
577
-		if(!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"];
578
-		if(!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr();
579
-		if(!isset($data['sign'])) $data['sign'] = $this->sign($data);
606
+		if(!isset($data['mch_id']) && !isset($data['mchid'])) {
607
+			$data["mch_id"] = $this->config["mch_id"];
608
+		}
609
+		if(!isset($data['nonce_str'])) {
610
+			$data["nonce_str"] = $this->getNonceStr();
611
+		}
612
+		if(!isset($data['sign'])) {
613
+			$data['sign'] = $this->sign($data);
614
+		}
580 615
 		$this->requestXML = $this->responseXML = null;
581 616
 		$this->requestArray = $this->responseArray = null;
582 617
 
@@ -598,15 +633,21 @@  discard block
 block discarded – undo
598 633
 		if(in_array($url,[self::URL_DOWNLOADBILL,self::URL_DOWNLOAD_FUND_FLOW,self::URL_BATCHQUERYCOMMENT])){
599 634
 			$processResponse = false;
600 635
 		}
601
-		if($this->sandbox === true) $url = "sandboxnew/{$url}";
636
+		if($this->sandbox === true) {
637
+			$url = "sandboxnew/{$url}";
638
+		}
602 639
 
603 640
 		$content = $this->httpClient->post(self::API_ENDPOINT . $url,$this->requestXML,[],$opts);
604
-		if(!$content) throw new Exception("Empty response with {$this->requestXML}");
641
+		if(!$content) {
642
+			throw new Exception("Empty response with {$this->requestXML}");
643
+		}
605 644
 
606 645
 		$this->responseXML = $content;
607
-		if($processResponse)
608
-			return $this->processResponseXML($this->responseXML);
609
-		else return $this->responseXML;
646
+		if($processResponse) {
647
+					return $this->processResponseXML($this->responseXML);
648
+		} else {
649
+			return $this->responseXML;
650
+		}
610 651
 	}
611 652
 
612 653
 	/**
@@ -629,7 +670,7 @@  discard block
 block discarded – undo
629 670
 				$this->errCode = $result['err_code'];
630 671
 				$this->errCodeDes = $result['err_code_des'];
631 672
 				throw new Exception("[$this->errCode]$this->errCodeDes");
632
-			}else{
673
+			} else{
633 674
 				return $result;
634 675
 			}
635 676
 		} else if($this->returnCode == 'FAIL'){
@@ -648,17 +689,20 @@  discard block
 block discarded – undo
648 689
 		$stringSignTemp = $string1 . "key=" . $this->config["api_key"];
649 690
 		if($sign_type == WechatPay::SIGNTYPE_MD5){
650 691
 			$sign = strtoupper(md5($stringSignTemp));
651
-		}elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){
692
+		} elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){
652 693
 			$sign = strtoupper(hash_hmac('sha256',$stringSignTemp,$this->config["api_key"]));
653
-		}else throw new Exception("Not supported sign type - $sign_type");
694
+		} else {
695
+			throw new Exception("Not supported sign type - $sign_type");
696
+		}
654 697
 		return $sign;
655 698
 	}
656 699
 
657 700
 	private function array2xml($array) {
658 701
 		$xml = "<xml>" . PHP_EOL;
659 702
 		foreach ($array as $k => $v) {
660
-			if($v && trim($v)!='')
661
-				$xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL;
703
+			if($v && trim($v)!='') {
704
+							$xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL;
705
+			}
662 706
 		}
663 707
 		$xml .= "</xml>";
664 708
 		return $xml;
Please login to merge, or discard this patch.
Spacing   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -30,10 +30,10 @@  discard block
 block discarded – undo
30 30
  * @method static service\Coupon    Coupon(array $config)
31 31
  */
32 32
 class WechatPay {
33
-	const TRADETYPE_JSAPI = 'JSAPI',TRADETYPE_NATIVE = 'NATIVE',TRADETYPE_APP = 'APP',TRADETYPE_MWEB = 'MWEB';
33
+	const TRADETYPE_JSAPI = 'JSAPI', TRADETYPE_NATIVE = 'NATIVE', TRADETYPE_APP = 'APP', TRADETYPE_MWEB = 'MWEB';
34 34
 	const SIGNTYPE_MD5 = 'MD5', SIGNTYPE_HMACSHA256 = 'HMAC-SHA256';
35
-	const CHECKNAME_FORCECHECK = 'FORCE_CHECK',CHECKNAME_NOCHECK = 'NO_CHECK';
36
-	const ACCOUNTTYPE_BASIC = 'Basic',ACCOUNTTYPE_OPERATION = 'Operation',ACCOUNTTYPE_FEES = 'Fees';
35
+	const CHECKNAME_FORCECHECK = 'FORCE_CHECK', CHECKNAME_NOCHECK = 'NO_CHECK';
36
+	const ACCOUNTTYPE_BASIC = 'Basic', ACCOUNTTYPE_OPERATION = 'Operation', ACCOUNTTYPE_FEES = 'Fees';
37 37
 	const API_ENDPOINT = 'https://api.mch.weixin.qq.com/';
38 38
 	/** 支付 */
39 39
 	const URL_UNIFIEDORDER = 'pay/unifiedorder';
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	 * @return mixed
119 119
 	 */
120 120
 	private static function load($name, $config) {
121
-		$service = __NAMESPACE__ . "\\service\\{$name}";
121
+		$service = __NAMESPACE__."\\service\\{$name}";
122 122
 		return new $service($config);
123 123
 	}
124 124
 
@@ -132,34 +132,34 @@  discard block
 block discarded – undo
132 132
 		return self::load($name, ...$config);
133 133
 	}
134 134
 
135
-	public function setWechatOAuth($wechatOAuth){
135
+	public function setWechatOAuth($wechatOAuth) {
136 136
 		$this->wechatOAuth = $wechatOAuth;
137 137
 	}
138 138
 
139
-	public function getWechatOAuth(){
140
-		if(!$this->wechatOAuth){
141
-			$this->wechatOAuth = new WechatOAuth($this->config['app_id'],$this->config['app_secret']);
139
+	public function getWechatOAuth() {
140
+		if (!$this->wechatOAuth) {
141
+			$this->wechatOAuth = new WechatOAuth($this->config['app_id'], $this->config['app_secret']);
142 142
 		}
143 143
 		return $this->wechatOAuth;
144 144
 	}
145 145
 
146
-	public function setConfig($config){
146
+	public function setConfig($config) {
147 147
 		$this->config = $config;
148 148
 	}
149 149
 
150
-	public function getConfig(){
150
+	public function getConfig() {
151 151
 		return $this->config;
152 152
 	}
153 153
 
154
-	public function setHttpClient($httpClient){
154
+	public function setHttpClient($httpClient) {
155 155
 		$this->httpClient = $httpClient;
156 156
 	}
157 157
 
158
-	public function setCacheProvider($cacheProvider){
158
+	public function setCacheProvider($cacheProvider) {
159 159
 		$this->cacheProvider = $cacheProvider;
160 160
 	}
161 161
 
162
-	public function getCacheProvider(){
162
+	public function getCacheProvider() {
163 163
 		return $this->cacheProvider;
164 164
 	}
165 165
 
@@ -173,25 +173,25 @@  discard block
 block discarded – undo
173 173
 	public function unifiedOrder($params) {
174 174
 		$data = array();
175 175
 		$data["appid"] = $this->config["app_id"];
176
-		$data["device_info"] = (isset($params['device_info'])&&trim($params['device_info'])!='')?$params['device_info']:null;
176
+		$data["device_info"] = (isset($params['device_info']) && trim($params['device_info']) != '') ? $params['device_info'] : null;
177 177
 		$data["body"] = $params['body'];
178
-		$data["detail"] = isset($params['detail'])?$params['detail']:null;//optional
179
-		$data["attach"] = isset($params['attach'])?$params['attach']:null;//optional
180
-		$data["out_trade_no"] = isset($params['out_trade_no'])?$params['out_trade_no']:null;
181
-		$data["fee_type"] = isset($params['fee_type'])?$params['fee_type']:'CNY';
178
+		$data["detail"] = isset($params['detail']) ? $params['detail'] : null; //optional
179
+		$data["attach"] = isset($params['attach']) ? $params['attach'] : null; //optional
180
+		$data["out_trade_no"] = isset($params['out_trade_no']) ? $params['out_trade_no'] : null;
181
+		$data["fee_type"] = isset($params['fee_type']) ? $params['fee_type'] : 'CNY';
182 182
 		$data["total_fee"]    = $params['total_fee'];
183 183
 		$data["spbill_create_ip"] = $params['spbill_create_ip'];
184
-		$data["time_start"] = isset($params['time_start'])?$params['time_start']:null;//optional
185
-		$data["time_expire"] = isset($params['time_expire'])?$params['time_expire']:null;//optional
186
-		$data["goods_tag"] = isset($params['goods_tag'])?$params['goods_tag']:null;
184
+		$data["time_start"] = isset($params['time_start']) ? $params['time_start'] : null; //optional
185
+		$data["time_expire"] = isset($params['time_expire']) ? $params['time_expire'] : null; //optional
186
+		$data["goods_tag"] = isset($params['goods_tag']) ? $params['goods_tag'] : null;
187 187
 		$data["notify_url"] = $this->config["notify_url"];
188 188
 		$data["trade_type"] = $params['trade_type'];
189
-		if($params['trade_type'] == WechatPay::TRADETYPE_NATIVE){
190
-			if(!isset($params['product_id'])) throw new Exception('product_id is required when trade_type is NATIVE');
189
+		if ($params['trade_type'] == WechatPay::TRADETYPE_NATIVE) {
190
+			if (!isset($params['product_id'])) throw new Exception('product_id is required when trade_type is NATIVE');
191 191
 			$data["product_id"] = $params['product_id'];
192 192
 		}
193
-		if($params['trade_type'] == WechatPay::TRADETYPE_JSAPI){
194
-			if(!isset($params['openid'])) throw new Exception('openid is required when trade_type is JSAPI');
193
+		if ($params['trade_type'] == WechatPay::TRADETYPE_JSAPI) {
194
+			if (!isset($params['openid'])) throw new Exception('openid is required when trade_type is JSAPI');
195 195
 			$data["openid"] = $params['openid'];
196 196
 		}
197 197
 		$result = $this->post(self::URL_UNIFIEDORDER, $data);
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 	 * @param $transaction_id string 微信订单号
205 205
 	 * @return array
206 206
 	 */
207
-	public function queryOrderByTransactionId($transaction_id){
207
+	public function queryOrderByTransactionId($transaction_id) {
208 208
 		$data = array();
209 209
 		$data["appid"] = $this->config["app_id"];
210 210
 		$data["transaction_id"] = $transaction_id;
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 	 * @param $out_trade_no string 商户订单号
219 219
 	 * @return array
220 220
 	 */
221
-	public function queryOrderByOutTradeNo($out_trade_no){
221
+	public function queryOrderByOutTradeNo($out_trade_no) {
222 222
 		$data = array();
223 223
 		$data["appid"] = $this->config["app_id"];
224 224
 		$data["out_trade_no"] = $out_trade_no;
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 	 * @param $offset int 偏移
234 234
 	 * @return array
235 235
 	 */
236
-	public function queryRefundByTransactionId($transaction_id,$offset = 0){
236
+	public function queryRefundByTransactionId($transaction_id, $offset = 0) {
237 237
 		$data = array();
238 238
 		$data["appid"] = $this->config["app_id"];
239 239
 		$data["transaction_id"] = $transaction_id;
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 	 * @param $offset int 偏移
250 250
 	 * @return array
251 251
 	 */
252
-	public function queryRefundByOutTradeNo($out_trade_no,$offset = 0){
252
+	public function queryRefundByOutTradeNo($out_trade_no, $offset = 0) {
253 253
 		$data = array();
254 254
 		$data["appid"] = $this->config["app_id"];
255 255
 		$data["out_trade_no"] = $out_trade_no;
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 	 * @param $offset int 偏移
266 266
 	 * @return array
267 267
 	 */
268
-	public function queryRefundByRefundId($refund_id,$offset = 0){
268
+	public function queryRefundByRefundId($refund_id, $offset = 0) {
269 269
 		$data = array();
270 270
 		$data["appid"] = $this->config["app_id"];
271 271
 		$data["refund_id"] = $refund_id;
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 	 * @param $offset int 偏移
282 282
 	 * @return array
283 283
 	 */
284
-	public function queryRefundByOutRefundNo($out_refund_no,$offset = 0){
284
+	public function queryRefundByOutRefundNo($out_refund_no, $offset = 0) {
285 285
 		$data = array();
286 286
 		$data["appid"] = $this->config["app_id"];
287 287
 		$data["out_refund_no"] = $out_refund_no;
@@ -296,11 +296,11 @@  discard block
 block discarded – undo
296 296
 	 * @param $out_trade_no string 商户订单号
297 297
 	 * @return array
298 298
 	 */
299
-	public function closeOrder($out_trade_no){
299
+	public function closeOrder($out_trade_no) {
300 300
 		$data = array();
301 301
 		$data["appid"] = $this->config["app_id"];
302 302
 		$data["out_trade_no"] = $out_trade_no;
303
-		$result = $this->post(self::URL_CLOSEORDER, $data,false);
303
+		$result = $this->post(self::URL_CLOSEORDER, $data, false);
304 304
 		return $result;
305 305
 	}
306 306
 
@@ -315,14 +315,14 @@  discard block
 block discarded – undo
315 315
 	 * @param $ext array 扩展数组
316 316
 	 * @return array
317 317
 	 */
318
-	public function refundByOutTradeNo($out_trade_no,$out_refund_no,$total_fee,$refund_fee,$ext = array()){
319
-		$data = ($ext && is_array($ext))?$ext:array();
318
+	public function refundByOutTradeNo($out_trade_no, $out_refund_no, $total_fee, $refund_fee, $ext = array()) {
319
+		$data = ($ext && is_array($ext)) ? $ext : array();
320 320
 		$data["appid"] = $this->config["app_id"];
321 321
 		$data["out_trade_no"] = $out_trade_no;
322 322
 		$data["out_refund_no"] = $out_refund_no;
323 323
 		$data["total_fee"] = $total_fee;
324 324
 		$data["refund_fee"] = $refund_fee;
325
-		$result = $this->post(self::URL_REFUND, $data,true);
325
+		$result = $this->post(self::URL_REFUND, $data, true);
326 326
 		return $result;
327 327
 	}
328 328
 
@@ -335,14 +335,14 @@  discard block
 block discarded – undo
335 335
 	 * @param $ext array 扩展数组
336 336
 	 * @return array
337 337
 	 */
338
-	public function refundByTransactionId($transaction_id,$out_refund_no,$total_fee,$refund_fee,$ext = array()){
339
-		$data = ($ext && is_array($ext))?$ext:array();
338
+	public function refundByTransactionId($transaction_id, $out_refund_no, $total_fee, $refund_fee, $ext = array()) {
339
+		$data = ($ext && is_array($ext)) ? $ext : array();
340 340
 		$data["appid"] = $this->config["app_id"];
341 341
 		$data["transaction_id"] = $transaction_id;
342 342
 		$data["out_refund_no"] = $out_refund_no;
343 343
 		$data["total_fee"] = $total_fee;
344 344
 		$data["refund_fee"] = $refund_fee;
345
-		$result = $this->post(self::URL_REFUND, $data,true);
345
+		$result = $this->post(self::URL_REFUND, $data, true);
346 346
 		return $result;
347 347
 	}
348 348
 
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 	 * @param $bill_type string 类型 ALL|SUCCESS
354 354
 	 * @return array
355 355
 	 */
356
-	public function downloadBill($bill_date,$bill_type = 'ALL'){
356
+	public function downloadBill($bill_date, $bill_type = 'ALL') {
357 357
 		$data = array();
358 358
 		$data["appid"] = $this->config["app_id"];
359 359
 		$data["bill_date"] = $bill_date;
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 	 * @param $tar_type string 压缩账单
371 371
 	 * @return array
372 372
 	 */
373
-	public function downloadFundFlow($bill_date,$account_type = self::ACCOUNTTYPE_BASIC,$tar_type = 'GZIP'){
373
+	public function downloadFundFlow($bill_date, $account_type = self::ACCOUNTTYPE_BASIC, $tar_type = 'GZIP') {
374 374
 		$data = array();
375 375
 		$data["appid"] = $this->config["app_id"];
376 376
 		$data["bill_date"] = $bill_date;
@@ -389,14 +389,14 @@  discard block
 block discarded – undo
389 389
 	 * @param int $limit 条数
390 390
 	 * @return array
391 391
 	 */
392
-	public function batchQueryComment($begin_time,$end_time,$offset = 0,$limit = 200){
392
+	public function batchQueryComment($begin_time, $end_time, $offset = 0, $limit = 200) {
393 393
 		$data = array();
394 394
 		$data["appid"] = $this->config["app_id"];
395 395
 		$data["begin_time"] = $begin_time;
396 396
 		$data["end_time"] = $end_time;
397 397
 		$data["offset"] = $offset;
398 398
 		$data["limit"] = $limit;
399
-		$data["sign"] = $this->sign($data,WechatPay::SIGNTYPE_HMACSHA256);
399
+		$data["sign"] = $this->sign($data, WechatPay::SIGNTYPE_HMACSHA256);
400 400
 		$result = $this->post(self::URL_BATCHQUERYCOMMENT, $data, true); //cert is required
401 401
 		return $result;
402 402
 	}
@@ -408,11 +408,11 @@  discard block
 block discarded – undo
408 408
 	 * @return null
409 409
 	 * @throws Exception
410 410
 	 */
411
-	public function onPaidNotify($notify_data,callable $callback = null){
412
-		if(!is_array($notify_data)) $notify_data = $this->xml2array($notify_data);
413
-		if(!$this->validateSign($notify_data)) throw new Exception('Invalid paid notify data');
414
-		if($callback && is_callable($callback)){
415
-			return call_user_func_array( $callback , [$notify_data] );
411
+	public function onPaidNotify($notify_data, callable $callback = null) {
412
+		if (!is_array($notify_data)) $notify_data = $this->xml2array($notify_data);
413
+		if (!$this->validateSign($notify_data)) throw new Exception('Invalid paid notify data');
414
+		if ($callback && is_callable($callback)) {
415
+			return call_user_func_array($callback, [$notify_data]);
416 416
 		}
417 417
 	}
418 418
 
@@ -423,11 +423,11 @@  discard block
 block discarded – undo
423 423
 	 * @return mixed
424 424
 	 * @throws Exception
425 425
 	 */
426
-	public function onRefundedNotify($notify_data,callable $callback = null){
427
-		if(!is_array($notify_data)) $notify_data = $this->xml2array($notify_data);
428
-		if(!$this->validateSign($notify_data)) throw new Exception('Invalid refund notify data');
429
-		if($callback && is_callable($callback)){
430
-			return call_user_func_array( $callback ,[$notify_data] );
426
+	public function onRefundedNotify($notify_data, callable $callback = null) {
427
+		if (!is_array($notify_data)) $notify_data = $this->xml2array($notify_data);
428
+		if (!$this->validateSign($notify_data)) throw new Exception('Invalid refund notify data');
429
+		if ($callback && is_callable($callback)) {
430
+			return call_user_func_array($callback, [$notify_data]);
431 431
 		}
432 432
 	}
433 433
 
@@ -453,13 +453,13 @@  discard block
 block discarded – undo
453 453
 	 * @param bool $print
454 454
 	 * @return string
455 455
 	 */
456
-	public function responseNotify($print = true,$data = [],$return_code="SUCCESS", $return_msg= 'OK') {
456
+	public function responseNotify($print = true, $data = [], $return_code = "SUCCESS", $return_msg = 'OK') {
457 457
 		$data["return_code"] = $return_code;
458 458
 		if ($return_msg) {
459 459
 			$data["return_msg"] = $return_msg;
460 460
 		}
461 461
 		$xml = $this->array2xml($data);
462
-		if($print === true) print $xml;
462
+		if ($print === true) print $xml;
463 463
 		else return $xml;
464 464
 	}
465 465
 
@@ -479,8 +479,8 @@  discard block
 block discarded – undo
479 479
 	 * @param string $err_code_des
480 480
 	 * @return array
481 481
 	 */
482
-	public function report($interface_url,$execution_time,$return_code,$result_code,$user_ip,$out_trade_no = null,$time = null,$device_info = null,
483
-	                       $return_msg = null,$err_code = null,$err_code_des = null){
482
+	public function report($interface_url, $execution_time, $return_code, $result_code, $user_ip, $out_trade_no = null, $time = null, $device_info = null,
483
+	                       $return_msg = null, $err_code = null, $err_code_des = null) {
484 484
 		$data = array();
485 485
 		$data["appid"] = $this->config["app_id"];
486 486
 		$data["interface_url"] = $interface_url;
@@ -488,12 +488,12 @@  discard block
 block discarded – undo
488 488
 		$data["return_code"] = $return_code;
489 489
 		$data["result_code"] = $result_code;
490 490
 		$data["user_ip"] = $user_ip;
491
-		if($out_trade_no) $data["out_trade_no"] = $out_trade_no;
492
-		if($time) $data["time"] = $time;
493
-		if($device_info) $data["device_info"] = $device_info;
494
-		if($return_msg) $data["return_msg"] = $return_msg;
495
-		if($err_code) $data["err_code"] = $err_code;
496
-		if($err_code_des) $data["err_code_des"] = $err_code_des;
491
+		if ($out_trade_no) $data["out_trade_no"] = $out_trade_no;
492
+		if ($time) $data["time"] = $time;
493
+		if ($device_info) $data["device_info"] = $device_info;
494
+		if ($return_msg) $data["return_msg"] = $return_msg;
495
+		if ($err_code) $data["err_code"] = $err_code;
496
+		if ($err_code_des) $data["err_code_des"] = $err_code_des;
497 497
 		return $this->post(self::URL_REPORT, $data, false);
498 498
 	}
499 499
 
@@ -503,11 +503,11 @@  discard block
 block discarded – undo
503 503
 	 * @param $longurl
504 504
 	 * @return string
505 505
 	 */
506
-	public function shortUrl($longurl){
506
+	public function shortUrl($longurl) {
507 507
 		$data = array();
508 508
 		$data["appid"] = $this->config["app_id"];
509 509
 		$data["long_url"] = $longurl;
510
-		$result = $this->post(self::URL_SHORTURL,$data,false);
510
+		$result = $this->post(self::URL_SHORTURL, $data, false);
511 511
 		return $result['short_url'];
512 512
 	}
513 513
 
@@ -516,10 +516,10 @@  discard block
 block discarded – undo
516 516
 	 * @link https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=23_1
517 517
 	 * @return array
518 518
 	 */
519
-	public function getSignKey(){
519
+	public function getSignKey() {
520 520
 		$data = array();
521 521
 		$data["mch_id"] = $this->config["mch_id"];
522
-		$result = $this->post($this->getSignKeyUrl,$data,false);
522
+		$result = $this->post($this->getSignKeyUrl, $data, false);
523 523
 		return $result['sandbox_signkey'];
524 524
 	}
525 525
 
@@ -529,8 +529,8 @@  discard block
 block discarded – undo
529 529
 	 * @param string $ticket
530 530
 	 * @return array
531 531
 	 */
532
-	public function getSignPackage($url, $ticket = null){
533
-		if(!$ticket) $ticket = $this->getTicket();
532
+	public function getSignPackage($url, $ticket = null) {
533
+		if (!$ticket) $ticket = $this->getTicket();
534 534
 		$timestamp = time();
535 535
 		$nonceStr = $this->getNonceStr();
536 536
 		$rawString = "jsapi_ticket=$ticket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
@@ -552,29 +552,29 @@  discard block
 block discarded – undo
552 552
 	 * @param boolean $cache
553 553
 	 * @return string
554 554
 	 */
555
-	public function getTicket($cache = true){
555
+	public function getTicket($cache = true) {
556 556
 		$ticket = null;
557 557
 		$cacheKey = 'jsapi_ticket';
558
-		if($cache === true){
558
+		if ($cache === true) {
559 559
 			$data = $this->cacheProvider->get($cacheKey);
560 560
 			if ($data && $data->expires_at > time()) {
561 561
 				$ticket = $data->ticket;
562 562
 			}
563 563
 		}
564
-		if(!$ticket){
564
+		if (!$ticket) {
565 565
 			$data = $this->getWechatOAuth()->getTicket();
566
-			if($cache === true){
567
-				$this->cacheProvider->set($cacheKey,$data,time() + $data->expires_in);
566
+			if ($cache === true) {
567
+				$this->cacheProvider->set($cacheKey, $data, time() + $data->expires_in);
568 568
 			}
569 569
 			$ticket = $data->ticket;
570 570
 		}
571 571
 		return $ticket;
572 572
 	}
573 573
 
574
-	protected function post($url, $data,$cert = true) {
575
-		if(!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"];
576
-		if(!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr();
577
-		if(!isset($data['sign'])) $data['sign'] = $this->sign($data);
574
+	protected function post($url, $data, $cert = true) {
575
+		if (!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"];
576
+		if (!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr();
577
+		if (!isset($data['sign'])) $data['sign'] = $this->sign($data);
578 578
 		$this->requestXML = $this->responseXML = null;
579 579
 		$this->requestArray = $this->responseArray = null;
580 580
 
@@ -586,23 +586,23 @@  discard block
 block discarded – undo
586 586
 			CURLOPT_RETURNTRANSFER => true,
587 587
 			CURLOPT_TIMEOUT => 10
588 588
 		];
589
-		if($cert == true){
589
+		if ($cert == true) {
590 590
 			$opts[CURLOPT_SSLCERTTYPE] = 'PEM';
591 591
 			$opts[CURLOPT_SSLCERT] = $this->config['ssl_cert_path'];
592 592
 			$opts[CURLOPT_SSLKEYTYPE] = 'PEM';
593 593
 			$opts[CURLOPT_SSLKEY] = $this->config['ssl_key_path'];
594 594
 		}
595 595
 		$processResponse = true;
596
-		if(in_array($url,[self::URL_DOWNLOADBILL,self::URL_DOWNLOAD_FUND_FLOW,self::URL_BATCHQUERYCOMMENT])){
596
+		if (in_array($url, [self::URL_DOWNLOADBILL, self::URL_DOWNLOAD_FUND_FLOW, self::URL_BATCHQUERYCOMMENT])) {
597 597
 			$processResponse = false;
598 598
 		}
599
-		if($this->sandbox === true) $url = "sandboxnew/{$url}";
599
+		if ($this->sandbox === true) $url = "sandboxnew/{$url}";
600 600
 
601
-		$content = $this->httpClient->post(self::API_ENDPOINT . $url,$this->requestXML,[],$opts);
602
-		if(!$content) throw new Exception("Empty response with {$this->requestXML}");
601
+		$content = $this->httpClient->post(self::API_ENDPOINT.$url, $this->requestXML, [], $opts);
602
+		if (!$content) throw new Exception("Empty response with {$this->requestXML}");
603 603
 
604 604
 		$this->responseXML = $content;
605
-		if($processResponse)
605
+		if ($processResponse)
606 606
 			return $this->processResponseXML($this->responseXML);
607 607
 		else return $this->responseXML;
608 608
 	}
@@ -612,51 +612,51 @@  discard block
 block discarded – undo
612 612
 	 * @return array
613 613
 	 * @throws Exception
614 614
 	 */
615
-	private function processResponseXML($responseXML){
615
+	private function processResponseXML($responseXML) {
616 616
 		$result = $this->xml2array($responseXML);
617 617
 		$this->responseArray = $result;
618
-		if(empty($result['return_code'])){
618
+		if (empty($result['return_code'])) {
619 619
 			throw new Exception("No return code presents in {$this->responseXML}");
620 620
 		}
621 621
 		$this->returnCode = $result["return_code"];
622
-		$this->returnMsg = isset($result['return_msg'])?$result['return_msg']:'';
622
+		$this->returnMsg = isset($result['return_msg']) ? $result['return_msg'] : '';
623 623
 
624 624
 		if ($this->returnCode == "SUCCESS") {
625
-			if(isset($result['result_code']) && $result['result_code'] == "FAIL"){
625
+			if (isset($result['result_code']) && $result['result_code'] == "FAIL") {
626 626
 				$this->resultCode = $result['result_code'];
627 627
 				$this->errCode = $result['err_code'];
628 628
 				$this->errCodeDes = $result['err_code_des'];
629 629
 				throw new Exception("[$this->errCode]$this->errCodeDes");
630
-			}else{
630
+			}else {
631 631
 				return $result;
632 632
 			}
633
-		} else if($this->returnCode == 'FAIL'){
633
+		}else if ($this->returnCode == 'FAIL') {
634 634
 			throw new Exception($this->returnMsg);
635 635
 		}
636 636
 	}
637 637
 
638
-	public function sign($data,$sign_type = WechatPay::SIGNTYPE_MD5) {
638
+	public function sign($data, $sign_type = WechatPay::SIGNTYPE_MD5) {
639 639
 		ksort($data);
640 640
 		$string1 = "";
641 641
 		foreach ($data as $k => $v) {
642
-			if ($v && trim($v)!='') {
642
+			if ($v && trim($v) != '') {
643 643
 				$string1 .= "$k=$v&";
644 644
 			}
645 645
 		}
646
-		$stringSignTemp = $string1 . "key=" . $this->config["api_key"];
647
-		if($sign_type == WechatPay::SIGNTYPE_MD5){
646
+		$stringSignTemp = $string1."key=".$this->config["api_key"];
647
+		if ($sign_type == WechatPay::SIGNTYPE_MD5) {
648 648
 			$sign = strtoupper(md5($stringSignTemp));
649
-		}elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){
650
-			$sign = strtoupper(hash_hmac('sha256',$stringSignTemp,$this->config["api_key"]));
649
+		}elseif ($sign_type == WechatPay::SIGNTYPE_HMACSHA256) {
650
+			$sign = strtoupper(hash_hmac('sha256', $stringSignTemp, $this->config["api_key"]));
651 651
 		}else throw new Exception("Not supported sign type - $sign_type");
652 652
 		return $sign;
653 653
 	}
654 654
 
655 655
 	private function array2xml($array) {
656
-		$xml = "<xml>" . PHP_EOL;
656
+		$xml = "<xml>".PHP_EOL;
657 657
 		foreach ($array as $k => $v) {
658
-			if($v && trim($v)!='')
659
-				$xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL;
658
+			if ($v && trim($v) != '')
659
+				$xml .= "<$k><![CDATA[$v]]></$k>".PHP_EOL;
660 660
 		}
661 661
 		$xml .= "</xml>";
662 662
 		return $xml;
@@ -665,14 +665,14 @@  discard block
 block discarded – undo
665 665
 	private function xml2array($xml) {
666 666
 		$array = [];
667 667
 		$tmp = (array) simplexml_load_string($xml);
668
-		foreach ( $tmp as $k => $v) {
668
+		foreach ($tmp as $k => $v) {
669 669
 			$array[$k] = (string) $v;
670 670
 		}
671 671
 		return $array;
672 672
 	}
673 673
 
674 674
 	protected function getNonceStr() {
675
-		return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"),0,32);
675
+		return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"), 0, 32);
676 676
 	}
677 677
 
678 678
 }
679 679
\ No newline at end of file
Please login to merge, or discard this patch.
src/cache/JsonFileCacheProvider.php 2 patches
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -10,8 +10,11 @@
 block discarded – undo
10 10
 	private $cacheDir = null;
11 11
 
12 12
 	public function __construct($cacheDir = null){
13
-		if(!$cacheDir) $this->cacheDir = __DIR__;
14
-		else $this->cacheDir = $cacheDir;
13
+		if(!$cacheDir) {
14
+			$this->cacheDir = __DIR__;
15
+		} else {
16
+			$this->cacheDir = $cacheDir;
17
+		}
15 18
 	}
16 19
 
17 20
 	public function set($key,$jsonobj,$expireAt = null){
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -6,30 +6,30 @@  discard block
 block discarded – undo
6 6
  * @author zhangv
7 7
  */
8 8
 namespace zhangv\wechat\pay\cache;
9
-class JsonFileCacheProvider implements CacheProvider{
9
+class JsonFileCacheProvider implements CacheProvider {
10 10
 	private $cacheDir = null;
11 11
 
12
-	public function __construct($cacheDir = null){
13
-		if(!$cacheDir) $this->cacheDir = __DIR__;
12
+	public function __construct($cacheDir = null) {
13
+		if (!$cacheDir) $this->cacheDir = __DIR__;
14 14
 		else $this->cacheDir = $cacheDir;
15 15
 	}
16 16
 
17
-	public function set($key,$jsonobj,$expireAt = null){
17
+	public function set($key, $jsonobj, $expireAt = null) {
18 18
 		$data = $jsonobj;
19 19
 		$data->expires_at = $expireAt;
20 20
 		$file = "{$this->cacheDir}/{$key}.json";
21
-		if($fp = @fopen($file, "w")){
21
+		if ($fp = @fopen($file, "w")) {
22 22
 			fwrite($fp, json_encode($data));
23 23
 			fclose($fp);
24 24
 		}
25 25
 	}
26 26
 
27
-	public function get($key){
27
+	public function get($key) {
28 28
 		$file = "{$this->cacheDir}/{$key}.json";
29 29
 		$cache = null;
30
-		if(file_exists($file)){
30
+		if (file_exists($file)) {
31 31
 			$cache = json_decode(file_get_contents($file));
32
-			if($cache->expires_at < time()){
32
+			if ($cache->expires_at < time()) {
33 33
 				$cache = null;
34 34
 				$this->clear($key);
35 35
 			}
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 		return $cache;
38 38
 	}
39 39
 
40
-	public function clear($key){
40
+	public function clear($key) {
41 41
 		$file = "{$this->cacheDir}/{$key}.json";
42 42
 		if (file_exists($file)) {
43 43
 			unlink($file);
Please login to merge, or discard this patch.
src/cache/CacheProvider.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@
 block discarded – undo
7 7
  */
8 8
 namespace zhangv\wechat\pay\cache;
9 9
 
10
-interface CacheProvider{
11
-	function set($key,$value,$expireAt);
10
+interface CacheProvider {
11
+	function set($key, $value, $expireAt);
12 12
 	function get($key);
13 13
 	function clear($key);
14 14
 }
15 15
\ No newline at end of file
Please login to merge, or discard this patch.
src/cache/RedisCacheProvider.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -6,25 +6,25 @@
 block discarded – undo
6 6
  * @author zhangv
7 7
  */
8 8
 namespace zhangv\wechat\pay\cache;
9
-class RedisCacheProvider implements CacheProvider{
9
+class RedisCacheProvider implements CacheProvider {
10 10
 	/** @var Redis */
11 11
 	private $redis = null;
12 12
 
13
-	public function __construct($redis = null){
13
+	public function __construct($redis = null) {
14 14
 		$this->redis = $redis;
15 15
 	}
16 16
 
17
-	public function set($key,$jsonobj,$expireAt){
17
+	public function set($key, $jsonobj, $expireAt) {
18 18
 		$data = $jsonobj;
19 19
 		$data->expires_at = $expireAt;
20 20
 		$this->redis->set($key, json_encode($data));
21 21
 	}
22 22
 
23
-	public function get($key){
23
+	public function get($key) {
24 24
 		return $this->redis->get($key);
25 25
 	}
26 26
 
27
-	public function clear($key){
27
+	public function clear($key) {
28 28
 		$this->redis->delete($key);
29 29
 	}
30 30
 }
31 31
\ No newline at end of file
Please login to merge, or discard this patch.
src/service/Mweb.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -35,15 +35,15 @@
 block discarded – undo
35 35
 	 * @return string
36 36
 	 * @throws Exception
37 37
 	 */
38
-	public function getMwebUrl($body,$out_trade_no,$total_fee,$ext = null){
39
-		$data = ($ext && is_array($ext))?$ext:array();
38
+	public function getMwebUrl($body, $out_trade_no, $total_fee, $ext = null) {
39
+		$data = ($ext && is_array($ext)) ? $ext : array();
40 40
 		$data["body"]         = $body;
41 41
 		$data["out_trade_no"] = $out_trade_no;
42 42
 		$data["total_fee"]    = $total_fee;
43
-		$data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:'';
43
+		$data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : '';
44 44
 		$data["notify_url"]   = $this->config["notify_url"];
45 45
 		$data["trade_type"]   = self::TRADETYPE_MWEB;
46
-		if(!isset($this->config['h5_scene_info'])) throw new Exception('h5_scene_info should be configured');
46
+		if (!isset($this->config['h5_scene_info'])) throw new Exception('h5_scene_info should be configured');
47 47
 		$data["scene_info"]   = json_encode($this->config['h5_scene_info']);
48 48
 		$result = $this->unifiedOrder($data);
49 49
 		return $result["mweb_url"];
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -43,7 +43,9 @@
 block discarded – undo
43 43
 		$data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:'';
44 44
 		$data["notify_url"]   = $this->config["notify_url"];
45 45
 		$data["trade_type"]   = self::TRADETYPE_MWEB;
46
-		if(!isset($this->config['h5_scene_info'])) throw new Exception('h5_scene_info should be configured');
46
+		if(!isset($this->config['h5_scene_info'])) {
47
+			throw new Exception('h5_scene_info should be configured');
48
+		}
47 49
 		$data["scene_info"]   = json_encode($this->config['h5_scene_info']);
48 50
 		$result = $this->unifiedOrder($data);
49 51
 		return $result["mweb_url"];
Please login to merge, or discard this patch.
src/service/Micro.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -37,15 +37,15 @@  discard block
 block discarded – undo
37 37
 	 * @param array $ext
38 38
 	 * @return array
39 39
 	 */
40
-	public function microPay($body,$out_trade_no,$total_fee,$spbill_create_ip,$auth_code,$ext = array()){
41
-		$data = (!empty($ext) && is_array($ext))?$ext:array();
40
+	public function microPay($body, $out_trade_no, $total_fee, $spbill_create_ip, $auth_code, $ext = array()) {
41
+		$data = (!empty($ext) && is_array($ext)) ? $ext : array();
42 42
 		$data["appid"] = $this->config["app_id"];
43 43
 		$data["body"]         = $body;
44 44
 		$data["out_trade_no"] = $out_trade_no;
45 45
 		$data["total_fee"]    = $total_fee;
46 46
 		$data["spbill_create_ip"] = $spbill_create_ip;
47 47
 		$data["auth_code"] = $auth_code;
48
-		$result = $this->post(self::URL_MICROPAY,$data,true);
48
+		$result = $this->post(self::URL_MICROPAY, $data, true);
49 49
 		return $result;
50 50
 	}
51 51
 
@@ -55,11 +55,11 @@  discard block
 block discarded – undo
55 55
 	 * @param $auth_code
56 56
 	 * @return mixed
57 57
 	 */
58
-	public function authCodeToOpenId($auth_code){
58
+	public function authCodeToOpenId($auth_code) {
59 59
 		$data = array();
60 60
 		$data["appid"] = $this->config["app_id"];
61 61
 		$data["auth_code"] = $auth_code;
62
-		$result = $this->post(self::URL_AUTHCODETOOPENID,$data,false);
62
+		$result = $this->post(self::URL_AUTHCODETOOPENID, $data, false);
63 63
 		return $result['openid'];
64 64
 	}
65 65
 
@@ -70,11 +70,11 @@  discard block
 block discarded – undo
70 70
 	 * @param $out_trade_no string 商户订单号
71 71
 	 * @return array
72 72
 	 */
73
-	public function reverseByOutTradeNo($out_trade_no){
73
+	public function reverseByOutTradeNo($out_trade_no) {
74 74
 		$data = array();
75 75
 		$data["appid"] = $this->config["app_id"];
76 76
 		$data["out_trade_no"] = $out_trade_no;
77
-		$result = $this->post(self::URL_REVERSE, $data,true);
77
+		$result = $this->post(self::URL_REVERSE, $data, true);
78 78
 		return $result;
79 79
 	}
80 80
 
@@ -84,11 +84,11 @@  discard block
 block discarded – undo
84 84
 	 * @param $transaction_id string 微信订单号
85 85
 	 * @return array
86 86
 	 */
87
-	public function reverseByTransactionId($transaction_id){
87
+	public function reverseByTransactionId($transaction_id) {
88 88
 		$data = array();
89 89
 		$data["appid"] = $this->config["app_id"];
90 90
 		$data["transaction_id"] = $transaction_id;
91
-		$result = $this->post(self::URL_REVERSE, $data,true);
91
+		$result = $this->post(self::URL_REVERSE, $data, true);
92 92
 		return $result;
93 93
 	}
94 94
 }
95 95
\ No newline at end of file
Please login to merge, or discard this patch.
src/service/Redpack.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -29,14 +29,14 @@  discard block
 block discarded – undo
29 29
 	 * @return array
30 30
 	 * @throws Exception
31 31
 	 */
32
-	public function sendRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark,$scene_id = '',$riskinfo = '',$consume_mch_id = ''){
32
+	public function sendRedPack($mch_billno, $send_name, $re_openid, $total_amount, $total_num, $wishing, $act_name, $remark, $scene_id = '', $riskinfo = '', $consume_mch_id = '') {
33 33
 		$data = array();
34 34
 		$data["wxappid"] = $this->config["app_id"];
35 35
 		$data["mch_billno"] = $mch_billno;
36 36
 		$data["send_name"] = $send_name;
37 37
 		$data["re_openid"] = $re_openid;
38 38
 		$data["total_amount"] = $total_amount;
39
-		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000");
39
+		if ($total_amount > 20000 && trim($scene_id) == '') throw new Exception("scene_id is required when total_amount beyond 20000");
40 40
 		$data["total_num"] = $total_num;
41 41
 		$data["wishing"] = $wishing;
42 42
 		$data["act_name"] = $act_name;
@@ -65,14 +65,14 @@  discard block
 block discarded – undo
65 65
 	 * @return array
66 66
 	 * @throws Exception
67 67
 	 */
68
-	public function sendGroupRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark,$scene_id = '',$riskinfo = '',$consume_mch_id = ''){
68
+	public function sendGroupRedPack($mch_billno, $send_name, $re_openid, $total_amount, $total_num, $wishing, $act_name, $remark, $scene_id = '', $riskinfo = '', $consume_mch_id = '') {
69 69
 		$data = array();
70
-		$data["wxappid"] = $this->config["app_id"];//NOTE: WXappid
70
+		$data["wxappid"] = $this->config["app_id"]; //NOTE: WXappid
71 71
 		$data["mch_billno"] = $mch_billno;
72 72
 		$data["send_name"] = $send_name;
73 73
 		$data["re_openid"] = $re_openid;
74 74
 		$data["total_amount"] = $total_amount;
75
-		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
75
+		if ($total_amount > 20000 && trim($scene_id) == '') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
76 76
 		$data["total_num"] = $total_num;
77 77
 		$data["amt_type"] = 'ALL_RAND'; //红包金额设置方式 ALL_RAND—全部随机
78 78
 		$data["wishing"] = $wishing;
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	 * @throws Exception
93 93
 	 * @link https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_6&index=5
94 94
 	 */
95
-	public function getHbInfo($mch_billno){
95
+	public function getHbInfo($mch_billno) {
96 96
 		$data = array();
97 97
 		$data["mch_billno"] = $mch_billno;
98 98
 		$data["appid"] = $this->config["app_id"];
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,7 +36,9 @@  discard block
 block discarded – undo
36 36
 		$data["send_name"] = $send_name;
37 37
 		$data["re_openid"] = $re_openid;
38 38
 		$data["total_amount"] = $total_amount;
39
-		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000");
39
+		if($total_amount > 20000 && trim($scene_id)=='') {
40
+			throw new Exception("scene_id is required when total_amount beyond 20000");
41
+		}
40 42
 		$data["total_num"] = $total_num;
41 43
 		$data["wishing"] = $wishing;
42 44
 		$data["act_name"] = $act_name;
@@ -72,7 +74,9 @@  discard block
 block discarded – undo
72 74
 		$data["send_name"] = $send_name;
73 75
 		$data["re_openid"] = $re_openid;
74 76
 		$data["total_amount"] = $total_amount;
75
-		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
77
+		if($total_amount > 20000 && trim($scene_id)=='') {
78
+			throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
79
+		}
76 80
 		$data["total_num"] = $total_num;
77 81
 		$data["amt_type"] = 'ALL_RAND'; //红包金额设置方式 ALL_RAND—全部随机
78 82
 		$data["wishing"] = $wishing;
Please login to merge, or discard this patch.
src/service/Weapp.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -38,16 +38,16 @@
 block discarded – undo
38 38
 	 * @return string
39 39
 	 * @throws \Exception
40 40
 	 */
41
-	public function getPrepayId($body,$out_trade_no,$total_fee,$openid,$spbill_create_ip = null,$ext = null) {
42
-		$data = ($ext && is_array($ext))?$ext:array();
41
+	public function getPrepayId($body, $out_trade_no, $total_fee, $openid, $spbill_create_ip = null, $ext = null) {
42
+		$data = ($ext && is_array($ext)) ? $ext : array();
43 43
 		$data["body"]         = $body;
44 44
 		$data["out_trade_no"] = $out_trade_no;
45 45
 		$data["total_fee"]    = $total_fee;
46
-		$data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["REMOTE_ADDR"];
46
+		$data["spbill_create_ip"] = $spbill_create_ip ?: $_SERVER["REMOTE_ADDR"];
47 47
 		$data["notify_url"]   = $this->config["notify_url"];
48 48
 		$data["trade_type"]   = WechatPay::TRADETYPE_JSAPI;
49
-		if(!$openid) throw new Exception('openid is required when trade_type is JSAPI');
50
-		$data["openid"]   = $openid;
49
+		if (!$openid) throw new Exception('openid is required when trade_type is JSAPI');
50
+		$data["openid"] = $openid;
51 51
 		$result = $this->unifiedOrder($data);
52 52
 		return $result["prepay_id"];
53 53
 	}
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -46,7 +46,9 @@
 block discarded – undo
46 46
 		$data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["REMOTE_ADDR"];
47 47
 		$data["notify_url"]   = $this->config["notify_url"];
48 48
 		$data["trade_type"]   = WechatPay::TRADETYPE_JSAPI;
49
-		if(!$openid) throw new Exception('openid is required when trade_type is JSAPI');
49
+		if(!$openid) {
50
+			throw new Exception('openid is required when trade_type is JSAPI');
51
+		}
50 52
 		$data["openid"]   = $openid;
51 53
 		$result = $this->unifiedOrder($data);
52 54
 		return $result["prepay_id"];
Please login to merge, or discard this patch.
src/service/Native.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -38,15 +38,15 @@
 block discarded – undo
38 38
 	 * @return string
39 39
 	 * @throws Exception
40 40
 	 */
41
-	public function getCodeUrl($body,$out_trade_no,$total_fee,$product_id,$spbill_create_ip = null,$ext = null){
42
-		$data = ($ext && is_array($ext))?$ext:array();
41
+	public function getCodeUrl($body, $out_trade_no, $total_fee, $product_id, $spbill_create_ip = null, $ext = null) {
42
+		$data = ($ext && is_array($ext)) ? $ext : array();
43 43
 		$data["body"]         = $body;
44 44
 		$data["out_trade_no"] = $out_trade_no;
45 45
 		$data["total_fee"]    = $total_fee;
46
-		$data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["SERVER_ADDR"];
46
+		$data["spbill_create_ip"] = $spbill_create_ip ?: $_SERVER["SERVER_ADDR"];
47 47
 		$data["notify_url"]   = $this->config["notify_url"];
48 48
 		$data["trade_type"]   = self::TRADETYPE_NATIVE;
49
-		if(!$product_id) throw new Exception('product_id is required when trade_type is NATIVE');
49
+		if (!$product_id) throw new Exception('product_id is required when trade_type is NATIVE');
50 50
 		$data["product_id"]   = $product_id;
51 51
 		$result = $this->unifiedOrder($data);
52 52
 		return $result["code_url"];
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -46,7 +46,9 @@
 block discarded – undo
46 46
 		$data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["SERVER_ADDR"];
47 47
 		$data["notify_url"]   = $this->config["notify_url"];
48 48
 		$data["trade_type"]   = self::TRADETYPE_NATIVE;
49
-		if(!$product_id) throw new Exception('product_id is required when trade_type is NATIVE');
49
+		if(!$product_id) {
50
+			throw new Exception('product_id is required when trade_type is NATIVE');
51
+		}
50 52
 		$data["product_id"]   = $product_id;
51 53
 		$result = $this->unifiedOrder($data);
52 54
 		return $result["code_url"];
Please login to merge, or discard this patch.