@@ -10,8 +10,11 @@ |
||
10 | 10 | private $cacheDir = null; |
11 | 11 | |
12 | 12 | public function __construct($cacheDir = null){ |
13 | - if(!$cacheDir) $this->cacheDir = __DIR__; |
|
14 | - else $this->cacheDir = $cacheDir; |
|
13 | + if(!$cacheDir) { |
|
14 | + $this->cacheDir = __DIR__; |
|
15 | + } else { |
|
16 | + $this->cacheDir = $cacheDir; |
|
17 | + } |
|
15 | 18 | } |
16 | 19 | |
17 | 20 | public function set($key,$jsonobj,$expireAt = null){ |
@@ -43,7 +43,9 @@ |
||
43 | 43 | $data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:''; |
44 | 44 | $data["notify_url"] = $this->config["notify_url"]; |
45 | 45 | $data["trade_type"] = self::TRADETYPE_MWEB; |
46 | - if(!isset($this->config['h5_scene_info'])) throw new Exception('h5_scene_info should be configured'); |
|
46 | + if(!isset($this->config['h5_scene_info'])) { |
|
47 | + throw new Exception('h5_scene_info should be configured'); |
|
48 | + } |
|
47 | 49 | $data["scene_info"] = json_encode($this->config['h5_scene_info']); |
48 | 50 | $result = $this->unifiedOrder($data); |
49 | 51 | return $result["mweb_url"]; |
@@ -36,7 +36,9 @@ discard block |
||
36 | 36 | $data["send_name"] = $send_name; |
37 | 37 | $data["re_openid"] = $re_openid; |
38 | 38 | $data["total_amount"] = $total_amount; |
39 | - if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000"); |
|
39 | + if($total_amount > 20000 && trim($scene_id)=='') { |
|
40 | + throw new Exception("scene_id is required when total_amount beyond 20000"); |
|
41 | + } |
|
40 | 42 | $data["total_num"] = $total_num; |
41 | 43 | $data["wishing"] = $wishing; |
42 | 44 | $data["act_name"] = $act_name; |
@@ -72,7 +74,9 @@ discard block |
||
72 | 74 | $data["send_name"] = $send_name; |
73 | 75 | $data["re_openid"] = $re_openid; |
74 | 76 | $data["total_amount"] = $total_amount; |
75 | - if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)"); |
|
77 | + if($total_amount > 20000 && trim($scene_id)=='') { |
|
78 | + throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)"); |
|
79 | + } |
|
76 | 80 | $data["total_num"] = $total_num; |
77 | 81 | $data["amt_type"] = 'ALL_RAND'; //红包金额设置方式 ALL_RAND—全部随机 |
78 | 82 | $data["wishing"] = $wishing; |
@@ -46,7 +46,9 @@ |
||
46 | 46 | $data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["REMOTE_ADDR"]; |
47 | 47 | $data["notify_url"] = $this->config["notify_url"]; |
48 | 48 | $data["trade_type"] = WechatPay::TRADETYPE_JSAPI; |
49 | - if(!$openid) throw new Exception('openid is required when trade_type is JSAPI'); |
|
49 | + if(!$openid) { |
|
50 | + throw new Exception('openid is required when trade_type is JSAPI'); |
|
51 | + } |
|
50 | 52 | $data["openid"] = $openid; |
51 | 53 | $result = $this->unifiedOrder($data); |
52 | 54 | return $result["prepay_id"]; |
@@ -46,7 +46,9 @@ |
||
46 | 46 | $data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["SERVER_ADDR"]; |
47 | 47 | $data["notify_url"] = $this->config["notify_url"]; |
48 | 48 | $data["trade_type"] = self::TRADETYPE_NATIVE; |
49 | - if(!$product_id) throw new Exception('product_id is required when trade_type is NATIVE'); |
|
49 | + if(!$product_id) { |
|
50 | + throw new Exception('product_id is required when trade_type is NATIVE'); |
|
51 | + } |
|
50 | 52 | $data["product_id"] = $product_id; |
51 | 53 | $result = $this->unifiedOrder($data); |
52 | 54 | return $result["code_url"]; |
@@ -66,7 +66,9 @@ discard block |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | public function getTicket($type = WechatOAuth::TICKETTYPE_JSAPI, $accessToken = null){ |
69 | - if(!$accessToken) $accessToken = $this->getAccessToken(); |
|
69 | + if(!$accessToken) { |
|
70 | + $accessToken = $this->getAccessToken(); |
|
71 | + } |
|
70 | 72 | // $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$accessToken"; |
71 | 73 | $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type={$type}&access_token=$accessToken"; |
72 | 74 | $this->responseJSON = $this->httpClient->get($url); |
@@ -85,7 +87,9 @@ discard block |
||
85 | 87 | (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)) ? "https://" : "http://"; |
86 | 88 | $url .= "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; |
87 | 89 | } |
88 | - if(!$ticket) $ticket = $this->getTicket(); |
|
90 | + if(!$ticket) { |
|
91 | + $ticket = $this->getTicket(); |
|
92 | + } |
|
89 | 93 | $timestamp = time(); |
90 | 94 | $nonceStr = $this->getNonceStr(); |
91 | 95 | $rawString = "jsapi_ticket=$ticket&noncestr=$nonceStr×tamp=$timestamp&url=$url"; |
@@ -28,8 +28,12 @@ discard block |
||
28 | 28 | } |
29 | 29 | |
30 | 30 | public function get($url,$params = array(),$headers = array(),$opts = array()) { |
31 | - if (!$this->instance) $this->initInstance($this->timeout); |
|
32 | - if($params && count($params) > 0) $url .= '?' . http_build_query($params); |
|
31 | + if (!$this->instance) { |
|
32 | + $this->initInstance($this->timeout); |
|
33 | + } |
|
34 | + if($params && count($params) > 0) { |
|
35 | + $url .= '?' . http_build_query($params); |
|
36 | + } |
|
33 | 37 | curl_setopt($this->instance, CURLOPT_URL, $url); |
34 | 38 | curl_setopt($this->instance, CURLOPT_HTTPGET, true); |
35 | 39 | curl_setopt($this->instance, CURLOPT_HTTPHEADER, $headers); |
@@ -41,7 +45,9 @@ discard block |
||
41 | 45 | } |
42 | 46 | |
43 | 47 | public function post($url, $params = array(),$headers = array(),$opts = array()) { |
44 | - if (!$this->instance) $this->initInstance($this->timeout); |
|
48 | + if (!$this->instance) { |
|
49 | + $this->initInstance($this->timeout); |
|
50 | + } |
|
45 | 51 | curl_setopt($this->instance, CURLOPT_URL, $url); |
46 | 52 | curl_setopt($this->instance, CURLOPT_POST, true); |
47 | 53 | curl_setopt($this->instance, CURLOPT_POSTFIELDS, $params); |
@@ -46,7 +46,9 @@ |
||
46 | 46 | $data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["REMOTE_ADDR"]; |
47 | 47 | $data["notify_url"] = $this->config["notify_url"]; |
48 | 48 | $data["trade_type"] = WechatPay::TRADETYPE_JSAPI; |
49 | - if(!$openid) throw new Exception('openid is required when trade_type is JSAPI'); |
|
49 | + if(!$openid) { |
|
50 | + throw new Exception('openid is required when trade_type is JSAPI'); |
|
51 | + } |
|
50 | 52 | $data["openid"] = $openid; |
51 | 53 | $result = $this->unifiedOrder($data); |
52 | 54 | return $result["prepay_id"]; |
@@ -27,7 +27,9 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function transferWallet($partner_trade_no,$openid,$amount,$desc,$spbill_create_ip = null,$re_user_name = null,$check_name = WechatPay::CHECKNAME_FORCECHECK){ |
29 | 29 | $data = array(); |
30 | - if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required'); |
|
30 | + if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) { |
|
31 | + throw new Exception('Real name is required'); |
|
32 | + } |
|
31 | 33 | $data["mch_appid"] = $this->config["app_id"]; |
32 | 34 | $data["mchid"] = $this->config["mch_id"]; |
33 | 35 | $data["partner_trade_no"] = $partner_trade_no; |
@@ -69,7 +71,9 @@ discard block |
||
69 | 71 | * @throws Exception |
70 | 72 | */ |
71 | 73 | public function transferBankCard($partner_trade_no,$bank_no,$true_name,$bank_code,$amount,$desc){ |
72 | - if(!in_array($bank_code,array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code: $bank_code"); |
|
74 | + if(!in_array($bank_code,array_values(self::$BANKCODE))) { |
|
75 | + throw new Exception("Unsupported bank code: $bank_code"); |
|
76 | + } |
|
73 | 77 | $data = array(); |
74 | 78 | $data["partner_trade_no"] = $partner_trade_no; |
75 | 79 | $enc_bank_no = $this->rsaEncrypt($bank_no); |
@@ -84,13 +88,16 @@ discard block |
||
84 | 88 | } |
85 | 89 | |
86 | 90 | public function rsaEncrypt($data,$pubkey = null){ |
87 | - if(!$pubkey) $pubkey = $this->getPublicKey(); |
|
91 | + if(!$pubkey) { |
|
92 | + $pubkey = $this->getPublicKey(); |
|
93 | + } |
|
88 | 94 | $encrypted = null; |
89 | 95 | $pubkey = openssl_get_publickey($pubkey); |
90 | - if (@openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING)) |
|
91 | - $data = base64_encode($encrypted); |
|
92 | - else |
|
93 | - throw new Exception('Unable to encrypt data'); |
|
96 | + if (@openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING)) { |
|
97 | + $data = base64_encode($encrypted); |
|
98 | + } else { |
|
99 | + throw new Exception('Unable to encrypt data'); |
|
100 | + } |
|
94 | 101 | return $data; |
95 | 102 | } |
96 | 103 | |
@@ -120,7 +127,7 @@ discard block |
||
120 | 127 | if(!$this->publicKey) { |
121 | 128 | if (!$refresh && file_exists($this->config["rsa_pubkey_path"])) { |
122 | 129 | $this->publicKey = file_get_contents($this->config["rsa_pubkey_path"]); |
123 | - }else{ |
|
130 | + } else{ |
|
124 | 131 | $data = array(); |
125 | 132 | $data["mch_id"] = $this->config["mch_id"]; |
126 | 133 | $data["sign_type"] = $this->config["sign_type"]; |