Passed
Push — master ( de13f2...c385cb )
by Wei
02:39
created
src/WechatOAuth.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 namespace zhangv\wechat;
7 7
 
8 8
 class WechatOAuth {
9
-	const TICKETTYPE_JSAPI = 'jsapi',TICKETTYPE_WXCARD = 'wx_card';
9
+	const TICKETTYPE_JSAPI = 'jsapi', TICKETTYPE_WXCARD = 'wx_card';
10 10
 	public $responseJSON = null;
11 11
 	public $errCode = null;
12 12
 	public $errMsg = null;
@@ -16,46 +16,46 @@  discard block
 block discarded – undo
16 16
 	private $httpClient = null;
17 17
 	private $accessToken = null;
18 18
 
19
-	public function __construct($appId,$appSecret) {
19
+	public function __construct($appId, $appSecret) {
20 20
 		$this->appId = $appId;
21 21
 		$this->appSecret = $appSecret;
22 22
 		$this->httpClient = new HttpClient();
23 23
 	}
24 24
 
25
-	public function setHttpClient($httpClient){
25
+	public function setHttpClient($httpClient) {
26 26
 		$this->httpClient = $httpClient;
27 27
 	}
28 28
 
29
-	public function authorizeURI($redirectURI,$scope = 'snsapi_userinfo',$state = ''){
29
+	public function authorizeURI($redirectURI, $scope = 'snsapi_userinfo', $state = '') {
30 30
 		$redirectURI = urlencode($redirectURI);
31 31
 		return "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$this->appId}&redirect_uri={$redirectURI}&response_type=code&scope=$scope&state=$state#wechat_redirect";
32 32
 	}
33 33
 
34
-	public function authorize($code){
34
+	public function authorize($code) {
35 35
 		$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$this->appId}&secret={$this->appSecret}&code=$code&grant_type=authorization_code";
36 36
 		$this->responseJSON = $this->httpClient->get($url);
37 37
 		return json_decode($this->responseJSON);
38 38
 	}
39 39
 
40
-	public function getUserInfo($openId){
40
+	public function getUserInfo($openId) {
41 41
 		$url = "https://api.weixin.qq.com/sns/userinfo?access_token={$this->accessToken}&openid=$openId&lang=zh_CN";
42 42
 		$this->responseJSON = $this->httpClient->get($url);
43 43
 		return json_decode($this->responseJSON);
44 44
 	}
45 45
 
46
-	public function refreshToken($refreshToken){
46
+	public function refreshToken($refreshToken) {
47 47
 		$url = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid={$this->appId}&grant_type=refresh_token&refresh_token=$refreshToken";
48 48
 		$this->responseJSON = $this->httpClient->get($url);
49 49
 		return json_decode($this->responseJSON);
50 50
 	}
51 51
 
52
-	public function verifyToken($accessToken,$openId){
52
+	public function verifyToken($accessToken, $openId) {
53 53
 		$url = "https://api.weixin.qq.com/sns/auth?access_token=$accessToken&openid=$openId";
54 54
 		$this->responseJSON = $this->httpClient->get($url);
55 55
 		return json_decode($this->responseJSON);
56 56
 	}
57 57
 
58
-	public function getAccessToken(){
58
+	public function getAccessToken() {
59 59
 		$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->appId}&secret={$this->appSecret}";
60 60
 		$this->responseJSON = $this->httpClient->get($url);
61 61
 		$json = json_decode($this->responseJSON);
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
 		return $this->accessToken;
64 64
 	}
65 65
 
66
-	public function getTicket($type = WechatOAuth::TICKETTYPE_JSAPI, $accessToken = null){
67
-		if(!$accessToken) $accessToken = $this->getAccessToken();
66
+	public function getTicket($type = WechatOAuth::TICKETTYPE_JSAPI, $accessToken = null) {
67
+		if (!$accessToken) $accessToken = $this->getAccessToken();
68 68
 		// $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$accessToken";
69 69
 		$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type={$type}&access_token=$accessToken";
70 70
 		$this->responseJSON = $this->httpClient->get($url);
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,9 @@
 block discarded – undo
64 64
 	}
65 65
 
66 66
 	public function getTicket($type = WechatOAuth::TICKETTYPE_JSAPI, $accessToken = null){
67
-		if(!$accessToken) $accessToken = $this->getAccessToken();
67
+		if(!$accessToken) {
68
+			$accessToken = $this->getAccessToken();
69
+		}
68 70
 		// $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$accessToken";
69 71
 		$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type={$type}&access_token=$accessToken";
70 72
 		$this->responseJSON = $this->httpClient->get($url);
Please login to merge, or discard this patch.
src/WechatPay.php 2 patches
Spacing   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -8,10 +8,10 @@  discard block
 block discarded – undo
8 8
 use \Exception;
9 9
 
10 10
 class WechatPay {
11
-	const TRADETYPE_JSAPI = 'JSAPI',TRADETYPE_NATIVE = 'NATIVE',TRADETYPE_APP = 'APP',TRADETYPE_MWEB = 'MWEB';
11
+	const TRADETYPE_JSAPI = 'JSAPI', TRADETYPE_NATIVE = 'NATIVE', TRADETYPE_APP = 'APP', TRADETYPE_MWEB = 'MWEB';
12 12
 	const SIGNTYPE_MD5 = 'MD5', SIGNTYPE_HMACSHA256 = 'HMAC-SHA256';
13
-	const CHECKNAME_FORCECHECK = 'FORCE_CHECK',CHECKNAME_NOCHECK = 'NO_CHECK';
14
-	const ACCOUNTTYPE_BASIC = 'Basic',ACCOUNTTYPE_OPERATION = 'Operation',ACCOUNTTYPE_FEES = 'Fees';
13
+	const CHECKNAME_FORCECHECK = 'FORCE_CHECK', CHECKNAME_NOCHECK = 'NO_CHECK';
14
+	const ACCOUNTTYPE_BASIC = 'Basic', ACCOUNTTYPE_OPERATION = 'Operation', ACCOUNTTYPE_FEES = 'Fees';
15 15
 	/** 支付 */
16 16
 	const URL_UNIFIEDORDER = "https://api.mch.weixin.qq.com/pay/unifiedorder";
17 17
 	const URL_ORDERQUERY = "https://api.mch.weixin.qq.com/pay/orderquery";
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	const URL_GETPUBLICKEY = 'https://fraud.mch.weixin.qq.com/risk/getpublickey';
44 44
 	public static $BANKCODE = ['工商银行' => '1002', '农业银行' => '1005', '中国银行' => '1026', '建设银行' => '1003', '招商银行' => '1001',
45 45
 		'邮储银行' => '1066', '交通银行' => '1020', '浦发银行' => '1004', '民生银行' => '1006', '兴业银行' => '1009', '平安银行' => '1010',
46
-		'中信银行' => '1021', '华夏银行' => '1025', '广发银行' => '1027', '光大银行' => '1022', '北京银行' => '1032', '宁波银行' => '1056',];
46
+		'中信银行' => '1021', '华夏银行' => '1025', '广发银行' => '1027', '光大银行' => '1022', '北京银行' => '1032', '宁波银行' => '1056', ];
47 47
 
48 48
 	public $getSignKeyUrl = "https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey";
49 49
 	public $sandbox = false;
@@ -83,26 +83,26 @@  discard block
 block discarded – undo
83 83
 		$this->httpClient = new HttpClient(5);
84 84
 	}
85 85
 
86
-	public function setWechatOAuth($wechatOAuth){
86
+	public function setWechatOAuth($wechatOAuth) {
87 87
 		$this->wechatOAuth = $wechatOAuth;
88 88
 	}
89 89
 
90
-	public function getWechatOAuth(){
91
-		if(!$this->wechatOAuth){
92
-			$this->wechatOAuth = new WechatOAuth($this->config['app_id'],$this->config['app_secret']);
90
+	public function getWechatOAuth() {
91
+		if (!$this->wechatOAuth) {
92
+			$this->wechatOAuth = new WechatOAuth($this->config['app_id'], $this->config['app_secret']);
93 93
 		}
94 94
 		return $this->wechatOAuth;
95 95
 	}
96 96
 
97
-	public function setConfig($config){
97
+	public function setConfig($config) {
98 98
 		$this->config = $config;
99 99
 	}
100 100
 
101
-	public function getConfig(){
101
+	public function getConfig() {
102 102
 		return $this->config;
103 103
 	}
104 104
 
105
-	public function setHttpClient($httpClient){
105
+	public function setHttpClient($httpClient) {
106 106
 		$this->httpClient = $httpClient;
107 107
 	}
108 108
 
@@ -118,16 +118,16 @@  discard block
 block discarded – undo
118 118
 	 * @return string
119 119
 	 * @throws \Exception
120 120
 	 */
121
-	public function getPrepayId($body,$out_trade_no,$total_fee,$openid,$spbill_create_ip = null,$ext = null) {
122
-		$data = ($ext && is_array($ext))?$ext:array();
121
+	public function getPrepayId($body, $out_trade_no, $total_fee, $openid, $spbill_create_ip = null, $ext = null) {
122
+		$data = ($ext && is_array($ext)) ? $ext : array();
123 123
 		$data["body"]         = $body;
124 124
 		$data["out_trade_no"] = $out_trade_no;
125 125
 		$data["total_fee"]    = $total_fee;
126
-		$data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["REMOTE_ADDR"];
126
+		$data["spbill_create_ip"] = $spbill_create_ip ?: $_SERVER["REMOTE_ADDR"];
127 127
 		$data["notify_url"]   = $this->config["notify_url"];
128 128
 		$data["trade_type"]   = WechatPay::TRADETYPE_JSAPI;
129
-		if(!$openid) throw new Exception('openid is required when trade_type is JSAPI');
130
-		$data["openid"]   = $openid;
129
+		if (!$openid) throw new Exception('openid is required when trade_type is JSAPI');
130
+		$data["openid"] = $openid;
131 131
 		$result = $this->unifiedOrder($data);
132 132
 		return $result["prepay_id"];
133 133
 	}
@@ -142,8 +142,8 @@  discard block
 block discarded – undo
142 142
 	 * @param $ext array
143 143
 	 * @return string
144 144
 	 */
145
-	public function getPrepayIdAPP($body,$out_trade_no,$total_fee,$spbill_create_ip,$ext = null) {
146
-		$data = ($ext && is_array($ext))?$ext:array();
145
+	public function getPrepayIdAPP($body, $out_trade_no, $total_fee, $spbill_create_ip, $ext = null) {
146
+		$data = ($ext && is_array($ext)) ? $ext : array();
147 147
 		$data["body"]         = $body;
148 148
 		$data["out_trade_no"] = $out_trade_no;
149 149
 		$data["total_fee"]    = $total_fee;
@@ -166,15 +166,15 @@  discard block
 block discarded – undo
166 166
 	 * @return string
167 167
 	 * @throws Exception
168 168
 	 */
169
-	public function getCodeUrl($body,$out_trade_no,$total_fee,$product_id,$spbill_create_ip = null,$ext = null){
170
-		$data = ($ext && is_array($ext))?$ext:array();
169
+	public function getCodeUrl($body, $out_trade_no, $total_fee, $product_id, $spbill_create_ip = null, $ext = null) {
170
+		$data = ($ext && is_array($ext)) ? $ext : array();
171 171
 		$data["body"]         = $body;
172 172
 		$data["out_trade_no"] = $out_trade_no;
173 173
 		$data["total_fee"]    = $total_fee;
174
-		$data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["SERVER_ADDR"];
174
+		$data["spbill_create_ip"] = $spbill_create_ip ?: $_SERVER["SERVER_ADDR"];
175 175
 		$data["notify_url"]   = $this->config["notify_url"];
176 176
 		$data["trade_type"]   = self::TRADETYPE_NATIVE;
177
-		if(!$product_id) throw new Exception('product_id is required when trade_type is NATIVE');
177
+		if (!$product_id) throw new Exception('product_id is required when trade_type is NATIVE');
178 178
 		$data["product_id"]   = $product_id;
179 179
 		$result = $this->unifiedOrder($data);
180 180
 		return $result["code_url"];
@@ -190,15 +190,15 @@  discard block
 block discarded – undo
190 190
 	 * @return string
191 191
 	 * @throws Exception
192 192
 	 */
193
-	public function getMwebUrl($body,$out_trade_no,$total_fee,$ext = null){
194
-		$data = ($ext && is_array($ext))?$ext:array();
193
+	public function getMwebUrl($body, $out_trade_no, $total_fee, $ext = null) {
194
+		$data = ($ext && is_array($ext)) ? $ext : array();
195 195
 		$data["body"]         = $body;
196 196
 		$data["out_trade_no"] = $out_trade_no;
197 197
 		$data["total_fee"]    = $total_fee;
198
-		$data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:'';
198
+		$data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : '';
199 199
 		$data["notify_url"]   = $this->config["notify_url"];
200 200
 		$data["trade_type"]   = self::TRADETYPE_MWEB;
201
-		if(!isset($this->config['h5_scene_info'])) throw new Exception('h5_scene_info should be configured');
201
+		if (!isset($this->config['h5_scene_info'])) throw new Exception('h5_scene_info should be configured');
202 202
 		$data["scene_info"]   = json_encode($this->config['h5_scene_info']);
203 203
 		$result = $this->unifiedOrder($data);
204 204
 		return $result["mweb_url"];
@@ -214,25 +214,25 @@  discard block
 block discarded – undo
214 214
 	public function unifiedOrder($params) {
215 215
 		$data = array();
216 216
 		$data["appid"] = $this->config["app_id"];
217
-		$data["device_info"] = (isset($params['device_info'])&&trim($params['device_info'])!='')?$params['device_info']:null;
217
+		$data["device_info"] = (isset($params['device_info']) && trim($params['device_info']) != '') ? $params['device_info'] : null;
218 218
 		$data["body"] = $params['body'];
219
-		$data["detail"] = isset($params['detail'])?$params['detail']:null;//optional
220
-		$data["attach"] = isset($params['attach'])?$params['attach']:null;//optional
221
-		$data["out_trade_no"] = isset($params['out_trade_no'])?$params['out_trade_no']:null;
222
-		$data["fee_type"] = isset($params['fee_type'])?$params['fee_type']:'CNY';
219
+		$data["detail"] = isset($params['detail']) ? $params['detail'] : null; //optional
220
+		$data["attach"] = isset($params['attach']) ? $params['attach'] : null; //optional
221
+		$data["out_trade_no"] = isset($params['out_trade_no']) ? $params['out_trade_no'] : null;
222
+		$data["fee_type"] = isset($params['fee_type']) ? $params['fee_type'] : 'CNY';
223 223
 		$data["total_fee"]    = $params['total_fee'];
224 224
 		$data["spbill_create_ip"] = $params['spbill_create_ip'];
225
-		$data["time_start"] = isset($params['time_start'])?$params['time_start']:null;//optional
226
-		$data["time_expire"] = isset($params['time_expire'])?$params['time_expire']:null;//optional
227
-		$data["goods_tag"] = isset($params['goods_tag'])?$params['goods_tag']:null;
225
+		$data["time_start"] = isset($params['time_start']) ? $params['time_start'] : null; //optional
226
+		$data["time_expire"] = isset($params['time_expire']) ? $params['time_expire'] : null; //optional
227
+		$data["goods_tag"] = isset($params['goods_tag']) ? $params['goods_tag'] : null;
228 228
 		$data["notify_url"] = $this->config["notify_url"];
229 229
 		$data["trade_type"] = $params['trade_type'];
230
-		if($params['trade_type'] == WechatPay::TRADETYPE_NATIVE){
231
-			if(!isset($params['product_id'])) throw new Exception('product_id is required when trade_type is NATIVE');
230
+		if ($params['trade_type'] == WechatPay::TRADETYPE_NATIVE) {
231
+			if (!isset($params['product_id'])) throw new Exception('product_id is required when trade_type is NATIVE');
232 232
 			$data["product_id"] = $params['product_id'];
233 233
 		}
234
-		if($params['trade_type'] == WechatPay::TRADETYPE_JSAPI){
235
-			if(!isset($params['openid'])) throw new Exception('openid is required when trade_type is JSAPI');
234
+		if ($params['trade_type'] == WechatPay::TRADETYPE_JSAPI) {
235
+			if (!isset($params['openid'])) throw new Exception('openid is required when trade_type is JSAPI');
236 236
 			$data["openid"] = $params['openid'];
237 237
 		}
238 238
 		$result = $this->post(self::URL_UNIFIEDORDER, $data);
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 	 * @param $transaction_id string 微信订单号
246 246
 	 * @return array
247 247
 	 */
248
-	public function queryOrderByTransactionId($transaction_id){
248
+	public function queryOrderByTransactionId($transaction_id) {
249 249
 		$data = array();
250 250
 		$data["appid"] = $this->config["app_id"];
251 251
 		$data["transaction_id"] = $transaction_id;
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 	 * @param $out_trade_no string 商户订单号
260 260
 	 * @return array
261 261
 	 */
262
-	public function queryOrderByOutTradeNo($out_trade_no){
262
+	public function queryOrderByOutTradeNo($out_trade_no) {
263 263
 		$data = array();
264 264
 		$data["appid"] = $this->config["app_id"];
265 265
 		$data["out_trade_no"] = $out_trade_no;
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 	 * @param $offset int 偏移
275 275
 	 * @return array
276 276
 	 */
277
-	public function queryRefundByTransactionId($transaction_id,$offset = 0){
277
+	public function queryRefundByTransactionId($transaction_id, $offset = 0) {
278 278
 		$data = array();
279 279
 		$data["appid"] = $this->config["app_id"];
280 280
 		$data["transaction_id"] = $transaction_id;
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 	 * @param $offset int 偏移
291 291
 	 * @return array
292 292
 	 */
293
-	public function queryRefundByOutTradeNo($out_trade_no,$offset = 0){
293
+	public function queryRefundByOutTradeNo($out_trade_no, $offset = 0) {
294 294
 		$data = array();
295 295
 		$data["appid"] = $this->config["app_id"];
296 296
 		$data["out_trade_no"] = $out_trade_no;
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
 	 * @param $offset int 偏移
307 307
 	 * @return array
308 308
 	 */
309
-	public function queryRefundByRefundId($refund_id,$offset = 0){
309
+	public function queryRefundByRefundId($refund_id, $offset = 0) {
310 310
 		$data = array();
311 311
 		$data["appid"] = $this->config["app_id"];
312 312
 		$data["refund_id"] = $refund_id;
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 	 * @param $offset int 偏移
323 323
 	 * @return array
324 324
 	 */
325
-	public function queryRefundByOutRefundNo($out_refund_no,$offset = 0){
325
+	public function queryRefundByOutRefundNo($out_refund_no, $offset = 0) {
326 326
 		$data = array();
327 327
 		$data["appid"] = $this->config["app_id"];
328 328
 		$data["out_refund_no"] = $out_refund_no;
@@ -337,11 +337,11 @@  discard block
 block discarded – undo
337 337
 	 * @param $out_trade_no string 商户订单号
338 338
 	 * @return array
339 339
 	 */
340
-	public function closeOrder($out_trade_no){
340
+	public function closeOrder($out_trade_no) {
341 341
 		$data = array();
342 342
 		$data["appid"] = $this->config["app_id"];
343 343
 		$data["out_trade_no"] = $out_trade_no;
344
-		$result = $this->post(self::URL_CLOSEORDER, $data,false);
344
+		$result = $this->post(self::URL_CLOSEORDER, $data, false);
345 345
 		return $result;
346 346
 	}
347 347
 
@@ -356,14 +356,14 @@  discard block
 block discarded – undo
356 356
 	 * @param $ext array 扩展数组
357 357
 	 * @return array
358 358
 	 */
359
-	public function refundByOutTradeNo($out_trade_no,$out_refund_no,$total_fee,$refund_fee,$ext = array()){
360
-		$data = ($ext && is_array($ext))?$ext:array();
359
+	public function refundByOutTradeNo($out_trade_no, $out_refund_no, $total_fee, $refund_fee, $ext = array()) {
360
+		$data = ($ext && is_array($ext)) ? $ext : array();
361 361
 		$data["appid"] = $this->config["app_id"];
362 362
 		$data["out_trade_no"] = $out_trade_no;
363 363
 		$data["out_refund_no"] = $out_refund_no;
364 364
 		$data["total_fee"] = $total_fee;
365 365
 		$data["refund_fee"] = $refund_fee;
366
-		$result = $this->post(self::URL_REFUND, $data,true);
366
+		$result = $this->post(self::URL_REFUND, $data, true);
367 367
 		return $result;
368 368
 	}
369 369
 
@@ -378,14 +378,14 @@  discard block
 block discarded – undo
378 378
 	 * @param $ext array 扩展数组
379 379
 	 * @return array
380 380
 	 */
381
-	public function refundByTransactionId($transaction_id,$out_refund_no,$total_fee,$refund_fee,$ext = array()){
382
-		$data = ($ext && is_array($ext))?$ext:array();
381
+	public function refundByTransactionId($transaction_id, $out_refund_no, $total_fee, $refund_fee, $ext = array()) {
382
+		$data = ($ext && is_array($ext)) ? $ext : array();
383 383
 		$data["appid"] = $this->config["app_id"];
384 384
 		$data["transaction_id"] = $transaction_id;
385 385
 		$data["out_refund_no"] = $out_refund_no;
386 386
 		$data["total_fee"] = $total_fee;
387 387
 		$data["refund_fee"] = $refund_fee;
388
-		$result = $this->post(self::URL_REFUND, $data,true);
388
+		$result = $this->post(self::URL_REFUND, $data, true);
389 389
 		return $result;
390 390
 	}
391 391
 
@@ -395,11 +395,11 @@  discard block
 block discarded – undo
395 395
 	 * @param $out_trade_no string 商户订单号
396 396
 	 * @return array
397 397
 	 */
398
-	public function reverseByOutTradeNo($out_trade_no){
398
+	public function reverseByOutTradeNo($out_trade_no) {
399 399
 		$data = array();
400 400
 		$data["appid"] = $this->config["app_id"];
401 401
 		$data["out_trade_no"] = $out_trade_no;
402
-		$result = $this->post(self::URL_REVERSE, $data,true);
402
+		$result = $this->post(self::URL_REVERSE, $data, true);
403 403
 		return $result;
404 404
 	}
405 405
 
@@ -409,11 +409,11 @@  discard block
 block discarded – undo
409 409
 	 * @param $transaction_id string 微信订单号
410 410
 	 * @return array
411 411
 	 */
412
-	public function reverseByTransactionId($transaction_id){
412
+	public function reverseByTransactionId($transaction_id) {
413 413
 		$data = array();
414 414
 		$data["appid"] = $this->config["app_id"];
415 415
 		$data["transaction_id"] = $transaction_id;
416
-		$result = $this->post(self::URL_REVERSE, $data,true);
416
+		$result = $this->post(self::URL_REVERSE, $data, true);
417 417
 		return $result;
418 418
 	}
419 419
 
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
 	 * @param $bill_type string 类型 ALL|SUCCESS
425 425
 	 * @return array
426 426
 	 */
427
-	public function downloadBill($bill_date,$bill_type = 'ALL'){
427
+	public function downloadBill($bill_date, $bill_type = 'ALL') {
428 428
 		$data = array();
429 429
 		$data["appid"] = $this->config["app_id"];
430 430
 		$data["bill_date"] = $bill_date;
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
 	 * @param $tar_type string 压缩账单
442 442
 	 * @return array
443 443
 	 */
444
-	public function downloadFundFlow($bill_date,$account_type = self::ACCOUNTTYPE_BASIC,$tar_type = 'GZIP'){
444
+	public function downloadFundFlow($bill_date, $account_type = self::ACCOUNTTYPE_BASIC, $tar_type = 'GZIP') {
445 445
 		$data = array();
446 446
 		$data["appid"] = $this->config["app_id"];
447 447
 		$data["bill_date"] = $bill_date;
@@ -468,14 +468,14 @@  discard block
 block discarded – undo
468 468
 	 * @return array
469 469
 	 * @throws Exception
470 470
 	 */
471
-	public function sendRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark,$scene_id = '',$riskinfo = '',$consume_mch_id = ''){
471
+	public function sendRedPack($mch_billno, $send_name, $re_openid, $total_amount, $total_num, $wishing, $act_name, $remark, $scene_id = '', $riskinfo = '', $consume_mch_id = '') {
472 472
 		$data = array();
473 473
 		$data["wxappid"] = $this->config["app_id"];
474 474
 		$data["mch_billno"] = $mch_billno;
475 475
 		$data["send_name"] = $send_name;
476 476
 		$data["re_openid"] = $re_openid;
477 477
 		$data["total_amount"] = $total_amount;
478
-		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000");
478
+		if ($total_amount > 20000 && trim($scene_id) == '') throw new Exception("scene_id is required when total_amount beyond 20000");
479 479
 		$data["total_num"] = $total_num;
480 480
 		$data["wishing"] = $wishing;
481 481
 		$data["act_name"] = $act_name;
@@ -504,14 +504,14 @@  discard block
 block discarded – undo
504 504
 	 * @return array
505 505
 	 * @throws Exception
506 506
 	 */
507
-	public function sendGroupRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark,$scene_id = '',$riskinfo = '',$consume_mch_id = ''){
507
+	public function sendGroupRedPack($mch_billno, $send_name, $re_openid, $total_amount, $total_num, $wishing, $act_name, $remark, $scene_id = '', $riskinfo = '', $consume_mch_id = '') {
508 508
 		$data = array();
509
-		$data["wxappid"] = $this->config["app_id"];//NOTE: WXappid
509
+		$data["wxappid"] = $this->config["app_id"]; //NOTE: WXappid
510 510
 		$data["mch_billno"] = $mch_billno;
511 511
 		$data["send_name"] = $send_name;
512 512
 		$data["re_openid"] = $re_openid;
513 513
 		$data["total_amount"] = $total_amount;
514
-		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
514
+		if ($total_amount > 20000 && trim($scene_id) == '') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
515 515
 		$data["total_num"] = $total_num;
516 516
 		$data["amt_type"] = 'ALL_RAND'; //红包金额设置方式 ALL_RAND—全部随机
517 517
 		$data["wishing"] = $wishing;
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
 	 * @throws Exception
532 532
 	 * @ref https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_6&index=5
533 533
 	 */
534
-	public function getHbInfo($mch_billno){
534
+	public function getHbInfo($mch_billno) {
535 535
 		$data = array();
536 536
 		$data["mch_billno"] = $mch_billno;
537 537
 		$data["appid"] = $this->config["app_id"];
@@ -549,14 +549,14 @@  discard block
 block discarded – undo
549 549
 	 * @param int $limit 条数
550 550
 	 * @return array
551 551
 	 */
552
-	public function batchQueryComment($begin_time,$end_time,$offset = 0,$limit = 200){
552
+	public function batchQueryComment($begin_time, $end_time, $offset = 0, $limit = 200) {
553 553
 		$data = array();
554 554
 		$data["appid"] = $this->config["app_id"];
555 555
 		$data["begin_time"] = $begin_time;
556 556
 		$data["end_time"] = $end_time;
557 557
 		$data["offset"] = $offset;
558 558
 		$data["limit"] = $limit;
559
-		$data["sign"] = $this->sign($data,WechatPay::SIGNTYPE_HMACSHA256);
559
+		$data["sign"] = $this->sign($data, WechatPay::SIGNTYPE_HMACSHA256);
560 560
 		$result = $this->post(self::URL_BATCHQUERYCOMMENT, $data, true); //cert is required
561 561
 		return $result;
562 562
 	}
@@ -569,21 +569,21 @@  discard block
 block discarded – undo
569 569
 	 */
570 570
 	public function getPackage($prepay_id, $trade_type = WechatPay::TRADETYPE_JSAPI) {
571 571
 		$data = array();
572
-		if ($trade_type == WechatPay::TRADETYPE_JSAPI){
572
+		if ($trade_type == WechatPay::TRADETYPE_JSAPI) {
573 573
 			$data["package"]   = "prepay_id=$prepay_id";
574 574
 			$data["timeStamp"] = time();
575 575
 			$data["nonceStr"]  = $this->getNonceStr();
576 576
 			$data["appId"] = $this->config["app_id"];
577 577
 			$data["signType"]  = "MD5";
578 578
 			$data["paySign"]   = $this->sign($data);
579
-		} else if ($trade_type == WechatPay::TRADETYPE_APP){
579
+		}else if ($trade_type == WechatPay::TRADETYPE_APP) {
580 580
 			$data["package"]   = "Sign=WXPay";
581 581
 			$data['prepayid'] = $prepay_id;
582 582
 			$data['partnerid'] = $this->config["mch_id"];
583 583
 			$data["timestamp"] = time();
584 584
 			$data["noncestr"]  = $this->getNonceStr();
585 585
 			$data["appid"] = $this->config["app_id"];
586
-			$data["sign"]   = $this->sign($data);
586
+			$data["sign"] = $this->sign($data);
587 587
 		}
588 588
 		return $data;
589 589
 	}
@@ -599,15 +599,15 @@  discard block
 block discarded – undo
599 599
 	 * @param array $ext
600 600
 	 * @return array
601 601
 	 */
602
-	public function microPay($body,$out_trade_no,$total_fee,$spbill_create_ip,$auth_code,$ext = array()){
603
-		$data = (!empty($ext) && is_array($ext))?$ext:array();
602
+	public function microPay($body, $out_trade_no, $total_fee, $spbill_create_ip, $auth_code, $ext = array()) {
603
+		$data = (!empty($ext) && is_array($ext)) ? $ext : array();
604 604
 		$data["appid"] = $this->config["app_id"];
605 605
 		$data["body"]         = $body;
606 606
 		$data["out_trade_no"] = $out_trade_no;
607 607
 		$data["total_fee"]    = $total_fee;
608 608
 		$data["spbill_create_ip"] = $spbill_create_ip;
609 609
 		$data["auth_code"] = $auth_code;
610
-		$result = $this->post(self::URL_MICROPAY,$data,false);
610
+		$result = $this->post(self::URL_MICROPAY, $data, false);
611 611
 		return $result;
612 612
 	}
613 613
 
@@ -618,15 +618,15 @@  discard block
 block discarded – undo
618 618
 	 * @return null
619 619
 	 * @throws Exception
620 620
 	 */
621
-	public function onPaidNotify($notify_data,callable $callback = null){
622
-		if(!is_array($notify_data)){
621
+	public function onPaidNotify($notify_data, callable $callback = null) {
622
+		if (!is_array($notify_data)) {
623 623
 			$notify_data = $this->xml2array($notify_data);
624 624
 		}
625
-		if($this->validateSign($notify_data)){
626
-			if($callback && is_callable($callback)){
627
-				return call_user_func_array( $callback , [$notify_data] );
625
+		if ($this->validateSign($notify_data)) {
626
+			if ($callback && is_callable($callback)) {
627
+				return call_user_func_array($callback, [$notify_data]);
628 628
 			}
629
-		}else{
629
+		}else {
630 630
 			throw new Exception('Invalid paid notify data');
631 631
 		}
632 632
 	}
@@ -638,15 +638,15 @@  discard block
 block discarded – undo
638 638
 	 * @return mixed
639 639
 	 * @throws Exception
640 640
 	 */
641
-	public function onRefundedNotify($notify_data,callable $callback = null){
642
-		if(!is_array($notify_data)){
641
+	public function onRefundedNotify($notify_data, callable $callback = null) {
642
+		if (!is_array($notify_data)) {
643 643
 			$notify_data = $this->xml2array($notify_data);
644 644
 		}
645
-		if($this->validateSign($notify_data)){
646
-			if($callback && is_callable($callback)){
647
-				return call_user_func_array( $callback ,[$notify_data] );
645
+		if ($this->validateSign($notify_data)) {
646
+			if ($callback && is_callable($callback)) {
647
+				return call_user_func_array($callback, [$notify_data]);
648 648
 			}
649
-		}else{
649
+		}else {
650 650
 			throw new Exception('Invalid refunded notify data');
651 651
 		}
652 652
 	}
@@ -673,13 +673,13 @@  discard block
 block discarded – undo
673 673
 	 * @param bool $print
674 674
 	 * @return string
675 675
 	 */
676
-	public function responseNotify($print = true,$data = [],$return_code="SUCCESS", $return_msg= 'OK') {
676
+	public function responseNotify($print = true, $data = [], $return_code = "SUCCESS", $return_msg = 'OK') {
677 677
 		$data["return_code"] = $return_code;
678 678
 		if ($return_msg) {
679 679
 			$data["return_msg"] = $return_msg;
680 680
 		}
681 681
 		$xml = $this->array2xml($data);
682
-		if($print === true) print $xml;
682
+		if ($print === true) print $xml;
683 683
 		else return $xml;
684 684
 	}
685 685
 
@@ -699,8 +699,8 @@  discard block
 block discarded – undo
699 699
 	 * @param string $err_code_des
700 700
 	 * @return array
701 701
 	 */
702
-	public function report($interface_url,$execution_time,$return_code,$result_code,$user_ip,$out_trade_no = null,$time = null,$device_info = null,
703
-	                       $return_msg = null,$err_code = null,$err_code_des = null){
702
+	public function report($interface_url, $execution_time, $return_code, $result_code, $user_ip, $out_trade_no = null, $time = null, $device_info = null,
703
+	                       $return_msg = null, $err_code = null, $err_code_des = null) {
704 704
 		$data = array();
705 705
 		$data["appid"] = $this->config["app_id"];
706 706
 		$data["interface_url"] = $interface_url;
@@ -708,12 +708,12 @@  discard block
 block discarded – undo
708 708
 		$data["return_code"] = $return_code;
709 709
 		$data["result_code"] = $result_code;
710 710
 		$data["user_ip"] = $user_ip;
711
-		if($out_trade_no) $data["out_trade_no"] = $out_trade_no;
712
-		if($time) $data["time"] = $time;
713
-		if($device_info) $data["device_info"] = $device_info;
714
-		if($return_msg) $data["return_msg"] = $return_msg;
715
-		if($err_code) $data["err_code"] = $err_code;
716
-		if($err_code_des) $data["err_code_des"] = $err_code_des;
711
+		if ($out_trade_no) $data["out_trade_no"] = $out_trade_no;
712
+		if ($time) $data["time"] = $time;
713
+		if ($device_info) $data["device_info"] = $device_info;
714
+		if ($return_msg) $data["return_msg"] = $return_msg;
715
+		if ($err_code) $data["err_code"] = $err_code;
716
+		if ($err_code_des) $data["err_code_des"] = $err_code_des;
717 717
 		$result = $this->post(self::URL_REPORT, $data, false);
718 718
 		return $result;
719 719
 	}
@@ -724,11 +724,11 @@  discard block
 block discarded – undo
724 724
 	 * @param $longurl
725 725
 	 * @return string
726 726
 	 */
727
-	public function shortUrl($longurl){
727
+	public function shortUrl($longurl) {
728 728
 		$data = array();
729 729
 		$data["appid"] = $this->config["app_id"];
730 730
 		$data["long_url"] = $longurl;
731
-		$result = $this->post(self::URL_SHORTURL,$data,false);
731
+		$result = $this->post(self::URL_SHORTURL, $data, false);
732 732
 		return $result['short_url'];
733 733
 	}
734 734
 
@@ -738,11 +738,11 @@  discard block
 block discarded – undo
738 738
 	 * @param $auth_code
739 739
 	 * @return mixed
740 740
 	 */
741
-	public function authCodeToOpenId($auth_code){
741
+	public function authCodeToOpenId($auth_code) {
742 742
 		$data = array();
743 743
 		$data["appid"] = $this->config["app_id"];
744 744
 		$data["auth_code"] = $auth_code;
745
-		$result = $this->post(self::URL_AUTHCODETOOPENID,$data,false);
745
+		$result = $this->post(self::URL_AUTHCODETOOPENID, $data, false);
746 746
 		return $result['openid'];
747 747
 	}
748 748
 
@@ -759,19 +759,19 @@  discard block
 block discarded – undo
759 759
 	 * @return array
760 760
 	 * @throws Exception
761 761
 	 */
762
-	public function transferWallet($partner_trade_no,$openid,$amount,$desc,$spbill_create_ip = null,$re_user_name = null,$check_name = WechatPay::CHECKNAME_FORCECHECK){
762
+	public function transferWallet($partner_trade_no, $openid, $amount, $desc, $spbill_create_ip = null, $re_user_name = null, $check_name = WechatPay::CHECKNAME_FORCECHECK) {
763 763
 		$data = array();
764
-		if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required');
764
+		if ($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required');
765 765
 		$data["mch_appid"] = $this->config["app_id"];
766 766
 		$data["mchid"] = $this->config["mch_id"];
767 767
 		$data["partner_trade_no"] = $partner_trade_no;
768 768
 		$data["openid"] = $openid;
769 769
 		$data["amount"] = $amount;
770 770
 		$data["desc"] = $desc;
771
-		$data['spbill_create_ip'] = $spbill_create_ip?:$_SERVER['SERVER_ADDR'];
771
+		$data['spbill_create_ip'] = $spbill_create_ip ?: $_SERVER['SERVER_ADDR'];
772 772
 		$data["check_name"] = $check_name;
773 773
 		$data["re_user_name"] = $re_user_name;
774
-		$result = $this->post(self::URL_TRANSFER_WALLET,$data,true);
774
+		$result = $this->post(self::URL_TRANSFER_WALLET, $data, true);
775 775
 		return $result;
776 776
 	}
777 777
 
@@ -781,12 +781,12 @@  discard block
 block discarded – undo
781 781
 	 * @param $partner_trade_no
782 782
 	 * @return array
783 783
 	 */
784
-	public function queryTransferWallet($partner_trade_no){
784
+	public function queryTransferWallet($partner_trade_no) {
785 785
 		$data = array();
786 786
 		$data["appid"] = $this->config["app_id"];
787 787
 		$data["mch_id"] = $this->config["mch_id"];
788 788
 		$data["partner_trade_no"] = $partner_trade_no;
789
-		$result = $this->post(self::URL_QUERY_TRANSFER_WALLET,$data,true);
789
+		$result = $this->post(self::URL_QUERY_TRANSFER_WALLET, $data, true);
790 790
 		return $result;
791 791
 	}
792 792
 
@@ -802,8 +802,8 @@  discard block
 block discarded – undo
802 802
 	 * @return array
803 803
 	 * @throws Exception
804 804
 	 */
805
-	public function transferBankCard($partner_trade_no,$bank_no,$true_name,$bank_code,$amount,$desc){
806
-		if(!in_array($bank_code,array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code: $bank_code");
805
+	public function transferBankCard($partner_trade_no, $bank_no, $true_name, $bank_code, $amount, $desc) {
806
+		if (!in_array($bank_code, array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code: $bank_code");
807 807
 		$data = array();
808 808
 		$data["partner_trade_no"] = $partner_trade_no;
809 809
 		$enc_bank_no = $this->rsaEncrypt($bank_no);
@@ -813,7 +813,7 @@  discard block
 block discarded – undo
813 813
 		$data["bank_code"] = $bank_code;
814 814
 		$data["desc"] = $desc;
815 815
 		$data["amount"] = $amount;
816
-		$result = $this->post(self::URL_TRANSFER_BANKCARD,$data,true);
816
+		$result = $this->post(self::URL_TRANSFER_BANKCARD, $data, true);
817 817
 		return $result;
818 818
 	}
819 819
 
@@ -823,12 +823,12 @@  discard block
 block discarded – undo
823 823
 	 * @param $partner_trade_no
824 824
 	 * @return array
825 825
 	 */
826
-	public function queryTransferBankCard($partner_trade_no){
826
+	public function queryTransferBankCard($partner_trade_no) {
827 827
 		$data = array();
828 828
 		$data["appid"] = $this->config["app_id"];
829 829
 		$data["mch_id"] = $this->config["mch_id"];
830 830
 		$data["partner_trade_no"] = $partner_trade_no;
831
-		$result = $this->post(self::URL_QUERY_TRANSFER_WALLET,$data,true);
831
+		$result = $this->post(self::URL_QUERY_TRANSFER_WALLET, $data, true);
832 832
 		return $result;
833 833
 	}
834 834
 
@@ -842,14 +842,14 @@  discard block
 block discarded – undo
842 842
 	 * @param array $ext
843 843
 	 * @return array
844 844
 	 */
845
-	public function sendCoupon($coupon_stock_id,$open_id,$partner_trade_no,$op_user_id = '',$ext = array()){
846
-		$data = (!empty($ext) && is_array($ext))?$ext:array();
845
+	public function sendCoupon($coupon_stock_id, $open_id, $partner_trade_no, $op_user_id = '', $ext = array()) {
846
+		$data = (!empty($ext) && is_array($ext)) ? $ext : array();
847 847
 		$data["partner_trade_no"] = $partner_trade_no;
848 848
 		$data["coupon_stock_id"] = $coupon_stock_id;
849 849
 		$data["openid_count"] = 1;
850 850
 		$data["open_id"] = $open_id;
851 851
 		$data["op_user_id"] = $op_user_id;
852
-		$result = $this->post(self::URL_SEND_COUPON,$data,true);
852
+		$result = $this->post(self::URL_SEND_COUPON, $data, true);
853 853
 		return $result;
854 854
 	}
855 855
 
@@ -860,11 +860,11 @@  discard block
 block discarded – undo
860 860
 	 * @param string $op_user_id
861 861
 	 * @return array
862 862
 	 */
863
-	public function queryCouponStock($coupon_stock_id,$op_user_id = ''){
863
+	public function queryCouponStock($coupon_stock_id, $op_user_id = '') {
864 864
 		$data = array();
865 865
 		$data["coupon_stock_id"] = $coupon_stock_id;
866 866
 		$data["op_user_id"] = $op_user_id;
867
-		$result = $this->post(self::URL_QUERY_COUPON_STOCK,$data,false);
867
+		$result = $this->post(self::URL_QUERY_COUPON_STOCK, $data, false);
868 868
 		return $result;
869 869
 	}
870 870
 
@@ -878,13 +878,13 @@  discard block
 block discarded – undo
878 878
 	 * @param array $ext
879 879
 	 * @return array
880 880
 	 */
881
-	public function queryCouponsInfo($coupon_id,$open_id,$stock_id,$op_user_id = '',$ext = array()){
882
-		$data = (!empty($ext) && is_array($ext))?$ext:array();
881
+	public function queryCouponsInfo($coupon_id, $open_id, $stock_id, $op_user_id = '', $ext = array()) {
882
+		$data = (!empty($ext) && is_array($ext)) ? $ext : array();
883 883
 		$data["coupon_id"] = $coupon_id;
884 884
 		$data["stock_id"] = $stock_id;
885 885
 		$data["open_id"] = $open_id;
886 886
 		$data["op_user_id"] = $op_user_id;
887
-		$result = $this->post(self::URL_QUERY_COUPON_INFO,$data,false);
887
+		$result = $this->post(self::URL_QUERY_COUPON_INFO, $data, false);
888 888
 		return $result;
889 889
 	}
890 890
 
@@ -895,8 +895,8 @@  discard block
 block discarded – undo
895 895
 	 * @return string
896 896
 	 * @throws Exception
897 897
 	 */
898
-	public function getPublicKey($refresh = false){
899
-		if(!$this->publicKey) {
898
+	public function getPublicKey($refresh = false) {
899
+		if (!$this->publicKey) {
900 900
 			if (!$refresh && file_exists($this->config["rsa_pubkey_path"])) {
901 901
 				$this->publicKey = file_get_contents($this->config["rsa_pubkey_path"]);
902 902
 			}
@@ -910,31 +910,31 @@  discard block
 block discarded – undo
910 910
 			if ($fp) {
911 911
 				fwrite($fp, $this->publicKey);
912 912
 				fclose($fp);
913
-			} else {
913
+			}else {
914 914
 				throw new Exception("RSA public key not found");
915 915
 			}
916 916
 		}
917 917
 		return $this->publicKey;
918 918
 	}
919 919
 
920
-	public function setPublicKey($publicKey){
920
+	public function setPublicKey($publicKey) {
921 921
 		$this->publicKey = $publicKey;
922 922
 	}
923 923
 
924
-	private function convertPKCS1toPKCS8($pkcs1){
924
+	private function convertPKCS1toPKCS8($pkcs1) {
925 925
 		$start_key = $pkcs1;
926 926
 		$start_key = str_replace('-----BEGIN RSA PUBLIC KEY-----', '', $start_key);
927 927
 		$start_key = trim(str_replace('-----END RSA PUBLIC KEY-----', '', $start_key));
928
-		$key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' . str_replace("\n", '', $start_key);
929
-		$key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($key, 64, "\n", true) . "\n-----END PUBLIC KEY-----";
928
+		$key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A'.str_replace("\n", '', $start_key);
929
+		$key = "-----BEGIN PUBLIC KEY-----\n".wordwrap($key, 64, "\n", true)."\n-----END PUBLIC KEY-----";
930 930
 		return $key;
931 931
 	}
932 932
 
933
-	public function rsaEncrypt($data,$pubkey = null){
934
-		if(!$pubkey) $pubkey = $this->getPublicKey();
933
+	public function rsaEncrypt($data, $pubkey = null) {
934
+		if (!$pubkey) $pubkey = $this->getPublicKey();
935 935
 		$encrypted = null;
936 936
 		$pubkey = openssl_get_publickey($pubkey);
937
-		if (openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING))
937
+		if (openssl_public_encrypt($data, $encrypted, $pubkey, OPENSSL_PKCS1_OAEP_PADDING))
938 938
 			$data = base64_encode($encrypted);
939 939
 		else
940 940
 			throw new Exception('Unable to encrypt data');
@@ -946,10 +946,10 @@  discard block
 block discarded – undo
946 946
 	 * @ref https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=23_1
947 947
 	 * @return array
948 948
 	 */
949
-	public function getSignKey(){
949
+	public function getSignKey() {
950 950
 		$data = array();
951 951
 		$data["mch_id"] = $this->config["mch_id"];
952
-		$result = $this->post($this->getSignKeyUrl,$data,false);
952
+		$result = $this->post($this->getSignKeyUrl, $data, false);
953 953
 		return $result['sandbox_signkey'];
954 954
 	}
955 955
 
@@ -959,8 +959,8 @@  discard block
 block discarded – undo
959 959
 	 * @param string $ticket
960 960
 	 * @return array
961 961
 	 */
962
-	public function getSignPackage($url, $ticket = null){
963
-		if(!$ticket) $ticket = $this->getTicket();
962
+	public function getSignPackage($url, $ticket = null) {
963
+		if (!$ticket) $ticket = $this->getTicket();
964 964
 		$timestamp = time();
965 965
 		$nonceStr = $this->getNonceStr();
966 966
 		$rawString = "jsapi_ticket=$ticket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
@@ -982,18 +982,18 @@  discard block
 block discarded – undo
982 982
 	 * @param boolean $cache
983 983
 	 * @return string
984 984
 	 */
985
-	public function getTicket($cache = true){
985
+	public function getTicket($cache = true) {
986 986
 		$ticket = null;
987
-		if(isset($this->config['jsapi_ticket']) && file_exists($this->config['jsapi_ticket'])){
987
+		if (isset($this->config['jsapi_ticket']) && file_exists($this->config['jsapi_ticket'])) {
988 988
 			$data = json_decode(file_get_contents($this->config['jsapi_ticket']));
989 989
 			if ($data && $data->expires_at < time()) {
990 990
 				$ticket = $data->ticket;
991 991
 			}
992 992
 		}
993
-		if(!$ticket){
993
+		if (!$ticket) {
994 994
 			$data = $this->getWechatOAuth()->getTicket();
995 995
 			$data->expires_at = time() + $data->expires_in;
996
-			if($cache === true){
996
+			if ($cache === true) {
997 997
 				$fp = fopen($this->config["jsapi_ticket"], "w");
998 998
 				fwrite($fp, json_encode($data));
999 999
 				if ($fp) fclose($fp);
@@ -1003,10 +1003,10 @@  discard block
 block discarded – undo
1003 1003
 		return $ticket;
1004 1004
 	}
1005 1005
 
1006
-	private function post($url, $data,$cert = true) {
1007
-		if(!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"];
1008
-		if(!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr();
1009
-		if(!isset($data['sign'])) $data['sign'] = $this->sign($data);
1006
+	private function post($url, $data, $cert = true) {
1007
+		if (!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"];
1008
+		if (!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr();
1009
+		if (!isset($data['sign'])) $data['sign'] = $this->sign($data);
1010 1010
 		$this->requestXML = $this->responseXML = null;
1011 1011
 		$this->requestArray = $this->responseArray = null;
1012 1012
 
@@ -1018,53 +1018,53 @@  discard block
 block discarded – undo
1018 1018
 			CURLOPT_RETURNTRANSFER => true,
1019 1019
 			CURLOPT_TIMEOUT => 10
1020 1020
 		];
1021
-		if($cert == true){
1021
+		if ($cert == true) {
1022 1022
 			$opts[CURLOPT_SSLCERTTYPE] = 'PEM';
1023 1023
 			$opts[CURLOPT_SSLCERT] = $this->config['ssl_cert_path'];
1024 1024
 			$opts[CURLOPT_SSLKEYTYPE] = 'PEM';
1025 1025
 			$opts[CURLOPT_SSLKEY] = $this->config['ssl_key_path'];
1026 1026
 		}
1027 1027
 		$processResponse = true;
1028
-		if(in_array($url,[self::URL_DOWNLOADBILL,self::URL_DOWNLOAD_FUND_FLOW,self::URL_BATCHQUERYCOMMENT])){
1028
+		if (in_array($url, [self::URL_DOWNLOADBILL, self::URL_DOWNLOAD_FUND_FLOW, self::URL_BATCHQUERYCOMMENT])) {
1029 1029
 			$processResponse = false;
1030 1030
 		}
1031
-		if($this->sandbox === true){
1031
+		if ($this->sandbox === true) {
1032 1032
 			$host = "https://api.mch.weixin.qq.com";
1033
-			$url = str_replace($host,'',$url);
1033
+			$url = str_replace($host, '', $url);
1034 1034
 			$url = "{$host}/sandboxnew{$url}";
1035 1035
 		}
1036
-		$content = $this->httpClient->post($url,$this->requestXML,[],$opts);
1037
-		if(!$content) throw new Exception("Empty response with {$this->requestXML}");
1036
+		$content = $this->httpClient->post($url, $this->requestXML, [], $opts);
1037
+		if (!$content) throw new Exception("Empty response with {$this->requestXML}");
1038 1038
 
1039 1039
 		$this->responseXML = $content;
1040
-		if($processResponse)
1040
+		if ($processResponse)
1041 1041
 			return $this->processResponseXML($this->responseXML);
1042 1042
 		else return $this->responseXML;
1043 1043
 
1044 1044
 	}
1045 1045
 
1046
-	private function processResponseXML($responseXML){
1046
+	private function processResponseXML($responseXML) {
1047 1047
 		$result = $this->xml2array($responseXML);
1048 1048
 		$this->responseArray = $result;
1049
-		if(empty($result['return_code'])){
1049
+		if (empty($result['return_code'])) {
1050 1050
 			throw new Exception("No return code presents in {$this->responseXML}");
1051 1051
 		}
1052 1052
 		$this->returnCode = $result["return_code"];
1053
-		$this->returnMsg = isset($result['return_msg'])?$result['return_msg']:'';
1053
+		$this->returnMsg = isset($result['return_msg']) ? $result['return_msg'] : '';
1054 1054
 
1055 1055
 		if ($this->returnCode == "SUCCESS") {
1056
-			if(isset($result['result_code']) && $result['result_code'] == "FAIL"){
1056
+			if (isset($result['result_code']) && $result['result_code'] == "FAIL") {
1057 1057
 				$this->resultCode = $result['result_code'];
1058 1058
 				$this->errCode = $result['err_code'];
1059 1059
 				$this->errCodeDes = $result['err_code_des'];
1060 1060
 				throw new Exception("[$this->errCode]$this->errCodeDes");
1061
-			}else{
1061
+			}else {
1062 1062
 				return $result;
1063 1063
 			}
1064
-		} else {
1065
-			if($result["return_code"] == "FAIL"){
1064
+		}else {
1065
+			if ($result["return_code"] == "FAIL") {
1066 1066
 				throw new Exception($this->returnMsg);
1067
-			}else{
1067
+			}else {
1068 1068
 				$this->resultCode = $result['result_code'];
1069 1069
 				$this->errCode = $result['err_code'];
1070 1070
 				$this->errCodeDes = $result['err_code_des'];
@@ -1073,28 +1073,28 @@  discard block
 block discarded – undo
1073 1073
 		}
1074 1074
 	}
1075 1075
 
1076
-	public function sign($data,$sign_type = WechatPay::SIGNTYPE_MD5) {
1076
+	public function sign($data, $sign_type = WechatPay::SIGNTYPE_MD5) {
1077 1077
 		ksort($data);
1078 1078
 		$string1 = "";
1079 1079
 		foreach ($data as $k => $v) {
1080
-			if ($v && trim($v)!='') {
1080
+			if ($v && trim($v) != '') {
1081 1081
 				$string1 .= "$k=$v&";
1082 1082
 			}
1083 1083
 		}
1084
-		$stringSignTemp = $string1 . "key=" . $this->config["api_key"];
1085
-		if($sign_type == WechatPay::SIGNTYPE_MD5){
1084
+		$stringSignTemp = $string1."key=".$this->config["api_key"];
1085
+		if ($sign_type == WechatPay::SIGNTYPE_MD5) {
1086 1086
 			$sign = strtoupper(md5($stringSignTemp));
1087
-		}elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){
1088
-			$sign = strtoupper(hash_hmac('sha256',$stringSignTemp,$this->config["api_key"]));
1087
+		}elseif ($sign_type == WechatPay::SIGNTYPE_HMACSHA256) {
1088
+			$sign = strtoupper(hash_hmac('sha256', $stringSignTemp, $this->config["api_key"]));
1089 1089
 		}else throw new Exception("Not supported sign type - $sign_type");
1090 1090
 		return $sign;
1091 1091
 	}
1092 1092
 
1093 1093
 	private function array2xml($array) {
1094
-		$xml = "<xml>" . PHP_EOL;
1094
+		$xml = "<xml>".PHP_EOL;
1095 1095
 		foreach ($array as $k => $v) {
1096
-			if($v && trim($v)!='')
1097
-				$xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL;
1096
+			if ($v && trim($v) != '')
1097
+				$xml .= "<$k><![CDATA[$v]]></$k>".PHP_EOL;
1098 1098
 		}
1099 1099
 		$xml .= "</xml>";
1100 1100
 		return $xml;
@@ -1103,19 +1103,19 @@  discard block
 block discarded – undo
1103 1103
 	private function xml2array($xml) {
1104 1104
 		$array = array();
1105 1105
 		$tmp = array();
1106
-		try{
1106
+		try {
1107 1107
 			$tmp = (array) simplexml_load_string($xml);
1108
-		}catch(Exception $e){
1108
+		} catch (Exception $e) {
1109 1109
 			throw $e;
1110 1110
 		}
1111
-		foreach ( $tmp as $k => $v) {
1111
+		foreach ($tmp as $k => $v) {
1112 1112
 			$array[$k] = (string) $v;
1113 1113
 		}
1114 1114
 		return $array;
1115 1115
 	}
1116 1116
 
1117 1117
 	private function getNonceStr() {
1118
-		return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"),0,32);
1118
+		return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"), 0, 32);
1119 1119
 	}
1120 1120
 
1121 1121
 }
1122 1122
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +93 added lines, -40 removed lines patch added patch discarded remove patch
@@ -126,7 +126,9 @@  discard block
 block discarded – undo
126 126
 		$data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["REMOTE_ADDR"];
127 127
 		$data["notify_url"]   = $this->config["notify_url"];
128 128
 		$data["trade_type"]   = WechatPay::TRADETYPE_JSAPI;
129
-		if(!$openid) throw new Exception('openid is required when trade_type is JSAPI');
129
+		if(!$openid) {
130
+			throw new Exception('openid is required when trade_type is JSAPI');
131
+		}
130 132
 		$data["openid"]   = $openid;
131 133
 		$result = $this->unifiedOrder($data);
132 134
 		return $result["prepay_id"];
@@ -174,7 +176,9 @@  discard block
 block discarded – undo
174 176
 		$data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["SERVER_ADDR"];
175 177
 		$data["notify_url"]   = $this->config["notify_url"];
176 178
 		$data["trade_type"]   = self::TRADETYPE_NATIVE;
177
-		if(!$product_id) throw new Exception('product_id is required when trade_type is NATIVE');
179
+		if(!$product_id) {
180
+			throw new Exception('product_id is required when trade_type is NATIVE');
181
+		}
178 182
 		$data["product_id"]   = $product_id;
179 183
 		$result = $this->unifiedOrder($data);
180 184
 		return $result["code_url"];
@@ -198,7 +202,9 @@  discard block
 block discarded – undo
198 202
 		$data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:'';
199 203
 		$data["notify_url"]   = $this->config["notify_url"];
200 204
 		$data["trade_type"]   = self::TRADETYPE_MWEB;
201
-		if(!isset($this->config['h5_scene_info'])) throw new Exception('h5_scene_info should be configured');
205
+		if(!isset($this->config['h5_scene_info'])) {
206
+			throw new Exception('h5_scene_info should be configured');
207
+		}
202 208
 		$data["scene_info"]   = json_encode($this->config['h5_scene_info']);
203 209
 		$result = $this->unifiedOrder($data);
204 210
 		return $result["mweb_url"];
@@ -228,11 +234,15 @@  discard block
 block discarded – undo
228 234
 		$data["notify_url"] = $this->config["notify_url"];
229 235
 		$data["trade_type"] = $params['trade_type'];
230 236
 		if($params['trade_type'] == WechatPay::TRADETYPE_NATIVE){
231
-			if(!isset($params['product_id'])) throw new Exception('product_id is required when trade_type is NATIVE');
237
+			if(!isset($params['product_id'])) {
238
+				throw new Exception('product_id is required when trade_type is NATIVE');
239
+			}
232 240
 			$data["product_id"] = $params['product_id'];
233 241
 		}
234 242
 		if($params['trade_type'] == WechatPay::TRADETYPE_JSAPI){
235
-			if(!isset($params['openid'])) throw new Exception('openid is required when trade_type is JSAPI');
243
+			if(!isset($params['openid'])) {
244
+				throw new Exception('openid is required when trade_type is JSAPI');
245
+			}
236 246
 			$data["openid"] = $params['openid'];
237 247
 		}
238 248
 		$result = $this->post(self::URL_UNIFIEDORDER, $data);
@@ -475,7 +485,9 @@  discard block
 block discarded – undo
475 485
 		$data["send_name"] = $send_name;
476 486
 		$data["re_openid"] = $re_openid;
477 487
 		$data["total_amount"] = $total_amount;
478
-		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000");
488
+		if($total_amount > 20000 && trim($scene_id)=='') {
489
+			throw new Exception("scene_id is required when total_amount beyond 20000");
490
+		}
479 491
 		$data["total_num"] = $total_num;
480 492
 		$data["wishing"] = $wishing;
481 493
 		$data["act_name"] = $act_name;
@@ -511,7 +523,9 @@  discard block
 block discarded – undo
511 523
 		$data["send_name"] = $send_name;
512 524
 		$data["re_openid"] = $re_openid;
513 525
 		$data["total_amount"] = $total_amount;
514
-		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
526
+		if($total_amount > 20000 && trim($scene_id)=='') {
527
+			throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
528
+		}
515 529
 		$data["total_num"] = $total_num;
516 530
 		$data["amt_type"] = 'ALL_RAND'; //红包金额设置方式 ALL_RAND—全部随机
517 531
 		$data["wishing"] = $wishing;
@@ -626,7 +640,7 @@  discard block
 block discarded – undo
626 640
 			if($callback && is_callable($callback)){
627 641
 				return call_user_func_array( $callback , [$notify_data] );
628 642
 			}
629
-		}else{
643
+		} else{
630 644
 			throw new Exception('Invalid paid notify data');
631 645
 		}
632 646
 	}
@@ -646,7 +660,7 @@  discard block
 block discarded – undo
646 660
 			if($callback && is_callable($callback)){
647 661
 				return call_user_func_array( $callback ,[$notify_data] );
648 662
 			}
649
-		}else{
663
+		} else{
650 664
 			throw new Exception('Invalid refunded notify data');
651 665
 		}
652 666
 	}
@@ -679,8 +693,11 @@  discard block
 block discarded – undo
679 693
 			$data["return_msg"] = $return_msg;
680 694
 		}
681 695
 		$xml = $this->array2xml($data);
682
-		if($print === true) print $xml;
683
-		else return $xml;
696
+		if($print === true) {
697
+			print $xml;
698
+		} else {
699
+			return $xml;
700
+		}
684 701
 	}
685 702
 
686 703
 	/**
@@ -708,12 +725,24 @@  discard block
 block discarded – undo
708 725
 		$data["return_code"] = $return_code;
709 726
 		$data["result_code"] = $result_code;
710 727
 		$data["user_ip"] = $user_ip;
711
-		if($out_trade_no) $data["out_trade_no"] = $out_trade_no;
712
-		if($time) $data["time"] = $time;
713
-		if($device_info) $data["device_info"] = $device_info;
714
-		if($return_msg) $data["return_msg"] = $return_msg;
715
-		if($err_code) $data["err_code"] = $err_code;
716
-		if($err_code_des) $data["err_code_des"] = $err_code_des;
728
+		if($out_trade_no) {
729
+			$data["out_trade_no"] = $out_trade_no;
730
+		}
731
+		if($time) {
732
+			$data["time"] = $time;
733
+		}
734
+		if($device_info) {
735
+			$data["device_info"] = $device_info;
736
+		}
737
+		if($return_msg) {
738
+			$data["return_msg"] = $return_msg;
739
+		}
740
+		if($err_code) {
741
+			$data["err_code"] = $err_code;
742
+		}
743
+		if($err_code_des) {
744
+			$data["err_code_des"] = $err_code_des;
745
+		}
717 746
 		$result = $this->post(self::URL_REPORT, $data, false);
718 747
 		return $result;
719 748
 	}
@@ -761,7 +790,9 @@  discard block
 block discarded – undo
761 790
 	 */
762 791
 	public function transferWallet($partner_trade_no,$openid,$amount,$desc,$spbill_create_ip = null,$re_user_name = null,$check_name = WechatPay::CHECKNAME_FORCECHECK){
763 792
 		$data = array();
764
-		if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required');
793
+		if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) {
794
+			throw new Exception('Real name is required');
795
+		}
765 796
 		$data["mch_appid"] = $this->config["app_id"];
766 797
 		$data["mchid"] = $this->config["mch_id"];
767 798
 		$data["partner_trade_no"] = $partner_trade_no;
@@ -803,7 +834,9 @@  discard block
 block discarded – undo
803 834
 	 * @throws Exception
804 835
 	 */
805 836
 	public function transferBankCard($partner_trade_no,$bank_no,$true_name,$bank_code,$amount,$desc){
806
-		if(!in_array($bank_code,array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code: $bank_code");
837
+		if(!in_array($bank_code,array_values(self::$BANKCODE))) {
838
+			throw new Exception("Unsupported bank code: $bank_code");
839
+		}
807 840
 		$data = array();
808 841
 		$data["partner_trade_no"] = $partner_trade_no;
809 842
 		$enc_bank_no = $this->rsaEncrypt($bank_no);
@@ -931,13 +964,16 @@  discard block
 block discarded – undo
931 964
 	}
932 965
 
933 966
 	public function rsaEncrypt($data,$pubkey = null){
934
-		if(!$pubkey) $pubkey = $this->getPublicKey();
967
+		if(!$pubkey) {
968
+			$pubkey = $this->getPublicKey();
969
+		}
935 970
 		$encrypted = null;
936 971
 		$pubkey = openssl_get_publickey($pubkey);
937
-		if (openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING))
938
-			$data = base64_encode($encrypted);
939
-		else
940
-			throw new Exception('Unable to encrypt data');
972
+		if (openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING)) {
973
+					$data = base64_encode($encrypted);
974
+		} else {
975
+					throw new Exception('Unable to encrypt data');
976
+		}
941 977
 		return $data;
942 978
 	}
943 979
 
@@ -960,7 +996,9 @@  discard block
 block discarded – undo
960 996
 	 * @return array
961 997
 	 */
962 998
 	public function getSignPackage($url, $ticket = null){
963
-		if(!$ticket) $ticket = $this->getTicket();
999
+		if(!$ticket) {
1000
+			$ticket = $this->getTicket();
1001
+		}
964 1002
 		$timestamp = time();
965 1003
 		$nonceStr = $this->getNonceStr();
966 1004
 		$rawString = "jsapi_ticket=$ticket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
@@ -996,7 +1034,9 @@  discard block
 block discarded – undo
996 1034
 			if($cache === true){
997 1035
 				$fp = fopen($this->config["jsapi_ticket"], "w");
998 1036
 				fwrite($fp, json_encode($data));
999
-				if ($fp) fclose($fp);
1037
+				if ($fp) {
1038
+					fclose($fp);
1039
+				}
1000 1040
 			}
1001 1041
 			$ticket = $data->ticket;
1002 1042
 		}
@@ -1004,9 +1044,15 @@  discard block
 block discarded – undo
1004 1044
 	}
1005 1045
 
1006 1046
 	private function post($url, $data,$cert = true) {
1007
-		if(!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"];
1008
-		if(!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr();
1009
-		if(!isset($data['sign'])) $data['sign'] = $this->sign($data);
1047
+		if(!isset($data['mch_id']) && !isset($data['mchid'])) {
1048
+			$data["mch_id"] = $this->config["mch_id"];
1049
+		}
1050
+		if(!isset($data['nonce_str'])) {
1051
+			$data["nonce_str"] = $this->getNonceStr();
1052
+		}
1053
+		if(!isset($data['sign'])) {
1054
+			$data['sign'] = $this->sign($data);
1055
+		}
1010 1056
 		$this->requestXML = $this->responseXML = null;
1011 1057
 		$this->requestArray = $this->responseArray = null;
1012 1058
 
@@ -1034,12 +1080,16 @@  discard block
 block discarded – undo
1034 1080
 			$url = "{$host}/sandboxnew{$url}";
1035 1081
 		}
1036 1082
 		$content = $this->httpClient->post($url,$this->requestXML,[],$opts);
1037
-		if(!$content) throw new Exception("Empty response with {$this->requestXML}");
1083
+		if(!$content) {
1084
+			throw new Exception("Empty response with {$this->requestXML}");
1085
+		}
1038 1086
 
1039 1087
 		$this->responseXML = $content;
1040
-		if($processResponse)
1041
-			return $this->processResponseXML($this->responseXML);
1042
-		else return $this->responseXML;
1088
+		if($processResponse) {
1089
+					return $this->processResponseXML($this->responseXML);
1090
+		} else {
1091
+			return $this->responseXML;
1092
+		}
1043 1093
 
1044 1094
 	}
1045 1095
 
@@ -1058,13 +1108,13 @@  discard block
 block discarded – undo
1058 1108
 				$this->errCode = $result['err_code'];
1059 1109
 				$this->errCodeDes = $result['err_code_des'];
1060 1110
 				throw new Exception("[$this->errCode]$this->errCodeDes");
1061
-			}else{
1111
+			} else{
1062 1112
 				return $result;
1063 1113
 			}
1064 1114
 		} else {
1065 1115
 			if($result["return_code"] == "FAIL"){
1066 1116
 				throw new Exception($this->returnMsg);
1067
-			}else{
1117
+			} else{
1068 1118
 				$this->resultCode = $result['result_code'];
1069 1119
 				$this->errCode = $result['err_code'];
1070 1120
 				$this->errCodeDes = $result['err_code_des'];
@@ -1084,17 +1134,20 @@  discard block
 block discarded – undo
1084 1134
 		$stringSignTemp = $string1 . "key=" . $this->config["api_key"];
1085 1135
 		if($sign_type == WechatPay::SIGNTYPE_MD5){
1086 1136
 			$sign = strtoupper(md5($stringSignTemp));
1087
-		}elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){
1137
+		} elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){
1088 1138
 			$sign = strtoupper(hash_hmac('sha256',$stringSignTemp,$this->config["api_key"]));
1089
-		}else throw new Exception("Not supported sign type - $sign_type");
1139
+		} else {
1140
+			throw new Exception("Not supported sign type - $sign_type");
1141
+		}
1090 1142
 		return $sign;
1091 1143
 	}
1092 1144
 
1093 1145
 	private function array2xml($array) {
1094 1146
 		$xml = "<xml>" . PHP_EOL;
1095 1147
 		foreach ($array as $k => $v) {
1096
-			if($v && trim($v)!='')
1097
-				$xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL;
1148
+			if($v && trim($v)!='') {
1149
+							$xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL;
1150
+			}
1098 1151
 		}
1099 1152
 		$xml .= "</xml>";
1100 1153
 		return $xml;
@@ -1105,7 +1158,7 @@  discard block
 block discarded – undo
1105 1158
 		$tmp = array();
1106 1159
 		try{
1107 1160
 			$tmp = (array) simplexml_load_string($xml);
1108
-		}catch(Exception $e){
1161
+		} catch(Exception $e){
1109 1162
 			throw $e;
1110 1163
 		}
1111 1164
 		foreach ( $tmp as $k => $v) {
Please login to merge, or discard this patch.
src/HttpClient.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -5,9 +5,9 @@  discard block
 block discarded – undo
5 5
  */
6 6
 namespace zhangv\wechat;
7 7
 
8
-class HttpClient{
8
+class HttpClient {
9 9
 
10
-	const GET = 'get',POST = 'post', DELETE = 'delete',PUT = 'put';
10
+	const GET = 'get', POST = 'post', DELETE = 'delete', PUT = 'put';
11 11
 	private $instance = null;
12 12
 	private $errNo = null;
13 13
 	private $info = null;
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
 		$this->initInstance($timeout);
18 18
 	}
19 19
 
20
-	public function initInstance($timeout){
21
-		if(!$this->instance) {
20
+	public function initInstance($timeout) {
21
+		if (!$this->instance) {
22 22
 			$this->instance = curl_init();
23 23
 			curl_setopt($this->instance, CURLOPT_TIMEOUT, intval($timeout));
24 24
 			curl_setopt($this->instance, CURLOPT_RETURNTRANSFER, true);
@@ -27,26 +27,26 @@  discard block
 block discarded – undo
27 27
 		}
28 28
 	}
29 29
 
30
-	public function get($url,$params = array(),$headers = array(),$opts = array()) {
30
+	public function get($url, $params = array(), $headers = array(), $opts = array()) {
31 31
 		if (!$this->instance)	$this->initInstance($this->timeout);
32
-		if($params && count($params) > 0) $url .= '?' . http_build_query($params);
32
+		if ($params && count($params) > 0) $url .= '?'.http_build_query($params);
33 33
 		curl_setopt($this->instance, CURLOPT_URL, $url);
34 34
 		curl_setopt($this->instance, CURLOPT_HTTPGET, true);
35 35
 		curl_setopt($this->instance, CURLOPT_HTTPHEADER, $headers);
36
-		curl_setopt_array($this->instance,$opts);
36
+		curl_setopt_array($this->instance, $opts);
37 37
 		$result = $this->execute();
38 38
 		curl_close($this->instance);
39 39
 		$this->instance = null;
40 40
 		return $result;
41 41
 	}
42 42
 
43
-	public function post($url, $params = array(),$headers = array(),$opts = array()) {
43
+	public function post($url, $params = array(), $headers = array(), $opts = array()) {
44 44
 		if (!$this->instance)	$this->initInstance($this->timeout);
45 45
 		curl_setopt($this->instance, CURLOPT_URL, $url);
46 46
 		curl_setopt($this->instance, CURLOPT_POST, true);
47 47
 		curl_setopt($this->instance, CURLOPT_POSTFIELDS, $params);
48 48
 		curl_setopt($this->instance, CURLOPT_HTTPHEADER, $headers);
49
-		curl_setopt_array($this->instance,$opts);
49
+		curl_setopt_array($this->instance, $opts);
50 50
 		$result = $this->execute();
51 51
 		curl_close($this->instance);
52 52
 		$this->instance = null;
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 		return $result;
61 61
 	}
62 62
 
63
-	public function getInfo(){
63
+	public function getInfo() {
64 64
 		return $this->info;
65 65
 	}
66 66
 }
67 67
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -28,8 +28,12 @@  discard block
 block discarded – undo
28 28
 	}
29 29
 
30 30
 	public function get($url,$params = array(),$headers = array(),$opts = array()) {
31
-		if (!$this->instance)	$this->initInstance($this->timeout);
32
-		if($params && count($params) > 0) $url .= '?' . http_build_query($params);
31
+		if (!$this->instance) {
32
+			$this->initInstance($this->timeout);
33
+		}
34
+		if($params && count($params) > 0) {
35
+			$url .= '?' . http_build_query($params);
36
+		}
33 37
 		curl_setopt($this->instance, CURLOPT_URL, $url);
34 38
 		curl_setopt($this->instance, CURLOPT_HTTPGET, true);
35 39
 		curl_setopt($this->instance, CURLOPT_HTTPHEADER, $headers);
@@ -41,7 +45,9 @@  discard block
 block discarded – undo
41 45
 	}
42 46
 
43 47
 	public function post($url, $params = array(),$headers = array(),$opts = array()) {
44
-		if (!$this->instance)	$this->initInstance($this->timeout);
48
+		if (!$this->instance) {
49
+			$this->initInstance($this->timeout);
50
+		}
45 51
 		curl_setopt($this->instance, CURLOPT_URL, $url);
46 52
 		curl_setopt($this->instance, CURLOPT_POST, true);
47 53
 		curl_setopt($this->instance, CURLOPT_POSTFIELDS, $params);
Please login to merge, or discard this patch.
demo/paidnotify.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-require_once __DIR__ . "/autoload.php";
3
+require_once __DIR__."/autoload.php";
4 4
 use zhangv\wechat\WechatPay;
5 5
 
6 6
 $xml = file_get_contents("php://input");
7 7
 
8 8
 $cfg = require './config.php';
9 9
 $payment = new WechatPay($cfg);
10
-$payment->onPaidNotify($xml,function($notifydata) use ($payment){
10
+$payment->onPaidNotify($xml, function($notifydata) use ($payment){
11 11
 	//do stuff
12 12
 	print_r($notifydata);
13 13
 	$payment->responseNotify();
Please login to merge, or discard this patch.