Completed
Push — master ( 76d6fa...9bc9b6 )
by Wei
08:43
created
src/service/Coupon.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -22,14 +22,14 @@  discard block
 block discarded – undo
22 22
 	 * @param array $ext
23 23
 	 * @return array
24 24
 	 */
25
-	public function sendCoupon($coupon_stock_id,$open_id,$partner_trade_no,$op_user_id = '',$ext = array()){
26
-		$data = (!empty($ext) && is_array($ext))?$ext:array();
25
+	public function sendCoupon($coupon_stock_id, $open_id, $partner_trade_no, $op_user_id = '', $ext = array()) {
26
+		$data = (!empty($ext) && is_array($ext)) ? $ext : array();
27 27
 		$data["partner_trade_no"] = $partner_trade_no;
28 28
 		$data["coupon_stock_id"] = $coupon_stock_id;
29 29
 		$data["openid_count"] = 1;
30 30
 		$data["open_id"] = $open_id;
31 31
 		$data["op_user_id"] = $op_user_id;
32
-		$result = $this->post(self::URL_SEND_COUPON,$data,true);
32
+		$result = $this->post(self::URL_SEND_COUPON, $data, true);
33 33
 		return $result;
34 34
 	}
35 35
 
@@ -40,11 +40,11 @@  discard block
 block discarded – undo
40 40
 	 * @param string $op_user_id
41 41
 	 * @return array
42 42
 	 */
43
-	public function queryCouponStock($coupon_stock_id,$op_user_id = ''){
43
+	public function queryCouponStock($coupon_stock_id, $op_user_id = '') {
44 44
 		$data = array();
45 45
 		$data["coupon_stock_id"] = $coupon_stock_id;
46 46
 		$data["op_user_id"] = $op_user_id;
47
-		$result = $this->post(self::URL_QUERY_COUPON_STOCK,$data,false);
47
+		$result = $this->post(self::URL_QUERY_COUPON_STOCK, $data, false);
48 48
 		return $result;
49 49
 	}
50 50
 
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
 	 * @param array $ext
59 59
 	 * @return array
60 60
 	 */
61
-	public function queryCouponsInfo($coupon_id,$open_id,$stock_id,$op_user_id = '',$ext = array()){
62
-		$data = (!empty($ext) && is_array($ext))?$ext:array();
61
+	public function queryCouponsInfo($coupon_id, $open_id, $stock_id, $op_user_id = '', $ext = array()) {
62
+		$data = (!empty($ext) && is_array($ext)) ? $ext : array();
63 63
 		$data["coupon_id"] = $coupon_id;
64 64
 		$data["stock_id"] = $stock_id;
65 65
 		$data["open_id"] = $open_id;
66 66
 		$data["op_user_id"] = $op_user_id;
67
-		$result = $this->post(self::URL_QUERY_COUPON_INFO,$data,false);
67
+		$result = $this->post(self::URL_QUERY_COUPON_INFO, $data, false);
68 68
 		return $result;
69 69
 	}
70 70
 
Please login to merge, or discard this patch.
src/service/App.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -36,8 +36,8 @@  discard block
 block discarded – undo
36 36
 	 * @param $ext array
37 37
 	 * @return string
38 38
 	 */
39
-	public function getPrepayId($body,$out_trade_no,$total_fee,$spbill_create_ip,$ext = null) {
40
-		$data = ($ext && is_array($ext))?$ext:array();
39
+	public function getPrepayId($body, $out_trade_no, $total_fee, $spbill_create_ip, $ext = null) {
40
+		$data = ($ext && is_array($ext)) ? $ext : array();
41 41
 		$data["body"]         = $body;
42 42
 		$data["out_trade_no"] = $out_trade_no;
43 43
 		$data["total_fee"]    = $total_fee;
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 		$data["timestamp"] = time();
63 63
 		$data["noncestr"]  = $this->getNonceStr();
64 64
 		$data["appid"] = $this->config["app_id"];
65
-		$data["sign"]   = $this->sign($data);
65
+		$data["sign"] = $this->sign($data);
66 66
 		return $data;
67 67
 	}
68 68
 }
69 69
\ No newline at end of file
Please login to merge, or discard this patch.
src/WechatPay.php 2 patches
Spacing   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -30,10 +30,10 @@  discard block
 block discarded – undo
30 30
  * @method static service\Coupon    Coupon(array $config)
31 31
  */
32 32
 class WechatPay {
33
-	const TRADETYPE_JSAPI = 'JSAPI',TRADETYPE_NATIVE = 'NATIVE',TRADETYPE_APP = 'APP',TRADETYPE_MWEB = 'MWEB';
33
+	const TRADETYPE_JSAPI = 'JSAPI', TRADETYPE_NATIVE = 'NATIVE', TRADETYPE_APP = 'APP', TRADETYPE_MWEB = 'MWEB';
34 34
 	const SIGNTYPE_MD5 = 'MD5', SIGNTYPE_HMACSHA256 = 'HMAC-SHA256';
35
-	const CHECKNAME_FORCECHECK = 'FORCE_CHECK',CHECKNAME_NOCHECK = 'NO_CHECK';
36
-	const ACCOUNTTYPE_BASIC = 'Basic',ACCOUNTTYPE_OPERATION = 'Operation',ACCOUNTTYPE_FEES = 'Fees';
35
+	const CHECKNAME_FORCECHECK = 'FORCE_CHECK', CHECKNAME_NOCHECK = 'NO_CHECK';
36
+	const ACCOUNTTYPE_BASIC = 'Basic', ACCOUNTTYPE_OPERATION = 'Operation', ACCOUNTTYPE_FEES = 'Fees';
37 37
 	const API_ENDPOINT = 'https://api.mch.weixin.qq.com/';
38 38
 	/** 支付 */
39 39
 	const URL_UNIFIEDORDER = 'pay/unifiedorder';
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	 * @return mixed
119 119
 	 */
120 120
 	private static function load($name, $config) {
121
-		$service = __NAMESPACE__ . "\\service\\{$name}";
121
+		$service = __NAMESPACE__."\\service\\{$name}";
122 122
 		return new $service($config);
123 123
 	}
124 124
 
@@ -132,34 +132,34 @@  discard block
 block discarded – undo
132 132
 		return self::load($name, ...$arguments);
133 133
 	}
134 134
 
135
-	public function setWechatOAuth($wechatOAuth){
135
+	public function setWechatOAuth($wechatOAuth) {
136 136
 		$this->wechatOAuth = $wechatOAuth;
137 137
 	}
138 138
 
139
-	public function getWechatOAuth(){
140
-		if(!$this->wechatOAuth){
141
-			$this->wechatOAuth = new WechatOAuth($this->config['app_id'],$this->config['app_secret']);
139
+	public function getWechatOAuth() {
140
+		if (!$this->wechatOAuth) {
141
+			$this->wechatOAuth = new WechatOAuth($this->config['app_id'], $this->config['app_secret']);
142 142
 		}
143 143
 		return $this->wechatOAuth;
144 144
 	}
145 145
 
146
-	public function setConfig($config){
146
+	public function setConfig($config) {
147 147
 		$this->config = $config;
148 148
 	}
149 149
 
150
-	public function getConfig(){
150
+	public function getConfig() {
151 151
 		return $this->config;
152 152
 	}
153 153
 
154
-	public function setHttpClient($httpClient){
154
+	public function setHttpClient($httpClient) {
155 155
 		$this->httpClient = $httpClient;
156 156
 	}
157 157
 
158
-	public function setCacheProvider($cacheProvider){
158
+	public function setCacheProvider($cacheProvider) {
159 159
 		$this->cacheProvider = $cacheProvider;
160 160
 	}
161 161
 
162
-	public function getCacheProvider(){
162
+	public function getCacheProvider() {
163 163
 		return $this->cacheProvider;
164 164
 	}
165 165
 
@@ -173,25 +173,25 @@  discard block
 block discarded – undo
173 173
 	public function unifiedOrder($params) {
174 174
 		$data = array();
175 175
 		$data["appid"] = $this->config["app_id"];
176
-		$data["device_info"] = (isset($params['device_info'])&&trim($params['device_info'])!='')?$params['device_info']:null;
176
+		$data["device_info"] = (isset($params['device_info']) && trim($params['device_info']) != '') ? $params['device_info'] : null;
177 177
 		$data["body"] = $params['body'];
178
-		$data["detail"] = isset($params['detail'])?$params['detail']:null;//optional
179
-		$data["attach"] = isset($params['attach'])?$params['attach']:null;//optional
180
-		$data["out_trade_no"] = isset($params['out_trade_no'])?$params['out_trade_no']:null;
181
-		$data["fee_type"] = isset($params['fee_type'])?$params['fee_type']:'CNY';
178
+		$data["detail"] = isset($params['detail']) ? $params['detail'] : null; //optional
179
+		$data["attach"] = isset($params['attach']) ? $params['attach'] : null; //optional
180
+		$data["out_trade_no"] = isset($params['out_trade_no']) ? $params['out_trade_no'] : null;
181
+		$data["fee_type"] = isset($params['fee_type']) ? $params['fee_type'] : 'CNY';
182 182
 		$data["total_fee"]    = $params['total_fee'];
183 183
 		$data["spbill_create_ip"] = $params['spbill_create_ip'];
184
-		$data["time_start"] = isset($params['time_start'])?$params['time_start']:null;//optional
185
-		$data["time_expire"] = isset($params['time_expire'])?$params['time_expire']:null;//optional
186
-		$data["goods_tag"] = isset($params['goods_tag'])?$params['goods_tag']:null;
184
+		$data["time_start"] = isset($params['time_start']) ? $params['time_start'] : null; //optional
185
+		$data["time_expire"] = isset($params['time_expire']) ? $params['time_expire'] : null; //optional
186
+		$data["goods_tag"] = isset($params['goods_tag']) ? $params['goods_tag'] : null;
187 187
 		$data["notify_url"] = $this->config["notify_url"];
188 188
 		$data["trade_type"] = $params['trade_type'];
189
-		if($params['trade_type'] == WechatPay::TRADETYPE_NATIVE){
190
-			if(!isset($params['product_id'])) throw new Exception('product_id is required when trade_type is NATIVE');
189
+		if ($params['trade_type'] == WechatPay::TRADETYPE_NATIVE) {
190
+			if (!isset($params['product_id'])) throw new Exception('product_id is required when trade_type is NATIVE');
191 191
 			$data["product_id"] = $params['product_id'];
192 192
 		}
193
-		if($params['trade_type'] == WechatPay::TRADETYPE_JSAPI){
194
-			if(!isset($params['openid'])) throw new Exception('openid is required when trade_type is JSAPI');
193
+		if ($params['trade_type'] == WechatPay::TRADETYPE_JSAPI) {
194
+			if (!isset($params['openid'])) throw new Exception('openid is required when trade_type is JSAPI');
195 195
 			$data["openid"] = $params['openid'];
196 196
 		}
197 197
 		$result = $this->post(self::URL_UNIFIEDORDER, $data);
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 	 * @param $transaction_id string 微信订单号
205 205
 	 * @return array
206 206
 	 */
207
-	public function queryOrderByTransactionId($transaction_id){
207
+	public function queryOrderByTransactionId($transaction_id) {
208 208
 		$data = array();
209 209
 		$data["appid"] = $this->config["app_id"];
210 210
 		$data["transaction_id"] = $transaction_id;
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 	 * @param $out_trade_no string 商户订单号
219 219
 	 * @return array
220 220
 	 */
221
-	public function queryOrderByOutTradeNo($out_trade_no){
221
+	public function queryOrderByOutTradeNo($out_trade_no) {
222 222
 		$data = array();
223 223
 		$data["appid"] = $this->config["app_id"];
224 224
 		$data["out_trade_no"] = $out_trade_no;
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 	 * @param $offset int 偏移
234 234
 	 * @return array
235 235
 	 */
236
-	public function queryRefundByTransactionId($transaction_id,$offset = 0){
236
+	public function queryRefundByTransactionId($transaction_id, $offset = 0) {
237 237
 		$data = array();
238 238
 		$data["appid"] = $this->config["app_id"];
239 239
 		$data["transaction_id"] = $transaction_id;
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 	 * @param $offset int 偏移
250 250
 	 * @return array
251 251
 	 */
252
-	public function queryRefundByOutTradeNo($out_trade_no,$offset = 0){
252
+	public function queryRefundByOutTradeNo($out_trade_no, $offset = 0) {
253 253
 		$data = array();
254 254
 		$data["appid"] = $this->config["app_id"];
255 255
 		$data["out_trade_no"] = $out_trade_no;
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 	 * @param $offset int 偏移
266 266
 	 * @return array
267 267
 	 */
268
-	public function queryRefundByRefundId($refund_id,$offset = 0){
268
+	public function queryRefundByRefundId($refund_id, $offset = 0) {
269 269
 		$data = array();
270 270
 		$data["appid"] = $this->config["app_id"];
271 271
 		$data["refund_id"] = $refund_id;
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 	 * @param $offset int 偏移
282 282
 	 * @return array
283 283
 	 */
284
-	public function queryRefundByOutRefundNo($out_refund_no,$offset = 0){
284
+	public function queryRefundByOutRefundNo($out_refund_no, $offset = 0) {
285 285
 		$data = array();
286 286
 		$data["appid"] = $this->config["app_id"];
287 287
 		$data["out_refund_no"] = $out_refund_no;
@@ -296,11 +296,11 @@  discard block
 block discarded – undo
296 296
 	 * @param $out_trade_no string 商户订单号
297 297
 	 * @return array
298 298
 	 */
299
-	public function closeOrder($out_trade_no){
299
+	public function closeOrder($out_trade_no) {
300 300
 		$data = array();
301 301
 		$data["appid"] = $this->config["app_id"];
302 302
 		$data["out_trade_no"] = $out_trade_no;
303
-		$result = $this->post(self::URL_CLOSEORDER, $data,false);
303
+		$result = $this->post(self::URL_CLOSEORDER, $data, false);
304 304
 		return $result;
305 305
 	}
306 306
 
@@ -315,14 +315,14 @@  discard block
 block discarded – undo
315 315
 	 * @param $ext array 扩展数组
316 316
 	 * @return array
317 317
 	 */
318
-	public function refundByOutTradeNo($out_trade_no,$out_refund_no,$total_fee,$refund_fee,$ext = array()){
319
-		$data = ($ext && is_array($ext))?$ext:array();
318
+	public function refundByOutTradeNo($out_trade_no, $out_refund_no, $total_fee, $refund_fee, $ext = array()) {
319
+		$data = ($ext && is_array($ext)) ? $ext : array();
320 320
 		$data["appid"] = $this->config["app_id"];
321 321
 		$data["out_trade_no"] = $out_trade_no;
322 322
 		$data["out_refund_no"] = $out_refund_no;
323 323
 		$data["total_fee"] = $total_fee;
324 324
 		$data["refund_fee"] = $refund_fee;
325
-		$result = $this->post(self::URL_REFUND, $data,true);
325
+		$result = $this->post(self::URL_REFUND, $data, true);
326 326
 		return $result;
327 327
 	}
328 328
 
@@ -337,14 +337,14 @@  discard block
 block discarded – undo
337 337
 	 * @param $ext array 扩展数组
338 338
 	 * @return array
339 339
 	 */
340
-	public function refundByTransactionId($transaction_id,$out_refund_no,$total_fee,$refund_fee,$ext = array()){
341
-		$data = ($ext && is_array($ext))?$ext:array();
340
+	public function refundByTransactionId($transaction_id, $out_refund_no, $total_fee, $refund_fee, $ext = array()) {
341
+		$data = ($ext && is_array($ext)) ? $ext : array();
342 342
 		$data["appid"] = $this->config["app_id"];
343 343
 		$data["transaction_id"] = $transaction_id;
344 344
 		$data["out_refund_no"] = $out_refund_no;
345 345
 		$data["total_fee"] = $total_fee;
346 346
 		$data["refund_fee"] = $refund_fee;
347
-		$result = $this->post(self::URL_REFUND, $data,true);
347
+		$result = $this->post(self::URL_REFUND, $data, true);
348 348
 		return $result;
349 349
 	}
350 350
 
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
 	 * @param $bill_type string 类型 ALL|SUCCESS
356 356
 	 * @return array
357 357
 	 */
358
-	public function downloadBill($bill_date,$bill_type = 'ALL'){
358
+	public function downloadBill($bill_date, $bill_type = 'ALL') {
359 359
 		$data = array();
360 360
 		$data["appid"] = $this->config["app_id"];
361 361
 		$data["bill_date"] = $bill_date;
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
 	 * @param $tar_type string 压缩账单
373 373
 	 * @return array
374 374
 	 */
375
-	public function downloadFundFlow($bill_date,$account_type = self::ACCOUNTTYPE_BASIC,$tar_type = 'GZIP'){
375
+	public function downloadFundFlow($bill_date, $account_type = self::ACCOUNTTYPE_BASIC, $tar_type = 'GZIP') {
376 376
 		$data = array();
377 377
 		$data["appid"] = $this->config["app_id"];
378 378
 		$data["bill_date"] = $bill_date;
@@ -391,14 +391,14 @@  discard block
 block discarded – undo
391 391
 	 * @param int $limit 条数
392 392
 	 * @return array
393 393
 	 */
394
-	public function batchQueryComment($begin_time,$end_time,$offset = 0,$limit = 200){
394
+	public function batchQueryComment($begin_time, $end_time, $offset = 0, $limit = 200) {
395 395
 		$data = array();
396 396
 		$data["appid"] = $this->config["app_id"];
397 397
 		$data["begin_time"] = $begin_time;
398 398
 		$data["end_time"] = $end_time;
399 399
 		$data["offset"] = $offset;
400 400
 		$data["limit"] = $limit;
401
-		$data["sign"] = $this->sign($data,WechatPay::SIGNTYPE_HMACSHA256);
401
+		$data["sign"] = $this->sign($data, WechatPay::SIGNTYPE_HMACSHA256);
402 402
 		$result = $this->post(self::URL_BATCHQUERYCOMMENT, $data, true); //cert is required
403 403
 		return $result;
404 404
 	}
@@ -410,11 +410,11 @@  discard block
 block discarded – undo
410 410
 	 * @return null
411 411
 	 * @throws Exception
412 412
 	 */
413
-	public function onPaidNotify($notify_data,callable $callback = null){
414
-		if(!is_array($notify_data)) $notify_data = $this->xml2array($notify_data);
415
-		if(!$this->validateSign($notify_data)) throw new Exception('Invalid paid notify data');
416
-		if($callback && is_callable($callback)){
417
-			return call_user_func_array( $callback , [$notify_data] );
413
+	public function onPaidNotify($notify_data, callable $callback = null) {
414
+		if (!is_array($notify_data)) $notify_data = $this->xml2array($notify_data);
415
+		if (!$this->validateSign($notify_data)) throw new Exception('Invalid paid notify data');
416
+		if ($callback && is_callable($callback)) {
417
+			return call_user_func_array($callback, [$notify_data]);
418 418
 		}
419 419
 	}
420 420
 
@@ -425,11 +425,11 @@  discard block
 block discarded – undo
425 425
 	 * @return mixed
426 426
 	 * @throws Exception
427 427
 	 */
428
-	public function onRefundedNotify($notify_data,callable $callback = null){
429
-		if(!is_array($notify_data)) $notify_data = $this->xml2array($notify_data);
430
-		if(!$this->validateSign($notify_data)) throw new Exception('Invalid refund notify data');
431
-		if($callback && is_callable($callback)){
432
-			return call_user_func_array( $callback ,[$notify_data] );
428
+	public function onRefundedNotify($notify_data, callable $callback = null) {
429
+		if (!is_array($notify_data)) $notify_data = $this->xml2array($notify_data);
430
+		if (!$this->validateSign($notify_data)) throw new Exception('Invalid refund notify data');
431
+		if ($callback && is_callable($callback)) {
432
+			return call_user_func_array($callback, [$notify_data]);
433 433
 		}
434 434
 	}
435 435
 
@@ -455,13 +455,13 @@  discard block
 block discarded – undo
455 455
 	 * @param bool $print
456 456
 	 * @return string
457 457
 	 */
458
-	public function responseNotify($print = true,$data = [],$return_code="SUCCESS", $return_msg= 'OK') {
458
+	public function responseNotify($print = true, $data = [], $return_code = "SUCCESS", $return_msg = 'OK') {
459 459
 		$data["return_code"] = $return_code;
460 460
 		if ($return_msg) {
461 461
 			$data["return_msg"] = $return_msg;
462 462
 		}
463 463
 		$xml = $this->array2xml($data);
464
-		if($print === true) print $xml;
464
+		if ($print === true) print $xml;
465 465
 		else return $xml;
466 466
 	}
467 467
 
@@ -481,8 +481,8 @@  discard block
 block discarded – undo
481 481
 	 * @param string $err_code_des
482 482
 	 * @return array
483 483
 	 */
484
-	public function report($interface_url,$execution_time,$return_code,$result_code,$user_ip,$out_trade_no = null,$time = null,$device_info = null,
485
-	                       $return_msg = null,$err_code = null,$err_code_des = null){
484
+	public function report($interface_url, $execution_time, $return_code, $result_code, $user_ip, $out_trade_no = null, $time = null, $device_info = null,
485
+	                       $return_msg = null, $err_code = null, $err_code_des = null) {
486 486
 		$data = array();
487 487
 		$data["appid"] = $this->config["app_id"];
488 488
 		$data["interface_url"] = $interface_url;
@@ -490,12 +490,12 @@  discard block
 block discarded – undo
490 490
 		$data["return_code"] = $return_code;
491 491
 		$data["result_code"] = $result_code;
492 492
 		$data["user_ip"] = $user_ip;
493
-		if($out_trade_no) $data["out_trade_no"] = $out_trade_no;
494
-		if($time) $data["time"] = $time;
495
-		if($device_info) $data["device_info"] = $device_info;
496
-		if($return_msg) $data["return_msg"] = $return_msg;
497
-		if($err_code) $data["err_code"] = $err_code;
498
-		if($err_code_des) $data["err_code_des"] = $err_code_des;
493
+		if ($out_trade_no) $data["out_trade_no"] = $out_trade_no;
494
+		if ($time) $data["time"] = $time;
495
+		if ($device_info) $data["device_info"] = $device_info;
496
+		if ($return_msg) $data["return_msg"] = $return_msg;
497
+		if ($err_code) $data["err_code"] = $err_code;
498
+		if ($err_code_des) $data["err_code_des"] = $err_code_des;
499 499
 		return $this->post(self::URL_REPORT, $data, false);
500 500
 	}
501 501
 
@@ -505,19 +505,19 @@  discard block
 block discarded – undo
505 505
 	 * @param $longurl
506 506
 	 * @return string
507 507
 	 */
508
-	public function shortUrl($longurl){
508
+	public function shortUrl($longurl) {
509 509
 		$data = array();
510 510
 		$data["appid"] = $this->config["app_id"];
511 511
 		$data["long_url"] = $longurl;
512
-		$result = $this->post(self::URL_SHORTURL,$data,false);
512
+		$result = $this->post(self::URL_SHORTURL, $data, false);
513 513
 		return $result['short_url'];
514 514
 	}
515 515
 
516
-	public function rsaEncrypt($data,$pubkey = null){
517
-		if(!$pubkey) $pubkey = $this->getPublicKey();
516
+	public function rsaEncrypt($data, $pubkey = null) {
517
+		if (!$pubkey) $pubkey = $this->getPublicKey();
518 518
 		$encrypted = null;
519 519
 		$pubkey = openssl_get_publickey($pubkey);
520
-		if (@openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING))
520
+		if (@openssl_public_encrypt($data, $encrypted, $pubkey, OPENSSL_PKCS1_OAEP_PADDING))
521 521
 			$data = base64_encode($encrypted);
522 522
 		else
523 523
 			throw new Exception('Unable to encrypt data');
@@ -529,10 +529,10 @@  discard block
 block discarded – undo
529 529
 	 * @link https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=23_1
530 530
 	 * @return array
531 531
 	 */
532
-	public function getSignKey(){
532
+	public function getSignKey() {
533 533
 		$data = array();
534 534
 		$data["mch_id"] = $this->config["mch_id"];
535
-		$result = $this->post($this->getSignKeyUrl,$data,false);
535
+		$result = $this->post($this->getSignKeyUrl, $data, false);
536 536
 		return $result['sandbox_signkey'];
537 537
 	}
538 538
 
@@ -542,8 +542,8 @@  discard block
 block discarded – undo
542 542
 	 * @param string $ticket
543 543
 	 * @return array
544 544
 	 */
545
-	public function getSignPackage($url, $ticket = null){
546
-		if(!$ticket) $ticket = $this->getTicket();
545
+	public function getSignPackage($url, $ticket = null) {
546
+		if (!$ticket) $ticket = $this->getTicket();
547 547
 		$timestamp = time();
548 548
 		$nonceStr = $this->getNonceStr();
549 549
 		$rawString = "jsapi_ticket=$ticket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
@@ -565,29 +565,29 @@  discard block
 block discarded – undo
565 565
 	 * @param boolean $cache
566 566
 	 * @return string
567 567
 	 */
568
-	public function getTicket($cache = true){
568
+	public function getTicket($cache = true) {
569 569
 		$ticket = null;
570 570
 		$cacheKey = 'jsapi_ticket';
571
-		if($cache === true){
571
+		if ($cache === true) {
572 572
 			$data = $this->cacheProvider->get($cacheKey);
573 573
 			if ($data && $data->expires_at > time()) {
574 574
 				$ticket = $data->ticket;
575 575
 			}
576 576
 		}
577
-		if(!$ticket){
577
+		if (!$ticket) {
578 578
 			$data = $this->getWechatOAuth()->getTicket();
579
-			if($cache === true){
580
-				$this->cacheProvider->set($cacheKey,$data,time() + $data->expires_in);
579
+			if ($cache === true) {
580
+				$this->cacheProvider->set($cacheKey, $data, time() + $data->expires_in);
581 581
 			}
582 582
 			$ticket = $data->ticket;
583 583
 		}
584 584
 		return $ticket;
585 585
 	}
586 586
 
587
-	protected function post($url, $data,$cert = true) {
588
-		if(!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"];
589
-		if(!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr();
590
-		if(!isset($data['sign'])) $data['sign'] = $this->sign($data);
587
+	protected function post($url, $data, $cert = true) {
588
+		if (!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"];
589
+		if (!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr();
590
+		if (!isset($data['sign'])) $data['sign'] = $this->sign($data);
591 591
 		$this->requestXML = $this->responseXML = null;
592 592
 		$this->requestArray = $this->responseArray = null;
593 593
 
@@ -599,23 +599,23 @@  discard block
 block discarded – undo
599 599
 			CURLOPT_RETURNTRANSFER => true,
600 600
 			CURLOPT_TIMEOUT => 10
601 601
 		];
602
-		if($cert == true){
602
+		if ($cert == true) {
603 603
 			$opts[CURLOPT_SSLCERTTYPE] = 'PEM';
604 604
 			$opts[CURLOPT_SSLCERT] = $this->config['ssl_cert_path'];
605 605
 			$opts[CURLOPT_SSLKEYTYPE] = 'PEM';
606 606
 			$opts[CURLOPT_SSLKEY] = $this->config['ssl_key_path'];
607 607
 		}
608 608
 		$processResponse = true;
609
-		if(in_array($url,[self::URL_DOWNLOADBILL,self::URL_DOWNLOAD_FUND_FLOW,self::URL_BATCHQUERYCOMMENT])){
609
+		if (in_array($url, [self::URL_DOWNLOADBILL, self::URL_DOWNLOAD_FUND_FLOW, self::URL_BATCHQUERYCOMMENT])) {
610 610
 			$processResponse = false;
611 611
 		}
612
-		if($this->sandbox === true) $url = "sandboxnew/{$url}";
612
+		if ($this->sandbox === true) $url = "sandboxnew/{$url}";
613 613
 
614
-		$content = $this->httpClient->post(self::API_ENDPOINT . $url,$this->requestXML,[],$opts);
615
-		if(!$content) throw new Exception("Empty response with {$this->requestXML}");
614
+		$content = $this->httpClient->post(self::API_ENDPOINT.$url, $this->requestXML, [], $opts);
615
+		if (!$content) throw new Exception("Empty response with {$this->requestXML}");
616 616
 
617 617
 		$this->responseXML = $content;
618
-		if($processResponse)
618
+		if ($processResponse)
619 619
 			return $this->processResponseXML($this->responseXML);
620 620
 		else return $this->responseXML;
621 621
 	}
@@ -625,51 +625,51 @@  discard block
 block discarded – undo
625 625
 	 * @return array
626 626
 	 * @throws Exception
627 627
 	 */
628
-	private function processResponseXML($responseXML){
628
+	private function processResponseXML($responseXML) {
629 629
 		$result = $this->xml2array($responseXML);
630 630
 		$this->responseArray = $result;
631
-		if(empty($result['return_code'])){
631
+		if (empty($result['return_code'])) {
632 632
 			throw new Exception("No return code presents in {$this->responseXML}");
633 633
 		}
634 634
 		$this->returnCode = $result["return_code"];
635
-		$this->returnMsg = isset($result['return_msg'])?$result['return_msg']:'';
635
+		$this->returnMsg = isset($result['return_msg']) ? $result['return_msg'] : '';
636 636
 
637 637
 		if ($this->returnCode == "SUCCESS") {
638
-			if(isset($result['result_code']) && $result['result_code'] == "FAIL"){
638
+			if (isset($result['result_code']) && $result['result_code'] == "FAIL") {
639 639
 				$this->resultCode = $result['result_code'];
640 640
 				$this->errCode = $result['err_code'];
641 641
 				$this->errCodeDes = $result['err_code_des'];
642 642
 				throw new Exception("[$this->errCode]$this->errCodeDes");
643
-			}else{
643
+			}else {
644 644
 				return $result;
645 645
 			}
646
-		} else if($this->returnCode == 'FAIL'){
646
+		}else if ($this->returnCode == 'FAIL') {
647 647
 			throw new Exception($this->returnMsg);
648 648
 		}
649 649
 	}
650 650
 
651
-	public function sign($data,$sign_type = WechatPay::SIGNTYPE_MD5) {
651
+	public function sign($data, $sign_type = WechatPay::SIGNTYPE_MD5) {
652 652
 		ksort($data);
653 653
 		$string1 = "";
654 654
 		foreach ($data as $k => $v) {
655
-			if ($v && trim($v)!='') {
655
+			if ($v && trim($v) != '') {
656 656
 				$string1 .= "$k=$v&";
657 657
 			}
658 658
 		}
659
-		$stringSignTemp = $string1 . "key=" . $this->config["api_key"];
660
-		if($sign_type == WechatPay::SIGNTYPE_MD5){
659
+		$stringSignTemp = $string1."key=".$this->config["api_key"];
660
+		if ($sign_type == WechatPay::SIGNTYPE_MD5) {
661 661
 			$sign = strtoupper(md5($stringSignTemp));
662
-		}elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){
663
-			$sign = strtoupper(hash_hmac('sha256',$stringSignTemp,$this->config["api_key"]));
662
+		}elseif ($sign_type == WechatPay::SIGNTYPE_HMACSHA256) {
663
+			$sign = strtoupper(hash_hmac('sha256', $stringSignTemp, $this->config["api_key"]));
664 664
 		}else throw new Exception("Not supported sign type - $sign_type");
665 665
 		return $sign;
666 666
 	}
667 667
 
668 668
 	private function array2xml($array) {
669
-		$xml = "<xml>" . PHP_EOL;
669
+		$xml = "<xml>".PHP_EOL;
670 670
 		foreach ($array as $k => $v) {
671
-			if($v && trim($v)!='')
672
-				$xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL;
671
+			if ($v && trim($v) != '')
672
+				$xml .= "<$k><![CDATA[$v]]></$k>".PHP_EOL;
673 673
 		}
674 674
 		$xml .= "</xml>";
675 675
 		return $xml;
@@ -678,14 +678,14 @@  discard block
 block discarded – undo
678 678
 	private function xml2array($xml) {
679 679
 		$array = [];
680 680
 		$tmp = (array) simplexml_load_string($xml);
681
-		foreach ( $tmp as $k => $v) {
681
+		foreach ($tmp as $k => $v) {
682 682
 			$array[$k] = (string) $v;
683 683
 		}
684 684
 		return $array;
685 685
 	}
686 686
 
687 687
 	protected function getNonceStr() {
688
-		return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"),0,32);
688
+		return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"), 0, 32);
689 689
 	}
690 690
 
691 691
 }
692 692
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +80 added lines, -33 removed lines patch added patch discarded remove patch
@@ -187,11 +187,15 @@  discard block
 block discarded – undo
187 187
 		$data["notify_url"] = $this->config["notify_url"];
188 188
 		$data["trade_type"] = $params['trade_type'];
189 189
 		if($params['trade_type'] == WechatPay::TRADETYPE_NATIVE){
190
-			if(!isset($params['product_id'])) throw new Exception('product_id is required when trade_type is NATIVE');
190
+			if(!isset($params['product_id'])) {
191
+				throw new Exception('product_id is required when trade_type is NATIVE');
192
+			}
191 193
 			$data["product_id"] = $params['product_id'];
192 194
 		}
193 195
 		if($params['trade_type'] == WechatPay::TRADETYPE_JSAPI){
194
-			if(!isset($params['openid'])) throw new Exception('openid is required when trade_type is JSAPI');
196
+			if(!isset($params['openid'])) {
197
+				throw new Exception('openid is required when trade_type is JSAPI');
198
+			}
195 199
 			$data["openid"] = $params['openid'];
196 200
 		}
197 201
 		$result = $this->post(self::URL_UNIFIEDORDER, $data);
@@ -411,8 +415,12 @@  discard block
 block discarded – undo
411 415
 	 * @throws Exception
412 416
 	 */
413 417
 	public function onPaidNotify($notify_data,callable $callback = null){
414
-		if(!is_array($notify_data)) $notify_data = $this->xml2array($notify_data);
415
-		if(!$this->validateSign($notify_data)) throw new Exception('Invalid paid notify data');
418
+		if(!is_array($notify_data)) {
419
+			$notify_data = $this->xml2array($notify_data);
420
+		}
421
+		if(!$this->validateSign($notify_data)) {
422
+			throw new Exception('Invalid paid notify data');
423
+		}
416 424
 		if($callback && is_callable($callback)){
417 425
 			return call_user_func_array( $callback , [$notify_data] );
418 426
 		}
@@ -426,8 +434,12 @@  discard block
 block discarded – undo
426 434
 	 * @throws Exception
427 435
 	 */
428 436
 	public function onRefundedNotify($notify_data,callable $callback = null){
429
-		if(!is_array($notify_data)) $notify_data = $this->xml2array($notify_data);
430
-		if(!$this->validateSign($notify_data)) throw new Exception('Invalid refund notify data');
437
+		if(!is_array($notify_data)) {
438
+			$notify_data = $this->xml2array($notify_data);
439
+		}
440
+		if(!$this->validateSign($notify_data)) {
441
+			throw new Exception('Invalid refund notify data');
442
+		}
431 443
 		if($callback && is_callable($callback)){
432 444
 			return call_user_func_array( $callback ,[$notify_data] );
433 445
 		}
@@ -461,8 +473,11 @@  discard block
 block discarded – undo
461 473
 			$data["return_msg"] = $return_msg;
462 474
 		}
463 475
 		$xml = $this->array2xml($data);
464
-		if($print === true) print $xml;
465
-		else return $xml;
476
+		if($print === true) {
477
+			print $xml;
478
+		} else {
479
+			return $xml;
480
+		}
466 481
 	}
467 482
 
468 483
 	/**
@@ -490,12 +505,24 @@  discard block
 block discarded – undo
490 505
 		$data["return_code"] = $return_code;
491 506
 		$data["result_code"] = $result_code;
492 507
 		$data["user_ip"] = $user_ip;
493
-		if($out_trade_no) $data["out_trade_no"] = $out_trade_no;
494
-		if($time) $data["time"] = $time;
495
-		if($device_info) $data["device_info"] = $device_info;
496
-		if($return_msg) $data["return_msg"] = $return_msg;
497
-		if($err_code) $data["err_code"] = $err_code;
498
-		if($err_code_des) $data["err_code_des"] = $err_code_des;
508
+		if($out_trade_no) {
509
+			$data["out_trade_no"] = $out_trade_no;
510
+		}
511
+		if($time) {
512
+			$data["time"] = $time;
513
+		}
514
+		if($device_info) {
515
+			$data["device_info"] = $device_info;
516
+		}
517
+		if($return_msg) {
518
+			$data["return_msg"] = $return_msg;
519
+		}
520
+		if($err_code) {
521
+			$data["err_code"] = $err_code;
522
+		}
523
+		if($err_code_des) {
524
+			$data["err_code_des"] = $err_code_des;
525
+		}
499 526
 		return $this->post(self::URL_REPORT, $data, false);
500 527
 	}
501 528
 
@@ -514,13 +541,16 @@  discard block
 block discarded – undo
514 541
 	}
515 542
 
516 543
 	public function rsaEncrypt($data,$pubkey = null){
517
-		if(!$pubkey) $pubkey = $this->getPublicKey();
544
+		if(!$pubkey) {
545
+			$pubkey = $this->getPublicKey();
546
+		}
518 547
 		$encrypted = null;
519 548
 		$pubkey = openssl_get_publickey($pubkey);
520
-		if (@openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING))
521
-			$data = base64_encode($encrypted);
522
-		else
523
-			throw new Exception('Unable to encrypt data');
549
+		if (@openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING)) {
550
+					$data = base64_encode($encrypted);
551
+		} else {
552
+					throw new Exception('Unable to encrypt data');
553
+		}
524 554
 		return $data;
525 555
 	}
526 556
 
@@ -543,7 +573,9 @@  discard block
 block discarded – undo
543 573
 	 * @return array
544 574
 	 */
545 575
 	public function getSignPackage($url, $ticket = null){
546
-		if(!$ticket) $ticket = $this->getTicket();
576
+		if(!$ticket) {
577
+			$ticket = $this->getTicket();
578
+		}
547 579
 		$timestamp = time();
548 580
 		$nonceStr = $this->getNonceStr();
549 581
 		$rawString = "jsapi_ticket=$ticket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
@@ -585,9 +617,15 @@  discard block
 block discarded – undo
585 617
 	}
586 618
 
587 619
 	protected function post($url, $data,$cert = true) {
588
-		if(!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"];
589
-		if(!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr();
590
-		if(!isset($data['sign'])) $data['sign'] = $this->sign($data);
620
+		if(!isset($data['mch_id']) && !isset($data['mchid'])) {
621
+			$data["mch_id"] = $this->config["mch_id"];
622
+		}
623
+		if(!isset($data['nonce_str'])) {
624
+			$data["nonce_str"] = $this->getNonceStr();
625
+		}
626
+		if(!isset($data['sign'])) {
627
+			$data['sign'] = $this->sign($data);
628
+		}
591 629
 		$this->requestXML = $this->responseXML = null;
592 630
 		$this->requestArray = $this->responseArray = null;
593 631
 
@@ -609,15 +647,21 @@  discard block
 block discarded – undo
609 647
 		if(in_array($url,[self::URL_DOWNLOADBILL,self::URL_DOWNLOAD_FUND_FLOW,self::URL_BATCHQUERYCOMMENT])){
610 648
 			$processResponse = false;
611 649
 		}
612
-		if($this->sandbox === true) $url = "sandboxnew/{$url}";
650
+		if($this->sandbox === true) {
651
+			$url = "sandboxnew/{$url}";
652
+		}
613 653
 
614 654
 		$content = $this->httpClient->post(self::API_ENDPOINT . $url,$this->requestXML,[],$opts);
615
-		if(!$content) throw new Exception("Empty response with {$this->requestXML}");
655
+		if(!$content) {
656
+			throw new Exception("Empty response with {$this->requestXML}");
657
+		}
616 658
 
617 659
 		$this->responseXML = $content;
618
-		if($processResponse)
619
-			return $this->processResponseXML($this->responseXML);
620
-		else return $this->responseXML;
660
+		if($processResponse) {
661
+					return $this->processResponseXML($this->responseXML);
662
+		} else {
663
+			return $this->responseXML;
664
+		}
621 665
 	}
622 666
 
623 667
 	/**
@@ -640,7 +684,7 @@  discard block
 block discarded – undo
640 684
 				$this->errCode = $result['err_code'];
641 685
 				$this->errCodeDes = $result['err_code_des'];
642 686
 				throw new Exception("[$this->errCode]$this->errCodeDes");
643
-			}else{
687
+			} else{
644 688
 				return $result;
645 689
 			}
646 690
 		} else if($this->returnCode == 'FAIL'){
@@ -659,17 +703,20 @@  discard block
 block discarded – undo
659 703
 		$stringSignTemp = $string1 . "key=" . $this->config["api_key"];
660 704
 		if($sign_type == WechatPay::SIGNTYPE_MD5){
661 705
 			$sign = strtoupper(md5($stringSignTemp));
662
-		}elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){
706
+		} elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){
663 707
 			$sign = strtoupper(hash_hmac('sha256',$stringSignTemp,$this->config["api_key"]));
664
-		}else throw new Exception("Not supported sign type - $sign_type");
708
+		} else {
709
+			throw new Exception("Not supported sign type - $sign_type");
710
+		}
665 711
 		return $sign;
666 712
 	}
667 713
 
668 714
 	private function array2xml($array) {
669 715
 		$xml = "<xml>" . PHP_EOL;
670 716
 		foreach ($array as $k => $v) {
671
-			if($v && trim($v)!='')
672
-				$xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL;
717
+			if($v && trim($v)!='') {
718
+							$xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL;
719
+			}
673 720
 		}
674 721
 		$xml .= "</xml>";
675 722
 		return $xml;
Please login to merge, or discard this patch.
src/util/WechatOAuth.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 namespace zhangv\wechat\pay\util;
9 9
 
10 10
 class WechatOAuth {
11
-	const TICKETTYPE_JSAPI = 'jsapi',TICKETTYPE_WXCARD = 'wx_card';
11
+	const TICKETTYPE_JSAPI = 'jsapi', TICKETTYPE_WXCARD = 'wx_card';
12 12
 	public $responseJSON = null;
13 13
 	public $errCode = null;
14 14
 	public $errMsg = null;
@@ -18,46 +18,46 @@  discard block
 block discarded – undo
18 18
 	private $httpClient = null;
19 19
 	private $accessToken = null;
20 20
 
21
-	public function __construct($appId,$appSecret) {
21
+	public function __construct($appId, $appSecret) {
22 22
 		$this->appId = $appId;
23 23
 		$this->appSecret = $appSecret;
24 24
 		$this->httpClient = new HttpClient();
25 25
 	}
26 26
 
27
-	public function setHttpClient($httpClient){
27
+	public function setHttpClient($httpClient) {
28 28
 		$this->httpClient = $httpClient;
29 29
 	}
30 30
 
31
-	public function authorizeURI($redirectURI,$scope = 'snsapi_userinfo',$state = ''){
31
+	public function authorizeURI($redirectURI, $scope = 'snsapi_userinfo', $state = '') {
32 32
 		$redirectURI = urlencode($redirectURI);
33 33
 		return "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$this->appId}&redirect_uri={$redirectURI}&response_type=code&scope=$scope&state=$state#wechat_redirect";
34 34
 	}
35 35
 
36
-	public function authorize($code){
36
+	public function authorize($code) {
37 37
 		$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$this->appId}&secret={$this->appSecret}&code=$code&grant_type=authorization_code";
38 38
 		$this->responseJSON = $this->httpClient->get($url);
39 39
 		return json_decode($this->responseJSON);
40 40
 	}
41 41
 
42
-	public function getUserInfo($openId){
42
+	public function getUserInfo($openId) {
43 43
 		$url = "https://api.weixin.qq.com/sns/userinfo?access_token={$this->accessToken}&openid=$openId&lang=zh_CN";
44 44
 		$this->responseJSON = $this->httpClient->get($url);
45 45
 		return json_decode($this->responseJSON);
46 46
 	}
47 47
 
48
-	public function refreshToken($refreshToken){
48
+	public function refreshToken($refreshToken) {
49 49
 		$url = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid={$this->appId}&grant_type=refresh_token&refresh_token=$refreshToken";
50 50
 		$this->responseJSON = $this->httpClient->get($url);
51 51
 		return json_decode($this->responseJSON);
52 52
 	}
53 53
 
54
-	public function verifyToken($accessToken,$openId){
54
+	public function verifyToken($accessToken, $openId) {
55 55
 		$url = "https://api.weixin.qq.com/sns/auth?access_token=$accessToken&openid=$openId";
56 56
 		$this->responseJSON = $this->httpClient->get($url);
57 57
 		return json_decode($this->responseJSON);
58 58
 	}
59 59
 
60
-	public function getAccessToken(){
60
+	public function getAccessToken() {
61 61
 		$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->appId}&secret={$this->appSecret}";
62 62
 		$this->responseJSON = $this->httpClient->get($url);
63 63
 		$json = json_decode($this->responseJSON);
@@ -65,27 +65,27 @@  discard block
 block discarded – undo
65 65
 		return $this->accessToken;
66 66
 	}
67 67
 
68
-	public function getTicket($type = WechatOAuth::TICKETTYPE_JSAPI, $accessToken = null){
69
-		if(!$accessToken) $accessToken = $this->getAccessToken();
68
+	public function getTicket($type = WechatOAuth::TICKETTYPE_JSAPI, $accessToken = null) {
69
+		if (!$accessToken) $accessToken = $this->getAccessToken();
70 70
 		// $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$accessToken";
71 71
 		$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type={$type}&access_token=$accessToken";
72 72
 		$this->responseJSON = $this->httpClient->get($url);
73 73
 		return json_decode($this->responseJSON);
74 74
 	}
75 75
 
76
-	public function getSession($code){
76
+	public function getSession($code) {
77 77
 		$url = "https://api.weixin.qq.com/sns/jscode2session?appid={$this->appId}&secret={$this->appSecret}&js_code=$code&grant_type=authorization_code";
78 78
 		$this->responseJSON = $this->httpClient->get($url);
79 79
 		return json_decode($this->responseJSON);
80 80
 	}
81 81
 
82
-	public function getSignPackage($url = null, $ticket = null){
83
-		if(!$url){
82
+	public function getSignPackage($url = null, $ticket = null) {
83
+		if (!$url) {
84 84
 			$url = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ||
85 85
 				(!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)) ? "https://" : "http://";
86 86
 			$url .= "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
87 87
 		}
88
-		if(!$ticket) $ticket = $this->getTicket();
88
+		if (!$ticket) $ticket = $this->getTicket();
89 89
 		$timestamp = time();
90 90
 		$nonceStr = $this->getNonceStr();
91 91
 		$rawString = "jsapi_ticket=$ticket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
@@ -103,6 +103,6 @@  discard block
 block discarded – undo
103 103
 	}
104 104
 
105 105
 	private function getNonceStr() {
106
-		return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"),0,32);
106
+		return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"), 0, 32);
107 107
 	}
108 108
 }
Please login to merge, or discard this patch.
src/util/HttpClient.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -7,9 +7,9 @@  discard block
 block discarded – undo
7 7
  */
8 8
 namespace zhangv\wechat\pay\util;
9 9
 
10
-class HttpClient{
10
+class HttpClient {
11 11
 
12
-	const GET = 'get',POST = 'post', DELETE = 'delete',PUT = 'put';
12
+	const GET = 'get', POST = 'post', DELETE = 'delete', PUT = 'put';
13 13
 	private $instance = null;
14 14
 	private $errNo = null;
15 15
 	private $info = null;
@@ -19,8 +19,8 @@  discard block
 block discarded – undo
19 19
 		$this->initInstance($timeout);
20 20
 	}
21 21
 
22
-	public function initInstance($timeout){
23
-		if(!$this->instance) {
22
+	public function initInstance($timeout) {
23
+		if (!$this->instance) {
24 24
 			$this->instance = curl_init();
25 25
 			curl_setopt($this->instance, CURLOPT_TIMEOUT, intval($timeout));
26 26
 			curl_setopt($this->instance, CURLOPT_RETURNTRANSFER, true);
@@ -29,26 +29,26 @@  discard block
 block discarded – undo
29 29
 		}
30 30
 	}
31 31
 
32
-	public function get($url,$params = array(),$headers = array(),$opts = array()) {
32
+	public function get($url, $params = array(), $headers = array(), $opts = array()) {
33 33
 		if (!$this->instance)	$this->initInstance($this->timeout);
34
-		if($params && count($params) > 0) $url .= '?' . http_build_query($params);
34
+		if ($params && count($params) > 0) $url .= '?'.http_build_query($params);
35 35
 		curl_setopt($this->instance, CURLOPT_URL, $url);
36 36
 		curl_setopt($this->instance, CURLOPT_HTTPGET, true);
37 37
 		curl_setopt($this->instance, CURLOPT_HTTPHEADER, $headers);
38
-		curl_setopt_array($this->instance,$opts);
38
+		curl_setopt_array($this->instance, $opts);
39 39
 		$result = $this->execute();
40 40
 		curl_close($this->instance);
41 41
 		$this->instance = null;
42 42
 		return $result;
43 43
 	}
44 44
 
45
-	public function post($url, $params = array(),$headers = array(),$opts = array()) {
45
+	public function post($url, $params = array(), $headers = array(), $opts = array()) {
46 46
 		if (!$this->instance)	$this->initInstance($this->timeout);
47 47
 		curl_setopt($this->instance, CURLOPT_URL, $url);
48 48
 		curl_setopt($this->instance, CURLOPT_POST, true);
49 49
 		curl_setopt($this->instance, CURLOPT_POSTFIELDS, $params);
50 50
 		curl_setopt($this->instance, CURLOPT_HTTPHEADER, $headers);
51
-		curl_setopt_array($this->instance,$opts);
51
+		curl_setopt_array($this->instance, $opts);
52 52
 		$result = $this->execute();
53 53
 		curl_close($this->instance);
54 54
 		$this->instance = null;
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 		return $result;
63 63
 	}
64 64
 
65
-	public function getInfo(){
65
+	public function getInfo() {
66 66
 		return $this->info;
67 67
 	}
68 68
 }
69 69
\ No newline at end of file
Please login to merge, or discard this patch.