@@ -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 | /** |
@@ -45,13 +45,13 @@ discard block |
||
| 45 | 45 | * @param $partner_trade_no |
| 46 | 46 | * @return array |
| 47 | 47 | */ |
| 48 | - public function queryTransferWallet($partner_trade_no){ |
|
| 48 | + public function queryTransferWallet($partner_trade_no) { |
|
| 49 | 49 | $data = [ |
| 50 | 50 | "appid" => $this->config["app_id"], |
| 51 | 51 | "mch_id" => $this->config["mch_id"], |
| 52 | 52 | "partner_trade_no" => $partner_trade_no |
| 53 | 53 | ]; |
| 54 | - return $this->post(self::URL_QUERY_TRANSFER_WALLET,$data,true); |
|
| 54 | + return $this->post(self::URL_QUERY_TRANSFER_WALLET, $data, true); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -65,8 +65,8 @@ discard block |
||
| 65 | 65 | * @return array |
| 66 | 66 | * @throws Exception |
| 67 | 67 | */ |
| 68 | - 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"); |
|
| 68 | + 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"); |
|
| 70 | 70 | $data = [ |
| 71 | 71 | "partner_trade_no" => $partner_trade_no, |
| 72 | 72 | "enc_bank_no" => $this->rsaEncrypt($bank_no), |
@@ -75,14 +75,14 @@ discard block |
||
| 75 | 75 | "desc" => $desc, |
| 76 | 76 | "amount" => $amount |
| 77 | 77 | ]; |
| 78 | - return $this->post(self::URL_TRANSFER_BANKCARD,$data,true); |
|
| 78 | + return $this->post(self::URL_TRANSFER_BANKCARD, $data, true); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - public function rsaEncrypt($data,$pubkey = null){ |
|
| 82 | - if(!$pubkey) $pubkey = $this->getPublicKey(); |
|
| 81 | + public function rsaEncrypt($data, $pubkey = null) { |
|
| 82 | + if (!$pubkey) $pubkey = $this->getPublicKey(); |
|
| 83 | 83 | $encrypted = null; |
| 84 | 84 | $pubkey = openssl_get_publickey($pubkey); |
| 85 | - if (@openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING)) |
|
| 85 | + if (@openssl_public_encrypt($data, $encrypted, $pubkey, OPENSSL_PKCS1_OAEP_PADDING)) |
|
| 86 | 86 | $data = base64_encode($encrypted); |
| 87 | 87 | else |
| 88 | 88 | throw new Exception('Unable to encrypt data'); |
@@ -94,13 +94,13 @@ discard block |
||
| 94 | 94 | * @param $partner_trade_no |
| 95 | 95 | * @return array |
| 96 | 96 | */ |
| 97 | - public function queryTransferBankCard($partner_trade_no){ |
|
| 97 | + public function queryTransferBankCard($partner_trade_no) { |
|
| 98 | 98 | $data = [ |
| 99 | 99 | "appid" => $this->config["app_id"], |
| 100 | 100 | "mch_id" => $this->config["mch_id"], |
| 101 | 101 | "partner_trade_no" => $partner_trade_no |
| 102 | 102 | ]; |
| 103 | - return $this->post(self::URL_QUERY_TRANSFER_WALLET,$data,true); |
|
| 103 | + return $this->post(self::URL_QUERY_TRANSFER_WALLET, $data, true); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -110,18 +110,18 @@ discard block |
||
| 110 | 110 | * @return string |
| 111 | 111 | * @throws Exception |
| 112 | 112 | */ |
| 113 | - public function getPublicKey($refresh = false){ |
|
| 114 | - if(!$this->publicKey) { |
|
| 113 | + public function getPublicKey($refresh = false) { |
|
| 114 | + if (!$this->publicKey) { |
|
| 115 | 115 | if (!$refresh && file_exists($this->config["rsa_pubkey_path"])) { |
| 116 | 116 | $this->publicKey = file_get_contents($this->config["rsa_pubkey_path"]); |
| 117 | - }else{ |
|
| 117 | + }else { |
|
| 118 | 118 | $data = array(); |
| 119 | 119 | $data["mch_id"] = $this->config["mch_id"]; |
| 120 | 120 | $data["sign_type"] = $this->config["sign_type"]; |
| 121 | 121 | $result = $this->post(self::URL_GETPUBLICKEY, $data, true); |
| 122 | 122 | $pubkey = $result['pub_key']; |
| 123 | 123 | $this->publicKey = $this->convertPKCS1toPKCS8($pubkey); |
| 124 | - if($fp = @fopen($this->config["rsa_pubkey_path"], "w")) { |
|
| 124 | + if ($fp = @fopen($this->config["rsa_pubkey_path"], "w")) { |
|
| 125 | 125 | fwrite($fp, $this->publicKey); |
| 126 | 126 | fclose($fp); |
| 127 | 127 | } |
@@ -130,16 +130,16 @@ discard block |
||
| 130 | 130 | return $this->publicKey; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - public function setPublicKey($publicKey){ |
|
| 133 | + public function setPublicKey($publicKey) { |
|
| 134 | 134 | $this->publicKey = $publicKey; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - private function convertPKCS1toPKCS8($pkcs1){ |
|
| 137 | + private function convertPKCS1toPKCS8($pkcs1) { |
|
| 138 | 138 | $start_key = $pkcs1; |
| 139 | 139 | $start_key = str_replace('-----BEGIN RSA PUBLIC KEY-----', '', $start_key); |
| 140 | 140 | $start_key = trim(str_replace('-----END RSA PUBLIC KEY-----', '', $start_key)); |
| 141 | - $key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' . str_replace("\n", '', $start_key); |
|
| 142 | - $key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($key, 64, "\n", true) . "\n-----END PUBLIC KEY-----"; |
|
| 141 | + $key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A'.str_replace("\n", '', $start_key); |
|
| 142 | + $key = "-----BEGIN PUBLIC KEY-----\n".wordwrap($key, 64, "\n", true)."\n-----END PUBLIC KEY-----"; |
|
| 143 | 143 | return $key; |
| 144 | 144 | } |
| 145 | 145 | |
@@ -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"]; |