Completed
Push — master ( d444bc...935144 )
by Wei
07:33
created
src/HttpClient.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -5,9 +5,9 @@  discard block
 block discarded – undo
5 5
  */
6 6
 namespace zhangv\wechat;
7 7
 
8
-class HttpClient{
8
+class HttpClient {
9 9
 
10
-	const GET = 'get',POST = 'post', DELETE = 'delete',PUT = 'put';
10
+	const GET = 'get', POST = 'post', DELETE = 'delete', PUT = 'put';
11 11
 	private $instance = null;
12 12
 	private $errNo = null;
13 13
 	private $info = null;
@@ -17,12 +17,12 @@  discard block
 block discarded – undo
17 17
 		$this->initInstance($timeout);
18 18
 	}
19 19
 
20
-	public function initInstance($timeout){
21
-		if(!$this->instance) {
20
+	public function initInstance($timeout) {
21
+		if (!$this->instance) {
22 22
 			$this->instance = curl_init();
23 23
 			if ($timeout < 1) {
24 24
 				curl_setopt($this->instance, CURLOPT_TIMEOUT_MS, intval($timeout * 1000));
25
-			} else {
25
+			}else {
26 26
 				curl_setopt($this->instance, CURLOPT_TIMEOUT, intval($timeout));
27 27
 			}
28 28
 			curl_setopt($this->instance, CURLOPT_RETURNTRANSFER, true);
@@ -31,26 +31,26 @@  discard block
 block discarded – undo
31 31
 		}
32 32
 	}
33 33
 
34
-	public function get($url,$params = array(),$headers = array(),$opts = array()) {
34
+	public function get($url, $params = array(), $headers = array(), $opts = array()) {
35 35
 		if (!$this->instance)	$this->initInstance($this->timeout);
36
-		if($params && count($params) > 0) $url .= '?' . http_build_query($params);
36
+		if ($params && count($params) > 0) $url .= '?'.http_build_query($params);
37 37
 		curl_setopt($this->instance, CURLOPT_URL, $url);
38 38
 		curl_setopt($this->instance, CURLOPT_HTTPGET, true);
39 39
 		curl_setopt($this->instance, CURLOPT_HTTPHEADER, $headers);
40
-		curl_setopt_array($this->instance,$opts);
40
+		curl_setopt_array($this->instance, $opts);
41 41
 		$result = $this->execute();
42 42
 		curl_close($this->instance);
43 43
 		$this->instance = null;
44 44
 		return $result;
45 45
 	}
46 46
 
47
-	public function post($url, $params = array(),$headers = array(),$opts = array()) {
47
+	public function post($url, $params = array(), $headers = array(), $opts = array()) {
48 48
 		if (!$this->instance)	$this->initInstance($this->timeout);
49 49
 		curl_setopt($this->instance, CURLOPT_URL, $url);
50 50
 		curl_setopt($this->instance, CURLOPT_POST, true);
51 51
 		curl_setopt($this->instance, CURLOPT_POSTFIELDS, $params);
52 52
 		curl_setopt($this->instance, CURLOPT_HTTPHEADER, $headers);
53
-		curl_setopt_array($this->instance,$opts);
53
+		curl_setopt_array($this->instance, $opts);
54 54
 		$result = $this->execute();
55 55
 		curl_close($this->instance);
56 56
 		$this->instance = null;
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 		curl_setopt_array($this->instance, $optArray);
71 71
 	}
72 72
 
73
-	public function getInfo(){
73
+	public function getInfo() {
74 74
 		return $this->info;
75 75
 	}
76 76
 }
77 77
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -32,8 +32,12 @@  discard block
 block discarded – undo
32 32
 	}
33 33
 
34 34
 	public function get($url,$params = array(),$headers = array(),$opts = array()) {
35
-		if (!$this->instance)	$this->initInstance($this->timeout);
36
-		if($params && count($params) > 0) $url .= '?' . http_build_query($params);
35
+		if (!$this->instance) {
36
+			$this->initInstance($this->timeout);
37
+		}
38
+		if($params && count($params) > 0) {
39
+			$url .= '?' . http_build_query($params);
40
+		}
37 41
 		curl_setopt($this->instance, CURLOPT_URL, $url);
38 42
 		curl_setopt($this->instance, CURLOPT_HTTPGET, true);
39 43
 		curl_setopt($this->instance, CURLOPT_HTTPHEADER, $headers);
@@ -45,7 +49,9 @@  discard block
 block discarded – undo
45 49
 	}
46 50
 
47 51
 	public function post($url, $params = array(),$headers = array(),$opts = array()) {
48
-		if (!$this->instance)	$this->initInstance($this->timeout);
52
+		if (!$this->instance) {
53
+			$this->initInstance($this->timeout);
54
+		}
49 55
 		curl_setopt($this->instance, CURLOPT_URL, $url);
50 56
 		curl_setopt($this->instance, CURLOPT_POST, true);
51 57
 		curl_setopt($this->instance, CURLOPT_POSTFIELDS, $params);
@@ -65,8 +71,12 @@  discard block
 block discarded – undo
65 71
 	}
66 72
 
67 73
 	public function setOpt($optArray) {
68
-		if (!$this->instance)	return;
69
-		if (!is_array($optArray))	throw new \Exception("Argument is not an array!");
74
+		if (!$this->instance) {
75
+			return;
76
+		}
77
+		if (!is_array($optArray)) {
78
+			throw new \Exception("Argument is not an array!");
79
+		}
70 80
 		curl_setopt_array($this->instance, $optArray);
71 81
 	}
72 82
 
Please login to merge, or discard this patch.
src/WechatOAuth.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -17,50 +17,50 @@  discard block
 block discarded – undo
17 17
 	private $httpClient = null;
18 18
 	private $accessToken = null;
19 19
 
20
-	public function __construct($appId,$appSecret) {
20
+	public function __construct($appId, $appSecret) {
21 21
 		$this->appId = $appId;
22 22
 		$this->appSecret = $appSecret;
23 23
 		$this->httpClient = new HttpClient();
24 24
 	}
25 25
 
26
-	public function setHttpClient($httpClient){
26
+	public function setHttpClient($httpClient) {
27 27
 		$this->httpClient = $httpClient;
28 28
 	}
29 29
 
30
-	public function setAccessToken($accessToken){
30
+	public function setAccessToken($accessToken) {
31 31
 		$this->accessToken = $accessToken;
32 32
 	}
33 33
 
34
-	public function authorizeURI($redirectURI,$scope = 'snsapi_userinfo',$state = ''){
34
+	public function authorizeURI($redirectURI, $scope = 'snsapi_userinfo', $state = '') {
35 35
 		$redirectURI = urlencode($redirectURI);
36 36
 		return "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$this->appId}&redirect_uri={$redirectURI}&response_type=code&scope=$scope&state=$state#wechat_redirect";
37 37
 	}
38 38
 
39
-	public function authorize($code){
39
+	public function authorize($code) {
40 40
 		$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$this->appId}&secret={$this->appSecret}&code=$code&grant_type=authorization_code";
41 41
 		$this->responseJSON = $this->httpClient->get($url);
42 42
 		return json_decode($this->responseJSON);
43 43
 	}
44 44
 
45
-	public function getUserInfo($openId){
45
+	public function getUserInfo($openId) {
46 46
 		$url = "https://api.weixin.qq.com/sns/userinfo?access_token={$this->accessToken}&openid=$openId&lang=zh_CN";
47 47
 		$this->responseJSON = $this->httpClient->get($url);
48 48
 		return json_decode($this->responseJSON);
49 49
 	}
50 50
 
51
-	public function refreshToken($refreshToken){
51
+	public function refreshToken($refreshToken) {
52 52
 		$url = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid={$this->appId}&grant_type=refresh_token&refresh_token=$refreshToken";
53 53
 		$this->responseJSON = $this->httpClient->get($url);
54 54
 		return $this->responseJSON;
55 55
 	}
56 56
 
57
-	public function verifyToken($accessToken,$openId){
57
+	public function verifyToken($accessToken, $openId) {
58 58
 		$url = "https://api.weixin.qq.com/sns/auth?access_token=$accessToken&openid=$openId";
59 59
 		$this->responseJSON = $this->httpClient->get($url);
60 60
 		return $this->responseJSON;
61 61
 	}
62 62
 
63
-	public function getAccessToken(){
63
+	public function getAccessToken() {
64 64
 		$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->appId}&secret={$this->appSecret}";
65 65
 		$this->responseJSON = $this->httpClient->get($url);
66 66
 		$json = json_decode($this->responseJSON);
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 		return $this->accessToken;
69 69
 	}
70 70
 
71
-	public function getTicket(){
71
+	public function getTicket() {
72 72
 		$accessToken = $this->getAccessToken();
73 73
 		// $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$accessToken";
74 74
 		$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$accessToken";
Please login to merge, or discard this patch.
src/WechatPay.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -655,7 +655,7 @@
 block discarded – undo
655 655
 	 * @return array
656 656
 	 */
657 657
 	public function report($interface_url,$execution_time,$return_code,$result_code,$user_ip,$out_trade_no = null,$time = null,$device_info = null,
658
-	                       $return_msg = null,$err_code = null,$err_code_des = null){
658
+						   $return_msg = null,$err_code = null,$err_code_des = null){
659 659
 		$data = array();
660 660
 		$data["appid"] = $this->config["app_id"];
661 661
 		$data["interface_url"] = $interface_url;
Please login to merge, or discard this patch.
Spacing   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -8,10 +8,10 @@  discard block
 block discarded – undo
8 8
 use \Exception;
9 9
 
10 10
 class WechatPay {
11
-	const TRADETYPE_JSAPI = 'JSAPI',TRADETYPE_NATIVE = 'NATIVE',TRADETYPE_APP = 'APP',TRADETYPE_MWEB = 'MWEB';
11
+	const TRADETYPE_JSAPI = 'JSAPI', TRADETYPE_NATIVE = 'NATIVE', TRADETYPE_APP = 'APP', TRADETYPE_MWEB = 'MWEB';
12 12
 	const SIGNTYPE_MD5 = 'MD5', SIGNTYPE_HMACSHA256 = 'HMAC-SHA256';
13
-	const CHECKNAME_FORCECHECK = 'FORCE_CHECK',CHECKNAME_NOCHECK = 'NO_CHECK';
14
-	const ACCOUNTTYPE_BASIC = 'Basic',ACCOUNTTYPE_OPERATION = 'Operation',ACCOUNTTYPE_FEES = 'Fees';
13
+	const CHECKNAME_FORCECHECK = 'FORCE_CHECK', CHECKNAME_NOCHECK = 'NO_CHECK';
14
+	const ACCOUNTTYPE_BASIC = 'Basic', ACCOUNTTYPE_OPERATION = 'Operation', ACCOUNTTYPE_FEES = 'Fees';
15 15
 	/** 支付 */
16 16
 	const URL_UNIFIEDORDER = "https://api.mch.weixin.qq.com/pay/unifiedorder";
17 17
 	const URL_ORDERQUERY = "https://api.mch.weixin.qq.com/pay/orderquery";
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	const URL_GETPUBLICKEY = 'https://fraud.mch.weixin.qq.com/risk/getpublickey';
44 44
 	public static $BANKCODE = ['工商银行' => '1002', '农业银行' => '1005', '中国银行' => '1026', '建设银行' => '1003', '招商银行' => '1001',
45 45
 		'邮储银行' => '1066', '交通银行' => '1020', '浦发银行' => '1004', '民生银行' => '1006', '兴业银行' => '1009', '平安银行' => '1010',
46
-		'中信银行' => '1021', '华夏银行' => '1025', '广发银行' => '1027', '光大银行' => '1022', '北京银行' => '1032', '宁波银行' => '1056',];
46
+		'中信银行' => '1021', '华夏银行' => '1025', '广发银行' => '1027', '光大银行' => '1022', '北京银行' => '1032', '宁波银行' => '1056', ];
47 47
 
48 48
 	public $getSignKeyUrl = "https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey";
49 49
 	public $sandbox = false;
@@ -81,18 +81,18 @@  discard block
 block discarded – undo
81 81
 		$this->httpClient = new HttpClient(5);
82 82
 	}
83 83
 
84
-	public function getWechatOAuth(){
85
-		if(!$this->wechatOAuth){
86
-			$this->wechatOAuth = new WechatOAuth($this->config['app_id'],$this->config['app_secret']);
84
+	public function getWechatOAuth() {
85
+		if (!$this->wechatOAuth) {
86
+			$this->wechatOAuth = new WechatOAuth($this->config['app_id'], $this->config['app_secret']);
87 87
 		}
88 88
 		return $this->wechatOAuth;
89 89
 	}
90 90
 
91
-	public function setConfig($config){
91
+	public function setConfig($config) {
92 92
 		$this->config = $config;
93 93
 	}
94 94
 
95
-	public function setHttpClient($httpClient){
95
+	public function setHttpClient($httpClient) {
96 96
 		$this->httpClient = $httpClient;
97 97
 	}
98 98
 
@@ -108,16 +108,16 @@  discard block
 block discarded – undo
108 108
 	 * @return string
109 109
 	 * @throws \Exception
110 110
 	 */
111
-	public function getPrepayId($body,$out_trade_no,$total_fee,$openid,$spbill_create_ip = null,$ext = null) {
112
-		$data = ($ext && is_array($ext))?$ext:array();
111
+	public function getPrepayId($body, $out_trade_no, $total_fee, $openid, $spbill_create_ip = null, $ext = null) {
112
+		$data = ($ext && is_array($ext)) ? $ext : array();
113 113
 		$data["body"]         = $body;
114 114
 		$data["out_trade_no"] = $out_trade_no;
115 115
 		$data["total_fee"]    = $total_fee;
116
-		$data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["REMOTE_ADDR"];
116
+		$data["spbill_create_ip"] = $spbill_create_ip ?: $_SERVER["REMOTE_ADDR"];
117 117
 		$data["notify_url"]   = $this->config["notify_url"];
118 118
 		$data["trade_type"]   = WechatPay::TRADETYPE_JSAPI;
119
-		if(!$openid) throw new Exception('openid is required when trade_type is JSAPI');
120
-		$data["openid"]   = $openid;
119
+		if (!$openid) throw new Exception('openid is required when trade_type is JSAPI');
120
+		$data["openid"] = $openid;
121 121
 		$result = $this->unifiedOrder($data);
122 122
 		return $result["prepay_id"];
123 123
 	}
@@ -132,8 +132,8 @@  discard block
 block discarded – undo
132 132
 	 * @param $ext array
133 133
 	 * @return string
134 134
 	 */
135
-	public function getPrepayIdAPP($body,$out_trade_no,$total_fee,$spbill_create_ip,$ext = null) {
136
-		$data = ($ext && is_array($ext))?$ext:array();
135
+	public function getPrepayIdAPP($body, $out_trade_no, $total_fee, $spbill_create_ip, $ext = null) {
136
+		$data = ($ext && is_array($ext)) ? $ext : array();
137 137
 		$data["body"]         = $body;
138 138
 		$data["out_trade_no"] = $out_trade_no;
139 139
 		$data["total_fee"]    = $total_fee;
@@ -156,15 +156,15 @@  discard block
 block discarded – undo
156 156
 	 * @return string
157 157
 	 * @throws Exception
158 158
 	 */
159
-	public function getCodeUrl($body,$out_trade_no,$total_fee,$product_id,$spbill_create_ip = null,$ext = null){
160
-		$data = ($ext && is_array($ext))?$ext:array();
159
+	public function getCodeUrl($body, $out_trade_no, $total_fee, $product_id, $spbill_create_ip = null, $ext = null) {
160
+		$data = ($ext && is_array($ext)) ? $ext : array();
161 161
 		$data["body"]         = $body;
162 162
 		$data["out_trade_no"] = $out_trade_no;
163 163
 		$data["total_fee"]    = $total_fee;
164
-		$data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["SERVER_ADDR"];
164
+		$data["spbill_create_ip"] = $spbill_create_ip ?: $_SERVER["SERVER_ADDR"];
165 165
 		$data["notify_url"]   = $this->config["notify_url"];
166 166
 		$data["trade_type"]   = self::TRADETYPE_NATIVE;
167
-		if(!$product_id) throw new Exception('product_id is required when trade_type is NATIVE');
167
+		if (!$product_id) throw new Exception('product_id is required when trade_type is NATIVE');
168 168
 		$data["product_id"]   = $product_id;
169 169
 		$result = $this->unifiedOrder($data);
170 170
 		return $result["code_url"];
@@ -180,15 +180,15 @@  discard block
 block discarded – undo
180 180
 	 * @return string
181 181
 	 * @throws Exception
182 182
 	 */
183
-	public function getMwebUrl($body,$out_trade_no,$total_fee,$ext = null){
184
-		$data = ($ext && is_array($ext))?$ext:array();
183
+	public function getMwebUrl($body, $out_trade_no, $total_fee, $ext = null) {
184
+		$data = ($ext && is_array($ext)) ? $ext : array();
185 185
 		$data["body"]         = $body;
186 186
 		$data["out_trade_no"] = $out_trade_no;
187 187
 		$data["total_fee"]    = $total_fee;
188
-		$data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:'';
188
+		$data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : '';
189 189
 		$data["notify_url"]   = $this->config["notify_url"];
190 190
 		$data["trade_type"]   = self::TRADETYPE_MWEB;
191
-		if(!isset($this->config['h5_scene_info'])) throw new Exception('h5_scene_info should be configured');
191
+		if (!isset($this->config['h5_scene_info'])) throw new Exception('h5_scene_info should be configured');
192 192
 		$data["scene_info"]   = json_encode($this->config['h5_scene_info']);
193 193
 		$result = $this->unifiedOrder($data);
194 194
 		return $result["mweb_url"];
@@ -204,25 +204,25 @@  discard block
 block discarded – undo
204 204
 	public function unifiedOrder($params) {
205 205
 		$data = array();
206 206
 		$data["appid"] = $this->config["app_id"];
207
-		$data["device_info"] = (isset($params['device_info'])&&trim($params['device_info'])!='')?$params['device_info']:null;
207
+		$data["device_info"] = (isset($params['device_info']) && trim($params['device_info']) != '') ? $params['device_info'] : null;
208 208
 		$data["body"] = $params['body'];
209
-		$data["detail"] = isset($params['detail'])?$params['detail']:null;//optional
210
-		$data["attach"] = isset($params['attach'])?$params['attach']:null;//optional
211
-		$data["out_trade_no"] = isset($params['out_trade_no'])?$params['out_trade_no']:null;
212
-		$data["fee_type"] = isset($params['fee_type'])?$params['fee_type']:'CNY';
209
+		$data["detail"] = isset($params['detail']) ? $params['detail'] : null; //optional
210
+		$data["attach"] = isset($params['attach']) ? $params['attach'] : null; //optional
211
+		$data["out_trade_no"] = isset($params['out_trade_no']) ? $params['out_trade_no'] : null;
212
+		$data["fee_type"] = isset($params['fee_type']) ? $params['fee_type'] : 'CNY';
213 213
 		$data["total_fee"]    = $params['total_fee'];
214 214
 		$data["spbill_create_ip"] = $params['spbill_create_ip'];
215
-		$data["time_start"] = isset($params['time_start'])?$params['time_start']:null;//optional
216
-		$data["time_expire"] = isset($params['time_expire'])?$params['time_expire']:null;//optional
217
-		$data["goods_tag"] = isset($params['goods_tag'])?$params['goods_tag']:null;
215
+		$data["time_start"] = isset($params['time_start']) ? $params['time_start'] : null; //optional
216
+		$data["time_expire"] = isset($params['time_expire']) ? $params['time_expire'] : null; //optional
217
+		$data["goods_tag"] = isset($params['goods_tag']) ? $params['goods_tag'] : null;
218 218
 		$data["notify_url"] = $this->config["notify_url"];
219 219
 		$data["trade_type"] = $params['trade_type'];
220
-		if($params['trade_type'] == WechatPay::TRADETYPE_NATIVE){
221
-			if(!isset($params['product_id'])) throw new Exception('product_id is required when trade_type is NATIVE');
220
+		if ($params['trade_type'] == WechatPay::TRADETYPE_NATIVE) {
221
+			if (!isset($params['product_id'])) throw new Exception('product_id is required when trade_type is NATIVE');
222 222
 			$data["product_id"] = $params['product_id'];
223 223
 		}
224
-		if($params['trade_type'] == WechatPay::TRADETYPE_JSAPI){
225
-			if(!isset($params['openid'])) throw new Exception('openid is required when trade_type is JSAPI');
224
+		if ($params['trade_type'] == WechatPay::TRADETYPE_JSAPI) {
225
+			if (!isset($params['openid'])) throw new Exception('openid is required when trade_type is JSAPI');
226 226
 			$data["openid"] = $params['openid'];
227 227
 		}
228 228
 		$result = $this->post(self::URL_UNIFIEDORDER, $data);
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 	 * @param $transaction_id string 微信订单号
236 236
 	 * @return array
237 237
 	 */
238
-	public function queryOrderByTransactionId($transaction_id){
238
+	public function queryOrderByTransactionId($transaction_id) {
239 239
 		$data = array();
240 240
 		$data["appid"] = $this->config["app_id"];
241 241
 		$data["transaction_id"] = $transaction_id;
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 	 * @param $out_trade_no string 商户订单号
250 250
 	 * @return array
251 251
 	 */
252
-	public function queryOrderByOutTradeNo($out_trade_no){
252
+	public function queryOrderByOutTradeNo($out_trade_no) {
253 253
 		$data = array();
254 254
 		$data["appid"] = $this->config["app_id"];
255 255
 		$data["out_trade_no"] = $out_trade_no;
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
 	 * @param $offset int 偏移
265 265
 	 * @return array
266 266
 	 */
267
-	public function queryRefundByTransactionId($transaction_id,$offset = 0){
267
+	public function queryRefundByTransactionId($transaction_id, $offset = 0) {
268 268
 		$data = array();
269 269
 		$data["appid"] = $this->config["app_id"];
270 270
 		$data["transaction_id"] = $transaction_id;
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 	 * @param $offset int 偏移
281 281
 	 * @return array
282 282
 	 */
283
-	public function queryRefundByOutTradeNo($out_trade_no,$offset = 0){
283
+	public function queryRefundByOutTradeNo($out_trade_no, $offset = 0) {
284 284
 		$data = array();
285 285
 		$data["appid"] = $this->config["app_id"];
286 286
 		$data["out_trade_no"] = $out_trade_no;
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
 	 * @param $offset int 偏移
297 297
 	 * @return array
298 298
 	 */
299
-	public function queryRefundByRefundId($refund_id,$offset = 0){
299
+	public function queryRefundByRefundId($refund_id, $offset = 0) {
300 300
 		$data = array();
301 301
 		$data["appid"] = $this->config["app_id"];
302 302
 		$data["refund_id"] = $refund_id;
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
 	 * @param $offset int 偏移
313 313
 	 * @return array
314 314
 	 */
315
-	public function queryRefundByOutRefundNo($out_refund_no,$offset = 0){
315
+	public function queryRefundByOutRefundNo($out_refund_no, $offset = 0) {
316 316
 		$data = array();
317 317
 		$data["appid"] = $this->config["app_id"];
318 318
 		$data["out_refund_no"] = $out_refund_no;
@@ -327,11 +327,11 @@  discard block
 block discarded – undo
327 327
 	 * @param $out_trade_no string 商户订单号
328 328
 	 * @return array
329 329
 	 */
330
-	public function closeOrder($out_trade_no){
330
+	public function closeOrder($out_trade_no) {
331 331
 		$data = array();
332 332
 		$data["appid"] = $this->config["app_id"];
333 333
 		$data["out_trade_no"] = $out_trade_no;
334
-		$result = $this->post(self::URL_CLOSEORDER, $data,false);
334
+		$result = $this->post(self::URL_CLOSEORDER, $data, false);
335 335
 		return $result;
336 336
 	}
337 337
 
@@ -346,14 +346,14 @@  discard block
 block discarded – undo
346 346
 	 * @param $ext array 扩展数组
347 347
 	 * @return array
348 348
 	 */
349
-	public function refundByOutTradeNo($out_trade_no,$out_refund_no,$total_fee,$refund_fee,$ext = array()){
350
-		$data = ($ext && is_array($ext))?$ext:array();
349
+	public function refundByOutTradeNo($out_trade_no, $out_refund_no, $total_fee, $refund_fee, $ext = array()) {
350
+		$data = ($ext && is_array($ext)) ? $ext : array();
351 351
 		$data["appid"] = $this->config["app_id"];
352 352
 		$data["out_trade_no"] = $out_trade_no;
353 353
 		$data["out_refund_no"] = $out_refund_no;
354 354
 		$data["total_fee"] = $total_fee;
355 355
 		$data["refund_fee"] = $refund_fee;
356
-		$result = $this->post(self::URL_REFUND, $data,true);
356
+		$result = $this->post(self::URL_REFUND, $data, true);
357 357
 		return $result;
358 358
 	}
359 359
 
@@ -368,14 +368,14 @@  discard block
 block discarded – undo
368 368
 	 * @param $ext array 扩展数组
369 369
 	 * @return array
370 370
 	 */
371
-	public function refundByTransactionId($transaction_id,$out_refund_no,$total_fee,$refund_fee,$ext = array()){
372
-		$data = ($ext && is_array($ext))?$ext:array();
371
+	public function refundByTransactionId($transaction_id, $out_refund_no, $total_fee, $refund_fee, $ext = array()) {
372
+		$data = ($ext && is_array($ext)) ? $ext : array();
373 373
 		$data["appid"] = $this->config["app_id"];
374 374
 		$data["transaction_id"] = $transaction_id;
375 375
 		$data["out_refund_no"] = $out_refund_no;
376 376
 		$data["total_fee"] = $total_fee;
377 377
 		$data["refund_fee"] = $refund_fee;
378
-		$result = $this->post(self::URL_REFUND, $data,true);
378
+		$result = $this->post(self::URL_REFUND, $data, true);
379 379
 		return $result;
380 380
 	}
381 381
 
@@ -385,11 +385,11 @@  discard block
 block discarded – undo
385 385
 	 * @param $out_trade_no string 商户订单号
386 386
 	 * @return array
387 387
 	 */
388
-	public function reverseByOutTradeNo($out_trade_no){
388
+	public function reverseByOutTradeNo($out_trade_no) {
389 389
 		$data = array();
390 390
 		$data["appid"] = $this->config["app_id"];
391 391
 		$data["out_trade_no"] = $out_trade_no;
392
-		$result = $this->post(self::URL_REVERSE, $data,true);
392
+		$result = $this->post(self::URL_REVERSE, $data, true);
393 393
 		return $result;
394 394
 	}
395 395
 
@@ -399,11 +399,11 @@  discard block
 block discarded – undo
399 399
 	 * @param $transaction_id string 微信订单号
400 400
 	 * @return array
401 401
 	 */
402
-	public function reverseByTransactionId($transaction_id){
402
+	public function reverseByTransactionId($transaction_id) {
403 403
 		$data = array();
404 404
 		$data["appid"] = $this->config["app_id"];
405 405
 		$data["transaction_id"] = $transaction_id;
406
-		$result = $this->post(self::URL_REVERSE, $data,true);
406
+		$result = $this->post(self::URL_REVERSE, $data, true);
407 407
 		return $result;
408 408
 	}
409 409
 
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
 	 * @param $bill_type string 类型 ALL|SUCCESS
415 415
 	 * @return array
416 416
 	 */
417
-	public function downloadBill($bill_date,$bill_type = 'ALL'){
417
+	public function downloadBill($bill_date, $bill_type = 'ALL') {
418 418
 		$data = array();
419 419
 		$data["appid"] = $this->config["app_id"];
420 420
 		$data["bill_date"] = $bill_date;
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
 	 * @param $tar_type string 压缩账单
432 432
 	 * @return array
433 433
 	 */
434
-	public function downloadFundFlow($bill_date,$account_type = self::ACCOUNTTYPE_BASIC,$tar_type = 'GZIP'){
434
+	public function downloadFundFlow($bill_date, $account_type = self::ACCOUNTTYPE_BASIC, $tar_type = 'GZIP') {
435 435
 		$data = array();
436 436
 		$data["appid"] = $this->config["app_id"];
437 437
 		$data["bill_date"] = $bill_date;
@@ -458,14 +458,14 @@  discard block
 block discarded – undo
458 458
 	 * @return array
459 459
 	 * @throws Exception
460 460
 	 */
461
-	public function sendRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark,$scene_id = '',$riskinfo = '',$consume_mch_id = ''){
461
+	public function sendRedPack($mch_billno, $send_name, $re_openid, $total_amount, $total_num, $wishing, $act_name, $remark, $scene_id = '', $riskinfo = '', $consume_mch_id = '') {
462 462
 		$data = array();
463 463
 		$data["wxappid"] = $this->config["app_id"];
464 464
 		$data["mch_billno"] = $mch_billno;
465 465
 		$data["send_name"] = $send_name;
466 466
 		$data["re_openid"] = $re_openid;
467 467
 		$data["total_amount"] = $total_amount;
468
-		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000");
468
+		if ($total_amount > 20000 && trim($scene_id) == '') throw new Exception("scene_id is required when total_amount beyond 20000");
469 469
 		$data["total_num"] = $total_num;
470 470
 		$data["wishing"] = $wishing;
471 471
 		$data["act_name"] = $act_name;
@@ -494,14 +494,14 @@  discard block
 block discarded – undo
494 494
 	 * @return array
495 495
 	 * @throws Exception
496 496
 	 */
497
-	public function sendGroupRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark,$scene_id = '',$riskinfo = '',$consume_mch_id = ''){
497
+	public function sendGroupRedPack($mch_billno, $send_name, $re_openid, $total_amount, $total_num, $wishing, $act_name, $remark, $scene_id = '', $riskinfo = '', $consume_mch_id = '') {
498 498
 		$data = array();
499
-		$data["wxappid"] = $this->config["app_id"];//NOTE: WXappid
499
+		$data["wxappid"] = $this->config["app_id"]; //NOTE: WXappid
500 500
 		$data["mch_billno"] = $mch_billno;
501 501
 		$data["send_name"] = $send_name;
502 502
 		$data["re_openid"] = $re_openid;
503 503
 		$data["total_amount"] = $total_amount;
504
-		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
504
+		if ($total_amount > 20000 && trim($scene_id) == '') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
505 505
 		$data["total_num"] = $total_num;
506 506
 		$data["amt_type"] = 'ALL_RAND'; //红包金额设置方式 ALL_RAND—全部随机
507 507
 		$data["wishing"] = $wishing;
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
 	 * @throws Exception
522 522
 	 * @ref https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_6&index=5
523 523
 	 */
524
-	public function getHbInfo($mch_billno){
524
+	public function getHbInfo($mch_billno) {
525 525
 		$data = array();
526 526
 		$data["mch_billno"] = $mch_billno;
527 527
 		$data["appid"] = $this->config["app_id"];
@@ -538,14 +538,14 @@  discard block
 block discarded – undo
538 538
 	 * @param int $limit 条数
539 539
 	 * @return array
540 540
 	 */
541
-	public function batchQueryComment($begin_time,$end_time,$offset = 0,$limit = 200){
541
+	public function batchQueryComment($begin_time, $end_time, $offset = 0, $limit = 200) {
542 542
 		$data = array();
543 543
 		$data["appid"] = $this->config["app_id"];
544 544
 		$data["begin_time"] = $begin_time;
545 545
 		$data["end_time"] = $end_time;
546 546
 		$data["offset"] = $offset;
547 547
 		$data["limit"] = $limit;
548
-		$data["sign"] = $this->sign($data,WechatPay::SIGNTYPE_HMACSHA256);
548
+		$data["sign"] = $this->sign($data, WechatPay::SIGNTYPE_HMACSHA256);
549 549
 		$result = $this->post(self::URL_BATCHQUERYCOMMENT, $data, true); //cert is required
550 550
 		return $result;
551 551
 	}
@@ -558,21 +558,21 @@  discard block
 block discarded – undo
558 558
 	 */
559 559
 	public function getPackage($prepay_id, $trade_type = WechatPay::TRADETYPE_JSAPI) {
560 560
 		$data = array();
561
-		if ($trade_type == WechatPay::TRADETYPE_JSAPI){
561
+		if ($trade_type == WechatPay::TRADETYPE_JSAPI) {
562 562
 			$data["package"]   = "prepay_id=$prepay_id";
563 563
 			$data["timeStamp"] = time();
564 564
 			$data["nonceStr"]  = $this->getNonceStr();
565 565
 			$data["appId"] = $this->config["app_id"];
566 566
 			$data["signType"]  = "MD5";
567 567
 			$data["paySign"]   = $this->sign($data);
568
-		} else if ($trade_type == WechatPay::TRADETYPE_APP){
568
+		}else if ($trade_type == WechatPay::TRADETYPE_APP) {
569 569
 			$data["package"]   = "Sign=WXPay";
570 570
 			$data['prepayid'] = $prepay_id;
571 571
 			$data['partnerid'] = $this->config["mch_id"];
572 572
 			$data["timestamp"] = time();
573 573
 			$data["noncestr"]  = $this->getNonceStr();
574 574
 			$data["appid"] = $this->config["app_id"];
575
-			$data["sign"]   = $this->sign($data);
575
+			$data["sign"] = $this->sign($data);
576 576
 		}
577 577
 		return $data;
578 578
 	}
@@ -588,15 +588,15 @@  discard block
 block discarded – undo
588 588
 	 * @param array $ext
589 589
 	 * @return array
590 590
 	 */
591
-	public function microPay($body,$out_trade_no,$total_fee,$spbill_create_ip,$auth_code,$ext = array()){
592
-		$data = (!empty($ext) && is_array($ext))?$ext:array();
591
+	public function microPay($body, $out_trade_no, $total_fee, $spbill_create_ip, $auth_code, $ext = array()) {
592
+		$data = (!empty($ext) && is_array($ext)) ? $ext : array();
593 593
 		$data["appid"] = $this->config["app_id"];
594 594
 		$data["body"]         = $body;
595 595
 		$data["out_trade_no"] = $out_trade_no;
596 596
 		$data["total_fee"]    = $total_fee;
597 597
 		$data["spbill_create_ip"] = $spbill_create_ip;
598 598
 		$data["auth_code"] = $auth_code;
599
-		$result = $this->post(self::URL_MICROPAY,$data,false);
599
+		$result = $this->post(self::URL_MICROPAY, $data, false);
600 600
 		return $result;
601 601
 	}
602 602
 
@@ -607,17 +607,17 @@  discard block
 block discarded – undo
607 607
 	 * @return null
608 608
 	 * @throws Exception
609 609
 	 */
610
-	public function onPaidNotify($notify_data,callable $callback = null){
611
-		if(!is_array($notify_data)){
610
+	public function onPaidNotify($notify_data, callable $callback = null) {
611
+		if (!is_array($notify_data)) {
612 612
 			$notify_data = $this->xml2array($notify_data);
613 613
 		}
614
-		if($this->validateSign($notify_data)){
615
-			if($callback && is_callable($callback)){
616
-				return call_user_func_array( $callback , [$notify_data] );
617
-			}else{
614
+		if ($this->validateSign($notify_data)) {
615
+			if ($callback && is_callable($callback)) {
616
+				return call_user_func_array($callback, [$notify_data]);
617
+			}else {
618 618
 				$this->responseNotify();
619 619
 			}
620
-		}else{
620
+		}else {
621 621
 			throw new Exception('Invalid paid notify data');
622 622
 		}
623 623
 	}
@@ -629,17 +629,17 @@  discard block
 block discarded – undo
629 629
 	 * @return mixed
630 630
 	 * @throws Exception
631 631
 	 */
632
-	public function onRefundedNotify($notify_data,callable $callback = null){
633
-		if(!is_array($notify_data)){
632
+	public function onRefundedNotify($notify_data, callable $callback = null) {
633
+		if (!is_array($notify_data)) {
634 634
 			$notify_data = $this->xml2array($notify_data);
635 635
 		}
636
-		if($this->validateSign($notify_data)){
637
-			if($callback && is_callable($callback)){
638
-				return call_user_func_array( $callback , $notify_data );
639
-			}else{
636
+		if ($this->validateSign($notify_data)) {
637
+			if ($callback && is_callable($callback)) {
638
+				return call_user_func_array($callback, $notify_data);
639
+			}else {
640 640
 				$this->responseNotify();
641 641
 			}
642
-		}else{
642
+		}else {
643 643
 			throw new Exception('Invalid refunded notify data');
644 644
 		}
645 645
 	}
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
 	 * @param $return_code string 返回状态码 SUCCESS/FAIL
664 664
 	 * @param $return_msg string 返回信息
665 665
 	 */
666
-	public function responseNotify($return_code="SUCCESS", $return_msg= 'OK') {
666
+	public function responseNotify($return_code = "SUCCESS", $return_msg = 'OK') {
667 667
 		$data = array();
668 668
 		$data["return_code"] = $return_code;
669 669
 		if ($return_msg) {
@@ -689,8 +689,8 @@  discard block
 block discarded – undo
689 689
 	 * @param string $err_code_des
690 690
 	 * @return array
691 691
 	 */
692
-	public function report($interface_url,$execution_time,$return_code,$result_code,$user_ip,$out_trade_no = null,$time = null,$device_info = null,
693
-	                       $return_msg = null,$err_code = null,$err_code_des = null){
692
+	public function report($interface_url, $execution_time, $return_code, $result_code, $user_ip, $out_trade_no = null, $time = null, $device_info = null,
693
+	                       $return_msg = null, $err_code = null, $err_code_des = null) {
694 694
 		$data = array();
695 695
 		$data["appid"] = $this->config["app_id"];
696 696
 		$data["interface_url"] = $interface_url;
@@ -698,12 +698,12 @@  discard block
 block discarded – undo
698 698
 		$data["return_code"] = $return_code;
699 699
 		$data["result_code"] = $result_code;
700 700
 		$data["user_ip"] = $user_ip;
701
-		if($out_trade_no) $data["out_trade_no"] = $out_trade_no;
702
-		if($time) $data["time"] = $time;
703
-		if($device_info) $data["device_info"] = $device_info;
704
-		if($return_msg) $data["return_msg"] = $return_msg;
705
-		if($err_code) $data["err_code"] = $err_code;
706
-		if($err_code_des) $data["err_code_des"] = $err_code_des;
701
+		if ($out_trade_no) $data["out_trade_no"] = $out_trade_no;
702
+		if ($time) $data["time"] = $time;
703
+		if ($device_info) $data["device_info"] = $device_info;
704
+		if ($return_msg) $data["return_msg"] = $return_msg;
705
+		if ($err_code) $data["err_code"] = $err_code;
706
+		if ($err_code_des) $data["err_code_des"] = $err_code_des;
707 707
 		$result = $this->post(self::URL_REPORT, $data, false);
708 708
 		return $result;
709 709
 	}
@@ -714,11 +714,11 @@  discard block
 block discarded – undo
714 714
 	 * @param $longurl
715 715
 	 * @return string
716 716
 	 */
717
-	public function shortUrl($longurl){
717
+	public function shortUrl($longurl) {
718 718
 		$data = array();
719 719
 		$data["appid"] = $this->config["app_id"];
720 720
 		$data["long_url"] = $longurl;
721
-		$result = $this->post(self::URL_SHORTURL,$data,false);
721
+		$result = $this->post(self::URL_SHORTURL, $data, false);
722 722
 		return $result['short_url'];
723 723
 	}
724 724
 
@@ -728,11 +728,11 @@  discard block
 block discarded – undo
728 728
 	 * @param $auth_code
729 729
 	 * @return mixed
730 730
 	 */
731
-	public function authCodeToOpenId($auth_code){
731
+	public function authCodeToOpenId($auth_code) {
732 732
 		$data = array();
733 733
 		$data["appid"] = $this->config["app_id"];
734 734
 		$data["auth_code"] = $auth_code;
735
-		$result = $this->post(self::URL_AUTHCODETOOPENID,$data,false);
735
+		$result = $this->post(self::URL_AUTHCODETOOPENID, $data, false);
736 736
 		return $result['openid'];
737 737
 	}
738 738
 
@@ -749,19 +749,19 @@  discard block
 block discarded – undo
749 749
 	 * @return array
750 750
 	 * @throws Exception
751 751
 	 */
752
-	public function transferWallet($partner_trade_no,$openid,$amount,$desc,$spbill_create_ip = null,$re_user_name = null,$check_name = WechatPay::CHECKNAME_FORCECHECK){
752
+	public function transferWallet($partner_trade_no, $openid, $amount, $desc, $spbill_create_ip = null, $re_user_name = null, $check_name = WechatPay::CHECKNAME_FORCECHECK) {
753 753
 		$data = array();
754
-		if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required');
754
+		if ($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required');
755 755
 		$data["mch_appid"] = $this->config["app_id"];
756 756
 		$data["mchid"] = $this->config["mch_id"];
757 757
 		$data["partner_trade_no"] = $partner_trade_no;
758 758
 		$data["openid"] = $openid;
759 759
 		$data["amount"] = $amount;
760 760
 		$data["desc"] = $desc;
761
-		$data['spbill_create_ip'] = $spbill_create_ip?:$_SERVER['SERVER_ADDR'];
761
+		$data['spbill_create_ip'] = $spbill_create_ip ?: $_SERVER['SERVER_ADDR'];
762 762
 		$data["check_name"] = $check_name;
763 763
 		$data["re_user_name"] = $re_user_name;
764
-		$result = $this->post(self::URL_TRANSFER_WALLET,$data,true);
764
+		$result = $this->post(self::URL_TRANSFER_WALLET, $data, true);
765 765
 		return $result;
766 766
 	}
767 767
 
@@ -771,12 +771,12 @@  discard block
 block discarded – undo
771 771
 	 * @param $partner_trade_no
772 772
 	 * @return array
773 773
 	 */
774
-	public function queryTransferWallet($partner_trade_no){
774
+	public function queryTransferWallet($partner_trade_no) {
775 775
 		$data = array();
776 776
 		$data["appid"] = $this->config["app_id"];
777 777
 		$data["mch_id"] = $this->config["mch_id"];
778 778
 		$data["partner_trade_no"] = $partner_trade_no;
779
-		$result = $this->post(self::URL_QUERY_TRANSFER_WALLET,$data,true);
779
+		$result = $this->post(self::URL_QUERY_TRANSFER_WALLET, $data, true);
780 780
 		return $result;
781 781
 	}
782 782
 
@@ -792,8 +792,8 @@  discard block
 block discarded – undo
792 792
 	 * @return array
793 793
 	 * @throws Exception
794 794
 	 */
795
-	public function transferBankCard($partner_trade_no,$bank_no,$true_name,$bank_code,$amount,$desc){
796
-		if(!in_array($bank_code,array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code: $bank_code");
795
+	public function transferBankCard($partner_trade_no, $bank_no, $true_name, $bank_code, $amount, $desc) {
796
+		if (!in_array($bank_code, array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code: $bank_code");
797 797
 		$data = array();
798 798
 		$data["partner_trade_no"] = $partner_trade_no;
799 799
 		$enc_bank_no = $this->rsaEncrypt($bank_no);
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
 		$data["bank_code"] = $bank_code;
804 804
 		$data["desc"] = $desc;
805 805
 		$data["amount"] = $amount;
806
-		$result = $this->post(self::URL_TRANSFER_BANKCARD,$data,true);
806
+		$result = $this->post(self::URL_TRANSFER_BANKCARD, $data, true);
807 807
 		return $result;
808 808
 	}
809 809
 
@@ -813,12 +813,12 @@  discard block
 block discarded – undo
813 813
 	 * @param $partner_trade_no
814 814
 	 * @return array
815 815
 	 */
816
-	public function queryTransferBankCard($partner_trade_no){
816
+	public function queryTransferBankCard($partner_trade_no) {
817 817
 		$data = array();
818 818
 		$data["appid"] = $this->config["app_id"];
819 819
 		$data["mch_id"] = $this->config["mch_id"];
820 820
 		$data["partner_trade_no"] = $partner_trade_no;
821
-		$result = $this->post(self::URL_QUERY_TRANSFER_WALLET,$data,true);
821
+		$result = $this->post(self::URL_QUERY_TRANSFER_WALLET, $data, true);
822 822
 		return $result;
823 823
 	}
824 824
 
@@ -832,14 +832,14 @@  discard block
 block discarded – undo
832 832
 	 * @param array $ext
833 833
 	 * @return array
834 834
 	 */
835
-	public function sendCoupon($coupon_stock_id,$open_id,$partner_trade_no,$op_user_id = '',$ext = array()){
836
-		$data = (!empty($ext) && is_array($ext))?$ext:array();
835
+	public function sendCoupon($coupon_stock_id, $open_id, $partner_trade_no, $op_user_id = '', $ext = array()) {
836
+		$data = (!empty($ext) && is_array($ext)) ? $ext : array();
837 837
 		$data["partner_trade_no"] = $partner_trade_no;
838 838
 		$data["coupon_stock_id"] = $coupon_stock_id;
839 839
 		$data["openid_count"] = 1;
840 840
 		$data["open_id"] = $open_id;
841 841
 		$data["op_user_id"] = $op_user_id;
842
-		$result = $this->post(self::URL_SEND_COUPON,$data,true);
842
+		$result = $this->post(self::URL_SEND_COUPON, $data, true);
843 843
 		return $result;
844 844
 	}
845 845
 
@@ -850,11 +850,11 @@  discard block
 block discarded – undo
850 850
 	 * @param string $op_user_id
851 851
 	 * @return array
852 852
 	 */
853
-	public function queryCouponStock($coupon_stock_id,$op_user_id = ''){
853
+	public function queryCouponStock($coupon_stock_id, $op_user_id = '') {
854 854
 		$data = array();
855 855
 		$data["coupon_stock_id"] = $coupon_stock_id;
856 856
 		$data["op_user_id"] = $op_user_id;
857
-		$result = $this->post(self::URL_QUERY_COUPON_STOCK,$data,false);
857
+		$result = $this->post(self::URL_QUERY_COUPON_STOCK, $data, false);
858 858
 		return $result;
859 859
 	}
860 860
 
@@ -868,13 +868,13 @@  discard block
 block discarded – undo
868 868
 	 * @param array $ext
869 869
 	 * @return array
870 870
 	 */
871
-	public function queryCouponsInfo($coupon_id,$open_id,$stock_id,$op_user_id = '',$ext = array()){
872
-		$data = (!empty($ext) && is_array($ext))?$ext:array();
871
+	public function queryCouponsInfo($coupon_id, $open_id, $stock_id, $op_user_id = '', $ext = array()) {
872
+		$data = (!empty($ext) && is_array($ext)) ? $ext : array();
873 873
 		$data["coupon_id"] = $coupon_id;
874 874
 		$data["stock_id"] = $stock_id;
875 875
 		$data["open_id"] = $open_id;
876 876
 		$data["op_user_id"] = $op_user_id;
877
-		$result = $this->post(self::URL_QUERY_COUPON_INFO,$data,false);
877
+		$result = $this->post(self::URL_QUERY_COUPON_INFO, $data, false);
878 878
 		return $result;
879 879
 	}
880 880
 
@@ -885,7 +885,7 @@  discard block
 block discarded – undo
885 885
 	 * @return string
886 886
 	 * @throws Exception
887 887
 	 */
888
-	public function getPublicKey($refresh = false){
888
+	public function getPublicKey($refresh = false) {
889 889
 		if (!$refresh && file_exists($this->config["rsa_pubkey_path"])) {
890 890
 			$pubkey = file_get_contents($this->config["rsa_pubkey_path"]);
891 891
 			return $pubkey;
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
 		$data = array();
894 894
 		$data["mch_id"] = $this->config["mch_id"];
895 895
 		$data["sign_type"] = $this->config["sign_type"];
896
-		$result = $this->post(self::URL_GETPUBLICKEY,$data,true);
896
+		$result = $this->post(self::URL_GETPUBLICKEY, $data, true);
897 897
 		$pubkey = $result['pub_key'];
898 898
 		$pubkey = $this->convertPKCS1toPKCS8($pubkey);
899 899
 		$fp = fopen($this->config["rsa_pubkey_path"], "w");
@@ -906,20 +906,20 @@  discard block
 block discarded – undo
906 906
 		}
907 907
 	}
908 908
 
909
-	private function convertPKCS1toPKCS8($pkcs1){
909
+	private function convertPKCS1toPKCS8($pkcs1) {
910 910
 		$start_key = $pkcs1;
911 911
 		$start_key = str_replace('-----BEGIN RSA PUBLIC KEY-----', '', $start_key);
912 912
 		$start_key = trim(str_replace('-----END RSA PUBLIC KEY-----', '', $start_key));
913
-		$key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' . str_replace("\n", '', $start_key);
914
-		$key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($key, 64, "\n", true) . "\n-----END PUBLIC KEY-----";
913
+		$key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A'.str_replace("\n", '', $start_key);
914
+		$key = "-----BEGIN PUBLIC KEY-----\n".wordwrap($key, 64, "\n", true)."\n-----END PUBLIC KEY-----";
915 915
 		return $key;
916 916
 	}
917 917
 
918
-	private function rsaEncrypt($data){
918
+	private function rsaEncrypt($data) {
919 919
 		$pubkey = $this->getPublicKey();
920 920
 		$encrypted = null;
921 921
 		$pubkey = openssl_get_publickey($pubkey);
922
-		if (openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING))
922
+		if (openssl_public_encrypt($data, $encrypted, $pubkey, OPENSSL_PKCS1_OAEP_PADDING))
923 923
 			$data = base64_encode($encrypted);
924 924
 		else
925 925
 			throw new Exception('Unable to encrypt data');
@@ -931,10 +931,10 @@  discard block
 block discarded – undo
931 931
 	 * @ref https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=23_1
932 932
 	 * @return array
933 933
 	 */
934
-	public function getSignKey(){
934
+	public function getSignKey() {
935 935
 		$data = array();
936 936
 		$data["mch_id"] = $this->config["mch_id"];
937
-		$result = $this->post($this->getSignKeyUrl,$data,false);
937
+		$result = $this->post($this->getSignKeyUrl, $data, false);
938 938
 		return $result['sandbox_signkey'];
939 939
 	}
940 940
 
@@ -942,7 +942,7 @@  discard block
 block discarded – undo
942 942
 	 * 获取JSAPI所需要的页面参数
943 943
 	 * @return array
944 944
 	 */
945
-	public function getSignPackage($url){
945
+	public function getSignPackage($url) {
946 946
 		$jsapiTicket = $this->getJSAPITicket();
947 947
 		$timestamp = time();
948 948
 		$nonceStr = $this->getNonceStr();
@@ -964,8 +964,8 @@  discard block
 block discarded – undo
964 964
 	 * 获取JSAPI Ticket
965 965
 	 * @return string
966 966
 	 */
967
-	public function getJSAPITicket(){
968
-		if(isset($this->config['jsapi_ticket']) && file_exists($this->config['jsapi_ticket'])){
967
+	public function getJSAPITicket() {
968
+		if (isset($this->config['jsapi_ticket']) && file_exists($this->config['jsapi_ticket'])) {
969 969
 			$data = json_decode(file_get_contents($this->config['jsapi_ticket']));
970 970
 			if (!$data || $data->expire_time < time()) {
971 971
 				$data = $this->getWechatOAuth()->getTicket();
@@ -978,10 +978,10 @@  discard block
 block discarded – undo
978 978
 		}
979 979
 	}
980 980
 
981
-	private function post($url, $data,$cert = true) {
982
-		if(!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"];
983
-		if(!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr();
984
-		if(!isset($data['sign'])) $data['sign'] = $this->sign($data);
981
+	private function post($url, $data, $cert = true) {
982
+		if (!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"];
983
+		if (!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr();
984
+		if (!isset($data['sign'])) $data['sign'] = $this->sign($data);
985 985
 		$this->requestXML = $this->responseXML = null;
986 986
 		$this->requestArray = $this->responseArray = null;
987 987
 
@@ -993,53 +993,53 @@  discard block
 block discarded – undo
993 993
 			CURLOPT_RETURNTRANSFER => true,
994 994
 			CURLOPT_TIMEOUT => 10
995 995
 		];
996
-		if($cert == true){
996
+		if ($cert == true) {
997 997
 			$opts[CURLOPT_SSLCERTTYPE] = 'PEM';
998 998
 			$opts[CURLOPT_SSLCERT] = $this->config['ssl_cert_path'];
999 999
 			$opts[CURLOPT_SSLKEYTYPE] = 'PEM';
1000 1000
 			$opts[CURLOPT_SSLKEY] = $this->config['ssl_key_path'];
1001 1001
 		}
1002 1002
 		$processResponse = true;
1003
-		if(in_array($url,[self::URL_DOWNLOADBILL,self::URL_DOWNLOAD_FUND_FLOW])){
1003
+		if (in_array($url, [self::URL_DOWNLOADBILL, self::URL_DOWNLOAD_FUND_FLOW])) {
1004 1004
 			$processResponse = false;
1005 1005
 		}
1006
-		if($this->sandbox === true){
1006
+		if ($this->sandbox === true) {
1007 1007
 			$host = "https://api.mch.weixin.qq.com";
1008
-			$url = str_replace($host,'',$url);
1008
+			$url = str_replace($host, '', $url);
1009 1009
 			$url = "{$host}/sandboxnew{$url}";
1010 1010
 		}
1011
-		$content = $this->httpClient->post($url,$this->requestXML,[],$opts);
1012
-		if(!$content) throw new Exception("Empty response with {$this->requestXML}");
1011
+		$content = $this->httpClient->post($url, $this->requestXML, [], $opts);
1012
+		if (!$content) throw new Exception("Empty response with {$this->requestXML}");
1013 1013
 
1014 1014
 		$this->responseXML = $content;
1015
-		if($processResponse)
1015
+		if ($processResponse)
1016 1016
 			return $this->processResponseXML($this->responseXML);
1017 1017
 		else return $this->responseXML;
1018 1018
 
1019 1019
 	}
1020 1020
 
1021
-	private function processResponseXML($responseXML){
1021
+	private function processResponseXML($responseXML) {
1022 1022
 		$result = $this->xml2array($responseXML);
1023 1023
 		$this->responseArray = $result;
1024
-		if(empty($result['return_code'])){
1024
+		if (empty($result['return_code'])) {
1025 1025
 			throw new Exception("No return code presents in {$this->responseXML}");
1026 1026
 		}
1027 1027
 		$this->returnCode = $result["return_code"];
1028
-		$this->returnMsg = isset($result['return_msg'])?$result['return_msg']:'';
1028
+		$this->returnMsg = isset($result['return_msg']) ? $result['return_msg'] : '';
1029 1029
 
1030 1030
 		if ($this->returnCode == "SUCCESS") {
1031
-			if(isset($result['result_code']) && $result['result_code'] == "FAIL"){
1031
+			if (isset($result['result_code']) && $result['result_code'] == "FAIL") {
1032 1032
 				$this->resultCode = $result['result_code'];
1033 1033
 				$this->errCode = $result['err_code'];
1034 1034
 				$this->errCodeDes = $result['err_code_des'];
1035 1035
 				throw new Exception("[$this->errCode]$this->errCodeDes");
1036
-			}else{
1036
+			}else {
1037 1037
 				return $result;
1038 1038
 			}
1039
-		} else {
1040
-			if($result["return_code"] == "FAIL"){
1039
+		}else {
1040
+			if ($result["return_code"] == "FAIL") {
1041 1041
 				throw new Exception($this->returnMsg);
1042
-			}else{
1042
+			}else {
1043 1043
 				$this->resultCode = $result['result_code'];
1044 1044
 				$this->errCode = $result['err_code'];
1045 1045
 				$this->errCodeDes = $result['err_code_des'];
@@ -1048,28 +1048,28 @@  discard block
 block discarded – undo
1048 1048
 		}
1049 1049
 	}
1050 1050
 
1051
-	public function sign($data,$sign_type = WechatPay::SIGNTYPE_MD5) {
1051
+	public function sign($data, $sign_type = WechatPay::SIGNTYPE_MD5) {
1052 1052
 		ksort($data);
1053 1053
 		$string1 = "";
1054 1054
 		foreach ($data as $k => $v) {
1055
-			if ($v && trim($v)!='') {
1055
+			if ($v && trim($v) != '') {
1056 1056
 				$string1 .= "$k=$v&";
1057 1057
 			}
1058 1058
 		}
1059
-		$stringSignTemp = $string1 . "key=" . $this->config["api_key"];
1060
-		if($sign_type == WechatPay::SIGNTYPE_MD5){
1059
+		$stringSignTemp = $string1."key=".$this->config["api_key"];
1060
+		if ($sign_type == WechatPay::SIGNTYPE_MD5) {
1061 1061
 			$sign = strtoupper(md5($stringSignTemp));
1062
-		}elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){
1063
-			$sign = strtoupper(hash_hmac('sha256',$stringSignTemp,$this->config["api_key"]));
1062
+		}elseif ($sign_type == WechatPay::SIGNTYPE_HMACSHA256) {
1063
+			$sign = strtoupper(hash_hmac('sha256', $stringSignTemp, $this->config["api_key"]));
1064 1064
 		}else throw new Exception("Not supported sign type - $sign_type");
1065 1065
 		return $sign;
1066 1066
 	}
1067 1067
 
1068 1068
 	private function array2xml($array) {
1069
-		$xml = "<xml>" . PHP_EOL;
1069
+		$xml = "<xml>".PHP_EOL;
1070 1070
 		foreach ($array as $k => $v) {
1071
-			if($v && trim($v)!='')
1072
-				$xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL;
1071
+			if ($v && trim($v) != '')
1072
+				$xml .= "<$k><![CDATA[$v]]></$k>".PHP_EOL;
1073 1073
 		}
1074 1074
 		$xml .= "</xml>";
1075 1075
 		return $xml;
@@ -1078,19 +1078,19 @@  discard block
 block discarded – undo
1078 1078
 	private function xml2array($xml) {
1079 1079
 		$array = array();
1080 1080
 		$tmp = array();
1081
-		try{
1081
+		try {
1082 1082
 			$tmp = (array) simplexml_load_string($xml);
1083
-		}catch(Exception $e){
1083
+		} catch (Exception $e) {
1084 1084
 			throw $e;
1085 1085
 		}
1086
-		foreach ( $tmp as $k => $v) {
1086
+		foreach ($tmp as $k => $v) {
1087 1087
 			$array[$k] = (string) $v;
1088 1088
 		}
1089 1089
 		return $array;
1090 1090
 	}
1091 1091
 
1092 1092
 	private function getNonceStr() {
1093
-		return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"),0,32);
1093
+		return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"), 0, 32);
1094 1094
 	}
1095 1095
 
1096 1096
 }
1097 1097
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +85 added lines, -39 removed lines patch added patch discarded remove patch
@@ -116,7 +116,9 @@  discard block
 block discarded – undo
116 116
 		$data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["REMOTE_ADDR"];
117 117
 		$data["notify_url"]   = $this->config["notify_url"];
118 118
 		$data["trade_type"]   = WechatPay::TRADETYPE_JSAPI;
119
-		if(!$openid) throw new Exception('openid is required when trade_type is JSAPI');
119
+		if(!$openid) {
120
+			throw new Exception('openid is required when trade_type is JSAPI');
121
+		}
120 122
 		$data["openid"]   = $openid;
121 123
 		$result = $this->unifiedOrder($data);
122 124
 		return $result["prepay_id"];
@@ -164,7 +166,9 @@  discard block
 block discarded – undo
164 166
 		$data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["SERVER_ADDR"];
165 167
 		$data["notify_url"]   = $this->config["notify_url"];
166 168
 		$data["trade_type"]   = self::TRADETYPE_NATIVE;
167
-		if(!$product_id) throw new Exception('product_id is required when trade_type is NATIVE');
169
+		if(!$product_id) {
170
+			throw new Exception('product_id is required when trade_type is NATIVE');
171
+		}
168 172
 		$data["product_id"]   = $product_id;
169 173
 		$result = $this->unifiedOrder($data);
170 174
 		return $result["code_url"];
@@ -188,7 +192,9 @@  discard block
 block discarded – undo
188 192
 		$data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:'';
189 193
 		$data["notify_url"]   = $this->config["notify_url"];
190 194
 		$data["trade_type"]   = self::TRADETYPE_MWEB;
191
-		if(!isset($this->config['h5_scene_info'])) throw new Exception('h5_scene_info should be configured');
195
+		if(!isset($this->config['h5_scene_info'])) {
196
+			throw new Exception('h5_scene_info should be configured');
197
+		}
192 198
 		$data["scene_info"]   = json_encode($this->config['h5_scene_info']);
193 199
 		$result = $this->unifiedOrder($data);
194 200
 		return $result["mweb_url"];
@@ -218,11 +224,15 @@  discard block
 block discarded – undo
218 224
 		$data["notify_url"] = $this->config["notify_url"];
219 225
 		$data["trade_type"] = $params['trade_type'];
220 226
 		if($params['trade_type'] == WechatPay::TRADETYPE_NATIVE){
221
-			if(!isset($params['product_id'])) throw new Exception('product_id is required when trade_type is NATIVE');
227
+			if(!isset($params['product_id'])) {
228
+				throw new Exception('product_id is required when trade_type is NATIVE');
229
+			}
222 230
 			$data["product_id"] = $params['product_id'];
223 231
 		}
224 232
 		if($params['trade_type'] == WechatPay::TRADETYPE_JSAPI){
225
-			if(!isset($params['openid'])) throw new Exception('openid is required when trade_type is JSAPI');
233
+			if(!isset($params['openid'])) {
234
+				throw new Exception('openid is required when trade_type is JSAPI');
235
+			}
226 236
 			$data["openid"] = $params['openid'];
227 237
 		}
228 238
 		$result = $this->post(self::URL_UNIFIEDORDER, $data);
@@ -465,7 +475,9 @@  discard block
 block discarded – undo
465 475
 		$data["send_name"] = $send_name;
466 476
 		$data["re_openid"] = $re_openid;
467 477
 		$data["total_amount"] = $total_amount;
468
-		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000");
478
+		if($total_amount > 20000 && trim($scene_id)=='') {
479
+			throw new Exception("scene_id is required when total_amount beyond 20000");
480
+		}
469 481
 		$data["total_num"] = $total_num;
470 482
 		$data["wishing"] = $wishing;
471 483
 		$data["act_name"] = $act_name;
@@ -501,7 +513,9 @@  discard block
 block discarded – undo
501 513
 		$data["send_name"] = $send_name;
502 514
 		$data["re_openid"] = $re_openid;
503 515
 		$data["total_amount"] = $total_amount;
504
-		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
516
+		if($total_amount > 20000 && trim($scene_id)=='') {
517
+			throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
518
+		}
505 519
 		$data["total_num"] = $total_num;
506 520
 		$data["amt_type"] = 'ALL_RAND'; //红包金额设置方式 ALL_RAND—全部随机
507 521
 		$data["wishing"] = $wishing;
@@ -614,10 +628,10 @@  discard block
 block discarded – undo
614 628
 		if($this->validateSign($notify_data)){
615 629
 			if($callback && is_callable($callback)){
616 630
 				return call_user_func_array( $callback , [$notify_data] );
617
-			}else{
631
+			} else{
618 632
 				$this->responseNotify();
619 633
 			}
620
-		}else{
634
+		} else{
621 635
 			throw new Exception('Invalid paid notify data');
622 636
 		}
623 637
 	}
@@ -636,10 +650,10 @@  discard block
 block discarded – undo
636 650
 		if($this->validateSign($notify_data)){
637 651
 			if($callback && is_callable($callback)){
638 652
 				return call_user_func_array( $callback , $notify_data );
639
-			}else{
653
+			} else{
640 654
 				$this->responseNotify();
641 655
 			}
642
-		}else{
656
+		} else{
643 657
 			throw new Exception('Invalid refunded notify data');
644 658
 		}
645 659
 	}
@@ -698,12 +712,24 @@  discard block
 block discarded – undo
698 712
 		$data["return_code"] = $return_code;
699 713
 		$data["result_code"] = $result_code;
700 714
 		$data["user_ip"] = $user_ip;
701
-		if($out_trade_no) $data["out_trade_no"] = $out_trade_no;
702
-		if($time) $data["time"] = $time;
703
-		if($device_info) $data["device_info"] = $device_info;
704
-		if($return_msg) $data["return_msg"] = $return_msg;
705
-		if($err_code) $data["err_code"] = $err_code;
706
-		if($err_code_des) $data["err_code_des"] = $err_code_des;
715
+		if($out_trade_no) {
716
+			$data["out_trade_no"] = $out_trade_no;
717
+		}
718
+		if($time) {
719
+			$data["time"] = $time;
720
+		}
721
+		if($device_info) {
722
+			$data["device_info"] = $device_info;
723
+		}
724
+		if($return_msg) {
725
+			$data["return_msg"] = $return_msg;
726
+		}
727
+		if($err_code) {
728
+			$data["err_code"] = $err_code;
729
+		}
730
+		if($err_code_des) {
731
+			$data["err_code_des"] = $err_code_des;
732
+		}
707 733
 		$result = $this->post(self::URL_REPORT, $data, false);
708 734
 		return $result;
709 735
 	}
@@ -751,7 +777,9 @@  discard block
 block discarded – undo
751 777
 	 */
752 778
 	public function transferWallet($partner_trade_no,$openid,$amount,$desc,$spbill_create_ip = null,$re_user_name = null,$check_name = WechatPay::CHECKNAME_FORCECHECK){
753 779
 		$data = array();
754
-		if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required');
780
+		if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) {
781
+			throw new Exception('Real name is required');
782
+		}
755 783
 		$data["mch_appid"] = $this->config["app_id"];
756 784
 		$data["mchid"] = $this->config["mch_id"];
757 785
 		$data["partner_trade_no"] = $partner_trade_no;
@@ -793,7 +821,9 @@  discard block
 block discarded – undo
793 821
 	 * @throws Exception
794 822
 	 */
795 823
 	public function transferBankCard($partner_trade_no,$bank_no,$true_name,$bank_code,$amount,$desc){
796
-		if(!in_array($bank_code,array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code: $bank_code");
824
+		if(!in_array($bank_code,array_values(self::$BANKCODE))) {
825
+			throw new Exception("Unsupported bank code: $bank_code");
826
+		}
797 827
 		$data = array();
798 828
 		$data["partner_trade_no"] = $partner_trade_no;
799 829
 		$enc_bank_no = $this->rsaEncrypt($bank_no);
@@ -901,7 +931,7 @@  discard block
 block discarded – undo
901 931
 			fwrite($fp, $pubkey);
902 932
 			fclose($fp);
903 933
 			return $pubkey;
904
-		}else {
934
+		} else {
905 935
 			throw new Exception("RSA public key not found");
906 936
 		}
907 937
 	}
@@ -919,10 +949,11 @@  discard block
 block discarded – undo
919 949
 		$pubkey = $this->getPublicKey();
920 950
 		$encrypted = null;
921 951
 		$pubkey = openssl_get_publickey($pubkey);
922
-		if (openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING))
923
-			$data = base64_encode($encrypted);
924
-		else
925
-			throw new Exception('Unable to encrypt data');
952
+		if (openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING)) {
953
+					$data = base64_encode($encrypted);
954
+		} else {
955
+					throw new Exception('Unable to encrypt data');
956
+		}
926 957
 		return $data;
927 958
 	}
928 959
 
@@ -971,7 +1002,9 @@  discard block
 block discarded – undo
971 1002
 				$data = $this->getWechatOAuth()->getTicket();
972 1003
 				$fp = fopen($this->config["jsapi_ticket"], "w");
973 1004
 				fwrite($fp, $data);
974
-				if ($fp) fclose($fp);
1005
+				if ($fp) {
1006
+					fclose($fp);
1007
+				}
975 1008
 				$data = json_decode($data);
976 1009
 			}
977 1010
 			return $data->jsapi_ticket;
@@ -979,9 +1012,15 @@  discard block
 block discarded – undo
979 1012
 	}
980 1013
 
981 1014
 	private function post($url, $data,$cert = true) {
982
-		if(!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"];
983
-		if(!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr();
984
-		if(!isset($data['sign'])) $data['sign'] = $this->sign($data);
1015
+		if(!isset($data['mch_id']) && !isset($data['mchid'])) {
1016
+			$data["mch_id"] = $this->config["mch_id"];
1017
+		}
1018
+		if(!isset($data['nonce_str'])) {
1019
+			$data["nonce_str"] = $this->getNonceStr();
1020
+		}
1021
+		if(!isset($data['sign'])) {
1022
+			$data['sign'] = $this->sign($data);
1023
+		}
985 1024
 		$this->requestXML = $this->responseXML = null;
986 1025
 		$this->requestArray = $this->responseArray = null;
987 1026
 
@@ -1009,12 +1048,16 @@  discard block
 block discarded – undo
1009 1048
 			$url = "{$host}/sandboxnew{$url}";
1010 1049
 		}
1011 1050
 		$content = $this->httpClient->post($url,$this->requestXML,[],$opts);
1012
-		if(!$content) throw new Exception("Empty response with {$this->requestXML}");
1051
+		if(!$content) {
1052
+			throw new Exception("Empty response with {$this->requestXML}");
1053
+		}
1013 1054
 
1014 1055
 		$this->responseXML = $content;
1015
-		if($processResponse)
1016
-			return $this->processResponseXML($this->responseXML);
1017
-		else return $this->responseXML;
1056
+		if($processResponse) {
1057
+					return $this->processResponseXML($this->responseXML);
1058
+		} else {
1059
+			return $this->responseXML;
1060
+		}
1018 1061
 
1019 1062
 	}
1020 1063
 
@@ -1033,13 +1076,13 @@  discard block
 block discarded – undo
1033 1076
 				$this->errCode = $result['err_code'];
1034 1077
 				$this->errCodeDes = $result['err_code_des'];
1035 1078
 				throw new Exception("[$this->errCode]$this->errCodeDes");
1036
-			}else{
1079
+			} else{
1037 1080
 				return $result;
1038 1081
 			}
1039 1082
 		} else {
1040 1083
 			if($result["return_code"] == "FAIL"){
1041 1084
 				throw new Exception($this->returnMsg);
1042
-			}else{
1085
+			} else{
1043 1086
 				$this->resultCode = $result['result_code'];
1044 1087
 				$this->errCode = $result['err_code'];
1045 1088
 				$this->errCodeDes = $result['err_code_des'];
@@ -1059,17 +1102,20 @@  discard block
 block discarded – undo
1059 1102
 		$stringSignTemp = $string1 . "key=" . $this->config["api_key"];
1060 1103
 		if($sign_type == WechatPay::SIGNTYPE_MD5){
1061 1104
 			$sign = strtoupper(md5($stringSignTemp));
1062
-		}elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){
1105
+		} elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){
1063 1106
 			$sign = strtoupper(hash_hmac('sha256',$stringSignTemp,$this->config["api_key"]));
1064
-		}else throw new Exception("Not supported sign type - $sign_type");
1107
+		} else {
1108
+			throw new Exception("Not supported sign type - $sign_type");
1109
+		}
1065 1110
 		return $sign;
1066 1111
 	}
1067 1112
 
1068 1113
 	private function array2xml($array) {
1069 1114
 		$xml = "<xml>" . PHP_EOL;
1070 1115
 		foreach ($array as $k => $v) {
1071
-			if($v && trim($v)!='')
1072
-				$xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL;
1116
+			if($v && trim($v)!='') {
1117
+							$xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL;
1118
+			}
1073 1119
 		}
1074 1120
 		$xml .= "</xml>";
1075 1121
 		return $xml;
@@ -1080,7 +1126,7 @@  discard block
 block discarded – undo
1080 1126
 		$tmp = array();
1081 1127
 		try{
1082 1128
 			$tmp = (array) simplexml_load_string($xml);
1083
-		}catch(Exception $e){
1129
+		} catch(Exception $e){
1084 1130
 			throw $e;
1085 1131
 		}
1086 1132
 		foreach ( $tmp as $k => $v) {
Please login to merge, or discard this patch.
demo/wxoauthcallback.php 2 patches
Braces   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,11 +13,11 @@
 block discarded – undo
13 13
 
14 14
 	if(!$at || empty($at->openid)){
15 15
 		die('授权失败');
16
-	}else{
16
+	} else{
17 17
 		$accesstoken = $at->access_token;
18 18
 		$openid = $at->openid;
19 19
 		header('Location: '."http://{$_SERVER['HTTP_HOST']}/wechat-pay/demo/pay.php?openid=$openid");
20 20
 	}
21
-}else{
21
+} else{
22 22
 	die('授权失败,请重试。');
23 23
 }
24 24
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,24 +1,24 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 //OAuth授权回调
4
-require_once __DIR__ . "/autoload.php";
4
+require_once __DIR__."/autoload.php";
5 5
 use zhangv\wechat\WechatOAuth;
6 6
 
7
-if (isset($_GET['code'])){
7
+if (isset($_GET['code'])) {
8 8
 	$cfg = require './config.php';
9 9
 
10 10
 	$code = trim($_GET['code']);
11 11
 	$state = trim($_GET['state']);
12
-	$oauth = new WechatOAuth($cfg['app_id'],$cfg['app_secret']);
12
+	$oauth = new WechatOAuth($cfg['app_id'], $cfg['app_secret']);
13 13
 	$at = $oauth->authorize($code);
14 14
 
15
-	if(!$at || empty($at->openid)){
15
+	if (!$at || empty($at->openid)) {
16 16
 		die('授权失败');
17
-	}else{
17
+	}else {
18 18
 		$accesstoken = $at->access_token;
19 19
 		$openid = $at->openid;
20 20
 		header('Location: '."http://{$_SERVER['HTTP_HOST']}/wechat-pay/demo/pay.php?openid=$openid");
21 21
 	}
22
-}else{
22
+}else {
23 23
 	die('授权失败,请重试。');
24 24
 }
25 25
\ No newline at end of file
Please login to merge, or discard this patch.
demo/config.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -5,14 +5,14 @@
 block discarded – undo
5 5
 	'app_id'            => 'XXXXXXXXXXXXXXXXXXX', //APPID
6 6
 	'app_secret'        => 'XXXXXXXXXXXXXXXXXXXXXXXXX', //App Secret
7 7
 	'api_key'           =>'XXXXXXXXXXXXXXXXXXXXXXX', //支付密钥
8
-	'ssl_cert_path'     => __DIR__ . '/../cert/apiclient_cert.pem',
9
-	'ssl_key_path'      => __DIR__ .'/../cert/apiclient_key.pem',
8
+	'ssl_cert_path'     => __DIR__.'/../cert/apiclient_cert.pem',
9
+	'ssl_key_path'      => __DIR__.'/../cert/apiclient_key.pem',
10 10
 	'sign_type'         => 'MD5',
11 11
 	'notify_url'        => 'http://XXX.XXX/paidnotify.php',
12 12
 	'refund_notify_url' => 'http://XXX.XXX/refundednotify.php',
13 13
 	'h5_scene_info'     => [//required in H5
14 14
 		'h5_info' => ['type' => 'Wap', 'wap_url' => 'http://wapurl', 'wap_name' => 'wapname']
15 15
 	],
16
-	'rsa_pubkey_path'   => __DIR__ .'/../cert/pubkey.pem',
17
-	'jsapi_ticket'      => __DIR__ .'/jsapi_ticket.json'
16
+	'rsa_pubkey_path'   => __DIR__.'/../cert/pubkey.pem',
17
+	'jsapi_ticket'      => __DIR__.'/jsapi_ticket.json'
18 18
 ];
19 19
\ No newline at end of file
Please login to merge, or discard this patch.
demo/pay-qrcode.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 //扫码支付
4
-require_once __DIR__ . "/autoload.php";
4
+require_once __DIR__."/autoload.php";
5 5
 use zhangv\wechat\WechatPay;
6 6
 
7 7
 $cfg = include './config.php';
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 $desc = "desc$stamp";
13 13
 $productid = "testproduct";
14 14
 $amt = 1;
15
-$codeurl = $payment->getCodeUrl($desc, $orderid, $amt,$productid);
15
+$codeurl = $payment->getCodeUrl($desc, $orderid, $amt, $productid);
16 16
 
17 17
 ?>
18 18
 <script type="text/javascript" src="js/jquery.js"></script>
Please login to merge, or discard this patch.
demo/autoload.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-if(file_exists(__DIR__ . '/../vendor/autoload.php')){
3
+if (file_exists(__DIR__.'/../vendor/autoload.php')) {
4 4
 	/** @var \Composer\Autoload\ClassLoader $loader */
5
-	$loader = require __DIR__ . '/../vendor/autoload.php';
6
-}else{//if the composer is not initialized, note: this is not work in phpunit, switch to composer when unit testing
5
+	$loader = require __DIR__.'/../vendor/autoload.php';
6
+}else {//if the composer is not initialized, note: this is not work in phpunit, switch to composer when unit testing
7 7
 	function __autoload($class) {
8 8
 		$class = str_replace('zhangv\\wechat\\', 'src/', $class);
9
-		$file = __DIR__ . '/../' . $class . '.php';
9
+		$file = __DIR__.'/../'.$class.'.php';
10 10
 		require_once $file;
11 11
 	}
12 12
 	spl_autoload_register('__autoload');
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@
 block discarded – undo
3 3
 if(file_exists(__DIR__ . '/../vendor/autoload.php')){
4 4
 	/** @var \Composer\Autoload\ClassLoader $loader */
5 5
 	$loader = require __DIR__ . '/../vendor/autoload.php';
6
-}else{//if the composer is not initialized, note: this is not work in phpunit, switch to composer when unit testing
6
+} else{//if the composer is not initialized, note: this is not work in phpunit, switch to composer when unit testing
7 7
 	function __autoload($class) {
8 8
 		$class = str_replace('zhangv\\wechat\\', 'src/', $class);
9 9
 		$file = __DIR__ . '/../' . $class . '.php';
Please login to merge, or discard this patch.
demo/wxoauth.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 //OAuth授权
4
-require_once __DIR__ . "/autoload.php";
4
+require_once __DIR__."/autoload.php";
5 5
 
6 6
 use zhangv\wechat\WechatOAuth;
7 7
 
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 $redirect = "http://{$_SERVER['HTTP_HOST']}/wechat-pay/demo/wxoauthcallback.php";
11 11
 $scope = 'snsapi_userinfo';
12 12
 $state = "";
13
-$oauth =new WechatOAuth($appid,$cfg['app_secret']);
14
-$url = $oauth->authorizeURI($redirect,$scope);
13
+$oauth = new WechatOAuth($appid, $cfg['app_secret']);
14
+$url = $oauth->authorizeURI($redirect, $scope);
15 15
 
16 16
 header('Location: '.$redirect);
17 17
\ No newline at end of file
Please login to merge, or discard this patch.
demo/refundednotify.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-require_once __DIR__ . "/autoload.php";
3
+require_once __DIR__."/autoload.php";
4 4
 use zhangv\wechat\WechatPay;
5 5
 
6 6
 $xml = file_get_contents("php://input");
7 7
 
8 8
 $cfg = require './config.php';
9 9
 $payment = new WechatPay($cfg);
10
-$payment->onRefundedNotify($xml,function($notifydata) use ($payment){
10
+$payment->onRefundedNotify($xml, function($notifydata) use ($payment){
11 11
 	//do stuff
12 12
 	print_r($notifydata);
13 13
 	$payment->responseNotify();
Please login to merge, or discard this patch.