Completed
Push — master ( c385cb...b0036f )
by Wei
04:12
created
src/cache/RedisCacheProvider.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -4,25 +4,25 @@
 block discarded – undo
4 4
  * Time: 2018/5/29 16:41
5 5
  */
6 6
 namespace zhangv\wechat\cache;
7
-class RedisCacheProvider implements CacheProvider{
7
+class RedisCacheProvider implements CacheProvider {
8 8
 	/** @var Redis */
9 9
 	private $redis = null;
10 10
 
11
-	public function __construct($redis = null){
11
+	public function __construct($redis = null) {
12 12
 		$this->redis = $redis;
13 13
 	}
14 14
 
15
-	public function set($key,$jsonobj,$expireAt){
15
+	public function set($key, $jsonobj, $expireAt) {
16 16
 		$data = $jsonobj;
17 17
 		$data->expires_at = $expireAt;
18 18
 		$this->redis->set($key, json_encode($data));
19 19
 	}
20 20
 
21
-	public function get($key){
21
+	public function get($key) {
22 22
 		return $this->redis->get($key);
23 23
 	}
24 24
 
25
-	public function clear($key){
25
+	public function clear($key) {
26 26
 		$this->redis->delete($key);
27 27
 	}
28 28
 }
29 29
\ No newline at end of file
Please login to merge, or discard this patch.
src/cache/JsonFileCacheProvider.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -4,15 +4,15 @@  discard block
 block discarded – undo
4 4
  * Time: 2018/5/29 16:41
5 5
  */
6 6
 namespace zhangv\wechat\cache;
7
-class JsonFileCacheProvider implements CacheProvider{
7
+class JsonFileCacheProvider implements CacheProvider {
8 8
 	private $cacheDir = null;
9 9
 
10
-	public function __construct($cacheDir = null){
11
-		if(!$cacheDir) $this->cacheDir = __DIR__;
10
+	public function __construct($cacheDir = null) {
11
+		if (!$cacheDir) $this->cacheDir = __DIR__;
12 12
 		else $this->cacheDir = $cacheDir;
13 13
 	}
14 14
 
15
-	public function set($key,$jsonobj,$expireAt){
15
+	public function set($key, $jsonobj, $expireAt) {
16 16
 		$data = $jsonobj;
17 17
 		$data->expires_at = $expireAt;
18 18
 		$file = "{$this->cacheDir}/{$key}.json";
@@ -21,16 +21,16 @@  discard block
 block discarded – undo
21 21
 		if ($fp) fclose($fp);
22 22
 	}
23 23
 
24
-	public function get($key){
24
+	public function get($key) {
25 25
 		$file = "{$this->cacheDir}/{$key}.json";
26 26
 		$cache = null;
27
-		if(file_exists($file)){
27
+		if (file_exists($file)) {
28 28
 			$cache = json_decode(file_get_contents($file));
29 29
 		}
30 30
 		return $cache;
31 31
 	}
32 32
 
33
-	public function clear($key){
33
+	public function clear($key) {
34 34
 		$file = "{$this->cacheDir}/{$key}.json";
35 35
 		if (file_exists($file)) {
36 36
 			unlink($file);
Please login to merge, or discard this patch.
Braces   +8 added lines, -3 removed lines patch added patch discarded remove patch
@@ -8,8 +8,11 @@  discard block
 block discarded – undo
8 8
 	private $cacheDir = null;
9 9
 
10 10
 	public function __construct($cacheDir = null){
11
-		if(!$cacheDir) $this->cacheDir = __DIR__;
12
-		else $this->cacheDir = $cacheDir;
11
+		if(!$cacheDir) {
12
+			$this->cacheDir = __DIR__;
13
+		} else {
14
+			$this->cacheDir = $cacheDir;
15
+		}
13 16
 	}
14 17
 
15 18
 	public function set($key,$jsonobj,$expireAt){
@@ -18,7 +21,9 @@  discard block
 block discarded – undo
18 21
 		$file = "{$this->cacheDir}/{$key}.json";
19 22
 		$fp = fopen($file, "w");
20 23
 		fwrite($fp, json_encode($data));
21
-		if ($fp) fclose($fp);
24
+		if ($fp) {
25
+			fclose($fp);
26
+		}
22 27
 	}
23 28
 
24 29
 	public function get($key){
Please login to merge, or discard this patch.
src/cache/CacheProvider.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,8 +5,8 @@
 block discarded – undo
5 5
  */
6 6
 namespace zhangv\wechat\cache;
7 7
 
8
-interface CacheProvider{
9
-	function set($key,$value,$expireAt);
8
+interface CacheProvider {
9
+	function set($key, $value, $expireAt);
10 10
 	function get($key);
11 11
 	function clear($key);
12 12
 }
13 13
\ No newline at end of file
Please login to merge, or discard this patch.
src/WechatPay.php 2 patches
Spacing   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -10,10 +10,10 @@  discard block
 block discarded – undo
10 10
 use zhangv\wechat\cache\JsonFileCacheProvider;
11 11
 
12 12
 class WechatPay {
13
-	const TRADETYPE_JSAPI = 'JSAPI',TRADETYPE_NATIVE = 'NATIVE',TRADETYPE_APP = 'APP',TRADETYPE_MWEB = 'MWEB';
13
+	const TRADETYPE_JSAPI = 'JSAPI', TRADETYPE_NATIVE = 'NATIVE', TRADETYPE_APP = 'APP', TRADETYPE_MWEB = 'MWEB';
14 14
 	const SIGNTYPE_MD5 = 'MD5', SIGNTYPE_HMACSHA256 = 'HMAC-SHA256';
15
-	const CHECKNAME_FORCECHECK = 'FORCE_CHECK',CHECKNAME_NOCHECK = 'NO_CHECK';
16
-	const ACCOUNTTYPE_BASIC = 'Basic',ACCOUNTTYPE_OPERATION = 'Operation',ACCOUNTTYPE_FEES = 'Fees';
15
+	const CHECKNAME_FORCECHECK = 'FORCE_CHECK', CHECKNAME_NOCHECK = 'NO_CHECK';
16
+	const ACCOUNTTYPE_BASIC = 'Basic', ACCOUNTTYPE_OPERATION = 'Operation', ACCOUNTTYPE_FEES = 'Fees';
17 17
 	/** 支付 */
18 18
 	const URL_UNIFIEDORDER = "https://api.mch.weixin.qq.com/pay/unifiedorder";
19 19
 	const URL_ORDERQUERY = "https://api.mch.weixin.qq.com/pay/orderquery";
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	const URL_GETPUBLICKEY = 'https://fraud.mch.weixin.qq.com/risk/getpublickey';
46 46
 	public static $BANKCODE = ['工商银行' => '1002', '农业银行' => '1005', '中国银行' => '1026', '建设银行' => '1003', '招商银行' => '1001',
47 47
 		'邮储银行' => '1066', '交通银行' => '1020', '浦发银行' => '1004', '民生银行' => '1006', '兴业银行' => '1009', '平安银行' => '1010',
48
-		'中信银行' => '1021', '华夏银行' => '1025', '广发银行' => '1027', '光大银行' => '1022', '北京银行' => '1032', '宁波银行' => '1056',];
48
+		'中信银行' => '1021', '华夏银行' => '1025', '广发银行' => '1027', '光大银行' => '1022', '北京银行' => '1032', '宁波银行' => '1056', ];
49 49
 
50 50
 	public $getSignKeyUrl = "https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey";
51 51
 	public $sandbox = false;
@@ -88,34 +88,34 @@  discard block
 block discarded – undo
88 88
 		$this->cacheProvider = new JsonFileCacheProvider();
89 89
 	}
90 90
 
91
-	public function setWechatOAuth($wechatOAuth){
91
+	public function setWechatOAuth($wechatOAuth) {
92 92
 		$this->wechatOAuth = $wechatOAuth;
93 93
 	}
94 94
 
95
-	public function getWechatOAuth(){
96
-		if(!$this->wechatOAuth){
97
-			$this->wechatOAuth = new WechatOAuth($this->config['app_id'],$this->config['app_secret']);
95
+	public function getWechatOAuth() {
96
+		if (!$this->wechatOAuth) {
97
+			$this->wechatOAuth = new WechatOAuth($this->config['app_id'], $this->config['app_secret']);
98 98
 		}
99 99
 		return $this->wechatOAuth;
100 100
 	}
101 101
 
102
-	public function setConfig($config){
102
+	public function setConfig($config) {
103 103
 		$this->config = $config;
104 104
 	}
105 105
 
106
-	public function getConfig(){
106
+	public function getConfig() {
107 107
 		return $this->config;
108 108
 	}
109 109
 
110
-	public function setHttpClient($httpClient){
110
+	public function setHttpClient($httpClient) {
111 111
 		$this->httpClient = $httpClient;
112 112
 	}
113 113
 
114
-	public function setCacheProvider($cacheProvider){
114
+	public function setCacheProvider($cacheProvider) {
115 115
 		$this->cacheProvider = $cacheProvider;
116 116
 	}
117 117
 
118
-	public function getCacheProvider(){
118
+	public function getCacheProvider() {
119 119
 		return $this->cacheProvider;
120 120
 	}
121 121
 
@@ -131,16 +131,16 @@  discard block
 block discarded – undo
131 131
 	 * @return string
132 132
 	 * @throws \Exception
133 133
 	 */
134
-	public function getPrepayId($body,$out_trade_no,$total_fee,$openid,$spbill_create_ip = null,$ext = null) {
135
-		$data = ($ext && is_array($ext))?$ext:array();
134
+	public function getPrepayId($body, $out_trade_no, $total_fee, $openid, $spbill_create_ip = null, $ext = null) {
135
+		$data = ($ext && is_array($ext)) ? $ext : array();
136 136
 		$data["body"]         = $body;
137 137
 		$data["out_trade_no"] = $out_trade_no;
138 138
 		$data["total_fee"]    = $total_fee;
139
-		$data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["REMOTE_ADDR"];
139
+		$data["spbill_create_ip"] = $spbill_create_ip ?: $_SERVER["REMOTE_ADDR"];
140 140
 		$data["notify_url"]   = $this->config["notify_url"];
141 141
 		$data["trade_type"]   = WechatPay::TRADETYPE_JSAPI;
142
-		if(!$openid) throw new Exception('openid is required when trade_type is JSAPI');
143
-		$data["openid"]   = $openid;
142
+		if (!$openid) throw new Exception('openid is required when trade_type is JSAPI');
143
+		$data["openid"] = $openid;
144 144
 		$result = $this->unifiedOrder($data);
145 145
 		return $result["prepay_id"];
146 146
 	}
@@ -155,8 +155,8 @@  discard block
 block discarded – undo
155 155
 	 * @param $ext array
156 156
 	 * @return string
157 157
 	 */
158
-	public function getPrepayIdAPP($body,$out_trade_no,$total_fee,$spbill_create_ip,$ext = null) {
159
-		$data = ($ext && is_array($ext))?$ext:array();
158
+	public function getPrepayIdAPP($body, $out_trade_no, $total_fee, $spbill_create_ip, $ext = null) {
159
+		$data = ($ext && is_array($ext)) ? $ext : array();
160 160
 		$data["body"]         = $body;
161 161
 		$data["out_trade_no"] = $out_trade_no;
162 162
 		$data["total_fee"]    = $total_fee;
@@ -179,15 +179,15 @@  discard block
 block discarded – undo
179 179
 	 * @return string
180 180
 	 * @throws Exception
181 181
 	 */
182
-	public function getCodeUrl($body,$out_trade_no,$total_fee,$product_id,$spbill_create_ip = null,$ext = null){
183
-		$data = ($ext && is_array($ext))?$ext:array();
182
+	public function getCodeUrl($body, $out_trade_no, $total_fee, $product_id, $spbill_create_ip = null, $ext = null) {
183
+		$data = ($ext && is_array($ext)) ? $ext : array();
184 184
 		$data["body"]         = $body;
185 185
 		$data["out_trade_no"] = $out_trade_no;
186 186
 		$data["total_fee"]    = $total_fee;
187
-		$data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["SERVER_ADDR"];
187
+		$data["spbill_create_ip"] = $spbill_create_ip ?: $_SERVER["SERVER_ADDR"];
188 188
 		$data["notify_url"]   = $this->config["notify_url"];
189 189
 		$data["trade_type"]   = self::TRADETYPE_NATIVE;
190
-		if(!$product_id) throw new Exception('product_id is required when trade_type is NATIVE');
190
+		if (!$product_id) throw new Exception('product_id is required when trade_type is NATIVE');
191 191
 		$data["product_id"]   = $product_id;
192 192
 		$result = $this->unifiedOrder($data);
193 193
 		return $result["code_url"];
@@ -203,15 +203,15 @@  discard block
 block discarded – undo
203 203
 	 * @return string
204 204
 	 * @throws Exception
205 205
 	 */
206
-	public function getMwebUrl($body,$out_trade_no,$total_fee,$ext = null){
207
-		$data = ($ext && is_array($ext))?$ext:array();
206
+	public function getMwebUrl($body, $out_trade_no, $total_fee, $ext = null) {
207
+		$data = ($ext && is_array($ext)) ? $ext : array();
208 208
 		$data["body"]         = $body;
209 209
 		$data["out_trade_no"] = $out_trade_no;
210 210
 		$data["total_fee"]    = $total_fee;
211
-		$data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:'';
211
+		$data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : '';
212 212
 		$data["notify_url"]   = $this->config["notify_url"];
213 213
 		$data["trade_type"]   = self::TRADETYPE_MWEB;
214
-		if(!isset($this->config['h5_scene_info'])) throw new Exception('h5_scene_info should be configured');
214
+		if (!isset($this->config['h5_scene_info'])) throw new Exception('h5_scene_info should be configured');
215 215
 		$data["scene_info"]   = json_encode($this->config['h5_scene_info']);
216 216
 		$result = $this->unifiedOrder($data);
217 217
 		return $result["mweb_url"];
@@ -227,25 +227,25 @@  discard block
 block discarded – undo
227 227
 	public function unifiedOrder($params) {
228 228
 		$data = array();
229 229
 		$data["appid"] = $this->config["app_id"];
230
-		$data["device_info"] = (isset($params['device_info'])&&trim($params['device_info'])!='')?$params['device_info']:null;
230
+		$data["device_info"] = (isset($params['device_info']) && trim($params['device_info']) != '') ? $params['device_info'] : null;
231 231
 		$data["body"] = $params['body'];
232
-		$data["detail"] = isset($params['detail'])?$params['detail']:null;//optional
233
-		$data["attach"] = isset($params['attach'])?$params['attach']:null;//optional
234
-		$data["out_trade_no"] = isset($params['out_trade_no'])?$params['out_trade_no']:null;
235
-		$data["fee_type"] = isset($params['fee_type'])?$params['fee_type']:'CNY';
232
+		$data["detail"] = isset($params['detail']) ? $params['detail'] : null; //optional
233
+		$data["attach"] = isset($params['attach']) ? $params['attach'] : null; //optional
234
+		$data["out_trade_no"] = isset($params['out_trade_no']) ? $params['out_trade_no'] : null;
235
+		$data["fee_type"] = isset($params['fee_type']) ? $params['fee_type'] : 'CNY';
236 236
 		$data["total_fee"]    = $params['total_fee'];
237 237
 		$data["spbill_create_ip"] = $params['spbill_create_ip'];
238
-		$data["time_start"] = isset($params['time_start'])?$params['time_start']:null;//optional
239
-		$data["time_expire"] = isset($params['time_expire'])?$params['time_expire']:null;//optional
240
-		$data["goods_tag"] = isset($params['goods_tag'])?$params['goods_tag']:null;
238
+		$data["time_start"] = isset($params['time_start']) ? $params['time_start'] : null; //optional
239
+		$data["time_expire"] = isset($params['time_expire']) ? $params['time_expire'] : null; //optional
240
+		$data["goods_tag"] = isset($params['goods_tag']) ? $params['goods_tag'] : null;
241 241
 		$data["notify_url"] = $this->config["notify_url"];
242 242
 		$data["trade_type"] = $params['trade_type'];
243
-		if($params['trade_type'] == WechatPay::TRADETYPE_NATIVE){
244
-			if(!isset($params['product_id'])) throw new Exception('product_id is required when trade_type is NATIVE');
243
+		if ($params['trade_type'] == WechatPay::TRADETYPE_NATIVE) {
244
+			if (!isset($params['product_id'])) throw new Exception('product_id is required when trade_type is NATIVE');
245 245
 			$data["product_id"] = $params['product_id'];
246 246
 		}
247
-		if($params['trade_type'] == WechatPay::TRADETYPE_JSAPI){
248
-			if(!isset($params['openid'])) throw new Exception('openid is required when trade_type is JSAPI');
247
+		if ($params['trade_type'] == WechatPay::TRADETYPE_JSAPI) {
248
+			if (!isset($params['openid'])) throw new Exception('openid is required when trade_type is JSAPI');
249 249
 			$data["openid"] = $params['openid'];
250 250
 		}
251 251
 		$result = $this->post(self::URL_UNIFIEDORDER, $data);
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 	 * @param $transaction_id string 微信订单号
259 259
 	 * @return array
260 260
 	 */
261
-	public function queryOrderByTransactionId($transaction_id){
261
+	public function queryOrderByTransactionId($transaction_id) {
262 262
 		$data = array();
263 263
 		$data["appid"] = $this->config["app_id"];
264 264
 		$data["transaction_id"] = $transaction_id;
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 	 * @param $out_trade_no string 商户订单号
273 273
 	 * @return array
274 274
 	 */
275
-	public function queryOrderByOutTradeNo($out_trade_no){
275
+	public function queryOrderByOutTradeNo($out_trade_no) {
276 276
 		$data = array();
277 277
 		$data["appid"] = $this->config["app_id"];
278 278
 		$data["out_trade_no"] = $out_trade_no;
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 	 * @param $offset int 偏移
288 288
 	 * @return array
289 289
 	 */
290
-	public function queryRefundByTransactionId($transaction_id,$offset = 0){
290
+	public function queryRefundByTransactionId($transaction_id, $offset = 0) {
291 291
 		$data = array();
292 292
 		$data["appid"] = $this->config["app_id"];
293 293
 		$data["transaction_id"] = $transaction_id;
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 	 * @param $offset int 偏移
304 304
 	 * @return array
305 305
 	 */
306
-	public function queryRefundByOutTradeNo($out_trade_no,$offset = 0){
306
+	public function queryRefundByOutTradeNo($out_trade_no, $offset = 0) {
307 307
 		$data = array();
308 308
 		$data["appid"] = $this->config["app_id"];
309 309
 		$data["out_trade_no"] = $out_trade_no;
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 	 * @param $offset int 偏移
320 320
 	 * @return array
321 321
 	 */
322
-	public function queryRefundByRefundId($refund_id,$offset = 0){
322
+	public function queryRefundByRefundId($refund_id, $offset = 0) {
323 323
 		$data = array();
324 324
 		$data["appid"] = $this->config["app_id"];
325 325
 		$data["refund_id"] = $refund_id;
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
 	 * @param $offset int 偏移
336 336
 	 * @return array
337 337
 	 */
338
-	public function queryRefundByOutRefundNo($out_refund_no,$offset = 0){
338
+	public function queryRefundByOutRefundNo($out_refund_no, $offset = 0) {
339 339
 		$data = array();
340 340
 		$data["appid"] = $this->config["app_id"];
341 341
 		$data["out_refund_no"] = $out_refund_no;
@@ -350,11 +350,11 @@  discard block
 block discarded – undo
350 350
 	 * @param $out_trade_no string 商户订单号
351 351
 	 * @return array
352 352
 	 */
353
-	public function closeOrder($out_trade_no){
353
+	public function closeOrder($out_trade_no) {
354 354
 		$data = array();
355 355
 		$data["appid"] = $this->config["app_id"];
356 356
 		$data["out_trade_no"] = $out_trade_no;
357
-		$result = $this->post(self::URL_CLOSEORDER, $data,false);
357
+		$result = $this->post(self::URL_CLOSEORDER, $data, false);
358 358
 		return $result;
359 359
 	}
360 360
 
@@ -369,14 +369,14 @@  discard block
 block discarded – undo
369 369
 	 * @param $ext array 扩展数组
370 370
 	 * @return array
371 371
 	 */
372
-	public function refundByOutTradeNo($out_trade_no,$out_refund_no,$total_fee,$refund_fee,$ext = array()){
373
-		$data = ($ext && is_array($ext))?$ext:array();
372
+	public function refundByOutTradeNo($out_trade_no, $out_refund_no, $total_fee, $refund_fee, $ext = array()) {
373
+		$data = ($ext && is_array($ext)) ? $ext : array();
374 374
 		$data["appid"] = $this->config["app_id"];
375 375
 		$data["out_trade_no"] = $out_trade_no;
376 376
 		$data["out_refund_no"] = $out_refund_no;
377 377
 		$data["total_fee"] = $total_fee;
378 378
 		$data["refund_fee"] = $refund_fee;
379
-		$result = $this->post(self::URL_REFUND, $data,true);
379
+		$result = $this->post(self::URL_REFUND, $data, true);
380 380
 		return $result;
381 381
 	}
382 382
 
@@ -391,14 +391,14 @@  discard block
 block discarded – undo
391 391
 	 * @param $ext array 扩展数组
392 392
 	 * @return array
393 393
 	 */
394
-	public function refundByTransactionId($transaction_id,$out_refund_no,$total_fee,$refund_fee,$ext = array()){
395
-		$data = ($ext && is_array($ext))?$ext:array();
394
+	public function refundByTransactionId($transaction_id, $out_refund_no, $total_fee, $refund_fee, $ext = array()) {
395
+		$data = ($ext && is_array($ext)) ? $ext : array();
396 396
 		$data["appid"] = $this->config["app_id"];
397 397
 		$data["transaction_id"] = $transaction_id;
398 398
 		$data["out_refund_no"] = $out_refund_no;
399 399
 		$data["total_fee"] = $total_fee;
400 400
 		$data["refund_fee"] = $refund_fee;
401
-		$result = $this->post(self::URL_REFUND, $data,true);
401
+		$result = $this->post(self::URL_REFUND, $data, true);
402 402
 		return $result;
403 403
 	}
404 404
 
@@ -408,11 +408,11 @@  discard block
 block discarded – undo
408 408
 	 * @param $out_trade_no string 商户订单号
409 409
 	 * @return array
410 410
 	 */
411
-	public function reverseByOutTradeNo($out_trade_no){
411
+	public function reverseByOutTradeNo($out_trade_no) {
412 412
 		$data = array();
413 413
 		$data["appid"] = $this->config["app_id"];
414 414
 		$data["out_trade_no"] = $out_trade_no;
415
-		$result = $this->post(self::URL_REVERSE, $data,true);
415
+		$result = $this->post(self::URL_REVERSE, $data, true);
416 416
 		return $result;
417 417
 	}
418 418
 
@@ -422,11 +422,11 @@  discard block
 block discarded – undo
422 422
 	 * @param $transaction_id string 微信订单号
423 423
 	 * @return array
424 424
 	 */
425
-	public function reverseByTransactionId($transaction_id){
425
+	public function reverseByTransactionId($transaction_id) {
426 426
 		$data = array();
427 427
 		$data["appid"] = $this->config["app_id"];
428 428
 		$data["transaction_id"] = $transaction_id;
429
-		$result = $this->post(self::URL_REVERSE, $data,true);
429
+		$result = $this->post(self::URL_REVERSE, $data, true);
430 430
 		return $result;
431 431
 	}
432 432
 
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
 	 * @param $bill_type string 类型 ALL|SUCCESS
438 438
 	 * @return array
439 439
 	 */
440
-	public function downloadBill($bill_date,$bill_type = 'ALL'){
440
+	public function downloadBill($bill_date, $bill_type = 'ALL') {
441 441
 		$data = array();
442 442
 		$data["appid"] = $this->config["app_id"];
443 443
 		$data["bill_date"] = $bill_date;
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 	 * @param $tar_type string 压缩账单
455 455
 	 * @return array
456 456
 	 */
457
-	public function downloadFundFlow($bill_date,$account_type = self::ACCOUNTTYPE_BASIC,$tar_type = 'GZIP'){
457
+	public function downloadFundFlow($bill_date, $account_type = self::ACCOUNTTYPE_BASIC, $tar_type = 'GZIP') {
458 458
 		$data = array();
459 459
 		$data["appid"] = $this->config["app_id"];
460 460
 		$data["bill_date"] = $bill_date;
@@ -481,14 +481,14 @@  discard block
 block discarded – undo
481 481
 	 * @return array
482 482
 	 * @throws Exception
483 483
 	 */
484
-	public function sendRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark,$scene_id = '',$riskinfo = '',$consume_mch_id = ''){
484
+	public function sendRedPack($mch_billno, $send_name, $re_openid, $total_amount, $total_num, $wishing, $act_name, $remark, $scene_id = '', $riskinfo = '', $consume_mch_id = '') {
485 485
 		$data = array();
486 486
 		$data["wxappid"] = $this->config["app_id"];
487 487
 		$data["mch_billno"] = $mch_billno;
488 488
 		$data["send_name"] = $send_name;
489 489
 		$data["re_openid"] = $re_openid;
490 490
 		$data["total_amount"] = $total_amount;
491
-		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000");
491
+		if ($total_amount > 20000 && trim($scene_id) == '') throw new Exception("scene_id is required when total_amount beyond 20000");
492 492
 		$data["total_num"] = $total_num;
493 493
 		$data["wishing"] = $wishing;
494 494
 		$data["act_name"] = $act_name;
@@ -517,14 +517,14 @@  discard block
 block discarded – undo
517 517
 	 * @return array
518 518
 	 * @throws Exception
519 519
 	 */
520
-	public function sendGroupRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark,$scene_id = '',$riskinfo = '',$consume_mch_id = ''){
520
+	public function sendGroupRedPack($mch_billno, $send_name, $re_openid, $total_amount, $total_num, $wishing, $act_name, $remark, $scene_id = '', $riskinfo = '', $consume_mch_id = '') {
521 521
 		$data = array();
522
-		$data["wxappid"] = $this->config["app_id"];//NOTE: WXappid
522
+		$data["wxappid"] = $this->config["app_id"]; //NOTE: WXappid
523 523
 		$data["mch_billno"] = $mch_billno;
524 524
 		$data["send_name"] = $send_name;
525 525
 		$data["re_openid"] = $re_openid;
526 526
 		$data["total_amount"] = $total_amount;
527
-		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
527
+		if ($total_amount > 20000 && trim($scene_id) == '') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
528 528
 		$data["total_num"] = $total_num;
529 529
 		$data["amt_type"] = 'ALL_RAND'; //红包金额设置方式 ALL_RAND—全部随机
530 530
 		$data["wishing"] = $wishing;
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
 	 * @throws Exception
545 545
 	 * @ref https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_6&index=5
546 546
 	 */
547
-	public function getHbInfo($mch_billno){
547
+	public function getHbInfo($mch_billno) {
548 548
 		$data = array();
549 549
 		$data["mch_billno"] = $mch_billno;
550 550
 		$data["appid"] = $this->config["app_id"];
@@ -562,14 +562,14 @@  discard block
 block discarded – undo
562 562
 	 * @param int $limit 条数
563 563
 	 * @return array
564 564
 	 */
565
-	public function batchQueryComment($begin_time,$end_time,$offset = 0,$limit = 200){
565
+	public function batchQueryComment($begin_time, $end_time, $offset = 0, $limit = 200) {
566 566
 		$data = array();
567 567
 		$data["appid"] = $this->config["app_id"];
568 568
 		$data["begin_time"] = $begin_time;
569 569
 		$data["end_time"] = $end_time;
570 570
 		$data["offset"] = $offset;
571 571
 		$data["limit"] = $limit;
572
-		$data["sign"] = $this->sign($data,WechatPay::SIGNTYPE_HMACSHA256);
572
+		$data["sign"] = $this->sign($data, WechatPay::SIGNTYPE_HMACSHA256);
573 573
 		$result = $this->post(self::URL_BATCHQUERYCOMMENT, $data, true); //cert is required
574 574
 		return $result;
575 575
 	}
@@ -582,21 +582,21 @@  discard block
 block discarded – undo
582 582
 	 */
583 583
 	public function getPackage($prepay_id, $trade_type = WechatPay::TRADETYPE_JSAPI) {
584 584
 		$data = array();
585
-		if ($trade_type == WechatPay::TRADETYPE_JSAPI){
585
+		if ($trade_type == WechatPay::TRADETYPE_JSAPI) {
586 586
 			$data["package"]   = "prepay_id=$prepay_id";
587 587
 			$data["timeStamp"] = time();
588 588
 			$data["nonceStr"]  = $this->getNonceStr();
589 589
 			$data["appId"] = $this->config["app_id"];
590 590
 			$data["signType"]  = "MD5";
591 591
 			$data["paySign"]   = $this->sign($data);
592
-		} else if ($trade_type == WechatPay::TRADETYPE_APP){
592
+		}else if ($trade_type == WechatPay::TRADETYPE_APP) {
593 593
 			$data["package"]   = "Sign=WXPay";
594 594
 			$data['prepayid'] = $prepay_id;
595 595
 			$data['partnerid'] = $this->config["mch_id"];
596 596
 			$data["timestamp"] = time();
597 597
 			$data["noncestr"]  = $this->getNonceStr();
598 598
 			$data["appid"] = $this->config["app_id"];
599
-			$data["sign"]   = $this->sign($data);
599
+			$data["sign"] = $this->sign($data);
600 600
 		}
601 601
 		return $data;
602 602
 	}
@@ -612,15 +612,15 @@  discard block
 block discarded – undo
612 612
 	 * @param array $ext
613 613
 	 * @return array
614 614
 	 */
615
-	public function microPay($body,$out_trade_no,$total_fee,$spbill_create_ip,$auth_code,$ext = array()){
616
-		$data = (!empty($ext) && is_array($ext))?$ext:array();
615
+	public function microPay($body, $out_trade_no, $total_fee, $spbill_create_ip, $auth_code, $ext = array()) {
616
+		$data = (!empty($ext) && is_array($ext)) ? $ext : array();
617 617
 		$data["appid"] = $this->config["app_id"];
618 618
 		$data["body"]         = $body;
619 619
 		$data["out_trade_no"] = $out_trade_no;
620 620
 		$data["total_fee"]    = $total_fee;
621 621
 		$data["spbill_create_ip"] = $spbill_create_ip;
622 622
 		$data["auth_code"] = $auth_code;
623
-		$result = $this->post(self::URL_MICROPAY,$data,false);
623
+		$result = $this->post(self::URL_MICROPAY, $data, false);
624 624
 		return $result;
625 625
 	}
626 626
 
@@ -631,15 +631,15 @@  discard block
 block discarded – undo
631 631
 	 * @return null
632 632
 	 * @throws Exception
633 633
 	 */
634
-	public function onPaidNotify($notify_data,callable $callback = null){
635
-		if(!is_array($notify_data)){
634
+	public function onPaidNotify($notify_data, callable $callback = null) {
635
+		if (!is_array($notify_data)) {
636 636
 			$notify_data = $this->xml2array($notify_data);
637 637
 		}
638
-		if($this->validateSign($notify_data)){
639
-			if($callback && is_callable($callback)){
640
-				return call_user_func_array( $callback , [$notify_data] );
638
+		if ($this->validateSign($notify_data)) {
639
+			if ($callback && is_callable($callback)) {
640
+				return call_user_func_array($callback, [$notify_data]);
641 641
 			}
642
-		}else{
642
+		}else {
643 643
 			throw new Exception('Invalid paid notify data');
644 644
 		}
645 645
 	}
@@ -651,15 +651,15 @@  discard block
 block discarded – undo
651 651
 	 * @return mixed
652 652
 	 * @throws Exception
653 653
 	 */
654
-	public function onRefundedNotify($notify_data,callable $callback = null){
655
-		if(!is_array($notify_data)){
654
+	public function onRefundedNotify($notify_data, callable $callback = null) {
655
+		if (!is_array($notify_data)) {
656 656
 			$notify_data = $this->xml2array($notify_data);
657 657
 		}
658
-		if($this->validateSign($notify_data)){
659
-			if($callback && is_callable($callback)){
660
-				return call_user_func_array( $callback ,[$notify_data] );
658
+		if ($this->validateSign($notify_data)) {
659
+			if ($callback && is_callable($callback)) {
660
+				return call_user_func_array($callback, [$notify_data]);
661 661
 			}
662
-		}else{
662
+		}else {
663 663
 			throw new Exception('Invalid refunded notify data');
664 664
 		}
665 665
 	}
@@ -686,13 +686,13 @@  discard block
 block discarded – undo
686 686
 	 * @param bool $print
687 687
 	 * @return string
688 688
 	 */
689
-	public function responseNotify($print = true,$data = [],$return_code="SUCCESS", $return_msg= 'OK') {
689
+	public function responseNotify($print = true, $data = [], $return_code = "SUCCESS", $return_msg = 'OK') {
690 690
 		$data["return_code"] = $return_code;
691 691
 		if ($return_msg) {
692 692
 			$data["return_msg"] = $return_msg;
693 693
 		}
694 694
 		$xml = $this->array2xml($data);
695
-		if($print === true) print $xml;
695
+		if ($print === true) print $xml;
696 696
 		else return $xml;
697 697
 	}
698 698
 
@@ -712,8 +712,8 @@  discard block
 block discarded – undo
712 712
 	 * @param string $err_code_des
713 713
 	 * @return array
714 714
 	 */
715
-	public function report($interface_url,$execution_time,$return_code,$result_code,$user_ip,$out_trade_no = null,$time = null,$device_info = null,
716
-	                       $return_msg = null,$err_code = null,$err_code_des = null){
715
+	public function report($interface_url, $execution_time, $return_code, $result_code, $user_ip, $out_trade_no = null, $time = null, $device_info = null,
716
+	                       $return_msg = null, $err_code = null, $err_code_des = null) {
717 717
 		$data = array();
718 718
 		$data["appid"] = $this->config["app_id"];
719 719
 		$data["interface_url"] = $interface_url;
@@ -721,12 +721,12 @@  discard block
 block discarded – undo
721 721
 		$data["return_code"] = $return_code;
722 722
 		$data["result_code"] = $result_code;
723 723
 		$data["user_ip"] = $user_ip;
724
-		if($out_trade_no) $data["out_trade_no"] = $out_trade_no;
725
-		if($time) $data["time"] = $time;
726
-		if($device_info) $data["device_info"] = $device_info;
727
-		if($return_msg) $data["return_msg"] = $return_msg;
728
-		if($err_code) $data["err_code"] = $err_code;
729
-		if($err_code_des) $data["err_code_des"] = $err_code_des;
724
+		if ($out_trade_no) $data["out_trade_no"] = $out_trade_no;
725
+		if ($time) $data["time"] = $time;
726
+		if ($device_info) $data["device_info"] = $device_info;
727
+		if ($return_msg) $data["return_msg"] = $return_msg;
728
+		if ($err_code) $data["err_code"] = $err_code;
729
+		if ($err_code_des) $data["err_code_des"] = $err_code_des;
730 730
 		$result = $this->post(self::URL_REPORT, $data, false);
731 731
 		return $result;
732 732
 	}
@@ -737,11 +737,11 @@  discard block
 block discarded – undo
737 737
 	 * @param $longurl
738 738
 	 * @return string
739 739
 	 */
740
-	public function shortUrl($longurl){
740
+	public function shortUrl($longurl) {
741 741
 		$data = array();
742 742
 		$data["appid"] = $this->config["app_id"];
743 743
 		$data["long_url"] = $longurl;
744
-		$result = $this->post(self::URL_SHORTURL,$data,false);
744
+		$result = $this->post(self::URL_SHORTURL, $data, false);
745 745
 		return $result['short_url'];
746 746
 	}
747 747
 
@@ -751,11 +751,11 @@  discard block
 block discarded – undo
751 751
 	 * @param $auth_code
752 752
 	 * @return mixed
753 753
 	 */
754
-	public function authCodeToOpenId($auth_code){
754
+	public function authCodeToOpenId($auth_code) {
755 755
 		$data = array();
756 756
 		$data["appid"] = $this->config["app_id"];
757 757
 		$data["auth_code"] = $auth_code;
758
-		$result = $this->post(self::URL_AUTHCODETOOPENID,$data,false);
758
+		$result = $this->post(self::URL_AUTHCODETOOPENID, $data, false);
759 759
 		return $result['openid'];
760 760
 	}
761 761
 
@@ -772,19 +772,19 @@  discard block
 block discarded – undo
772 772
 	 * @return array
773 773
 	 * @throws Exception
774 774
 	 */
775
-	public function transferWallet($partner_trade_no,$openid,$amount,$desc,$spbill_create_ip = null,$re_user_name = null,$check_name = WechatPay::CHECKNAME_FORCECHECK){
775
+	public function transferWallet($partner_trade_no, $openid, $amount, $desc, $spbill_create_ip = null, $re_user_name = null, $check_name = WechatPay::CHECKNAME_FORCECHECK) {
776 776
 		$data = array();
777
-		if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required');
777
+		if ($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required');
778 778
 		$data["mch_appid"] = $this->config["app_id"];
779 779
 		$data["mchid"] = $this->config["mch_id"];
780 780
 		$data["partner_trade_no"] = $partner_trade_no;
781 781
 		$data["openid"] = $openid;
782 782
 		$data["amount"] = $amount;
783 783
 		$data["desc"] = $desc;
784
-		$data['spbill_create_ip'] = $spbill_create_ip?:$_SERVER['SERVER_ADDR'];
784
+		$data['spbill_create_ip'] = $spbill_create_ip ?: $_SERVER['SERVER_ADDR'];
785 785
 		$data["check_name"] = $check_name;
786 786
 		$data["re_user_name"] = $re_user_name;
787
-		$result = $this->post(self::URL_TRANSFER_WALLET,$data,true);
787
+		$result = $this->post(self::URL_TRANSFER_WALLET, $data, true);
788 788
 		return $result;
789 789
 	}
790 790
 
@@ -794,12 +794,12 @@  discard block
 block discarded – undo
794 794
 	 * @param $partner_trade_no
795 795
 	 * @return array
796 796
 	 */
797
-	public function queryTransferWallet($partner_trade_no){
797
+	public function queryTransferWallet($partner_trade_no) {
798 798
 		$data = array();
799 799
 		$data["appid"] = $this->config["app_id"];
800 800
 		$data["mch_id"] = $this->config["mch_id"];
801 801
 		$data["partner_trade_no"] = $partner_trade_no;
802
-		$result = $this->post(self::URL_QUERY_TRANSFER_WALLET,$data,true);
802
+		$result = $this->post(self::URL_QUERY_TRANSFER_WALLET, $data, true);
803 803
 		return $result;
804 804
 	}
805 805
 
@@ -815,8 +815,8 @@  discard block
 block discarded – undo
815 815
 	 * @return array
816 816
 	 * @throws Exception
817 817
 	 */
818
-	public function transferBankCard($partner_trade_no,$bank_no,$true_name,$bank_code,$amount,$desc){
819
-		if(!in_array($bank_code,array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code: $bank_code");
818
+	public function transferBankCard($partner_trade_no, $bank_no, $true_name, $bank_code, $amount, $desc) {
819
+		if (!in_array($bank_code, array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code: $bank_code");
820 820
 		$data = array();
821 821
 		$data["partner_trade_no"] = $partner_trade_no;
822 822
 		$enc_bank_no = $this->rsaEncrypt($bank_no);
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
 		$data["bank_code"] = $bank_code;
827 827
 		$data["desc"] = $desc;
828 828
 		$data["amount"] = $amount;
829
-		$result = $this->post(self::URL_TRANSFER_BANKCARD,$data,true);
829
+		$result = $this->post(self::URL_TRANSFER_BANKCARD, $data, true);
830 830
 		return $result;
831 831
 	}
832 832
 
@@ -836,12 +836,12 @@  discard block
 block discarded – undo
836 836
 	 * @param $partner_trade_no
837 837
 	 * @return array
838 838
 	 */
839
-	public function queryTransferBankCard($partner_trade_no){
839
+	public function queryTransferBankCard($partner_trade_no) {
840 840
 		$data = array();
841 841
 		$data["appid"] = $this->config["app_id"];
842 842
 		$data["mch_id"] = $this->config["mch_id"];
843 843
 		$data["partner_trade_no"] = $partner_trade_no;
844
-		$result = $this->post(self::URL_QUERY_TRANSFER_WALLET,$data,true);
844
+		$result = $this->post(self::URL_QUERY_TRANSFER_WALLET, $data, true);
845 845
 		return $result;
846 846
 	}
847 847
 
@@ -855,14 +855,14 @@  discard block
 block discarded – undo
855 855
 	 * @param array $ext
856 856
 	 * @return array
857 857
 	 */
858
-	public function sendCoupon($coupon_stock_id,$open_id,$partner_trade_no,$op_user_id = '',$ext = array()){
859
-		$data = (!empty($ext) && is_array($ext))?$ext:array();
858
+	public function sendCoupon($coupon_stock_id, $open_id, $partner_trade_no, $op_user_id = '', $ext = array()) {
859
+		$data = (!empty($ext) && is_array($ext)) ? $ext : array();
860 860
 		$data["partner_trade_no"] = $partner_trade_no;
861 861
 		$data["coupon_stock_id"] = $coupon_stock_id;
862 862
 		$data["openid_count"] = 1;
863 863
 		$data["open_id"] = $open_id;
864 864
 		$data["op_user_id"] = $op_user_id;
865
-		$result = $this->post(self::URL_SEND_COUPON,$data,true);
865
+		$result = $this->post(self::URL_SEND_COUPON, $data, true);
866 866
 		return $result;
867 867
 	}
868 868
 
@@ -873,11 +873,11 @@  discard block
 block discarded – undo
873 873
 	 * @param string $op_user_id
874 874
 	 * @return array
875 875
 	 */
876
-	public function queryCouponStock($coupon_stock_id,$op_user_id = ''){
876
+	public function queryCouponStock($coupon_stock_id, $op_user_id = '') {
877 877
 		$data = array();
878 878
 		$data["coupon_stock_id"] = $coupon_stock_id;
879 879
 		$data["op_user_id"] = $op_user_id;
880
-		$result = $this->post(self::URL_QUERY_COUPON_STOCK,$data,false);
880
+		$result = $this->post(self::URL_QUERY_COUPON_STOCK, $data, false);
881 881
 		return $result;
882 882
 	}
883 883
 
@@ -891,13 +891,13 @@  discard block
 block discarded – undo
891 891
 	 * @param array $ext
892 892
 	 * @return array
893 893
 	 */
894
-	public function queryCouponsInfo($coupon_id,$open_id,$stock_id,$op_user_id = '',$ext = array()){
895
-		$data = (!empty($ext) && is_array($ext))?$ext:array();
894
+	public function queryCouponsInfo($coupon_id, $open_id, $stock_id, $op_user_id = '', $ext = array()) {
895
+		$data = (!empty($ext) && is_array($ext)) ? $ext : array();
896 896
 		$data["coupon_id"] = $coupon_id;
897 897
 		$data["stock_id"] = $stock_id;
898 898
 		$data["open_id"] = $open_id;
899 899
 		$data["op_user_id"] = $op_user_id;
900
-		$result = $this->post(self::URL_QUERY_COUPON_INFO,$data,false);
900
+		$result = $this->post(self::URL_QUERY_COUPON_INFO, $data, false);
901 901
 		return $result;
902 902
 	}
903 903
 
@@ -908,8 +908,8 @@  discard block
 block discarded – undo
908 908
 	 * @return string
909 909
 	 * @throws Exception
910 910
 	 */
911
-	public function getPublicKey($refresh = false){
912
-		if(!$this->publicKey) {
911
+	public function getPublicKey($refresh = false) {
912
+		if (!$this->publicKey) {
913 913
 			if (!$refresh && file_exists($this->config["rsa_pubkey_path"])) {
914 914
 				$this->publicKey = file_get_contents($this->config["rsa_pubkey_path"]);
915 915
 			}
@@ -923,31 +923,31 @@  discard block
 block discarded – undo
923 923
 			if ($fp) {
924 924
 				fwrite($fp, $this->publicKey);
925 925
 				fclose($fp);
926
-			} else {
926
+			}else {
927 927
 				throw new Exception("RSA public key not found");
928 928
 			}
929 929
 		}
930 930
 		return $this->publicKey;
931 931
 	}
932 932
 
933
-	public function setPublicKey($publicKey){
933
+	public function setPublicKey($publicKey) {
934 934
 		$this->publicKey = $publicKey;
935 935
 	}
936 936
 
937
-	private function convertPKCS1toPKCS8($pkcs1){
937
+	private function convertPKCS1toPKCS8($pkcs1) {
938 938
 		$start_key = $pkcs1;
939 939
 		$start_key = str_replace('-----BEGIN RSA PUBLIC KEY-----', '', $start_key);
940 940
 		$start_key = trim(str_replace('-----END RSA PUBLIC KEY-----', '', $start_key));
941
-		$key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' . str_replace("\n", '', $start_key);
942
-		$key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($key, 64, "\n", true) . "\n-----END PUBLIC KEY-----";
941
+		$key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A'.str_replace("\n", '', $start_key);
942
+		$key = "-----BEGIN PUBLIC KEY-----\n".wordwrap($key, 64, "\n", true)."\n-----END PUBLIC KEY-----";
943 943
 		return $key;
944 944
 	}
945 945
 
946
-	public function rsaEncrypt($data,$pubkey = null){
947
-		if(!$pubkey) $pubkey = $this->getPublicKey();
946
+	public function rsaEncrypt($data, $pubkey = null) {
947
+		if (!$pubkey) $pubkey = $this->getPublicKey();
948 948
 		$encrypted = null;
949 949
 		$pubkey = openssl_get_publickey($pubkey);
950
-		if (openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING))
950
+		if (openssl_public_encrypt($data, $encrypted, $pubkey, OPENSSL_PKCS1_OAEP_PADDING))
951 951
 			$data = base64_encode($encrypted);
952 952
 		else
953 953
 			throw new Exception('Unable to encrypt data');
@@ -959,10 +959,10 @@  discard block
 block discarded – undo
959 959
 	 * @ref https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=23_1
960 960
 	 * @return array
961 961
 	 */
962
-	public function getSignKey(){
962
+	public function getSignKey() {
963 963
 		$data = array();
964 964
 		$data["mch_id"] = $this->config["mch_id"];
965
-		$result = $this->post($this->getSignKeyUrl,$data,false);
965
+		$result = $this->post($this->getSignKeyUrl, $data, false);
966 966
 		return $result['sandbox_signkey'];
967 967
 	}
968 968
 
@@ -972,8 +972,8 @@  discard block
 block discarded – undo
972 972
 	 * @param string $ticket
973 973
 	 * @return array
974 974
 	 */
975
-	public function getSignPackage($url, $ticket = null){
976
-		if(!$ticket) $ticket = $this->getTicket();
975
+	public function getSignPackage($url, $ticket = null) {
976
+		if (!$ticket) $ticket = $this->getTicket();
977 977
 		$timestamp = time();
978 978
 		$nonceStr = $this->getNonceStr();
979 979
 		$rawString = "jsapi_ticket=$ticket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
@@ -995,29 +995,29 @@  discard block
 block discarded – undo
995 995
 	 * @param boolean $cache
996 996
 	 * @return string
997 997
 	 */
998
-	public function getTicket($cache = true){
998
+	public function getTicket($cache = true) {
999 999
 		$ticket = null;
1000 1000
 		$cacheKey = 'jsapi_ticket';
1001
-		if($cache === true){
1001
+		if ($cache === true) {
1002 1002
 			$data = $this->cacheProvider->get($cacheKey);
1003 1003
 			if ($data && $data->expires_at < time()) {
1004 1004
 				$ticket = $data->ticket;
1005 1005
 			}
1006 1006
 		}
1007
-		if(!$ticket){
1007
+		if (!$ticket) {
1008 1008
 			$data = $this->getWechatOAuth()->getTicket();
1009
-			if($cache === true){
1010
-				$this->cacheProvider->set($cacheKey,$data,time() + $data->expires_in);
1009
+			if ($cache === true) {
1010
+				$this->cacheProvider->set($cacheKey, $data, time() + $data->expires_in);
1011 1011
 			}
1012 1012
 			$ticket = $data->ticket;
1013 1013
 		}
1014 1014
 		return $ticket;
1015 1015
 	}
1016 1016
 
1017
-	private function post($url, $data,$cert = true) {
1018
-		if(!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"];
1019
-		if(!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr();
1020
-		if(!isset($data['sign'])) $data['sign'] = $this->sign($data);
1017
+	private function post($url, $data, $cert = true) {
1018
+		if (!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"];
1019
+		if (!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr();
1020
+		if (!isset($data['sign'])) $data['sign'] = $this->sign($data);
1021 1021
 		$this->requestXML = $this->responseXML = null;
1022 1022
 		$this->requestArray = $this->responseArray = null;
1023 1023
 
@@ -1029,53 +1029,53 @@  discard block
 block discarded – undo
1029 1029
 			CURLOPT_RETURNTRANSFER => true,
1030 1030
 			CURLOPT_TIMEOUT => 10
1031 1031
 		];
1032
-		if($cert == true){
1032
+		if ($cert == true) {
1033 1033
 			$opts[CURLOPT_SSLCERTTYPE] = 'PEM';
1034 1034
 			$opts[CURLOPT_SSLCERT] = $this->config['ssl_cert_path'];
1035 1035
 			$opts[CURLOPT_SSLKEYTYPE] = 'PEM';
1036 1036
 			$opts[CURLOPT_SSLKEY] = $this->config['ssl_key_path'];
1037 1037
 		}
1038 1038
 		$processResponse = true;
1039
-		if(in_array($url,[self::URL_DOWNLOADBILL,self::URL_DOWNLOAD_FUND_FLOW,self::URL_BATCHQUERYCOMMENT])){
1039
+		if (in_array($url, [self::URL_DOWNLOADBILL, self::URL_DOWNLOAD_FUND_FLOW, self::URL_BATCHQUERYCOMMENT])) {
1040 1040
 			$processResponse = false;
1041 1041
 		}
1042
-		if($this->sandbox === true){
1042
+		if ($this->sandbox === true) {
1043 1043
 			$host = "https://api.mch.weixin.qq.com";
1044
-			$url = str_replace($host,'',$url);
1044
+			$url = str_replace($host, '', $url);
1045 1045
 			$url = "{$host}/sandboxnew{$url}";
1046 1046
 		}
1047
-		$content = $this->httpClient->post($url,$this->requestXML,[],$opts);
1048
-		if(!$content) throw new Exception("Empty response with {$this->requestXML}");
1047
+		$content = $this->httpClient->post($url, $this->requestXML, [], $opts);
1048
+		if (!$content) throw new Exception("Empty response with {$this->requestXML}");
1049 1049
 
1050 1050
 		$this->responseXML = $content;
1051
-		if($processResponse)
1051
+		if ($processResponse)
1052 1052
 			return $this->processResponseXML($this->responseXML);
1053 1053
 		else return $this->responseXML;
1054 1054
 
1055 1055
 	}
1056 1056
 
1057
-	private function processResponseXML($responseXML){
1057
+	private function processResponseXML($responseXML) {
1058 1058
 		$result = $this->xml2array($responseXML);
1059 1059
 		$this->responseArray = $result;
1060
-		if(empty($result['return_code'])){
1060
+		if (empty($result['return_code'])) {
1061 1061
 			throw new Exception("No return code presents in {$this->responseXML}");
1062 1062
 		}
1063 1063
 		$this->returnCode = $result["return_code"];
1064
-		$this->returnMsg = isset($result['return_msg'])?$result['return_msg']:'';
1064
+		$this->returnMsg = isset($result['return_msg']) ? $result['return_msg'] : '';
1065 1065
 
1066 1066
 		if ($this->returnCode == "SUCCESS") {
1067
-			if(isset($result['result_code']) && $result['result_code'] == "FAIL"){
1067
+			if (isset($result['result_code']) && $result['result_code'] == "FAIL") {
1068 1068
 				$this->resultCode = $result['result_code'];
1069 1069
 				$this->errCode = $result['err_code'];
1070 1070
 				$this->errCodeDes = $result['err_code_des'];
1071 1071
 				throw new Exception("[$this->errCode]$this->errCodeDes");
1072
-			}else{
1072
+			}else {
1073 1073
 				return $result;
1074 1074
 			}
1075
-		} else {
1076
-			if($result["return_code"] == "FAIL"){
1075
+		}else {
1076
+			if ($result["return_code"] == "FAIL") {
1077 1077
 				throw new Exception($this->returnMsg);
1078
-			}else{
1078
+			}else {
1079 1079
 				$this->resultCode = $result['result_code'];
1080 1080
 				$this->errCode = $result['err_code'];
1081 1081
 				$this->errCodeDes = $result['err_code_des'];
@@ -1084,28 +1084,28 @@  discard block
 block discarded – undo
1084 1084
 		}
1085 1085
 	}
1086 1086
 
1087
-	public function sign($data,$sign_type = WechatPay::SIGNTYPE_MD5) {
1087
+	public function sign($data, $sign_type = WechatPay::SIGNTYPE_MD5) {
1088 1088
 		ksort($data);
1089 1089
 		$string1 = "";
1090 1090
 		foreach ($data as $k => $v) {
1091
-			if ($v && trim($v)!='') {
1091
+			if ($v && trim($v) != '') {
1092 1092
 				$string1 .= "$k=$v&";
1093 1093
 			}
1094 1094
 		}
1095
-		$stringSignTemp = $string1 . "key=" . $this->config["api_key"];
1096
-		if($sign_type == WechatPay::SIGNTYPE_MD5){
1095
+		$stringSignTemp = $string1."key=".$this->config["api_key"];
1096
+		if ($sign_type == WechatPay::SIGNTYPE_MD5) {
1097 1097
 			$sign = strtoupper(md5($stringSignTemp));
1098
-		}elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){
1099
-			$sign = strtoupper(hash_hmac('sha256',$stringSignTemp,$this->config["api_key"]));
1098
+		}elseif ($sign_type == WechatPay::SIGNTYPE_HMACSHA256) {
1099
+			$sign = strtoupper(hash_hmac('sha256', $stringSignTemp, $this->config["api_key"]));
1100 1100
 		}else throw new Exception("Not supported sign type - $sign_type");
1101 1101
 		return $sign;
1102 1102
 	}
1103 1103
 
1104 1104
 	private function array2xml($array) {
1105
-		$xml = "<xml>" . PHP_EOL;
1105
+		$xml = "<xml>".PHP_EOL;
1106 1106
 		foreach ($array as $k => $v) {
1107
-			if($v && trim($v)!='')
1108
-				$xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL;
1107
+			if ($v && trim($v) != '')
1108
+				$xml .= "<$k><![CDATA[$v]]></$k>".PHP_EOL;
1109 1109
 		}
1110 1110
 		$xml .= "</xml>";
1111 1111
 		return $xml;
@@ -1114,19 +1114,19 @@  discard block
 block discarded – undo
1114 1114
 	private function xml2array($xml) {
1115 1115
 		$array = array();
1116 1116
 		$tmp = array();
1117
-		try{
1117
+		try {
1118 1118
 			$tmp = (array) simplexml_load_string($xml);
1119
-		}catch(Exception $e){
1119
+		} catch (Exception $e) {
1120 1120
 			throw $e;
1121 1121
 		}
1122
-		foreach ( $tmp as $k => $v) {
1122
+		foreach ($tmp as $k => $v) {
1123 1123
 			$array[$k] = (string) $v;
1124 1124
 		}
1125 1125
 		return $array;
1126 1126
 	}
1127 1127
 
1128 1128
 	private function getNonceStr() {
1129
-		return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"),0,32);
1129
+		return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"), 0, 32);
1130 1130
 	}
1131 1131
 
1132 1132
 }
1133 1133
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +90 added lines, -39 removed lines patch added patch discarded remove patch
@@ -139,7 +139,9 @@  discard block
 block discarded – undo
139 139
 		$data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["REMOTE_ADDR"];
140 140
 		$data["notify_url"]   = $this->config["notify_url"];
141 141
 		$data["trade_type"]   = WechatPay::TRADETYPE_JSAPI;
142
-		if(!$openid) throw new Exception('openid is required when trade_type is JSAPI');
142
+		if(!$openid) {
143
+			throw new Exception('openid is required when trade_type is JSAPI');
144
+		}
143 145
 		$data["openid"]   = $openid;
144 146
 		$result = $this->unifiedOrder($data);
145 147
 		return $result["prepay_id"];
@@ -187,7 +189,9 @@  discard block
 block discarded – undo
187 189
 		$data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["SERVER_ADDR"];
188 190
 		$data["notify_url"]   = $this->config["notify_url"];
189 191
 		$data["trade_type"]   = self::TRADETYPE_NATIVE;
190
-		if(!$product_id) throw new Exception('product_id is required when trade_type is NATIVE');
192
+		if(!$product_id) {
193
+			throw new Exception('product_id is required when trade_type is NATIVE');
194
+		}
191 195
 		$data["product_id"]   = $product_id;
192 196
 		$result = $this->unifiedOrder($data);
193 197
 		return $result["code_url"];
@@ -211,7 +215,9 @@  discard block
 block discarded – undo
211 215
 		$data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:'';
212 216
 		$data["notify_url"]   = $this->config["notify_url"];
213 217
 		$data["trade_type"]   = self::TRADETYPE_MWEB;
214
-		if(!isset($this->config['h5_scene_info'])) throw new Exception('h5_scene_info should be configured');
218
+		if(!isset($this->config['h5_scene_info'])) {
219
+			throw new Exception('h5_scene_info should be configured');
220
+		}
215 221
 		$data["scene_info"]   = json_encode($this->config['h5_scene_info']);
216 222
 		$result = $this->unifiedOrder($data);
217 223
 		return $result["mweb_url"];
@@ -241,11 +247,15 @@  discard block
 block discarded – undo
241 247
 		$data["notify_url"] = $this->config["notify_url"];
242 248
 		$data["trade_type"] = $params['trade_type'];
243 249
 		if($params['trade_type'] == WechatPay::TRADETYPE_NATIVE){
244
-			if(!isset($params['product_id'])) throw new Exception('product_id is required when trade_type is NATIVE');
250
+			if(!isset($params['product_id'])) {
251
+				throw new Exception('product_id is required when trade_type is NATIVE');
252
+			}
245 253
 			$data["product_id"] = $params['product_id'];
246 254
 		}
247 255
 		if($params['trade_type'] == WechatPay::TRADETYPE_JSAPI){
248
-			if(!isset($params['openid'])) throw new Exception('openid is required when trade_type is JSAPI');
256
+			if(!isset($params['openid'])) {
257
+				throw new Exception('openid is required when trade_type is JSAPI');
258
+			}
249 259
 			$data["openid"] = $params['openid'];
250 260
 		}
251 261
 		$result = $this->post(self::URL_UNIFIEDORDER, $data);
@@ -488,7 +498,9 @@  discard block
 block discarded – undo
488 498
 		$data["send_name"] = $send_name;
489 499
 		$data["re_openid"] = $re_openid;
490 500
 		$data["total_amount"] = $total_amount;
491
-		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000");
501
+		if($total_amount > 20000 && trim($scene_id)=='') {
502
+			throw new Exception("scene_id is required when total_amount beyond 20000");
503
+		}
492 504
 		$data["total_num"] = $total_num;
493 505
 		$data["wishing"] = $wishing;
494 506
 		$data["act_name"] = $act_name;
@@ -524,7 +536,9 @@  discard block
 block discarded – undo
524 536
 		$data["send_name"] = $send_name;
525 537
 		$data["re_openid"] = $re_openid;
526 538
 		$data["total_amount"] = $total_amount;
527
-		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
539
+		if($total_amount > 20000 && trim($scene_id)=='') {
540
+			throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
541
+		}
528 542
 		$data["total_num"] = $total_num;
529 543
 		$data["amt_type"] = 'ALL_RAND'; //红包金额设置方式 ALL_RAND—全部随机
530 544
 		$data["wishing"] = $wishing;
@@ -639,7 +653,7 @@  discard block
 block discarded – undo
639 653
 			if($callback && is_callable($callback)){
640 654
 				return call_user_func_array( $callback , [$notify_data] );
641 655
 			}
642
-		}else{
656
+		} else{
643 657
 			throw new Exception('Invalid paid notify data');
644 658
 		}
645 659
 	}
@@ -659,7 +673,7 @@  discard block
 block discarded – undo
659 673
 			if($callback && is_callable($callback)){
660 674
 				return call_user_func_array( $callback ,[$notify_data] );
661 675
 			}
662
-		}else{
676
+		} else{
663 677
 			throw new Exception('Invalid refunded notify data');
664 678
 		}
665 679
 	}
@@ -692,8 +706,11 @@  discard block
 block discarded – undo
692 706
 			$data["return_msg"] = $return_msg;
693 707
 		}
694 708
 		$xml = $this->array2xml($data);
695
-		if($print === true) print $xml;
696
-		else return $xml;
709
+		if($print === true) {
710
+			print $xml;
711
+		} else {
712
+			return $xml;
713
+		}
697 714
 	}
698 715
 
699 716
 	/**
@@ -721,12 +738,24 @@  discard block
 block discarded – undo
721 738
 		$data["return_code"] = $return_code;
722 739
 		$data["result_code"] = $result_code;
723 740
 		$data["user_ip"] = $user_ip;
724
-		if($out_trade_no) $data["out_trade_no"] = $out_trade_no;
725
-		if($time) $data["time"] = $time;
726
-		if($device_info) $data["device_info"] = $device_info;
727
-		if($return_msg) $data["return_msg"] = $return_msg;
728
-		if($err_code) $data["err_code"] = $err_code;
729
-		if($err_code_des) $data["err_code_des"] = $err_code_des;
741
+		if($out_trade_no) {
742
+			$data["out_trade_no"] = $out_trade_no;
743
+		}
744
+		if($time) {
745
+			$data["time"] = $time;
746
+		}
747
+		if($device_info) {
748
+			$data["device_info"] = $device_info;
749
+		}
750
+		if($return_msg) {
751
+			$data["return_msg"] = $return_msg;
752
+		}
753
+		if($err_code) {
754
+			$data["err_code"] = $err_code;
755
+		}
756
+		if($err_code_des) {
757
+			$data["err_code_des"] = $err_code_des;
758
+		}
730 759
 		$result = $this->post(self::URL_REPORT, $data, false);
731 760
 		return $result;
732 761
 	}
@@ -774,7 +803,9 @@  discard block
 block discarded – undo
774 803
 	 */
775 804
 	public function transferWallet($partner_trade_no,$openid,$amount,$desc,$spbill_create_ip = null,$re_user_name = null,$check_name = WechatPay::CHECKNAME_FORCECHECK){
776 805
 		$data = array();
777
-		if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required');
806
+		if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) {
807
+			throw new Exception('Real name is required');
808
+		}
778 809
 		$data["mch_appid"] = $this->config["app_id"];
779 810
 		$data["mchid"] = $this->config["mch_id"];
780 811
 		$data["partner_trade_no"] = $partner_trade_no;
@@ -816,7 +847,9 @@  discard block
 block discarded – undo
816 847
 	 * @throws Exception
817 848
 	 */
818 849
 	public function transferBankCard($partner_trade_no,$bank_no,$true_name,$bank_code,$amount,$desc){
819
-		if(!in_array($bank_code,array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code: $bank_code");
850
+		if(!in_array($bank_code,array_values(self::$BANKCODE))) {
851
+			throw new Exception("Unsupported bank code: $bank_code");
852
+		}
820 853
 		$data = array();
821 854
 		$data["partner_trade_no"] = $partner_trade_no;
822 855
 		$enc_bank_no = $this->rsaEncrypt($bank_no);
@@ -944,13 +977,16 @@  discard block
 block discarded – undo
944 977
 	}
945 978
 
946 979
 	public function rsaEncrypt($data,$pubkey = null){
947
-		if(!$pubkey) $pubkey = $this->getPublicKey();
980
+		if(!$pubkey) {
981
+			$pubkey = $this->getPublicKey();
982
+		}
948 983
 		$encrypted = null;
949 984
 		$pubkey = openssl_get_publickey($pubkey);
950
-		if (openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING))
951
-			$data = base64_encode($encrypted);
952
-		else
953
-			throw new Exception('Unable to encrypt data');
985
+		if (openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING)) {
986
+					$data = base64_encode($encrypted);
987
+		} else {
988
+					throw new Exception('Unable to encrypt data');
989
+		}
954 990
 		return $data;
955 991
 	}
956 992
 
@@ -973,7 +1009,9 @@  discard block
 block discarded – undo
973 1009
 	 * @return array
974 1010
 	 */
975 1011
 	public function getSignPackage($url, $ticket = null){
976
-		if(!$ticket) $ticket = $this->getTicket();
1012
+		if(!$ticket) {
1013
+			$ticket = $this->getTicket();
1014
+		}
977 1015
 		$timestamp = time();
978 1016
 		$nonceStr = $this->getNonceStr();
979 1017
 		$rawString = "jsapi_ticket=$ticket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
@@ -1015,9 +1053,15 @@  discard block
 block discarded – undo
1015 1053
 	}
1016 1054
 
1017 1055
 	private function post($url, $data,$cert = true) {
1018
-		if(!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"];
1019
-		if(!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr();
1020
-		if(!isset($data['sign'])) $data['sign'] = $this->sign($data);
1056
+		if(!isset($data['mch_id']) && !isset($data['mchid'])) {
1057
+			$data["mch_id"] = $this->config["mch_id"];
1058
+		}
1059
+		if(!isset($data['nonce_str'])) {
1060
+			$data["nonce_str"] = $this->getNonceStr();
1061
+		}
1062
+		if(!isset($data['sign'])) {
1063
+			$data['sign'] = $this->sign($data);
1064
+		}
1021 1065
 		$this->requestXML = $this->responseXML = null;
1022 1066
 		$this->requestArray = $this->responseArray = null;
1023 1067
 
@@ -1045,12 +1089,16 @@  discard block
 block discarded – undo
1045 1089
 			$url = "{$host}/sandboxnew{$url}";
1046 1090
 		}
1047 1091
 		$content = $this->httpClient->post($url,$this->requestXML,[],$opts);
1048
-		if(!$content) throw new Exception("Empty response with {$this->requestXML}");
1092
+		if(!$content) {
1093
+			throw new Exception("Empty response with {$this->requestXML}");
1094
+		}
1049 1095
 
1050 1096
 		$this->responseXML = $content;
1051
-		if($processResponse)
1052
-			return $this->processResponseXML($this->responseXML);
1053
-		else return $this->responseXML;
1097
+		if($processResponse) {
1098
+					return $this->processResponseXML($this->responseXML);
1099
+		} else {
1100
+			return $this->responseXML;
1101
+		}
1054 1102
 
1055 1103
 	}
1056 1104
 
@@ -1069,13 +1117,13 @@  discard block
 block discarded – undo
1069 1117
 				$this->errCode = $result['err_code'];
1070 1118
 				$this->errCodeDes = $result['err_code_des'];
1071 1119
 				throw new Exception("[$this->errCode]$this->errCodeDes");
1072
-			}else{
1120
+			} else{
1073 1121
 				return $result;
1074 1122
 			}
1075 1123
 		} else {
1076 1124
 			if($result["return_code"] == "FAIL"){
1077 1125
 				throw new Exception($this->returnMsg);
1078
-			}else{
1126
+			} else{
1079 1127
 				$this->resultCode = $result['result_code'];
1080 1128
 				$this->errCode = $result['err_code'];
1081 1129
 				$this->errCodeDes = $result['err_code_des'];
@@ -1095,17 +1143,20 @@  discard block
 block discarded – undo
1095 1143
 		$stringSignTemp = $string1 . "key=" . $this->config["api_key"];
1096 1144
 		if($sign_type == WechatPay::SIGNTYPE_MD5){
1097 1145
 			$sign = strtoupper(md5($stringSignTemp));
1098
-		}elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){
1146
+		} elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){
1099 1147
 			$sign = strtoupper(hash_hmac('sha256',$stringSignTemp,$this->config["api_key"]));
1100
-		}else throw new Exception("Not supported sign type - $sign_type");
1148
+		} else {
1149
+			throw new Exception("Not supported sign type - $sign_type");
1150
+		}
1101 1151
 		return $sign;
1102 1152
 	}
1103 1153
 
1104 1154
 	private function array2xml($array) {
1105 1155
 		$xml = "<xml>" . PHP_EOL;
1106 1156
 		foreach ($array as $k => $v) {
1107
-			if($v && trim($v)!='')
1108
-				$xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL;
1157
+			if($v && trim($v)!='') {
1158
+							$xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL;
1159
+			}
1109 1160
 		}
1110 1161
 		$xml .= "</xml>";
1111 1162
 		return $xml;
@@ -1116,7 +1167,7 @@  discard block
 block discarded – undo
1116 1167
 		$tmp = array();
1117 1168
 		try{
1118 1169
 			$tmp = (array) simplexml_load_string($xml);
1119
-		}catch(Exception $e){
1170
+		} catch(Exception $e){
1120 1171
 			throw $e;
1121 1172
 		}
1122 1173
 		foreach ( $tmp as $k => $v) {
Please login to merge, or discard this patch.
src/WechatOAuth.php 2 patches
Spacing   +15 added lines, -15 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,20 +63,20 @@  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);
71 71
 		return json_decode($this->responseJSON);
72 72
 	}
73 73
 
74
-	public function getSignPackage($url = null, $ticket = null){
75
-		if(!$url){
74
+	public function getSignPackage($url = null, $ticket = null) {
75
+		if (!$url) {
76 76
 			$url = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
77 77
 			$url .= "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
78 78
 		}
79
-		if(!$ticket) $ticket = $this->getTicket();
79
+		if (!$ticket) $ticket = $this->getTicket();
80 80
 		$timestamp = time();
81 81
 		$nonceStr = $this->getNonceStr();
82 82
 		$rawString = "jsapi_ticket=$ticket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
@@ -94,6 +94,6 @@  discard block
 block discarded – undo
94 94
 	}
95 95
 
96 96
 	private function getNonceStr() {
97
-		return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"),0,32);
97
+		return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"), 0, 32);
98 98
 	}
99 99
 }
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -64,7 +64,9 @@  discard block
 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);
@@ -76,7 +78,9 @@  discard block
 block discarded – undo
76 78
 			$url = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
77 79
 			$url .= "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
78 80
 		}
79
-		if(!$ticket) $ticket = $this->getTicket();
81
+		if(!$ticket) {
82
+			$ticket = $this->getTicket();
83
+		}
80 84
 		$timestamp = time();
81 85
 		$nonceStr = $this->getNonceStr();
82 86
 		$rawString = "jsapi_ticket=$ticket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
Please login to merge, or discard this patch.