@@ -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 |
@@ -22,14 +22,14 @@ discard block |
||
| 22 | 22 | * @return array |
| 23 | 23 | * @throws Exception |
| 24 | 24 | */ |
| 25 | - public function sendCoupon($coupon_stock_id,$open_id,$partner_trade_no,$op_user_id = '',$ext = array()){ |
|
| 26 | - $data = (!empty($ext) && is_array($ext))?$ext:array(); |
|
| 25 | + public function sendCoupon($coupon_stock_id, $open_id, $partner_trade_no, $op_user_id = '', $ext = array()) { |
|
| 26 | + $data = (!empty($ext) && is_array($ext)) ? $ext : array(); |
|
| 27 | 27 | $data["partner_trade_no"] = $partner_trade_no; |
| 28 | 28 | $data["coupon_stock_id"] = $coupon_stock_id; |
| 29 | 29 | $data["openid_count"] = 1; |
| 30 | 30 | $data["open_id"] = $open_id; |
| 31 | 31 | $data["op_user_id"] = $op_user_id; |
| 32 | - return $this->post(self::URL_SEND_COUPON,$data,true); |
|
| 32 | + return $this->post(self::URL_SEND_COUPON, $data, true); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -39,11 +39,11 @@ discard block |
||
| 39 | 39 | * @return array |
| 40 | 40 | * @throws Exception |
| 41 | 41 | */ |
| 42 | - public function queryCouponStock($coupon_stock_id,$op_user_id = ''){ |
|
| 42 | + public function queryCouponStock($coupon_stock_id, $op_user_id = '') { |
|
| 43 | 43 | $data = array(); |
| 44 | 44 | $data["coupon_stock_id"] = $coupon_stock_id; |
| 45 | 45 | $data["op_user_id"] = $op_user_id; |
| 46 | - return $this->post(self::URL_QUERY_COUPON_STOCK,$data,false); |
|
| 46 | + return $this->post(self::URL_QUERY_COUPON_STOCK, $data, false); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -56,13 +56,13 @@ discard block |
||
| 56 | 56 | * @return array |
| 57 | 57 | * @throws Exception |
| 58 | 58 | */ |
| 59 | - public function queryCouponsInfo($coupon_id,$open_id,$stock_id,$op_user_id = '',$ext = array()){ |
|
| 60 | - $data = (!empty($ext) && is_array($ext))?$ext:array(); |
|
| 59 | + public function queryCouponsInfo($coupon_id, $open_id, $stock_id, $op_user_id = '', $ext = array()) { |
|
| 60 | + $data = (!empty($ext) && is_array($ext)) ? $ext : array(); |
|
| 61 | 61 | $data["coupon_id"] = $coupon_id; |
| 62 | 62 | $data["stock_id"] = $stock_id; |
| 63 | 63 | $data["open_id"] = $open_id; |
| 64 | 64 | $data["op_user_id"] = $op_user_id; |
| 65 | - return $this->post(self::URL_QUERY_COUPON_INFO,$data,false); |
|
| 65 | + return $this->post(self::URL_QUERY_COUPON_INFO, $data, false); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | } |
| 69 | 69 | \ No newline at end of file |
@@ -37,8 +37,8 @@ discard block |
||
| 37 | 37 | * @return string |
| 38 | 38 | * @throws Exception |
| 39 | 39 | */ |
| 40 | - public function getPrepayId($body,$out_trade_no,$total_fee,$spbill_create_ip,$ext = null) { |
|
| 41 | - $data = ($ext && is_array($ext))?$ext:array(); |
|
| 40 | + public function getPrepayId($body, $out_trade_no, $total_fee, $spbill_create_ip, $ext = null) { |
|
| 41 | + $data = ($ext && is_array($ext)) ? $ext : array(); |
|
| 42 | 42 | $data["body"] = $body; |
| 43 | 43 | $data["out_trade_no"] = $out_trade_no; |
| 44 | 44 | $data["total_fee"] = $total_fee; |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | $data["timestamp"] = time(); |
| 64 | 64 | $data["noncestr"] = $this->getNonceStr(); |
| 65 | 65 | $data["appid"] = $this->config["app_id"]; |
| 66 | - $data["sign"] = $this->sign($data); |
|
| 66 | + $data["sign"] = $this->sign($data); |
|
| 67 | 67 | return $data; |
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | \ No newline at end of file |
@@ -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 | |
@@ -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"]; |
@@ -471,7 +471,7 @@ |
||
| 471 | 471 | * @throws Exception |
| 472 | 472 | */ |
| 473 | 473 | public function report($interface_url,$execution_time,$return_code,$result_code,$user_ip,$out_trade_no = null,$time = null,$device_info = null, |
| 474 | - $return_msg = null,$err_code = null,$err_code_des = null){ |
|
| 474 | + $return_msg = null,$err_code = null,$err_code_des = null){ |
|
| 475 | 475 | $data = array(); |
| 476 | 476 | $data["appid"] = $this->config["app_id"]; |
| 477 | 477 | $data["interface_url"] = $interface_url; |
@@ -30,10 +30,10 @@ discard block |
||
| 30 | 30 | * @method static service\Coupon Coupon(array $config) |
| 31 | 31 | */ |
| 32 | 32 | class WechatPay { |
| 33 | - const TRADETYPE_JSAPI = 'JSAPI',TRADETYPE_NATIVE = 'NATIVE',TRADETYPE_APP = 'APP',TRADETYPE_MWEB = 'MWEB'; |
|
| 33 | + const TRADETYPE_JSAPI = 'JSAPI', TRADETYPE_NATIVE = 'NATIVE', TRADETYPE_APP = 'APP', TRADETYPE_MWEB = 'MWEB'; |
|
| 34 | 34 | const SIGNTYPE_MD5 = 'MD5', SIGNTYPE_HMACSHA256 = 'HMAC-SHA256'; |
| 35 | - const CHECKNAME_FORCECHECK = 'FORCE_CHECK',CHECKNAME_NOCHECK = 'NO_CHECK'; |
|
| 36 | - const ACCOUNTTYPE_BASIC = 'Basic',ACCOUNTTYPE_OPERATION = 'Operation',ACCOUNTTYPE_FEES = 'Fees'; |
|
| 35 | + const CHECKNAME_FORCECHECK = 'FORCE_CHECK', CHECKNAME_NOCHECK = 'NO_CHECK'; |
|
| 36 | + const ACCOUNTTYPE_BASIC = 'Basic', ACCOUNTTYPE_OPERATION = 'Operation', ACCOUNTTYPE_FEES = 'Fees'; |
|
| 37 | 37 | const API_ENDPOINT = 'https://api.mch.weixin.qq.com/'; |
| 38 | 38 | /** 支付 */ |
| 39 | 39 | const URL_UNIFIEDORDER = 'pay/unifiedorder'; |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | * @return mixed |
| 119 | 119 | */ |
| 120 | 120 | private static function load($name, $config) { |
| 121 | - $service = __NAMESPACE__ . "\\service\\{$name}"; |
|
| 121 | + $service = __NAMESPACE__."\\service\\{$name}"; |
|
| 122 | 122 | return new $service($config); |
| 123 | 123 | } |
| 124 | 124 | |
@@ -132,34 +132,34 @@ discard block |
||
| 132 | 132 | return self::load($name, ...$config); |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - public function setWechatOAuth($wechatOAuth){ |
|
| 135 | + public function setWechatOAuth($wechatOAuth) { |
|
| 136 | 136 | $this->wechatOAuth = $wechatOAuth; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - public function getWechatOAuth(){ |
|
| 140 | - if(!$this->wechatOAuth){ |
|
| 141 | - $this->wechatOAuth = new WechatOAuth($this->config['app_id'],$this->config['app_secret']); |
|
| 139 | + public function getWechatOAuth() { |
|
| 140 | + if (!$this->wechatOAuth) { |
|
| 141 | + $this->wechatOAuth = new WechatOAuth($this->config['app_id'], $this->config['app_secret']); |
|
| 142 | 142 | } |
| 143 | 143 | return $this->wechatOAuth; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - public function setConfig($config){ |
|
| 146 | + public function setConfig($config) { |
|
| 147 | 147 | $this->config = $config; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - public function getConfig(){ |
|
| 150 | + public function getConfig() { |
|
| 151 | 151 | return $this->config; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - public function setHttpClient($httpClient){ |
|
| 154 | + public function setHttpClient($httpClient) { |
|
| 155 | 155 | $this->httpClient = $httpClient; |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - public function setCacheProvider($cacheProvider){ |
|
| 158 | + public function setCacheProvider($cacheProvider) { |
|
| 159 | 159 | $this->cacheProvider = $cacheProvider; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - public function getCacheProvider(){ |
|
| 162 | + public function getCacheProvider() { |
|
| 163 | 163 | return $this->cacheProvider; |
| 164 | 164 | } |
| 165 | 165 | |
@@ -172,25 +172,25 @@ discard block |
||
| 172 | 172 | public function unifiedOrder($params) { |
| 173 | 173 | $data = array(); |
| 174 | 174 | $data["appid"] = $this->config["app_id"]; |
| 175 | - $data["device_info"] = (isset($params['device_info'])&&trim($params['device_info'])!='')?$params['device_info']:null; |
|
| 175 | + $data["device_info"] = (isset($params['device_info']) && trim($params['device_info']) != '') ? $params['device_info'] : null; |
|
| 176 | 176 | $data["body"] = $params['body']; |
| 177 | - $data["detail"] = isset($params['detail'])?$params['detail']:null;//optional |
|
| 178 | - $data["attach"] = isset($params['attach'])?$params['attach']:null;//optional |
|
| 179 | - $data["out_trade_no"] = isset($params['out_trade_no'])?$params['out_trade_no']:null; |
|
| 180 | - $data["fee_type"] = isset($params['fee_type'])?$params['fee_type']:'CNY'; |
|
| 177 | + $data["detail"] = isset($params['detail']) ? $params['detail'] : null; //optional |
|
| 178 | + $data["attach"] = isset($params['attach']) ? $params['attach'] : null; //optional |
|
| 179 | + $data["out_trade_no"] = isset($params['out_trade_no']) ? $params['out_trade_no'] : null; |
|
| 180 | + $data["fee_type"] = isset($params['fee_type']) ? $params['fee_type'] : 'CNY'; |
|
| 181 | 181 | $data["total_fee"] = $params['total_fee']; |
| 182 | 182 | $data["spbill_create_ip"] = $params['spbill_create_ip']; |
| 183 | - $data["time_start"] = isset($params['time_start'])?$params['time_start']:null;//optional |
|
| 184 | - $data["time_expire"] = isset($params['time_expire'])?$params['time_expire']:null;//optional |
|
| 185 | - $data["goods_tag"] = isset($params['goods_tag'])?$params['goods_tag']:null; |
|
| 183 | + $data["time_start"] = isset($params['time_start']) ? $params['time_start'] : null; //optional |
|
| 184 | + $data["time_expire"] = isset($params['time_expire']) ? $params['time_expire'] : null; //optional |
|
| 185 | + $data["goods_tag"] = isset($params['goods_tag']) ? $params['goods_tag'] : null; |
|
| 186 | 186 | $data["notify_url"] = $this->config["notify_url"]; |
| 187 | 187 | $data["trade_type"] = $params['trade_type']; |
| 188 | - if($params['trade_type'] == WechatPay::TRADETYPE_NATIVE){ |
|
| 189 | - if(!isset($params['product_id'])) throw new Exception('product_id is required when trade_type is NATIVE'); |
|
| 188 | + if ($params['trade_type'] == WechatPay::TRADETYPE_NATIVE) { |
|
| 189 | + if (!isset($params['product_id'])) throw new Exception('product_id is required when trade_type is NATIVE'); |
|
| 190 | 190 | $data["product_id"] = $params['product_id']; |
| 191 | 191 | } |
| 192 | - if($params['trade_type'] == WechatPay::TRADETYPE_JSAPI){ |
|
| 193 | - if(!isset($params['openid'])) throw new Exception('openid is required when trade_type is JSAPI'); |
|
| 192 | + if ($params['trade_type'] == WechatPay::TRADETYPE_JSAPI) { |
|
| 193 | + if (!isset($params['openid'])) throw new Exception('openid is required when trade_type is JSAPI'); |
|
| 194 | 194 | $data["openid"] = $params['openid']; |
| 195 | 195 | } |
| 196 | 196 | $result = $this->post(self::URL_UNIFIEDORDER, $data); |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | * @return array |
| 204 | 204 | * @throws Exception |
| 205 | 205 | */ |
| 206 | - public function queryOrderByTransactionId($transaction_id){ |
|
| 206 | + public function queryOrderByTransactionId($transaction_id) { |
|
| 207 | 207 | $data = array(); |
| 208 | 208 | $data["appid"] = $this->config["app_id"]; |
| 209 | 209 | $data["transaction_id"] = $transaction_id; |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * @return array |
| 218 | 218 | * @throws Exception |
| 219 | 219 | */ |
| 220 | - public function queryOrderByOutTradeNo($out_trade_no){ |
|
| 220 | + public function queryOrderByOutTradeNo($out_trade_no) { |
|
| 221 | 221 | $data = array(); |
| 222 | 222 | $data["appid"] = $this->config["app_id"]; |
| 223 | 223 | $data["out_trade_no"] = $out_trade_no; |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | * @return array |
| 232 | 232 | * @throws Exception |
| 233 | 233 | */ |
| 234 | - public function queryRefundByTransactionId($transaction_id,$offset = 0){ |
|
| 234 | + public function queryRefundByTransactionId($transaction_id, $offset = 0) { |
|
| 235 | 235 | $data = array(); |
| 236 | 236 | $data["appid"] = $this->config["app_id"]; |
| 237 | 237 | $data["transaction_id"] = $transaction_id; |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | * @return array |
| 247 | 247 | * @throws Exception |
| 248 | 248 | */ |
| 249 | - public function queryRefundByOutTradeNo($out_trade_no,$offset = 0){ |
|
| 249 | + public function queryRefundByOutTradeNo($out_trade_no, $offset = 0) { |
|
| 250 | 250 | $data = array(); |
| 251 | 251 | $data["appid"] = $this->config["app_id"]; |
| 252 | 252 | $data["out_trade_no"] = $out_trade_no; |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | * @return array |
| 262 | 262 | * @throws Exception |
| 263 | 263 | */ |
| 264 | - public function queryRefundByRefundId($refund_id,$offset = 0){ |
|
| 264 | + public function queryRefundByRefundId($refund_id, $offset = 0) { |
|
| 265 | 265 | $data = array(); |
| 266 | 266 | $data["appid"] = $this->config["app_id"]; |
| 267 | 267 | $data["refund_id"] = $refund_id; |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | * @return array |
| 277 | 277 | * @throws Exception |
| 278 | 278 | */ |
| 279 | - public function queryRefundByOutRefundNo($out_refund_no,$offset = 0){ |
|
| 279 | + public function queryRefundByOutRefundNo($out_refund_no, $offset = 0) { |
|
| 280 | 280 | $data = array(); |
| 281 | 281 | $data["appid"] = $this->config["app_id"]; |
| 282 | 282 | $data["out_refund_no"] = $out_refund_no; |
@@ -290,11 +290,11 @@ discard block |
||
| 290 | 290 | * @return array |
| 291 | 291 | * @throws Exception |
| 292 | 292 | */ |
| 293 | - public function closeOrder($out_trade_no){ |
|
| 293 | + public function closeOrder($out_trade_no) { |
|
| 294 | 294 | $data = array(); |
| 295 | 295 | $data["appid"] = $this->config["app_id"]; |
| 296 | 296 | $data["out_trade_no"] = $out_trade_no; |
| 297 | - return $this->post(self::URL_CLOSEORDER, $data,false); |
|
| 297 | + return $this->post(self::URL_CLOSEORDER, $data, false); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /** |
@@ -307,14 +307,14 @@ discard block |
||
| 307 | 307 | * @return array |
| 308 | 308 | * @throws Exception |
| 309 | 309 | */ |
| 310 | - public function refundByOutTradeNo($out_trade_no,$out_refund_no,$total_fee,$refund_fee,$ext = array()){ |
|
| 311 | - $data = ($ext && is_array($ext))?$ext:array(); |
|
| 310 | + public function refundByOutTradeNo($out_trade_no, $out_refund_no, $total_fee, $refund_fee, $ext = array()) { |
|
| 311 | + $data = ($ext && is_array($ext)) ? $ext : array(); |
|
| 312 | 312 | $data["appid"] = $this->config["app_id"]; |
| 313 | 313 | $data["out_trade_no"] = $out_trade_no; |
| 314 | 314 | $data["out_refund_no"] = $out_refund_no; |
| 315 | 315 | $data["total_fee"] = $total_fee; |
| 316 | 316 | $data["refund_fee"] = $refund_fee; |
| 317 | - return $this->post(self::URL_REFUND, $data,true); |
|
| 317 | + return $this->post(self::URL_REFUND, $data, true); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | /** |
@@ -327,14 +327,14 @@ discard block |
||
| 327 | 327 | * @return array |
| 328 | 328 | * @throws Exception |
| 329 | 329 | */ |
| 330 | - public function refundByTransactionId($transaction_id,$out_refund_no,$total_fee,$refund_fee,$ext = array()){ |
|
| 331 | - $data = ($ext && is_array($ext))?$ext:array(); |
|
| 330 | + public function refundByTransactionId($transaction_id, $out_refund_no, $total_fee, $refund_fee, $ext = array()) { |
|
| 331 | + $data = ($ext && is_array($ext)) ? $ext : array(); |
|
| 332 | 332 | $data["appid"] = $this->config["app_id"]; |
| 333 | 333 | $data["transaction_id"] = $transaction_id; |
| 334 | 334 | $data["out_refund_no"] = $out_refund_no; |
| 335 | 335 | $data["total_fee"] = $total_fee; |
| 336 | 336 | $data["refund_fee"] = $refund_fee; |
| 337 | - return $this->post(self::URL_REFUND, $data,true); |
|
| 337 | + return $this->post(self::URL_REFUND, $data, true); |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | /** |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | * @return array |
| 345 | 345 | * @throws Exception |
| 346 | 346 | */ |
| 347 | - public function downloadBill($bill_date,$bill_type = 'ALL'){ |
|
| 347 | + public function downloadBill($bill_date, $bill_type = 'ALL') { |
|
| 348 | 348 | $data = array(); |
| 349 | 349 | $data["appid"] = $this->config["app_id"]; |
| 350 | 350 | $data["bill_date"] = $bill_date; |
@@ -360,7 +360,7 @@ discard block |
||
| 360 | 360 | * @return array |
| 361 | 361 | * @throws Exception |
| 362 | 362 | */ |
| 363 | - public function downloadFundFlow($bill_date,$account_type = self::ACCOUNTTYPE_BASIC,$tar_type = 'GZIP'){ |
|
| 363 | + public function downloadFundFlow($bill_date, $account_type = self::ACCOUNTTYPE_BASIC, $tar_type = 'GZIP') { |
|
| 364 | 364 | $data = array(); |
| 365 | 365 | $data["appid"] = $this->config["app_id"]; |
| 366 | 366 | $data["bill_date"] = $bill_date; |
@@ -378,14 +378,14 @@ discard block |
||
| 378 | 378 | * @return array |
| 379 | 379 | * @throws Exception |
| 380 | 380 | */ |
| 381 | - public function batchQueryComment($begin_time,$end_time,$offset = 0,$limit = 200){ |
|
| 381 | + public function batchQueryComment($begin_time, $end_time, $offset = 0, $limit = 200) { |
|
| 382 | 382 | $data = array(); |
| 383 | 383 | $data["appid"] = $this->config["app_id"]; |
| 384 | 384 | $data["begin_time"] = $begin_time; |
| 385 | 385 | $data["end_time"] = $end_time; |
| 386 | 386 | $data["offset"] = $offset; |
| 387 | 387 | $data["limit"] = $limit; |
| 388 | - $data["sign"] = $this->sign($data,WechatPay::SIGNTYPE_HMACSHA256); |
|
| 388 | + $data["sign"] = $this->sign($data, WechatPay::SIGNTYPE_HMACSHA256); |
|
| 389 | 389 | return $this->post(self::URL_BATCHQUERYCOMMENT, $data, true); //cert is required |
| 390 | 390 | } |
| 391 | 391 | |
@@ -396,11 +396,11 @@ discard block |
||
| 396 | 396 | * @return null |
| 397 | 397 | * @throws Exception |
| 398 | 398 | */ |
| 399 | - public function onPaidNotify($notify_data,callable $callback = null){ |
|
| 400 | - if(!is_array($notify_data)) $notify_data = $this->xml2array($notify_data); |
|
| 401 | - if(!$this->validateSign($notify_data)) throw new Exception('Invalid paid notify data'); |
|
| 402 | - if($callback && is_callable($callback)){ |
|
| 403 | - return call_user_func_array( $callback , [$notify_data] ); |
|
| 399 | + public function onPaidNotify($notify_data, callable $callback = null) { |
|
| 400 | + if (!is_array($notify_data)) $notify_data = $this->xml2array($notify_data); |
|
| 401 | + if (!$this->validateSign($notify_data)) throw new Exception('Invalid paid notify data'); |
|
| 402 | + if ($callback && is_callable($callback)) { |
|
| 403 | + return call_user_func_array($callback, [$notify_data]); |
|
| 404 | 404 | } |
| 405 | 405 | return null; |
| 406 | 406 | } |
@@ -412,11 +412,11 @@ discard block |
||
| 412 | 412 | * @return mixed |
| 413 | 413 | * @throws Exception |
| 414 | 414 | */ |
| 415 | - public function onRefundedNotify($notify_data,callable $callback = null){ |
|
| 416 | - if(!is_array($notify_data)) $notify_data = $this->xml2array($notify_data); |
|
| 417 | - if(!$this->validateSign($notify_data)) throw new Exception('Invalid refund notify data'); |
|
| 418 | - if($callback && is_callable($callback)){ |
|
| 419 | - return call_user_func_array( $callback ,[$notify_data] ); |
|
| 415 | + public function onRefundedNotify($notify_data, callable $callback = null) { |
|
| 416 | + if (!is_array($notify_data)) $notify_data = $this->xml2array($notify_data); |
|
| 417 | + if (!$this->validateSign($notify_data)) throw new Exception('Invalid refund notify data'); |
|
| 418 | + if ($callback && is_callable($callback)) { |
|
| 419 | + return call_user_func_array($callback, [$notify_data]); |
|
| 420 | 420 | } |
| 421 | 421 | return null; |
| 422 | 422 | } |
@@ -444,13 +444,13 @@ discard block |
||
| 444 | 444 | * @param bool $print |
| 445 | 445 | * @return string |
| 446 | 446 | */ |
| 447 | - public function responseNotify($print = true,$data = [],$return_code="SUCCESS", $return_msg= 'OK') { |
|
| 447 | + public function responseNotify($print = true, $data = [], $return_code = "SUCCESS", $return_msg = 'OK') { |
|
| 448 | 448 | $data["return_code"] = $return_code; |
| 449 | 449 | if ($return_msg) { |
| 450 | 450 | $data["return_msg"] = $return_msg; |
| 451 | 451 | } |
| 452 | 452 | $xml = $this->array2xml($data); |
| 453 | - if($print === true) print $xml; |
|
| 453 | + if ($print === true) print $xml; |
|
| 454 | 454 | else return $xml; |
| 455 | 455 | } |
| 456 | 456 | |
@@ -470,8 +470,8 @@ discard block |
||
| 470 | 470 | * @return array |
| 471 | 471 | * @throws Exception |
| 472 | 472 | */ |
| 473 | - public function report($interface_url,$execution_time,$return_code,$result_code,$user_ip,$out_trade_no = null,$time = null,$device_info = null, |
|
| 474 | - $return_msg = null,$err_code = null,$err_code_des = null){ |
|
| 473 | + public function report($interface_url, $execution_time, $return_code, $result_code, $user_ip, $out_trade_no = null, $time = null, $device_info = null, |
|
| 474 | + $return_msg = null, $err_code = null, $err_code_des = null) { |
|
| 475 | 475 | $data = array(); |
| 476 | 476 | $data["appid"] = $this->config["app_id"]; |
| 477 | 477 | $data["interface_url"] = $interface_url; |
@@ -479,12 +479,12 @@ discard block |
||
| 479 | 479 | $data["return_code"] = $return_code; |
| 480 | 480 | $data["result_code"] = $result_code; |
| 481 | 481 | $data["user_ip"] = $user_ip; |
| 482 | - if($out_trade_no) $data["out_trade_no"] = $out_trade_no; |
|
| 483 | - if($time) $data["time"] = $time; |
|
| 484 | - if($device_info) $data["device_info"] = $device_info; |
|
| 485 | - if($return_msg) $data["return_msg"] = $return_msg; |
|
| 486 | - if($err_code) $data["err_code"] = $err_code; |
|
| 487 | - if($err_code_des) $data["err_code_des"] = $err_code_des; |
|
| 482 | + if ($out_trade_no) $data["out_trade_no"] = $out_trade_no; |
|
| 483 | + if ($time) $data["time"] = $time; |
|
| 484 | + if ($device_info) $data["device_info"] = $device_info; |
|
| 485 | + if ($return_msg) $data["return_msg"] = $return_msg; |
|
| 486 | + if ($err_code) $data["err_code"] = $err_code; |
|
| 487 | + if ($err_code_des) $data["err_code_des"] = $err_code_des; |
|
| 488 | 488 | return $this->post(self::URL_REPORT, $data, false); |
| 489 | 489 | } |
| 490 | 490 | |
@@ -494,11 +494,11 @@ discard block |
||
| 494 | 494 | * @return string |
| 495 | 495 | * @throws Exception |
| 496 | 496 | */ |
| 497 | - public function shortUrl($longurl){ |
|
| 497 | + public function shortUrl($longurl) { |
|
| 498 | 498 | $data = array(); |
| 499 | 499 | $data["appid"] = $this->config["app_id"]; |
| 500 | 500 | $data["long_url"] = $longurl; |
| 501 | - $result = $this->post(self::URL_SHORTURL,$data,false); |
|
| 501 | + $result = $this->post(self::URL_SHORTURL, $data, false); |
|
| 502 | 502 | return $result['short_url']; |
| 503 | 503 | } |
| 504 | 504 | |
@@ -507,10 +507,10 @@ discard block |
||
| 507 | 507 | * @return array |
| 508 | 508 | * @throws Exception |
| 509 | 509 | */ |
| 510 | - public function getSignKey(){ |
|
| 510 | + public function getSignKey() { |
|
| 511 | 511 | $data = array(); |
| 512 | 512 | $data["mch_id"] = $this->config["mch_id"]; |
| 513 | - $result = $this->post($this->getSignKeyUrl,$data,false); |
|
| 513 | + $result = $this->post($this->getSignKeyUrl, $data, false); |
|
| 514 | 514 | return $result['sandbox_signkey']; |
| 515 | 515 | } |
| 516 | 516 | |
@@ -520,8 +520,8 @@ discard block |
||
| 520 | 520 | * @param string $ticket |
| 521 | 521 | * @return array |
| 522 | 522 | */ |
| 523 | - public function getSignPackage($url, $ticket = null){ |
|
| 524 | - if(!$ticket) $ticket = $this->getTicket(); |
|
| 523 | + public function getSignPackage($url, $ticket = null) { |
|
| 524 | + if (!$ticket) $ticket = $this->getTicket(); |
|
| 525 | 525 | $timestamp = time(); |
| 526 | 526 | $nonceStr = $this->getNonceStr(); |
| 527 | 527 | $rawString = "jsapi_ticket=$ticket&noncestr=$nonceStr×tamp=$timestamp&url=$url"; |
@@ -543,29 +543,29 @@ discard block |
||
| 543 | 543 | * @param boolean $cache |
| 544 | 544 | * @return string |
| 545 | 545 | */ |
| 546 | - public function getTicket($cache = true){ |
|
| 546 | + public function getTicket($cache = true) { |
|
| 547 | 547 | $ticket = null; |
| 548 | 548 | $cacheKey = 'jsapi_ticket'; |
| 549 | - if($cache === true){ |
|
| 549 | + if ($cache === true) { |
|
| 550 | 550 | $data = $this->cacheProvider->get($cacheKey); |
| 551 | 551 | if ($data && $data->expires_at > time()) { |
| 552 | 552 | $ticket = $data->ticket; |
| 553 | 553 | } |
| 554 | 554 | } |
| 555 | - if(!$ticket){ |
|
| 555 | + if (!$ticket) { |
|
| 556 | 556 | $data = $this->getWechatOAuth()->getTicket(); |
| 557 | - if($cache === true){ |
|
| 558 | - $this->cacheProvider->set($cacheKey,$data,time() + $data->expires_in); |
|
| 557 | + if ($cache === true) { |
|
| 558 | + $this->cacheProvider->set($cacheKey, $data, time() + $data->expires_in); |
|
| 559 | 559 | } |
| 560 | 560 | $ticket = $data->ticket; |
| 561 | 561 | } |
| 562 | 562 | return $ticket; |
| 563 | 563 | } |
| 564 | 564 | |
| 565 | - protected function post($url, $data,$cert = true) { |
|
| 566 | - if(!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"]; |
|
| 567 | - if(!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr(); |
|
| 568 | - if(!isset($data['sign'])) $data['sign'] = $this->sign($data); |
|
| 565 | + protected function post($url, $data, $cert = true) { |
|
| 566 | + if (!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"]; |
|
| 567 | + if (!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr(); |
|
| 568 | + if (!isset($data['sign'])) $data['sign'] = $this->sign($data); |
|
| 569 | 569 | $this->requestXML = $this->responseXML = null; |
| 570 | 570 | $this->requestArray = $this->responseArray = null; |
| 571 | 571 | |
@@ -577,23 +577,23 @@ discard block |
||
| 577 | 577 | CURLOPT_RETURNTRANSFER => true, |
| 578 | 578 | CURLOPT_TIMEOUT => 10 |
| 579 | 579 | ]; |
| 580 | - if($cert == true){ |
|
| 580 | + if ($cert == true) { |
|
| 581 | 581 | $opts[CURLOPT_SSLCERTTYPE] = 'PEM'; |
| 582 | 582 | $opts[CURLOPT_SSLCERT] = $this->config['ssl_cert_path']; |
| 583 | 583 | $opts[CURLOPT_SSLKEYTYPE] = 'PEM'; |
| 584 | 584 | $opts[CURLOPT_SSLKEY] = $this->config['ssl_key_path']; |
| 585 | 585 | } |
| 586 | 586 | $processResponse = true; |
| 587 | - if(in_array($url,[self::URL_DOWNLOADBILL,self::URL_DOWNLOAD_FUND_FLOW,self::URL_BATCHQUERYCOMMENT])){ |
|
| 587 | + if (in_array($url, [self::URL_DOWNLOADBILL, self::URL_DOWNLOAD_FUND_FLOW, self::URL_BATCHQUERYCOMMENT])) { |
|
| 588 | 588 | $processResponse = false; |
| 589 | 589 | } |
| 590 | - if($this->sandbox === true) $url = "sandboxnew/{$url}"; |
|
| 590 | + if ($this->sandbox === true) $url = "sandboxnew/{$url}"; |
|
| 591 | 591 | |
| 592 | - $content = $this->httpClient->post(self::API_ENDPOINT . $url,$this->requestXML,[],$opts); |
|
| 593 | - if(!$content) throw new Exception("Empty response with {$this->requestXML}"); |
|
| 592 | + $content = $this->httpClient->post(self::API_ENDPOINT.$url, $this->requestXML, [], $opts); |
|
| 593 | + if (!$content) throw new Exception("Empty response with {$this->requestXML}"); |
|
| 594 | 594 | |
| 595 | 595 | $this->responseXML = $content; |
| 596 | - if($processResponse) |
|
| 596 | + if ($processResponse) |
|
| 597 | 597 | return $this->processResponseXML($this->responseXML); |
| 598 | 598 | else return $this->responseXML; |
| 599 | 599 | } |
@@ -603,51 +603,51 @@ discard block |
||
| 603 | 603 | * @return array |
| 604 | 604 | * @throws Exception |
| 605 | 605 | */ |
| 606 | - private function processResponseXML($responseXML){ |
|
| 606 | + private function processResponseXML($responseXML) { |
|
| 607 | 607 | $result = $this->xml2array($responseXML); |
| 608 | 608 | $this->responseArray = $result; |
| 609 | - if(empty($result['return_code'])){ |
|
| 609 | + if (empty($result['return_code'])) { |
|
| 610 | 610 | throw new Exception("No return code presents in {$this->responseXML}"); |
| 611 | 611 | } |
| 612 | 612 | $this->returnCode = $result["return_code"]; |
| 613 | - $this->returnMsg = isset($result['return_msg'])?$result['return_msg']:''; |
|
| 613 | + $this->returnMsg = isset($result['return_msg']) ? $result['return_msg'] : ''; |
|
| 614 | 614 | |
| 615 | 615 | if ($this->returnCode == "SUCCESS") { |
| 616 | - if(isset($result['result_code']) && $result['result_code'] == "FAIL"){ |
|
| 616 | + if (isset($result['result_code']) && $result['result_code'] == "FAIL") { |
|
| 617 | 617 | $this->resultCode = $result['result_code']; |
| 618 | 618 | $this->errCode = $result['err_code']; |
| 619 | 619 | $this->errCodeDes = $result['err_code_des']; |
| 620 | 620 | throw new Exception("[$this->errCode]$this->errCodeDes"); |
| 621 | - }else{ |
|
| 621 | + }else { |
|
| 622 | 622 | return $result; |
| 623 | 623 | } |
| 624 | - } else if($this->returnCode == 'FAIL'){ |
|
| 624 | + }else if ($this->returnCode == 'FAIL') { |
|
| 625 | 625 | throw new Exception($this->returnMsg); |
| 626 | 626 | } |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | - public function sign($data,$sign_type = WechatPay::SIGNTYPE_MD5) { |
|
| 629 | + public function sign($data, $sign_type = WechatPay::SIGNTYPE_MD5) { |
|
| 630 | 630 | ksort($data); |
| 631 | 631 | $string1 = ""; |
| 632 | 632 | foreach ($data as $k => $v) { |
| 633 | - if ($v && trim($v)!='') { |
|
| 633 | + if ($v && trim($v) != '') { |
|
| 634 | 634 | $string1 .= "$k=$v&"; |
| 635 | 635 | } |
| 636 | 636 | } |
| 637 | - $stringSignTemp = $string1 . "key=" . $this->config["api_key"]; |
|
| 638 | - if($sign_type == WechatPay::SIGNTYPE_MD5){ |
|
| 637 | + $stringSignTemp = $string1."key=".$this->config["api_key"]; |
|
| 638 | + if ($sign_type == WechatPay::SIGNTYPE_MD5) { |
|
| 639 | 639 | $sign = strtoupper(md5($stringSignTemp)); |
| 640 | - }elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){ |
|
| 641 | - $sign = strtoupper(hash_hmac('sha256',$stringSignTemp,$this->config["api_key"])); |
|
| 640 | + }elseif ($sign_type == WechatPay::SIGNTYPE_HMACSHA256) { |
|
| 641 | + $sign = strtoupper(hash_hmac('sha256', $stringSignTemp, $this->config["api_key"])); |
|
| 642 | 642 | }else throw new Exception("Not supported sign type - $sign_type"); |
| 643 | 643 | return $sign; |
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | private function array2xml($array) { |
| 647 | - $xml = "<xml>" . PHP_EOL; |
|
| 647 | + $xml = "<xml>".PHP_EOL; |
|
| 648 | 648 | foreach ($array as $k => $v) { |
| 649 | - if($v && trim($v)!='') |
|
| 650 | - $xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL; |
|
| 649 | + if ($v && trim($v) != '') |
|
| 650 | + $xml .= "<$k><![CDATA[$v]]></$k>".PHP_EOL; |
|
| 651 | 651 | } |
| 652 | 652 | $xml .= "</xml>"; |
| 653 | 653 | return $xml; |
@@ -656,14 +656,14 @@ discard block |
||
| 656 | 656 | private function xml2array($xml) { |
| 657 | 657 | $array = []; |
| 658 | 658 | $tmp = (array) simplexml_load_string($xml); |
| 659 | - foreach ( $tmp as $k => $v) { |
|
| 659 | + foreach ($tmp as $k => $v) { |
|
| 660 | 660 | $array[$k] = (string) $v; |
| 661 | 661 | } |
| 662 | 662 | return $array; |
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | protected function getNonceStr() { |
| 666 | - return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"),0,32); |
|
| 666 | + return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"), 0, 32); |
|
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | } |
| 670 | 670 | \ No newline at end of file |