@@ -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){ |
@@ -6,30 +6,30 @@ discard block |
||
6 | 6 | * @author zhangv |
7 | 7 | */ |
8 | 8 | namespace zhangv\wechat\pay\cache; |
9 | -class JsonFileCacheProvider implements CacheProvider{ |
|
9 | +class JsonFileCacheProvider implements CacheProvider { |
|
10 | 10 | private $cacheDir = null; |
11 | 11 | |
12 | - public function __construct($cacheDir = null){ |
|
13 | - if(!$cacheDir) $this->cacheDir = __DIR__; |
|
12 | + public function __construct($cacheDir = null) { |
|
13 | + if (!$cacheDir) $this->cacheDir = __DIR__; |
|
14 | 14 | else $this->cacheDir = $cacheDir; |
15 | 15 | } |
16 | 16 | |
17 | - public function set($key,$jsonobj,$expireAt = null){ |
|
17 | + public function set($key, $jsonobj, $expireAt = null) { |
|
18 | 18 | $data = $jsonobj; |
19 | 19 | $data->expires_at = $expireAt; |
20 | 20 | $file = "{$this->cacheDir}/{$key}.json"; |
21 | - if($fp = @fopen($file, "w")){ |
|
21 | + if ($fp = @fopen($file, "w")) { |
|
22 | 22 | fwrite($fp, json_encode($data)); |
23 | 23 | fclose($fp); |
24 | 24 | } |
25 | 25 | } |
26 | 26 | |
27 | - public function get($key){ |
|
27 | + public function get($key) { |
|
28 | 28 | $file = "{$this->cacheDir}/{$key}.json"; |
29 | 29 | $cache = null; |
30 | - if(file_exists($file)){ |
|
30 | + if (file_exists($file)) { |
|
31 | 31 | $cache = json_decode(file_get_contents($file)); |
32 | - if($cache->expires_at < time()){ |
|
32 | + if ($cache->expires_at < time()) { |
|
33 | 33 | $cache = null; |
34 | 34 | $this->clear($key); |
35 | 35 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | return $cache; |
38 | 38 | } |
39 | 39 | |
40 | - public function clear($key){ |
|
40 | + public function clear($key) { |
|
41 | 41 | $file = "{$this->cacheDir}/{$key}.json"; |
42 | 42 | if (file_exists($file)) { |
43 | 43 | unlink($file); |
@@ -7,8 +7,8 @@ |
||
7 | 7 | */ |
8 | 8 | namespace zhangv\wechat\pay\cache; |
9 | 9 | |
10 | -interface CacheProvider{ |
|
11 | - function set($key,$value,$expireAt); |
|
10 | +interface CacheProvider { |
|
11 | + function set($key, $value, $expireAt); |
|
12 | 12 | function get($key); |
13 | 13 | function clear($key); |
14 | 14 | } |
15 | 15 | \ No newline at end of file |
@@ -6,25 +6,25 @@ |
||
6 | 6 | * @author zhangv |
7 | 7 | */ |
8 | 8 | namespace zhangv\wechat\pay\cache; |
9 | -class RedisCacheProvider implements CacheProvider{ |
|
9 | +class RedisCacheProvider implements CacheProvider { |
|
10 | 10 | /** @var Redis */ |
11 | 11 | private $redis = null; |
12 | 12 | |
13 | - public function __construct($redis = null){ |
|
13 | + public function __construct($redis = null) { |
|
14 | 14 | $this->redis = $redis; |
15 | 15 | } |
16 | 16 | |
17 | - public function set($key,$jsonobj,$expireAt){ |
|
17 | + public function set($key, $jsonobj, $expireAt) { |
|
18 | 18 | $data = $jsonobj; |
19 | 19 | $data->expires_at = $expireAt; |
20 | 20 | $this->redis->set($key, json_encode($data)); |
21 | 21 | } |
22 | 22 | |
23 | - public function get($key){ |
|
23 | + public function get($key) { |
|
24 | 24 | return $this->redis->get($key); |
25 | 25 | } |
26 | 26 | |
27 | - public function clear($key){ |
|
27 | + public function clear($key) { |
|
28 | 28 | $this->redis->delete($key); |
29 | 29 | } |
30 | 30 | } |
31 | 31 | \ No newline at end of file |
@@ -35,15 +35,15 @@ |
||
35 | 35 | * @return string |
36 | 36 | * @throws Exception |
37 | 37 | */ |
38 | - public function getMwebUrl($body,$out_trade_no,$total_fee,$ext = null){ |
|
39 | - $data = ($ext && is_array($ext))?$ext:array(); |
|
38 | + public function getMwebUrl($body, $out_trade_no, $total_fee, $ext = null) { |
|
39 | + $data = ($ext && is_array($ext)) ? $ext : array(); |
|
40 | 40 | $data["body"] = $body; |
41 | 41 | $data["out_trade_no"] = $out_trade_no; |
42 | 42 | $data["total_fee"] = $total_fee; |
43 | - $data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:''; |
|
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'])) throw new Exception('h5_scene_info should be configured'); |
|
47 | 47 | $data["scene_info"] = json_encode($this->config['h5_scene_info']); |
48 | 48 | $result = $this->unifiedOrder($data); |
49 | 49 | return $result["mweb_url"]; |
@@ -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; |
@@ -28,14 +28,14 @@ discard block |
||
28 | 28 | * @return array |
29 | 29 | * @throws Exception |
30 | 30 | */ |
31 | - public function sendRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark,$scene_id = '',$riskinfo = '',$consume_mch_id = ''){ |
|
31 | + public function sendRedPack($mch_billno, $send_name, $re_openid, $total_amount, $total_num, $wishing, $act_name, $remark, $scene_id = '', $riskinfo = '', $consume_mch_id = '') { |
|
32 | 32 | $data = array(); |
33 | 33 | $data["wxappid"] = $this->config["app_id"]; |
34 | 34 | $data["mch_billno"] = $mch_billno; |
35 | 35 | $data["send_name"] = $send_name; |
36 | 36 | $data["re_openid"] = $re_openid; |
37 | 37 | $data["total_amount"] = $total_amount; |
38 | - if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000"); |
|
38 | + if ($total_amount > 20000 && trim($scene_id) == '') throw new Exception("scene_id is required when total_amount beyond 20000"); |
|
39 | 39 | $data["total_num"] = $total_num; |
40 | 40 | $data["wishing"] = $wishing; |
41 | 41 | $data["act_name"] = $act_name; |
@@ -62,14 +62,14 @@ discard block |
||
62 | 62 | * @return array |
63 | 63 | * @throws Exception |
64 | 64 | */ |
65 | - public function sendGroupRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark,$scene_id = '',$riskinfo = '',$consume_mch_id = ''){ |
|
65 | + public function sendGroupRedPack($mch_billno, $send_name, $re_openid, $total_amount, $total_num, $wishing, $act_name, $remark, $scene_id = '', $riskinfo = '', $consume_mch_id = '') { |
|
66 | 66 | $data = array(); |
67 | - $data["wxappid"] = $this->config["app_id"];//NOTE: WXappid |
|
67 | + $data["wxappid"] = $this->config["app_id"]; //NOTE: WXappid |
|
68 | 68 | $data["mch_billno"] = $mch_billno; |
69 | 69 | $data["send_name"] = $send_name; |
70 | 70 | $data["re_openid"] = $re_openid; |
71 | 71 | $data["total_amount"] = $total_amount; |
72 | - if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)"); |
|
72 | + if ($total_amount > 20000 && trim($scene_id) == '') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)"); |
|
73 | 73 | $data["total_num"] = $total_num; |
74 | 74 | $data["amt_type"] = 'ALL_RAND'; //红包金额设置方式 ALL_RAND—全部随机 |
75 | 75 | $data["wishing"] = $wishing; |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @return array |
88 | 88 | * @throws Exception |
89 | 89 | */ |
90 | - public function getHbInfo($mch_billno){ |
|
90 | + public function getHbInfo($mch_billno) { |
|
91 | 91 | $data = array(); |
92 | 92 | $data["mch_billno"] = $mch_billno; |
93 | 93 | $data["appid"] = $this->config["app_id"]; |
@@ -38,15 +38,15 @@ |
||
38 | 38 | * @return string |
39 | 39 | * @throws Exception |
40 | 40 | */ |
41 | - public function getCodeUrl($body,$out_trade_no,$total_fee,$product_id,$spbill_create_ip = null,$ext = null){ |
|
42 | - $data = ($ext && is_array($ext))?$ext:array(); |
|
41 | + public function getCodeUrl($body, $out_trade_no, $total_fee, $product_id, $spbill_create_ip = null, $ext = null) { |
|
42 | + $data = ($ext && is_array($ext)) ? $ext : array(); |
|
43 | 43 | $data["body"] = $body; |
44 | 44 | $data["out_trade_no"] = $out_trade_no; |
45 | 45 | $data["total_fee"] = $total_fee; |
46 | - $data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["SERVER_ADDR"]; |
|
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) throw new Exception('product_id is required when trade_type is NATIVE'); |
|
50 | 50 | $data["product_id"] = $product_id; |
51 | 51 | $result = $this->unifiedOrder($data); |
52 | 52 | return $result["code_url"]; |
@@ -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"]; |
@@ -38,16 +38,16 @@ |
||
38 | 38 | * @return string |
39 | 39 | * @throws \Exception |
40 | 40 | */ |
41 | - public function getPrepayId($body,$out_trade_no,$total_fee,$openid,$spbill_create_ip = null,$ext = null) { |
|
42 | - $data = ($ext && is_array($ext))?$ext:array(); |
|
41 | + public function getPrepayId($body, $out_trade_no, $total_fee, $openid, $spbill_create_ip = null, $ext = null) { |
|
42 | + $data = ($ext && is_array($ext)) ? $ext : array(); |
|
43 | 43 | $data["body"] = $body; |
44 | 44 | $data["out_trade_no"] = $out_trade_no; |
45 | 45 | $data["total_fee"] = $total_fee; |
46 | - $data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["REMOTE_ADDR"]; |
|
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'); |
|
50 | - $data["openid"] = $openid; |
|
49 | + if (!$openid) throw new Exception('openid is required when trade_type is JSAPI'); |
|
50 | + $data["openid"] = $openid; |
|
51 | 51 | $result = $this->unifiedOrder($data); |
52 | 52 | return $result["prepay_id"]; |
53 | 53 | } |
@@ -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"]; |
@@ -25,7 +25,9 @@ discard block |
||
25 | 25 | * @throws Exception |
26 | 26 | */ |
27 | 27 | public function transferWallet($partner_trade_no,$openid,$amount,$desc,$spbill_create_ip = null,$re_user_name = null,$check_name = WechatPay::CHECKNAME_FORCECHECK){ |
28 | - if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required'); |
|
28 | + if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) { |
|
29 | + throw new Exception('Real name is required'); |
|
30 | + } |
|
29 | 31 | $data = [ |
30 | 32 | "mch_appid" => $this->config["app_id"], |
31 | 33 | "mchid" => $this->config["mch_id"], |
@@ -66,7 +68,9 @@ discard block |
||
66 | 68 | * @throws Exception |
67 | 69 | */ |
68 | 70 | public function transferBankCard($partner_trade_no,$bank_no,$true_name,$bank_code,$amount,$desc){ |
69 | - if(!in_array($bank_code,array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code: $bank_code"); |
|
71 | + if(!in_array($bank_code,array_values(self::$BANKCODE))) { |
|
72 | + throw new Exception("Unsupported bank code: $bank_code"); |
|
73 | + } |
|
70 | 74 | $data = [ |
71 | 75 | "partner_trade_no" => $partner_trade_no, |
72 | 76 | "enc_bank_no" => $this->rsaEncrypt($bank_no), |
@@ -79,13 +83,16 @@ discard block |
||
79 | 83 | } |
80 | 84 | |
81 | 85 | public function rsaEncrypt($data,$pubkey = null){ |
82 | - if(!$pubkey) $pubkey = $this->getPublicKey(); |
|
86 | + if(!$pubkey) { |
|
87 | + $pubkey = $this->getPublicKey(); |
|
88 | + } |
|
83 | 89 | $encrypted = null; |
84 | 90 | $pubkey = openssl_get_publickey($pubkey); |
85 | - if (@openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING)) |
|
86 | - $data = base64_encode($encrypted); |
|
87 | - else |
|
88 | - throw new Exception('Unable to encrypt data'); |
|
91 | + if (@openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING)) { |
|
92 | + $data = base64_encode($encrypted); |
|
93 | + } else { |
|
94 | + throw new Exception('Unable to encrypt data'); |
|
95 | + } |
|
89 | 96 | return $data; |
90 | 97 | } |
91 | 98 | |
@@ -114,7 +121,7 @@ discard block |
||
114 | 121 | if(!$this->publicKey) { |
115 | 122 | if (!$refresh && file_exists($this->config["rsa_pubkey_path"])) { |
116 | 123 | $this->publicKey = file_get_contents($this->config["rsa_pubkey_path"]); |
117 | - }else{ |
|
124 | + } else{ |
|
118 | 125 | $data = array(); |
119 | 126 | $data["mch_id"] = $this->config["mch_id"]; |
120 | 127 | $data["sign_type"] = $this->config["sign_type"]; |
@@ -24,8 +24,8 @@ discard block |
||
24 | 24 | * @return array |
25 | 25 | * @throws Exception |
26 | 26 | */ |
27 | - public function transferWallet($partner_trade_no,$openid,$amount,$desc,$spbill_create_ip = null,$re_user_name = null,$check_name = WechatPay::CHECKNAME_FORCECHECK){ |
|
28 | - if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required'); |
|
27 | + public function transferWallet($partner_trade_no, $openid, $amount, $desc, $spbill_create_ip = null, $re_user_name = null, $check_name = WechatPay::CHECKNAME_FORCECHECK) { |
|
28 | + if ($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required'); |
|
29 | 29 | $data = [ |
30 | 30 | "mch_appid" => $this->config["app_id"], |
31 | 31 | "mchid" => $this->config["mch_id"], |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | "openid" => $openid, |
34 | 34 | "amount" => $amount, |
35 | 35 | "desc" => $desc, |
36 | - 'spbill_create_ip' => $spbill_create_ip?:$_SERVER['SERVER_ADDR'], |
|
36 | + 'spbill_create_ip' => $spbill_create_ip ?: $_SERVER['SERVER_ADDR'], |
|
37 | 37 | "check_name" => $check_name, |
38 | 38 | "re_user_name" => $re_user_name |
39 | 39 | ]; |
40 | - return $this->post(self::URL_TRANSFER_WALLET,$data,true); |
|
40 | + return $this->post(self::URL_TRANSFER_WALLET, $data, true); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -46,13 +46,13 @@ discard block |
||
46 | 46 | * @return array |
47 | 47 | * @throws Exception |
48 | 48 | */ |
49 | - public function queryTransferWallet($partner_trade_no){ |
|
49 | + public function queryTransferWallet($partner_trade_no) { |
|
50 | 50 | $data = [ |
51 | 51 | "appid" => $this->config["app_id"], |
52 | 52 | "mch_id" => $this->config["mch_id"], |
53 | 53 | "partner_trade_no" => $partner_trade_no |
54 | 54 | ]; |
55 | - return $this->post(self::URL_QUERY_TRANSFER_WALLET,$data,true); |
|
55 | + return $this->post(self::URL_QUERY_TRANSFER_WALLET, $data, true); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | * @return array |
67 | 67 | * @throws Exception |
68 | 68 | */ |
69 | - public function transferBankCard($partner_trade_no,$bank_no,$true_name,$bank_code,$amount,$desc){ |
|
70 | - if(!in_array($bank_code,array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code: $bank_code"); |
|
69 | + public function transferBankCard($partner_trade_no, $bank_no, $true_name, $bank_code, $amount, $desc) { |
|
70 | + if (!in_array($bank_code, array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code: $bank_code"); |
|
71 | 71 | $data = [ |
72 | 72 | "partner_trade_no" => $partner_trade_no, |
73 | 73 | "enc_bank_no" => $this->rsaEncrypt($bank_no), |
@@ -76,14 +76,14 @@ discard block |
||
76 | 76 | "desc" => $desc, |
77 | 77 | "amount" => $amount |
78 | 78 | ]; |
79 | - return $this->post(self::URL_TRANSFER_BANKCARD,$data,true); |
|
79 | + return $this->post(self::URL_TRANSFER_BANKCARD, $data, true); |
|
80 | 80 | } |
81 | 81 | |
82 | - public function rsaEncrypt($data,$pubkey = null){ |
|
83 | - if(!$pubkey) $pubkey = $this->getPublicKey(); |
|
82 | + public function rsaEncrypt($data, $pubkey = null) { |
|
83 | + if (!$pubkey) $pubkey = $this->getPublicKey(); |
|
84 | 84 | $encrypted = null; |
85 | 85 | $pubkey = openssl_get_publickey($pubkey); |
86 | - if (@openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING)) |
|
86 | + if (@openssl_public_encrypt($data, $encrypted, $pubkey, OPENSSL_PKCS1_OAEP_PADDING)) |
|
87 | 87 | $data = base64_encode($encrypted); |
88 | 88 | else |
89 | 89 | throw new Exception('Unable to encrypt data'); |
@@ -96,13 +96,13 @@ discard block |
||
96 | 96 | * @return array |
97 | 97 | * @throws Exception |
98 | 98 | */ |
99 | - public function queryTransferBankCard($partner_trade_no){ |
|
99 | + public function queryTransferBankCard($partner_trade_no) { |
|
100 | 100 | $data = [ |
101 | 101 | "appid" => $this->config["app_id"], |
102 | 102 | "mch_id" => $this->config["mch_id"], |
103 | 103 | "partner_trade_no" => $partner_trade_no |
104 | 104 | ]; |
105 | - return $this->post(self::URL_QUERY_TRANSFER_WALLET,$data,true); |
|
105 | + return $this->post(self::URL_QUERY_TRANSFER_WALLET, $data, true); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -111,18 +111,18 @@ discard block |
||
111 | 111 | * @return string |
112 | 112 | * @throws Exception |
113 | 113 | */ |
114 | - public function getPublicKey($refresh = false){ |
|
115 | - if(!$this->publicKey) { |
|
114 | + public function getPublicKey($refresh = false) { |
|
115 | + if (!$this->publicKey) { |
|
116 | 116 | if (!$refresh && file_exists($this->config["rsa_pubkey_path"])) { |
117 | 117 | $this->publicKey = file_get_contents($this->config["rsa_pubkey_path"]); |
118 | - }else{ |
|
118 | + }else { |
|
119 | 119 | $data = array(); |
120 | 120 | $data["mch_id"] = $this->config["mch_id"]; |
121 | 121 | $data["sign_type"] = $this->config["sign_type"]; |
122 | 122 | $result = $this->post(self::URL_GETPUBLICKEY, $data, true); |
123 | 123 | $pubkey = $result['pub_key']; |
124 | 124 | $this->publicKey = $this->convertPKCS1toPKCS8($pubkey); |
125 | - if($fp = @fopen($this->config["rsa_pubkey_path"], "w")) { |
|
125 | + if ($fp = @fopen($this->config["rsa_pubkey_path"], "w")) { |
|
126 | 126 | fwrite($fp, $this->publicKey); |
127 | 127 | fclose($fp); |
128 | 128 | } |
@@ -131,16 +131,16 @@ discard block |
||
131 | 131 | return $this->publicKey; |
132 | 132 | } |
133 | 133 | |
134 | - public function setPublicKey($publicKey){ |
|
134 | + public function setPublicKey($publicKey) { |
|
135 | 135 | $this->publicKey = $publicKey; |
136 | 136 | } |
137 | 137 | |
138 | - private function convertPKCS1toPKCS8($pkcs1){ |
|
138 | + private function convertPKCS1toPKCS8($pkcs1) { |
|
139 | 139 | $start_key = $pkcs1; |
140 | 140 | $start_key = str_replace('-----BEGIN RSA PUBLIC KEY-----', '', $start_key); |
141 | 141 | $start_key = trim(str_replace('-----END RSA PUBLIC KEY-----', '', $start_key)); |
142 | - $key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' . str_replace("\n", '', $start_key); |
|
143 | - $key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($key, 64, "\n", true) . "\n-----END PUBLIC KEY-----"; |
|
142 | + $key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A'.str_replace("\n", '', $start_key); |
|
143 | + $key = "-----BEGIN PUBLIC KEY-----\n".wordwrap($key, 64, "\n", true)."\n-----END PUBLIC KEY-----"; |
|
144 | 144 | return $key; |
145 | 145 | } |
146 | 146 |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | * @return array |
39 | 39 | * @throws Exception |
40 | 40 | */ |
41 | - public function microPay($body,$out_trade_no,$total_fee,$spbill_create_ip,$auth_code,$ext = array()){ |
|
42 | - $data = (!empty($ext) && is_array($ext))?$ext:array(); |
|
41 | + public function microPay($body, $out_trade_no, $total_fee, $spbill_create_ip, $auth_code, $ext = array()) { |
|
42 | + $data = (!empty($ext) && is_array($ext)) ? $ext : array(); |
|
43 | 43 | $data["appid"] = $this->config["app_id"]; |
44 | 44 | $data["body"] = $body; |
45 | 45 | $data["out_trade_no"] = $out_trade_no; |
46 | 46 | $data["total_fee"] = $total_fee; |
47 | 47 | $data["spbill_create_ip"] = $spbill_create_ip; |
48 | 48 | $data["auth_code"] = $auth_code; |
49 | - return $this->post(self::URL_MICROPAY,$data,true); |
|
49 | + return $this->post(self::URL_MICROPAY, $data, true); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -55,11 +55,11 @@ discard block |
||
55 | 55 | * @return mixed |
56 | 56 | * @throws Exception |
57 | 57 | */ |
58 | - public function authCodeToOpenId($auth_code){ |
|
58 | + public function authCodeToOpenId($auth_code) { |
|
59 | 59 | $data = array(); |
60 | 60 | $data["appid"] = $this->config["app_id"]; |
61 | 61 | $data["auth_code"] = $auth_code; |
62 | - return $this->post(self::URL_AUTHCODETOOPENID,$data,false); |
|
62 | + return $this->post(self::URL_AUTHCODETOOPENID, $data, false); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | |
@@ -69,11 +69,11 @@ discard block |
||
69 | 69 | * @return array |
70 | 70 | * @throws Exception |
71 | 71 | */ |
72 | - public function reverseByOutTradeNo($out_trade_no){ |
|
72 | + public function reverseByOutTradeNo($out_trade_no) { |
|
73 | 73 | $data = array(); |
74 | 74 | $data["appid"] = $this->config["app_id"]; |
75 | 75 | $data["out_trade_no"] = $out_trade_no; |
76 | - return $this->post(self::URL_REVERSE, $data,true); |
|
76 | + return $this->post(self::URL_REVERSE, $data, true); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -82,10 +82,10 @@ discard block |
||
82 | 82 | * @return array |
83 | 83 | * @throws Exception |
84 | 84 | */ |
85 | - public function reverseByTransactionId($transaction_id){ |
|
85 | + public function reverseByTransactionId($transaction_id) { |
|
86 | 86 | $data = array(); |
87 | 87 | $data["appid"] = $this->config["app_id"]; |
88 | 88 | $data["transaction_id"] = $transaction_id; |
89 | - return $this->post(self::URL_REVERSE, $data,true); |
|
89 | + return $this->post(self::URL_REVERSE, $data, true); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | \ No newline at end of file |