Passed
Push — master ( 5657ba...3032ea )
by Wei
02:21
created
demo/config.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -5,14 +5,14 @@
 block discarded – undo
5 5
 	'app_id' => 'XXXXXXXXXXXXXXXXXXX', //APPID
6 6
 	'app_secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXX', //App Secret
7 7
 	'api_key' =>'XXXXXXXXXXXXXXXXXXXXXXX', //支付密钥
8
-	'ssl_cert_path' => __DIR__ . '/../cert/apiclient_cert.pem',
9
-	'ssl_key_path' => __DIR__ .'/../cert/apiclient_key.pem',
8
+	'ssl_cert_path' => __DIR__.'/../cert/apiclient_cert.pem',
9
+	'ssl_key_path' => __DIR__.'/../cert/apiclient_key.pem',
10 10
 	'sign_type' => 'MD5',
11 11
 	'notify_url' => 'http://XXX.XXX/paidnotify.php',
12 12
 	'refund_notify_url' => 'http://XXX.XXX/refundednotify.php',
13 13
 	'h5_scene_info' => [//required in H5
14 14
 		'h5_info' => ['type' => 'Wap', 'wap_url' => 'http://wapurl', 'wap_name' => 'wapname']
15 15
 	],
16
-	'rsa_pubkey_path' => __DIR__ .'/../cert/pubkey.pem',
17
-	'jsapi_ticket' => __DIR__ .'/jsapi_ticket.json'
16
+	'rsa_pubkey_path' => __DIR__.'/../cert/pubkey.pem',
17
+	'jsapi_ticket' => __DIR__.'/jsapi_ticket.json'
18 18
 ];
19 19
\ No newline at end of file
Please login to merge, or discard this patch.
src/WechatPay.php 2 patches
Spacing   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -8,9 +8,9 @@  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';
13
+	const CHECKNAME_FORCECHECK = 'FORCE_CHECK', CHECKNAME_NOCHECK = 'NO_CHECK';
14 14
 	/** 支付 */
15 15
 	const URL_UNIFIEDORDER = "https://api.mch.weixin.qq.com/pay/unifiedorder";
16 16
 	const URL_ORDERQUERY = "https://api.mch.weixin.qq.com/pay/orderquery";
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	const URL_GETPUBLICKEY = 'https://fraud.mch.weixin.qq.com/risk/getpublickey';
42 42
 	public static $BANKCODE = ['工商银行' => '1002', '农业银行' => '1005', '中国银行' => '1026', '建设银行' => '1003', '招商银行' => '1001',
43 43
 		'邮储银行' => '1066', '交通银行' => '1020', '浦发银行' => '1004', '民生银行' => '1006', '兴业银行' => '1009', '平安银行' => '1010',
44
-		'中信银行' => '1021', '华夏银行' => '1025', '广发银行' => '1027', '光大银行' => '1022', '北京银行' => '1032', '宁波银行' => '1056',];
44
+		'中信银行' => '1021', '华夏银行' => '1025', '广发银行' => '1027', '光大银行' => '1022', '北京银行' => '1032', '宁波银行' => '1056', ];
45 45
 
46 46
 	public $getSignKeyUrl = "https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey";
47 47
 	public $sandbox = false;
@@ -79,18 +79,18 @@  discard block
 block discarded – undo
79 79
 		$this->httpClient = new HttpClient(5);
80 80
 	}
81 81
 
82
-	public function getWechatOAuth(){
83
-		if(!$this->wechatOAuth){
84
-			$this->wechatOAuth = new WechatOAuth($this->config['app_id'],$this->config['app_secret']);
82
+	public function getWechatOAuth() {
83
+		if (!$this->wechatOAuth) {
84
+			$this->wechatOAuth = new WechatOAuth($this->config['app_id'], $this->config['app_secret']);
85 85
 		}
86 86
 		return $this->wechatOAuth;
87 87
 	}
88 88
 
89
-	public function setConfig($config){
89
+	public function setConfig($config) {
90 90
 		$this->config = $config;
91 91
 	}
92 92
 
93
-	public function setHttpClient($httpClient){
93
+	public function setHttpClient($httpClient) {
94 94
 		$this->httpClient = $httpClient;
95 95
 	}
96 96
 
@@ -105,15 +105,15 @@  discard block
 block discarded – undo
105 105
 	 * @param $ext array
106 106
 	 * @return string
107 107
 	 */
108
-	public function getPrepayId($body,$out_trade_no,$total_fee,$openid,$spbill_create_ip = null,$ext = null) {
109
-		$data = ($ext && is_array($ext))?$ext:array();
108
+	public function getPrepayId($body, $out_trade_no, $total_fee, $openid, $spbill_create_ip = null, $ext = null) {
109
+		$data = ($ext && is_array($ext)) ? $ext : array();
110 110
 		$data["body"]         = $body;
111 111
 		$data["out_trade_no"] = $out_trade_no;
112 112
 		$data["total_fee"]    = $total_fee;
113
-		$data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["REMOTE_ADDR"];
113
+		$data["spbill_create_ip"] = $spbill_create_ip ?: $_SERVER["REMOTE_ADDR"];
114 114
 		$data["notify_url"]   = $this->config["notify_url"];
115 115
 		$data["trade_type"]   = WechatPay::TRADETYPE_JSAPI;
116
-		$data["openid"]   = $openid;
116
+		$data["openid"] = $openid;
117 117
 		$result = $this->unifiedOrder($data);
118 118
 		return $result["prepay_id"];
119 119
 	}
@@ -128,8 +128,8 @@  discard block
 block discarded – undo
128 128
 	 * @param $ext array
129 129
 	 * @return string
130 130
 	 */
131
-	public function getPrepayIdAPP($body,$out_trade_no,$total_fee,$spbill_create_ip,$ext = null) {
132
-		$data = ($ext && is_array($ext))?$ext:array();
131
+	public function getPrepayIdAPP($body, $out_trade_no, $total_fee, $spbill_create_ip, $ext = null) {
132
+		$data = ($ext && is_array($ext)) ? $ext : array();
133 133
 		$data["body"]         = $body;
134 134
 		$data["out_trade_no"] = $out_trade_no;
135 135
 		$data["total_fee"]    = $total_fee;
@@ -151,12 +151,12 @@  discard block
 block discarded – undo
151 151
 	 * @param $ext array
152 152
 	 * @return null
153 153
 	 */
154
-	public function getCodeUrl($body,$out_trade_no,$total_fee,$product_id,$spbill_create_ip = null,$ext = null){
155
-		$data = ($ext && is_array($ext))?$ext:array();
154
+	public function getCodeUrl($body, $out_trade_no, $total_fee, $product_id, $spbill_create_ip = null, $ext = null) {
155
+		$data = ($ext && is_array($ext)) ? $ext : array();
156 156
 		$data["body"]         = $body;
157 157
 		$data["out_trade_no"] = $out_trade_no;
158 158
 		$data["total_fee"]    = $total_fee;
159
-		$data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["SERVER_ADDR"];
159
+		$data["spbill_create_ip"] = $spbill_create_ip ?: $_SERVER["SERVER_ADDR"];
160 160
 		$data["notify_url"]   = $this->config["notify_url"];
161 161
 		$data["trade_type"]   = self::TRADETYPE_NATIVE;
162 162
 		$data["product_id"]   = $product_id;
@@ -174,15 +174,15 @@  discard block
 block discarded – undo
174 174
 	 * @return string
175 175
 	 * @throws Exception
176 176
 	 */
177
-	public function getMwebUrl($body,$out_trade_no,$total_fee,$ext = null){
178
-		$data = ($ext && is_array($ext))?$ext:array();
177
+	public function getMwebUrl($body, $out_trade_no, $total_fee, $ext = null) {
178
+		$data = ($ext && is_array($ext)) ? $ext : array();
179 179
 		$data["body"]         = $body;
180 180
 		$data["out_trade_no"] = $out_trade_no;
181 181
 		$data["total_fee"]    = $total_fee;
182
-		$data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:'';
182
+		$data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : '';
183 183
 		$data["notify_url"]   = $this->config["notify_url"];
184 184
 		$data["trade_type"]   = self::TRADETYPE_MWEB;
185
-		if(!isset($this->config['h5_scene_info'])) throw new Exception('h5_scene_info should be configured');
185
+		if (!isset($this->config['h5_scene_info'])) throw new Exception('h5_scene_info should be configured');
186 186
 		$data["scene_info"]   = json_encode($this->config['h5_scene_info']);
187 187
 		$result = $this->unifiedOrder($data);
188 188
 		return $result["mweb_url"];
@@ -197,21 +197,21 @@  discard block
 block discarded – undo
197 197
 	private function unifiedOrder($params) {
198 198
 		$data = array();
199 199
 		$data["appid"] = $this->config["app_id"];
200
-		$data["device_info"] = (isset($params['device_info'])&&trim($params['device_info'])!='')?$params['device_info']:null;
200
+		$data["device_info"] = (isset($params['device_info']) && trim($params['device_info']) != '') ? $params['device_info'] : null;
201 201
 		$data["body"] = $params['body'];
202
-		$data["detail"] = isset($params['detail'])?$params['detail']:null;//optional
203
-		$data["attach"] = isset($params['attach'])?$params['attach']:null;//optional
204
-		$data["out_trade_no"] = isset($params['out_trade_no'])?$params['out_trade_no']:null;
205
-		$data["fee_type"] = isset($params['fee_type'])?$params['fee_type']:'CNY';
202
+		$data["detail"] = isset($params['detail']) ? $params['detail'] : null; //optional
203
+		$data["attach"] = isset($params['attach']) ? $params['attach'] : null; //optional
204
+		$data["out_trade_no"] = isset($params['out_trade_no']) ? $params['out_trade_no'] : null;
205
+		$data["fee_type"] = isset($params['fee_type']) ? $params['fee_type'] : 'CNY';
206 206
 		$data["total_fee"]    = $params['total_fee'];
207 207
 		$data["spbill_create_ip"] = $params['spbill_create_ip'];
208
-		$data["time_start"] = isset($params['time_start'])?$params['time_start']:null;//optional
209
-		$data["time_expire"] = isset($params['time_expire'])?$params['time_expire']:null;//optional
210
-		$data["goods_tag"] = isset($params['goods_tag'])?$params['goods_tag']:null;
208
+		$data["time_start"] = isset($params['time_start']) ? $params['time_start'] : null; //optional
209
+		$data["time_expire"] = isset($params['time_expire']) ? $params['time_expire'] : null; //optional
210
+		$data["goods_tag"] = isset($params['goods_tag']) ? $params['goods_tag'] : null;
211 211
 		$data["notify_url"] = $this->config["notify_url"];
212 212
 		$data["trade_type"] = $params['trade_type'];
213
-		$data["product_id"] = isset($params['product_id'])?$params['product_id']:null;//required when trade_type = NATIVE
214
-		$data["openid"] = isset($params['openid'])?$params['openid']:null;//required when trade_type = JSAPI
213
+		$data["product_id"] = isset($params['product_id']) ? $params['product_id'] : null; //required when trade_type = NATIVE
214
+		$data["openid"] = isset($params['openid']) ? $params['openid'] : null; //required when trade_type = JSAPI
215 215
 		$result = $this->post(self::URL_UNIFIEDORDER, $data);
216 216
 		return $result;
217 217
 	}
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 	 * @param $transaction_id string 微信订单号
223 223
 	 * @return array
224 224
 	 */
225
-	public function queryOrderByTransactionId($transaction_id){
225
+	public function queryOrderByTransactionId($transaction_id) {
226 226
 		$data = array();
227 227
 		$data["appid"] = $this->config["app_id"];
228 228
 		$data["transaction_id"] = $transaction_id;
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
 	 * @param $out_trade_no string 商户订单号
237 237
 	 * @return array
238 238
 	 */
239
-	public function queryOrderByOutTradeNo($out_trade_no){
239
+	public function queryOrderByOutTradeNo($out_trade_no) {
240 240
 		$data = array();
241 241
 		$data["appid"] = $this->config["app_id"];
242 242
 		$data["out_trade_no"] = $out_trade_no;
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 	 * @param $offset int 偏移
252 252
 	 * @return array
253 253
 	 */
254
-	public function queryRefundByTransactionId($transaction_id,$offset = 0){
254
+	public function queryRefundByTransactionId($transaction_id, $offset = 0) {
255 255
 		$data = array();
256 256
 		$data["appid"] = $this->config["app_id"];
257 257
 		$data["transaction_id"] = $transaction_id;
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	 * @param $offset int 偏移
268 268
 	 * @return array
269 269
 	 */
270
-	public function queryRefundByOutTradeNo($out_trade_no,$offset = 0){
270
+	public function queryRefundByOutTradeNo($out_trade_no, $offset = 0) {
271 271
 		$data = array();
272 272
 		$data["appid"] = $this->config["app_id"];
273 273
 		$data["out_trade_no"] = $out_trade_no;
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 	 * @param $offset int 偏移
284 284
 	 * @return array
285 285
 	 */
286
-	public function queryRefundByRefundId($refund_id,$offset = 0){
286
+	public function queryRefundByRefundId($refund_id, $offset = 0) {
287 287
 		$data = array();
288 288
 		$data["appid"] = $this->config["app_id"];
289 289
 		$data["refund_id"] = $refund_id;
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 	 * @param $offset int 偏移
300 300
 	 * @return array
301 301
 	 */
302
-	public function queryRefundByOutRefundNo($out_refund_no,$offset = 0){
302
+	public function queryRefundByOutRefundNo($out_refund_no, $offset = 0) {
303 303
 		$data = array();
304 304
 		$data["appid"] = $this->config["app_id"];
305 305
 		$data["out_refund_no"] = $out_refund_no;
@@ -314,11 +314,11 @@  discard block
 block discarded – undo
314 314
 	 * @param $out_trade_no string 商户订单号
315 315
 	 * @return array
316 316
 	 */
317
-	public function closeOrder($out_trade_no){
317
+	public function closeOrder($out_trade_no) {
318 318
 		$data = array();
319 319
 		$data["appid"] = $this->config["app_id"];
320 320
 		$data["out_trade_no"] = $out_trade_no;
321
-		$result = $this->post(self::URL_CLOSEORDER, $data,false);
321
+		$result = $this->post(self::URL_CLOSEORDER, $data, false);
322 322
 		return $result;
323 323
 	}
324 324
 
@@ -333,14 +333,14 @@  discard block
 block discarded – undo
333 333
 	 * @param $ext array 扩展数组
334 334
 	 * @return array
335 335
 	 */
336
-	public function refundByOutTradeNo($out_trade_no,$out_refund_no,$total_fee,$refund_fee,$ext = array()){
337
-		$data = ($ext && is_array($ext))?$ext:array();
336
+	public function refundByOutTradeNo($out_trade_no, $out_refund_no, $total_fee, $refund_fee, $ext = array()) {
337
+		$data = ($ext && is_array($ext)) ? $ext : array();
338 338
 		$data["appid"] = $this->config["app_id"];
339 339
 		$data["out_trade_no"] = $out_trade_no;
340 340
 		$data["out_refund_no"] = $out_refund_no;
341 341
 		$data["total_fee"] = $total_fee;
342 342
 		$data["refund_fee"] = $refund_fee;
343
-		$result = $this->post(self::URL_REFUND, $data,true);
343
+		$result = $this->post(self::URL_REFUND, $data, true);
344 344
 		return $result;
345 345
 	}
346 346
 
@@ -355,14 +355,14 @@  discard block
 block discarded – undo
355 355
 	 * @param $ext array 扩展数组
356 356
 	 * @return array
357 357
 	 */
358
-	public function refundByTransactionId($transaction_id,$out_refund_no,$total_fee,$refund_fee,$ext = array()){
359
-		$data = ($ext && is_array($ext))?$ext:array();
358
+	public function refundByTransactionId($transaction_id, $out_refund_no, $total_fee, $refund_fee, $ext = array()) {
359
+		$data = ($ext && is_array($ext)) ? $ext : array();
360 360
 		$data["appid"] = $this->config["app_id"];
361 361
 		$data["transaction_id"] = $transaction_id;
362 362
 		$data["out_refund_no"] = $out_refund_no;
363 363
 		$data["total_fee"] = $total_fee;
364 364
 		$data["refund_fee"] = $refund_fee;
365
-		$result = $this->post(self::URL_REFUND, $data,true);
365
+		$result = $this->post(self::URL_REFUND, $data, true);
366 366
 		return $result;
367 367
 	}
368 368
 
@@ -372,11 +372,11 @@  discard block
 block discarded – undo
372 372
 	 * @param $out_trade_no string 商户订单号
373 373
 	 * @return array
374 374
 	 */
375
-	public function reverseByOutTradeNo($out_trade_no){
375
+	public function reverseByOutTradeNo($out_trade_no) {
376 376
 		$data = array();
377 377
 		$data["appid"] = $this->config["app_id"];
378 378
 		$data["out_trade_no"] = $out_trade_no;
379
-		$result = $this->post(self::URL_REVERSE, $data,true);
379
+		$result = $this->post(self::URL_REVERSE, $data, true);
380 380
 		return $result;
381 381
 	}
382 382
 
@@ -386,11 +386,11 @@  discard block
 block discarded – undo
386 386
 	 * @param $transaction_id string 微信订单号
387 387
 	 * @return array
388 388
 	 */
389
-	public function reverseByTransactionId($transaction_id){
389
+	public function reverseByTransactionId($transaction_id) {
390 390
 		$data = array();
391 391
 		$data["appid"] = $this->config["app_id"];
392 392
 		$data["transaction_id"] = $transaction_id;
393
-		$result = $this->post(self::URL_REVERSE, $data,true);
393
+		$result = $this->post(self::URL_REVERSE, $data, true);
394 394
 		return $result;
395 395
 	}
396 396
 
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 	 * @param $bill_type string 类型 ALL|SUCCESS
401 401
 	 * @return array
402 402
 	 */
403
-	public function downloadBill($bill_date,$bill_type = 'ALL'){
403
+	public function downloadBill($bill_date, $bill_type = 'ALL') {
404 404
 		$data = array();
405 405
 		$data["appid"] = $this->config["app_id"];
406 406
 		$data["bill_date"] = $bill_date;
@@ -426,14 +426,14 @@  discard block
 block discarded – undo
426 426
 	 * @return array
427 427
 	 * @throws Exception
428 428
 	 */
429
-	public function sendRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark,$scene_id = '',$riskinfo = '',$consume_mch_id = ''){
429
+	public function sendRedPack($mch_billno, $send_name, $re_openid, $total_amount, $total_num, $wishing, $act_name, $remark, $scene_id = '', $riskinfo = '', $consume_mch_id = '') {
430 430
 		$data = array();
431 431
 		$data["wxappid"] = $this->config["app_id"];
432 432
 		$data["mch_billno"] = $mch_billno;
433 433
 		$data["send_name"] = $send_name;
434 434
 		$data["re_openid"] = $re_openid;
435 435
 		$data["total_amount"] = $total_amount;
436
-		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000");
436
+		if ($total_amount > 20000 && trim($scene_id) == '') throw new Exception("scene_id is required when total_amount beyond 20000");
437 437
 		$data["total_num"] = $total_num;
438 438
 		$data["wishing"] = $wishing;
439 439
 		$data["act_name"] = $act_name;
@@ -462,14 +462,14 @@  discard block
 block discarded – undo
462 462
 	 * @return array
463 463
 	 * @throws Exception
464 464
 	 */
465
-	public function sendGroupRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark,$scene_id = '',$riskinfo = '',$consume_mch_id = ''){
465
+	public function sendGroupRedPack($mch_billno, $send_name, $re_openid, $total_amount, $total_num, $wishing, $act_name, $remark, $scene_id = '', $riskinfo = '', $consume_mch_id = '') {
466 466
 		$data = array();
467
-		$data["wxappid"] = $this->config["app_id"];//NOTE: WXappid
467
+		$data["wxappid"] = $this->config["app_id"]; //NOTE: WXappid
468 468
 		$data["mch_billno"] = $mch_billno;
469 469
 		$data["send_name"] = $send_name;
470 470
 		$data["re_openid"] = $re_openid;
471 471
 		$data["total_amount"] = $total_amount;
472
-		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
472
+		if ($total_amount > 20000 && trim($scene_id) == '') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
473 473
 		$data["total_num"] = $total_num;
474 474
 		$data["amt_type"] = 'ALL_RAND'; //红包金额设置方式 ALL_RAND—全部随机
475 475
 		$data["wishing"] = $wishing;
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
 	 * @throws Exception
490 490
 	 * @ref https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_6&index=5
491 491
 	 */
492
-	public function getHbInfo($mch_billno){
492
+	public function getHbInfo($mch_billno) {
493 493
 		$data = array();
494 494
 		$data["mch_billno"] = $mch_billno;
495 495
 		$data["appid"] = $this->config["app_id"];
@@ -506,14 +506,14 @@  discard block
 block discarded – undo
506 506
 	 * @param int $limit 条数
507 507
 	 * @return array
508 508
 	 */
509
-	public function batchQueryComment($begin_time,$end_time,$offset = 0,$limit = 200){
509
+	public function batchQueryComment($begin_time, $end_time, $offset = 0, $limit = 200) {
510 510
 		$data = array();
511 511
 		$data["appid"] = $this->config["app_id"];
512 512
 		$data["begin_time"] = $begin_time;
513 513
 		$data["end_time"] = $end_time;
514 514
 		$data["offset"] = $offset;
515 515
 		$data["limit"] = $limit;
516
-		$data["sign"] = $this->sign($data,WechatPay::SIGNTYPE_HMACSHA256);
516
+		$data["sign"] = $this->sign($data, WechatPay::SIGNTYPE_HMACSHA256);
517 517
 		$result = $this->post(self::URL_BATCHQUERYCOMMENT, $data, true); //cert is required
518 518
 		return $result;
519 519
 	}
@@ -526,21 +526,21 @@  discard block
 block discarded – undo
526 526
 	 */
527 527
 	public function getPackage($prepay_id, $trade_type = WechatPay::TRADETYPE_JSAPI) {
528 528
 		$data = array();
529
-		if ($trade_type == WechatPay::TRADETYPE_JSAPI){
529
+		if ($trade_type == WechatPay::TRADETYPE_JSAPI) {
530 530
 			$data["package"]   = "prepay_id=$prepay_id";
531 531
 			$data["timeStamp"] = time();
532 532
 			$data["nonceStr"]  = $this->getNonceStr();
533 533
 			$data["appId"] = $this->config["app_id"];
534 534
 			$data["signType"]  = "MD5";
535 535
 			$data["paySign"]   = $this->sign($data);
536
-		} else if ($trade_type == WechatPay::TRADETYPE_APP){
536
+		}else if ($trade_type == WechatPay::TRADETYPE_APP) {
537 537
 			$data["package"]   = "Sign=WXPay";
538 538
 			$data['prepayid'] = $prepay_id;
539 539
 			$data['partnerid'] = $this->config["mch_id"];
540 540
 			$data["timestamp"] = time();
541 541
 			$data["noncestr"]  = $this->getNonceStr();
542 542
 			$data["appid"] = $this->config["app_id"];
543
-			$data["sign"]   = $this->sign($data);
543
+			$data["sign"] = $this->sign($data);
544 544
 		}
545 545
 		return $data;
546 546
 	}
@@ -556,15 +556,15 @@  discard block
 block discarded – undo
556 556
 	 * @param array $ext
557 557
 	 * @return array
558 558
 	 */
559
-	public function microPay($body,$out_trade_no,$total_fee,$spbill_create_ip,$auth_code,$ext = array()){
560
-		$data = (!empty($ext) && is_array($ext))?$ext:array();
559
+	public function microPay($body, $out_trade_no, $total_fee, $spbill_create_ip, $auth_code, $ext = array()) {
560
+		$data = (!empty($ext) && is_array($ext)) ? $ext : array();
561 561
 		$data["appid"] = $this->config["app_id"];
562 562
 		$data["body"]         = $body;
563 563
 		$data["out_trade_no"] = $out_trade_no;
564 564
 		$data["total_fee"]    = $total_fee;
565 565
 		$data["spbill_create_ip"] = $spbill_create_ip;
566 566
 		$data["auth_code"] = $auth_code;
567
-		$result = $this->post(self::URL_MICROPAY,$data,false);
567
+		$result = $this->post(self::URL_MICROPAY, $data, false);
568 568
 		return $result;
569 569
 	}
570 570
 
@@ -575,17 +575,17 @@  discard block
 block discarded – undo
575 575
 	 * @return null
576 576
 	 * @throws Exception
577 577
 	 */
578
-	public function onPaidNotify($notify_data,callable $callback = null){
579
-		if(!is_array($notify_data)){
578
+	public function onPaidNotify($notify_data, callable $callback = null) {
579
+		if (!is_array($notify_data)) {
580 580
 			$notify_data = $this->xml2array($notify_data);
581 581
 		}
582
-		if($this->validateSign($notify_data)){
583
-			if($callback && is_callable($callback)){
584
-				return call_user_func_array( $callback , [$notify_data] );
585
-			}else{
582
+		if ($this->validateSign($notify_data)) {
583
+			if ($callback && is_callable($callback)) {
584
+				return call_user_func_array($callback, [$notify_data]);
585
+			}else {
586 586
 				$this->responseNotify();
587 587
 			}
588
-		}else{
588
+		}else {
589 589
 			throw new Exception('Invalid paid notify data');
590 590
 		}
591 591
 	}
@@ -597,17 +597,17 @@  discard block
 block discarded – undo
597 597
 	 * @return mixed
598 598
 	 * @throws Exception
599 599
 	 */
600
-	public function onRefundedNotify($notify_data,callable $callback = null){
601
-		if(!is_array($notify_data)){
600
+	public function onRefundedNotify($notify_data, callable $callback = null) {
601
+		if (!is_array($notify_data)) {
602 602
 			$notify_data = $this->xml2array($notify_data);
603 603
 		}
604
-		if($this->validateSign($notify_data)){
605
-			if($callback && is_callable($callback)){
606
-				return call_user_func_array( $callback , $notify_data );
607
-			}else{
604
+		if ($this->validateSign($notify_data)) {
605
+			if ($callback && is_callable($callback)) {
606
+				return call_user_func_array($callback, $notify_data);
607
+			}else {
608 608
 				$this->responseNotify();
609 609
 			}
610
-		}else{
610
+		}else {
611 611
 			throw new Exception('Invalid refunded notify data');
612 612
 		}
613 613
 	}
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
 	 * @param $return_code string 返回状态码 SUCCESS/FAIL
632 632
 	 * @param $return_msg string 返回信息
633 633
 	 */
634
-	public function responseNotify($return_code="SUCCESS", $return_msg= 'OK') {
634
+	public function responseNotify($return_code = "SUCCESS", $return_msg = 'OK') {
635 635
 		$data = array();
636 636
 		$data["return_code"] = $return_code;
637 637
 		if ($return_msg) {
@@ -657,8 +657,8 @@  discard block
 block discarded – undo
657 657
 	 * @param string $err_code_des
658 658
 	 * @return array
659 659
 	 */
660
-	public function report($interface_url,$execution_time,$return_code,$result_code,$user_ip,$out_trade_no = null,$time = null,$device_info = null,
661
-	                       $return_msg = null,$err_code = null,$err_code_des = null){
660
+	public function report($interface_url, $execution_time, $return_code, $result_code, $user_ip, $out_trade_no = null, $time = null, $device_info = null,
661
+	                       $return_msg = null, $err_code = null, $err_code_des = null) {
662 662
 		$data = array();
663 663
 		$data["appid"] = $this->config["app_id"];
664 664
 		$data["interface_url"] = $interface_url;
@@ -666,12 +666,12 @@  discard block
 block discarded – undo
666 666
 		$data["return_code"] = $return_code;
667 667
 		$data["result_code"] = $result_code;
668 668
 		$data["user_ip"] = $user_ip;
669
-		if($out_trade_no) $data["out_trade_no"] = $out_trade_no;
670
-		if($time) $data["time"] = $time;
671
-		if($device_info) $data["device_info"] = $device_info;
672
-		if($return_msg) $data["return_msg"] = $return_msg;
673
-		if($err_code) $data["err_code"] = $err_code;
674
-		if($err_code_des) $data["err_code_des"] = $err_code_des;
669
+		if ($out_trade_no) $data["out_trade_no"] = $out_trade_no;
670
+		if ($time) $data["time"] = $time;
671
+		if ($device_info) $data["device_info"] = $device_info;
672
+		if ($return_msg) $data["return_msg"] = $return_msg;
673
+		if ($err_code) $data["err_code"] = $err_code;
674
+		if ($err_code_des) $data["err_code_des"] = $err_code_des;
675 675
 		$result = $this->post(self::URL_REPORT, $data, false);
676 676
 		return $result;
677 677
 	}
@@ -682,11 +682,11 @@  discard block
 block discarded – undo
682 682
 	 * @param $longurl
683 683
 	 * @return string
684 684
 	 */
685
-	public function shortUrl($longurl){
685
+	public function shortUrl($longurl) {
686 686
 		$data = array();
687 687
 		$data["appid"] = $this->config["app_id"];
688 688
 		$data["long_url"] = $longurl;
689
-		$result = $this->post(self::URL_SHORTURL,$data,false);
689
+		$result = $this->post(self::URL_SHORTURL, $data, false);
690 690
 		return $result['short_url'];
691 691
 	}
692 692
 
@@ -695,11 +695,11 @@  discard block
 block discarded – undo
695 695
 	 * @param $auth_code
696 696
 	 * @return mixed
697 697
 	 */
698
-	public function authCodeToOpenId($auth_code){
698
+	public function authCodeToOpenId($auth_code) {
699 699
 		$data = array();
700 700
 		$data["appid"] = $this->config["app_id"];
701 701
 		$data["auth_code"] = $auth_code;
702
-		$result = $this->post(self::URL_AUTHCODETOOPENID,$data,false);
702
+		$result = $this->post(self::URL_AUTHCODETOOPENID, $data, false);
703 703
 		return $result['openid'];
704 704
 	}
705 705
 
@@ -716,19 +716,19 @@  discard block
 block discarded – undo
716 716
 	 * @return array
717 717
 	 * @throws Exception
718 718
 	 */
719
-	public function transferWallet($partner_trade_no,$openid,$amount,$desc,$spbill_create_ip = null,$re_user_name = null,$check_name = WechatPay::CHECKNAME_FORCECHECK){
719
+	public function transferWallet($partner_trade_no, $openid, $amount, $desc, $spbill_create_ip = null, $re_user_name = null, $check_name = WechatPay::CHECKNAME_FORCECHECK) {
720 720
 		$data = array();
721
-		if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required');
721
+		if ($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required');
722 722
 		$data["mch_appid"] = $this->config["app_id"];
723 723
 		$data["mchid"] = $this->config["mch_id"];
724 724
 		$data["partner_trade_no"] = $partner_trade_no;
725 725
 		$data["openid"] = $openid;
726 726
 		$data["amount"] = $amount;
727 727
 		$data["desc"] = $desc;
728
-		$data['spbill_create_ip'] = $spbill_create_ip?:$_SERVER['SERVER_ADDR'];
728
+		$data['spbill_create_ip'] = $spbill_create_ip ?: $_SERVER['SERVER_ADDR'];
729 729
 		$data["check_name"] = $check_name;
730 730
 		$data["re_user_name"] = $re_user_name;
731
-		$result = $this->post(self::URL_TRANSFER_WALLET,$data,true);
731
+		$result = $this->post(self::URL_TRANSFER_WALLET, $data, true);
732 732
 		return $result;
733 733
 	}
734 734
 
@@ -738,12 +738,12 @@  discard block
 block discarded – undo
738 738
 	 * @param $partner_trade_no
739 739
 	 * @return array
740 740
 	 */
741
-	public function queryTransferWallet($partner_trade_no){
741
+	public function queryTransferWallet($partner_trade_no) {
742 742
 		$data = array();
743 743
 		$data["appid"] = $this->config["app_id"];
744 744
 		$data["mch_id"] = $this->config["mch_id"];
745 745
 		$data["partner_trade_no"] = $partner_trade_no;
746
-		$result = $this->post(self::URL_QUERY_TRANSFER_WALLET,$data,true);
746
+		$result = $this->post(self::URL_QUERY_TRANSFER_WALLET, $data, true);
747 747
 		return $result;
748 748
 	}
749 749
 
@@ -759,8 +759,8 @@  discard block
 block discarded – undo
759 759
 	 * @return array
760 760
 	 * @throws Exception
761 761
 	 */
762
-	public function transferBankCard($partner_trade_no,$bank_no,$true_name,$bank_code,$amount,$desc){
763
-		if(!in_array($bank_code,array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code - $bank_code");
762
+	public function transferBankCard($partner_trade_no, $bank_no, $true_name, $bank_code, $amount, $desc) {
763
+		if (!in_array($bank_code, array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code - $bank_code");
764 764
 		$data = array();
765 765
 		$data["partner_trade_no"] = $partner_trade_no;
766 766
 		$enc_bank_no = $this->rsaEncrypt($bank_no);
@@ -770,7 +770,7 @@  discard block
 block discarded – undo
770 770
 		$data["bank_code"] = $bank_code;
771 771
 		$data["desc"] = $desc;
772 772
 		$data["amount"] = $amount;
773
-		$result = $this->post(self::URL_TRANSFER_BANKCARD,$data,true);
773
+		$result = $this->post(self::URL_TRANSFER_BANKCARD, $data, true);
774 774
 		return $result;
775 775
 	}
776 776
 
@@ -784,14 +784,14 @@  discard block
 block discarded – undo
784 784
 	 * @param array $ext
785 785
 	 * @return array
786 786
 	 */
787
-	public function sendCoupon($coupon_stock_id,$open_id,$partner_trade_no,$op_user_id = '',$ext = array()){
788
-		$data = (!empty($ext) && is_array($ext))?$ext:array();
787
+	public function sendCoupon($coupon_stock_id, $open_id, $partner_trade_no, $op_user_id = '', $ext = array()) {
788
+		$data = (!empty($ext) && is_array($ext)) ? $ext : array();
789 789
 		$data["partner_trade_no"] = $partner_trade_no;
790 790
 		$data["coupon_stock_id"] = $coupon_stock_id;
791 791
 		$data["openid_count"] = 1;
792 792
 		$data["open_id"] = $open_id;
793 793
 		$data["op_user_id"] = $op_user_id;
794
-		$result = $this->post(self::URL_SEND_COUPON,$data,true);
794
+		$result = $this->post(self::URL_SEND_COUPON, $data, true);
795 795
 		return $result;
796 796
 	}
797 797
 
@@ -802,11 +802,11 @@  discard block
 block discarded – undo
802 802
 	 * @param string $op_user_id
803 803
 	 * @return array
804 804
 	 */
805
-	public function queryCouponStock($coupon_stock_id,$op_user_id = ''){
805
+	public function queryCouponStock($coupon_stock_id, $op_user_id = '') {
806 806
 		$data = array();
807 807
 		$data["coupon_stock_id"] = $coupon_stock_id;
808 808
 		$data["op_user_id"] = $op_user_id;
809
-		$result = $this->post(self::URL_QUERY_COUPON_STOCK,$data,false);
809
+		$result = $this->post(self::URL_QUERY_COUPON_STOCK, $data, false);
810 810
 		return $result;
811 811
 	}
812 812
 
@@ -820,13 +820,13 @@  discard block
 block discarded – undo
820 820
 	 * @param array $ext
821 821
 	 * @return array
822 822
 	 */
823
-	public function queryCouponsInfo($coupon_id,$open_id,$stock_id,$op_user_id = '',$ext = array()){
824
-		$data = (!empty($ext) && is_array($ext))?$ext:array();
823
+	public function queryCouponsInfo($coupon_id, $open_id, $stock_id, $op_user_id = '', $ext = array()) {
824
+		$data = (!empty($ext) && is_array($ext)) ? $ext : array();
825 825
 		$data["coupon_id"] = $coupon_id;
826 826
 		$data["stock_id"] = $stock_id;
827 827
 		$data["open_id"] = $open_id;
828 828
 		$data["op_user_id"] = $op_user_id;
829
-		$result = $this->post(self::URL_QUERY_COUPON_INFO,$data,false);
829
+		$result = $this->post(self::URL_QUERY_COUPON_INFO, $data, false);
830 830
 		return $result;
831 831
 	}
832 832
 
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
 	 * @return string
838 838
 	 * @throws Exception
839 839
 	 */
840
-	public function getPublicKey($refresh = false){
840
+	public function getPublicKey($refresh = false) {
841 841
 		if (!$refresh && file_exists($this->config["rsa_pubkey_path"])) {
842 842
 			$pubkey = file_get_contents($this->config["rsa_pubkey_path"]);
843 843
 			return $pubkey;
@@ -845,7 +845,7 @@  discard block
 block discarded – undo
845 845
 		$data = array();
846 846
 		$data["mch_id"] = $this->config["mch_id"];
847 847
 		$data["sign_type"] = $this->config["sign_type"];
848
-		$result = $this->post(self::URL_GETPUBLICKEY,$data,true);
848
+		$result = $this->post(self::URL_GETPUBLICKEY, $data, true);
849 849
 		$pubkey = $result['pub_key'];
850 850
 		$pubkey = $this->convertPKCS1toPKCS8($pubkey);
851 851
 		$fp = fopen($this->config["rsa_pubkey_path"], "w");
@@ -858,20 +858,20 @@  discard block
 block discarded – undo
858 858
 		}
859 859
 	}
860 860
 
861
-	private function convertPKCS1toPKCS8($pkcs1){
861
+	private function convertPKCS1toPKCS8($pkcs1) {
862 862
 		$start_key = $pkcs1;
863 863
 		$start_key = str_replace('-----BEGIN RSA PUBLIC KEY-----', '', $start_key);
864 864
 		$start_key = trim(str_replace('-----END RSA PUBLIC KEY-----', '', $start_key));
865
-		$key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' . str_replace("\n", '', $start_key);
866
-		$key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($key, 64, "\n", true) . "\n-----END PUBLIC KEY-----";
865
+		$key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A'.str_replace("\n", '', $start_key);
866
+		$key = "-----BEGIN PUBLIC KEY-----\n".wordwrap($key, 64, "\n", true)."\n-----END PUBLIC KEY-----";
867 867
 		return $key;
868 868
 	}
869 869
 
870
-	public function rsaEncrypt($data){
870
+	public function rsaEncrypt($data) {
871 871
 		$pubkey = $this->getPublicKey();
872 872
 		$encrypted = null;
873 873
 		$pubkey = openssl_get_publickey($pubkey);
874
-		if (openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING))
874
+		if (openssl_public_encrypt($data, $encrypted, $pubkey, OPENSSL_PKCS1_OAEP_PADDING))
875 875
 			$data = base64_encode($encrypted);
876 876
 		else
877 877
 			throw new Exception('Unable to encrypt data');
@@ -884,12 +884,12 @@  discard block
 block discarded – undo
884 884
 	 * @param $partner_trade_no
885 885
 	 * @return array
886 886
 	 */
887
-	public function queryTransferBankCard($partner_trade_no){
887
+	public function queryTransferBankCard($partner_trade_no) {
888 888
 		$data = array();
889 889
 		$data["appid"] = $this->config["app_id"];
890 890
 		$data["mch_id"] = $this->config["mch_id"];
891 891
 		$data["partner_trade_no"] = $partner_trade_no;
892
-		$result = $this->post(self::URL_QUERY_TRANSFER_WALLET,$data,true);
892
+		$result = $this->post(self::URL_QUERY_TRANSFER_WALLET, $data, true);
893 893
 		return $result;
894 894
 	}
895 895
 
@@ -898,10 +898,10 @@  discard block
 block discarded – undo
898 898
 	 * @ref https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=23_1
899 899
 	 * @return array
900 900
 	 */
901
-	public function getSignKey(){
901
+	public function getSignKey() {
902 902
 		$data = array();
903 903
 		$data["mch_id"] = $this->config["mch_id"];
904
-		$result = $this->post($this->getSignKeyUrl,$data,false);
904
+		$result = $this->post($this->getSignKeyUrl, $data, false);
905 905
 		return $result['sandbox_signkey'];
906 906
 	}
907 907
 
@@ -909,7 +909,7 @@  discard block
 block discarded – undo
909 909
 	 * 获取JSAPI所需要的页面参数
910 910
 	 * @return array
911 911
 	 */
912
-	public function getSignPackage($url){
912
+	public function getSignPackage($url) {
913 913
 		$jsapiTicket = $this->getJSAPITicket();
914 914
 		$timestamp = time();
915 915
 		$nonceStr = $this->getNonceStr();
@@ -931,8 +931,8 @@  discard block
 block discarded – undo
931 931
 	 * 获取JSAPI Ticket
932 932
 	 * @return string
933 933
 	 */
934
-	public function getJSAPITicket(){
935
-		if(isset($this->config['jsapi_ticket']) && file_exists($this->config['jsapi_ticket'])){
934
+	public function getJSAPITicket() {
935
+		if (isset($this->config['jsapi_ticket']) && file_exists($this->config['jsapi_ticket'])) {
936 936
 			$data = json_decode(file_get_contents($this->config['jsapi_ticket']));
937 937
 			if (!$data || $data->expire_time < time()) {
938 938
 				$data = $this->getWechatOAuth()->getTicket();
@@ -945,10 +945,10 @@  discard block
 block discarded – undo
945 945
 		}
946 946
 	}
947 947
 
948
-	private function post($url, $data,$cert = true) {
949
-		if(!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"];
950
-		if(!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr();
951
-		if(!isset($data['sign'])) $data['sign'] = $this->sign($data);
948
+	private function post($url, $data, $cert = true) {
949
+		if (!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"];
950
+		if (!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr();
951
+		if (!isset($data['sign'])) $data['sign'] = $this->sign($data);
952 952
 		$this->requestXML = $this->responseXML = null;
953 953
 		$this->requestArray = $this->responseArray = null;
954 954
 
@@ -960,53 +960,53 @@  discard block
 block discarded – undo
960 960
 			CURLOPT_RETURNTRANSFER => true,
961 961
 			CURLOPT_TIMEOUT => 10
962 962
 		];
963
-		if($cert == true){
963
+		if ($cert == true) {
964 964
 			$opts[CURLOPT_SSLCERTTYPE] = 'PEM';
965 965
 			$opts[CURLOPT_SSLCERT] = $this->config['ssl_cert_path'];
966 966
 			$opts[CURLOPT_SSLKEYTYPE] = 'PEM';
967 967
 			$opts[CURLOPT_SSLKEY] = $this->config['ssl_key_path'];
968 968
 		}
969 969
 		$processResponse = true;
970
-		if(in_array($url,[self::URL_DOWNLOADBILL])){
970
+		if (in_array($url, [self::URL_DOWNLOADBILL])) {
971 971
 			$processResponse = false;
972 972
 		}
973
-		if($this->sandbox === true){
973
+		if ($this->sandbox === true) {
974 974
 			$host = "https://api.mch.weixin.qq.com";
975
-			$url = str_replace($host,'',$url);
975
+			$url = str_replace($host, '', $url);
976 976
 			$url = "{$host}/sandboxnew{$url}";
977 977
 		}
978
-		$content = $this->httpClient->post($url,$this->requestXML,[],$opts);
979
-		if(!$content) throw new Exception("Empty response with {$this->requestXML}");
978
+		$content = $this->httpClient->post($url, $this->requestXML, [], $opts);
979
+		if (!$content) throw new Exception("Empty response with {$this->requestXML}");
980 980
 
981 981
 		$this->responseXML = $content;
982
-		if($processResponse)
982
+		if ($processResponse)
983 983
 			return $this->processResponseXML($this->responseXML);
984 984
 		else return $this->responseXML;
985 985
 
986 986
 	}
987 987
 
988
-	private function processResponseXML($responseXML){
988
+	private function processResponseXML($responseXML) {
989 989
 		$result = $this->xml2array($responseXML);
990 990
 		$this->responseArray = $result;
991
-		if(empty($result['return_code'])){
991
+		if (empty($result['return_code'])) {
992 992
 			throw new Exception("No return code presents in {$this->responseXML}");
993 993
 		}
994 994
 		$this->returnCode = $result["return_code"];
995
-		$this->returnMsg = isset($result['return_msg'])?$result['return_msg']:'';
995
+		$this->returnMsg = isset($result['return_msg']) ? $result['return_msg'] : '';
996 996
 
997 997
 		if ($this->returnCode == "SUCCESS") {
998
-			if(isset($result['result_code']) && $result['result_code'] == "FAIL"){
998
+			if (isset($result['result_code']) && $result['result_code'] == "FAIL") {
999 999
 				$this->resultCode = $result['result_code'];
1000 1000
 				$this->errCode = $result['err_code'];
1001 1001
 				$this->errCodeDes = $result['err_code_des'];
1002 1002
 				throw new Exception("[$this->errCode]$this->errCodeDes");
1003
-			}else{
1003
+			}else {
1004 1004
 				return $result;
1005 1005
 			}
1006
-		} else {
1007
-			if($result["return_code"] == "FAIL"){
1006
+		}else {
1007
+			if ($result["return_code"] == "FAIL") {
1008 1008
 				throw new Exception($this->returnMsg);
1009
-			}else{
1009
+			}else {
1010 1010
 				$this->resultCode = $result['result_code'];
1011 1011
 				$this->errCode = $result['err_code'];
1012 1012
 				$this->errCodeDes = $result['err_code_des'];
@@ -1015,28 +1015,28 @@  discard block
 block discarded – undo
1015 1015
 		}
1016 1016
 	}
1017 1017
 
1018
-	public function sign($data,$sign_type = WechatPay::SIGNTYPE_MD5) {
1018
+	public function sign($data, $sign_type = WechatPay::SIGNTYPE_MD5) {
1019 1019
 		ksort($data);
1020 1020
 		$string1 = "";
1021 1021
 		foreach ($data as $k => $v) {
1022
-			if ($v && trim($v)!='') {
1022
+			if ($v && trim($v) != '') {
1023 1023
 				$string1 .= "$k=$v&";
1024 1024
 			}
1025 1025
 		}
1026
-		$stringSignTemp = $string1 . "key=" . $this->config["api_key"];
1027
-		if($sign_type == WechatPay::SIGNTYPE_MD5){
1026
+		$stringSignTemp = $string1."key=".$this->config["api_key"];
1027
+		if ($sign_type == WechatPay::SIGNTYPE_MD5) {
1028 1028
 			$sign = strtoupper(md5($stringSignTemp));
1029
-		}elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){
1030
-			$sign = strtoupper(hash_hmac('sha256',$stringSignTemp,$this->config["api_key"]));
1029
+		}elseif ($sign_type == WechatPay::SIGNTYPE_HMACSHA256) {
1030
+			$sign = strtoupper(hash_hmac('sha256', $stringSignTemp, $this->config["api_key"]));
1031 1031
 		}else throw new Exception("Not supported sign type - $sign_type");
1032 1032
 		return $sign;
1033 1033
 	}
1034 1034
 
1035 1035
 	private function array2xml($array) {
1036
-		$xml = "<xml>" . PHP_EOL;
1036
+		$xml = "<xml>".PHP_EOL;
1037 1037
 		foreach ($array as $k => $v) {
1038
-			if($v && trim($v)!='')
1039
-				$xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL;
1038
+			if ($v && trim($v) != '')
1039
+				$xml .= "<$k><![CDATA[$v]]></$k>".PHP_EOL;
1040 1040
 		}
1041 1041
 		$xml .= "</xml>";
1042 1042
 		return $xml;
@@ -1045,17 +1045,17 @@  discard block
 block discarded – undo
1045 1045
 	private function xml2array($xml) {
1046 1046
 		$array = array();
1047 1047
 		$tmp = array();
1048
-		try{
1048
+		try {
1049 1049
 			$tmp = (array) simplexml_load_string($xml);
1050
-		}catch(Exception $e){}
1051
-		foreach ( $tmp as $k => $v) {
1050
+		} catch (Exception $e) {}
1051
+		foreach ($tmp as $k => $v) {
1052 1052
 			$array[$k] = (string) $v;
1053 1053
 		}
1054 1054
 		return $array;
1055 1055
 	}
1056 1056
 
1057 1057
 	private function getNonceStr() {
1058
-		return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"),0,32);
1058
+		return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"), 0, 32);
1059 1059
 	}
1060 1060
 
1061 1061
 }
1062 1062
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +73 added lines, -35 removed lines patch added patch discarded remove patch
@@ -182,7 +182,9 @@  discard block
 block discarded – undo
182 182
 		$data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:'';
183 183
 		$data["notify_url"]   = $this->config["notify_url"];
184 184
 		$data["trade_type"]   = self::TRADETYPE_MWEB;
185
-		if(!isset($this->config['h5_scene_info'])) throw new Exception('h5_scene_info should be configured');
185
+		if(!isset($this->config['h5_scene_info'])) {
186
+			throw new Exception('h5_scene_info should be configured');
187
+		}
186 188
 		$data["scene_info"]   = json_encode($this->config['h5_scene_info']);
187 189
 		$result = $this->unifiedOrder($data);
188 190
 		return $result["mweb_url"];
@@ -433,7 +435,9 @@  discard block
 block discarded – undo
433 435
 		$data["send_name"] = $send_name;
434 436
 		$data["re_openid"] = $re_openid;
435 437
 		$data["total_amount"] = $total_amount;
436
-		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000");
438
+		if($total_amount > 20000 && trim($scene_id)=='') {
439
+			throw new Exception("scene_id is required when total_amount beyond 20000");
440
+		}
437 441
 		$data["total_num"] = $total_num;
438 442
 		$data["wishing"] = $wishing;
439 443
 		$data["act_name"] = $act_name;
@@ -469,7 +473,9 @@  discard block
 block discarded – undo
469 473
 		$data["send_name"] = $send_name;
470 474
 		$data["re_openid"] = $re_openid;
471 475
 		$data["total_amount"] = $total_amount;
472
-		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
476
+		if($total_amount > 20000 && trim($scene_id)=='') {
477
+			throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
478
+		}
473 479
 		$data["total_num"] = $total_num;
474 480
 		$data["amt_type"] = 'ALL_RAND'; //红包金额设置方式 ALL_RAND—全部随机
475 481
 		$data["wishing"] = $wishing;
@@ -582,10 +588,10 @@  discard block
 block discarded – undo
582 588
 		if($this->validateSign($notify_data)){
583 589
 			if($callback && is_callable($callback)){
584 590
 				return call_user_func_array( $callback , [$notify_data] );
585
-			}else{
591
+			} else{
586 592
 				$this->responseNotify();
587 593
 			}
588
-		}else{
594
+		} else{
589 595
 			throw new Exception('Invalid paid notify data');
590 596
 		}
591 597
 	}
@@ -604,10 +610,10 @@  discard block
 block discarded – undo
604 610
 		if($this->validateSign($notify_data)){
605 611
 			if($callback && is_callable($callback)){
606 612
 				return call_user_func_array( $callback , $notify_data );
607
-			}else{
613
+			} else{
608 614
 				$this->responseNotify();
609 615
 			}
610
-		}else{
616
+		} else{
611 617
 			throw new Exception('Invalid refunded notify data');
612 618
 		}
613 619
 	}
@@ -666,12 +672,24 @@  discard block
 block discarded – undo
666 672
 		$data["return_code"] = $return_code;
667 673
 		$data["result_code"] = $result_code;
668 674
 		$data["user_ip"] = $user_ip;
669
-		if($out_trade_no) $data["out_trade_no"] = $out_trade_no;
670
-		if($time) $data["time"] = $time;
671
-		if($device_info) $data["device_info"] = $device_info;
672
-		if($return_msg) $data["return_msg"] = $return_msg;
673
-		if($err_code) $data["err_code"] = $err_code;
674
-		if($err_code_des) $data["err_code_des"] = $err_code_des;
675
+		if($out_trade_no) {
676
+			$data["out_trade_no"] = $out_trade_no;
677
+		}
678
+		if($time) {
679
+			$data["time"] = $time;
680
+		}
681
+		if($device_info) {
682
+			$data["device_info"] = $device_info;
683
+		}
684
+		if($return_msg) {
685
+			$data["return_msg"] = $return_msg;
686
+		}
687
+		if($err_code) {
688
+			$data["err_code"] = $err_code;
689
+		}
690
+		if($err_code_des) {
691
+			$data["err_code_des"] = $err_code_des;
692
+		}
675 693
 		$result = $this->post(self::URL_REPORT, $data, false);
676 694
 		return $result;
677 695
 	}
@@ -718,7 +736,9 @@  discard block
 block discarded – undo
718 736
 	 */
719 737
 	public function transferWallet($partner_trade_no,$openid,$amount,$desc,$spbill_create_ip = null,$re_user_name = null,$check_name = WechatPay::CHECKNAME_FORCECHECK){
720 738
 		$data = array();
721
-		if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required');
739
+		if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) {
740
+			throw new Exception('Real name is required');
741
+		}
722 742
 		$data["mch_appid"] = $this->config["app_id"];
723 743
 		$data["mchid"] = $this->config["mch_id"];
724 744
 		$data["partner_trade_no"] = $partner_trade_no;
@@ -760,7 +780,9 @@  discard block
 block discarded – undo
760 780
 	 * @throws Exception
761 781
 	 */
762 782
 	public function transferBankCard($partner_trade_no,$bank_no,$true_name,$bank_code,$amount,$desc){
763
-		if(!in_array($bank_code,array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code - $bank_code");
783
+		if(!in_array($bank_code,array_values(self::$BANKCODE))) {
784
+			throw new Exception("Unsupported bank code - $bank_code");
785
+		}
764 786
 		$data = array();
765 787
 		$data["partner_trade_no"] = $partner_trade_no;
766 788
 		$enc_bank_no = $this->rsaEncrypt($bank_no);
@@ -853,7 +875,7 @@  discard block
 block discarded – undo
853 875
 			fwrite($fp, $pubkey);
854 876
 			fclose($fp);
855 877
 			return $pubkey;
856
-		}else {
878
+		} else {
857 879
 			throw new Exception("RSA public key not found");
858 880
 		}
859 881
 	}
@@ -871,10 +893,11 @@  discard block
 block discarded – undo
871 893
 		$pubkey = $this->getPublicKey();
872 894
 		$encrypted = null;
873 895
 		$pubkey = openssl_get_publickey($pubkey);
874
-		if (openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING))
875
-			$data = base64_encode($encrypted);
876
-		else
877
-			throw new Exception('Unable to encrypt data');
896
+		if (openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING)) {
897
+					$data = base64_encode($encrypted);
898
+		} else {
899
+					throw new Exception('Unable to encrypt data');
900
+		}
878 901
 		return $data;
879 902
 	}
880 903
 
@@ -938,7 +961,9 @@  discard block
 block discarded – undo
938 961
 				$data = $this->getWechatOAuth()->getTicket();
939 962
 				$fp = fopen($this->config["jsapi_ticket"], "w");
940 963
 				fwrite($fp, $data);
941
-				if ($fp) fclose($fp);
964
+				if ($fp) {
965
+					fclose($fp);
966
+				}
942 967
 				$data = json_decode($data);
943 968
 			}
944 969
 			return $data->jsapi_ticket;
@@ -946,9 +971,15 @@  discard block
 block discarded – undo
946 971
 	}
947 972
 
948 973
 	private function post($url, $data,$cert = true) {
949
-		if(!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"];
950
-		if(!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr();
951
-		if(!isset($data['sign'])) $data['sign'] = $this->sign($data);
974
+		if(!isset($data['mch_id']) && !isset($data['mchid'])) {
975
+			$data["mch_id"] = $this->config["mch_id"];
976
+		}
977
+		if(!isset($data['nonce_str'])) {
978
+			$data["nonce_str"] = $this->getNonceStr();
979
+		}
980
+		if(!isset($data['sign'])) {
981
+			$data['sign'] = $this->sign($data);
982
+		}
952 983
 		$this->requestXML = $this->responseXML = null;
953 984
 		$this->requestArray = $this->responseArray = null;
954 985
 
@@ -976,12 +1007,16 @@  discard block
 block discarded – undo
976 1007
 			$url = "{$host}/sandboxnew{$url}";
977 1008
 		}
978 1009
 		$content = $this->httpClient->post($url,$this->requestXML,[],$opts);
979
-		if(!$content) throw new Exception("Empty response with {$this->requestXML}");
1010
+		if(!$content) {
1011
+			throw new Exception("Empty response with {$this->requestXML}");
1012
+		}
980 1013
 
981 1014
 		$this->responseXML = $content;
982
-		if($processResponse)
983
-			return $this->processResponseXML($this->responseXML);
984
-		else return $this->responseXML;
1015
+		if($processResponse) {
1016
+					return $this->processResponseXML($this->responseXML);
1017
+		} else {
1018
+			return $this->responseXML;
1019
+		}
985 1020
 
986 1021
 	}
987 1022
 
@@ -1000,13 +1035,13 @@  discard block
 block discarded – undo
1000 1035
 				$this->errCode = $result['err_code'];
1001 1036
 				$this->errCodeDes = $result['err_code_des'];
1002 1037
 				throw new Exception("[$this->errCode]$this->errCodeDes");
1003
-			}else{
1038
+			} else{
1004 1039
 				return $result;
1005 1040
 			}
1006 1041
 		} else {
1007 1042
 			if($result["return_code"] == "FAIL"){
1008 1043
 				throw new Exception($this->returnMsg);
1009
-			}else{
1044
+			} else{
1010 1045
 				$this->resultCode = $result['result_code'];
1011 1046
 				$this->errCode = $result['err_code'];
1012 1047
 				$this->errCodeDes = $result['err_code_des'];
@@ -1026,17 +1061,20 @@  discard block
 block discarded – undo
1026 1061
 		$stringSignTemp = $string1 . "key=" . $this->config["api_key"];
1027 1062
 		if($sign_type == WechatPay::SIGNTYPE_MD5){
1028 1063
 			$sign = strtoupper(md5($stringSignTemp));
1029
-		}elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){
1064
+		} elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){
1030 1065
 			$sign = strtoupper(hash_hmac('sha256',$stringSignTemp,$this->config["api_key"]));
1031
-		}else throw new Exception("Not supported sign type - $sign_type");
1066
+		} else {
1067
+			throw new Exception("Not supported sign type - $sign_type");
1068
+		}
1032 1069
 		return $sign;
1033 1070
 	}
1034 1071
 
1035 1072
 	private function array2xml($array) {
1036 1073
 		$xml = "<xml>" . PHP_EOL;
1037 1074
 		foreach ($array as $k => $v) {
1038
-			if($v && trim($v)!='')
1039
-				$xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL;
1075
+			if($v && trim($v)!='') {
1076
+							$xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL;
1077
+			}
1040 1078
 		}
1041 1079
 		$xml .= "</xml>";
1042 1080
 		return $xml;
@@ -1047,7 +1085,7 @@  discard block
 block discarded – undo
1047 1085
 		$tmp = array();
1048 1086
 		try{
1049 1087
 			$tmp = (array) simplexml_load_string($xml);
1050
-		}catch(Exception $e){}
1088
+		} catch(Exception $e){}
1051 1089
 		foreach ( $tmp as $k => $v) {
1052 1090
 			$array[$k] = (string) $v;
1053 1091
 		}
Please login to merge, or discard this patch.