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