@@ -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"]; |
@@ -37,15 +37,15 @@ discard block |
||
| 37 | 37 | * @param array $ext |
| 38 | 38 | * @return array |
| 39 | 39 | */ |
| 40 | - public function microPay($body,$out_trade_no,$total_fee,$spbill_create_ip,$auth_code,$ext = array()){ |
|
| 41 | - $data = (!empty($ext) && is_array($ext))?$ext:array(); |
|
| 40 | + public function microPay($body, $out_trade_no, $total_fee, $spbill_create_ip, $auth_code, $ext = array()) { |
|
| 41 | + $data = (!empty($ext) && is_array($ext)) ? $ext : array(); |
|
| 42 | 42 | $data["appid"] = $this->config["app_id"]; |
| 43 | 43 | $data["body"] = $body; |
| 44 | 44 | $data["out_trade_no"] = $out_trade_no; |
| 45 | 45 | $data["total_fee"] = $total_fee; |
| 46 | 46 | $data["spbill_create_ip"] = $spbill_create_ip; |
| 47 | 47 | $data["auth_code"] = $auth_code; |
| 48 | - $result = $this->post(self::URL_MICROPAY,$data,true); |
|
| 48 | + $result = $this->post(self::URL_MICROPAY, $data, true); |
|
| 49 | 49 | return $result; |
| 50 | 50 | } |
| 51 | 51 | |
@@ -55,11 +55,11 @@ discard block |
||
| 55 | 55 | * @param $auth_code |
| 56 | 56 | * @return mixed |
| 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 | - $result = $this->post(self::URL_AUTHCODETOOPENID,$data,false); |
|
| 62 | + $result = $this->post(self::URL_AUTHCODETOOPENID, $data, false); |
|
| 63 | 63 | return $result['openid']; |
| 64 | 64 | } |
| 65 | 65 | |
@@ -70,11 +70,11 @@ discard block |
||
| 70 | 70 | * @param $out_trade_no string 商户订单号 |
| 71 | 71 | * @return array |
| 72 | 72 | */ |
| 73 | - public function reverseByOutTradeNo($out_trade_no){ |
|
| 73 | + public function reverseByOutTradeNo($out_trade_no) { |
|
| 74 | 74 | $data = array(); |
| 75 | 75 | $data["appid"] = $this->config["app_id"]; |
| 76 | 76 | $data["out_trade_no"] = $out_trade_no; |
| 77 | - $result = $this->post(self::URL_REVERSE, $data,true); |
|
| 77 | + $result = $this->post(self::URL_REVERSE, $data, true); |
|
| 78 | 78 | return $result; |
| 79 | 79 | } |
| 80 | 80 | |
@@ -84,11 +84,11 @@ discard block |
||
| 84 | 84 | * @param $transaction_id string 微信订单号 |
| 85 | 85 | * @return array |
| 86 | 86 | */ |
| 87 | - public function reverseByTransactionId($transaction_id){ |
|
| 87 | + public function reverseByTransactionId($transaction_id) { |
|
| 88 | 88 | $data = array(); |
| 89 | 89 | $data["appid"] = $this->config["app_id"]; |
| 90 | 90 | $data["transaction_id"] = $transaction_id; |
| 91 | - $result = $this->post(self::URL_REVERSE, $data,true); |
|
| 91 | + $result = $this->post(self::URL_REVERSE, $data, true); |
|
| 92 | 92 | return $result; |
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | \ No newline at end of file |
@@ -29,14 +29,14 @@ discard block |
||
| 29 | 29 | * @return array |
| 30 | 30 | * @throws Exception |
| 31 | 31 | */ |
| 32 | - public function sendRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark,$scene_id = '',$riskinfo = '',$consume_mch_id = ''){ |
|
| 32 | + public function sendRedPack($mch_billno, $send_name, $re_openid, $total_amount, $total_num, $wishing, $act_name, $remark, $scene_id = '', $riskinfo = '', $consume_mch_id = '') { |
|
| 33 | 33 | $data = array(); |
| 34 | 34 | $data["wxappid"] = $this->config["app_id"]; |
| 35 | 35 | $data["mch_billno"] = $mch_billno; |
| 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) == '') throw new Exception("scene_id is required when total_amount beyond 20000"); |
|
| 40 | 40 | $data["total_num"] = $total_num; |
| 41 | 41 | $data["wishing"] = $wishing; |
| 42 | 42 | $data["act_name"] = $act_name; |
@@ -65,14 +65,14 @@ discard block |
||
| 65 | 65 | * @return array |
| 66 | 66 | * @throws Exception |
| 67 | 67 | */ |
| 68 | - public function sendGroupRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark,$scene_id = '',$riskinfo = '',$consume_mch_id = ''){ |
|
| 68 | + public function sendGroupRedPack($mch_billno, $send_name, $re_openid, $total_amount, $total_num, $wishing, $act_name, $remark, $scene_id = '', $riskinfo = '', $consume_mch_id = '') { |
|
| 69 | 69 | $data = array(); |
| 70 | - $data["wxappid"] = $this->config["app_id"];//NOTE: WXappid |
|
| 70 | + $data["wxappid"] = $this->config["app_id"]; //NOTE: WXappid |
|
| 71 | 71 | $data["mch_billno"] = $mch_billno; |
| 72 | 72 | $data["send_name"] = $send_name; |
| 73 | 73 | $data["re_openid"] = $re_openid; |
| 74 | 74 | $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)"); |
|
| 75 | + if ($total_amount > 20000 && trim($scene_id) == '') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)"); |
|
| 76 | 76 | $data["total_num"] = $total_num; |
| 77 | 77 | $data["amt_type"] = 'ALL_RAND'; //红包金额设置方式 ALL_RAND—全部随机 |
| 78 | 78 | $data["wishing"] = $wishing; |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | * @throws Exception |
| 93 | 93 | * @link https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_6&index=5 |
| 94 | 94 | */ |
| 95 | - public function getHbInfo($mch_billno){ |
|
| 95 | + public function getHbInfo($mch_billno) { |
|
| 96 | 96 | $data = array(); |
| 97 | 97 | $data["mch_billno"] = $mch_billno; |
| 98 | 98 | $data["appid"] = $this->config["app_id"]; |
@@ -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; |
@@ -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,19 +25,19 @@ discard block |
||
| 25 | 25 | * @return array |
| 26 | 26 | * @throws Exception |
| 27 | 27 | */ |
| 28 | - public function transferWallet($partner_trade_no,$openid,$amount,$desc,$spbill_create_ip = null,$re_user_name = null,$check_name = WechatPay::CHECKNAME_FORCECHECK){ |
|
| 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) throw new Exception('Real name is required'); |
|
| 31 | 31 | $data["mch_appid"] = $this->config["app_id"]; |
| 32 | 32 | $data["mchid"] = $this->config["mch_id"]; |
| 33 | 33 | $data["partner_trade_no"] = $partner_trade_no; |
| 34 | 34 | $data["openid"] = $openid; |
| 35 | 35 | $data["amount"] = $amount; |
| 36 | 36 | $data["desc"] = $desc; |
| 37 | - $data['spbill_create_ip'] = $spbill_create_ip?:$_SERVER['SERVER_ADDR']; |
|
| 37 | + $data['spbill_create_ip'] = $spbill_create_ip ?: $_SERVER['SERVER_ADDR']; |
|
| 38 | 38 | $data["check_name"] = $check_name; |
| 39 | 39 | $data["re_user_name"] = $re_user_name; |
| 40 | - $result = $this->post(self::URL_TRANSFER_WALLET,$data,true); |
|
| 40 | + $result = $this->post(self::URL_TRANSFER_WALLET, $data, true); |
|
| 41 | 41 | return $result; |
| 42 | 42 | } |
| 43 | 43 | |
@@ -47,12 +47,12 @@ discard block |
||
| 47 | 47 | * @param $partner_trade_no |
| 48 | 48 | * @return array |
| 49 | 49 | */ |
| 50 | - public function queryTransferWallet($partner_trade_no){ |
|
| 50 | + public function queryTransferWallet($partner_trade_no) { |
|
| 51 | 51 | $data = array(); |
| 52 | 52 | $data["appid"] = $this->config["app_id"]; |
| 53 | 53 | $data["mch_id"] = $this->config["mch_id"]; |
| 54 | 54 | $data["partner_trade_no"] = $partner_trade_no; |
| 55 | - $result = $this->post(self::URL_QUERY_TRANSFER_WALLET,$data,true); |
|
| 55 | + $result = $this->post(self::URL_QUERY_TRANSFER_WALLET, $data, true); |
|
| 56 | 56 | return $result; |
| 57 | 57 | } |
| 58 | 58 | |
@@ -68,8 +68,8 @@ discard block |
||
| 68 | 68 | * @return array |
| 69 | 69 | * @throws Exception |
| 70 | 70 | */ |
| 71 | - 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"); |
|
| 71 | + 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"); |
|
| 73 | 73 | $data = array(); |
| 74 | 74 | $data["partner_trade_no"] = $partner_trade_no; |
| 75 | 75 | $enc_bank_no = $this->rsaEncrypt($bank_no); |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $data["bank_code"] = $bank_code; |
| 80 | 80 | $data["desc"] = $desc; |
| 81 | 81 | $data["amount"] = $amount; |
| 82 | - $result = $this->post(self::URL_TRANSFER_BANKCARD,$data,true); |
|
| 82 | + $result = $this->post(self::URL_TRANSFER_BANKCARD, $data, true); |
|
| 83 | 83 | return $result; |
| 84 | 84 | } |
| 85 | 85 | |
@@ -89,12 +89,12 @@ discard block |
||
| 89 | 89 | * @param $partner_trade_no |
| 90 | 90 | * @return array |
| 91 | 91 | */ |
| 92 | - public function queryTransferBankCard($partner_trade_no){ |
|
| 92 | + public function queryTransferBankCard($partner_trade_no) { |
|
| 93 | 93 | $data = array(); |
| 94 | 94 | $data["appid"] = $this->config["app_id"]; |
| 95 | 95 | $data["mch_id"] = $this->config["mch_id"]; |
| 96 | 96 | $data["partner_trade_no"] = $partner_trade_no; |
| 97 | - $result = $this->post(self::URL_QUERY_TRANSFER_WALLET,$data,true); |
|
| 97 | + $result = $this->post(self::URL_QUERY_TRANSFER_WALLET, $data, true); |
|
| 98 | 98 | return $result; |
| 99 | 99 | } |
| 100 | 100 | |
@@ -105,18 +105,18 @@ discard block |
||
| 105 | 105 | * @return string |
| 106 | 106 | * @throws Exception |
| 107 | 107 | */ |
| 108 | - public function getPublicKey($refresh = false){ |
|
| 109 | - if(!$this->publicKey) { |
|
| 108 | + public function getPublicKey($refresh = false) { |
|
| 109 | + if (!$this->publicKey) { |
|
| 110 | 110 | if (!$refresh && file_exists($this->config["rsa_pubkey_path"])) { |
| 111 | 111 | $this->publicKey = file_get_contents($this->config["rsa_pubkey_path"]); |
| 112 | - }else{ |
|
| 112 | + }else { |
|
| 113 | 113 | $data = array(); |
| 114 | 114 | $data["mch_id"] = $this->config["mch_id"]; |
| 115 | 115 | $data["sign_type"] = $this->config["sign_type"]; |
| 116 | 116 | $result = $this->post(self::URL_GETPUBLICKEY, $data, true); |
| 117 | 117 | $pubkey = $result['pub_key']; |
| 118 | 118 | $this->publicKey = $this->convertPKCS1toPKCS8($pubkey); |
| 119 | - if($fp = @fopen($this->config["rsa_pubkey_path"], "w")) { |
|
| 119 | + if ($fp = @fopen($this->config["rsa_pubkey_path"], "w")) { |
|
| 120 | 120 | fwrite($fp, $this->publicKey); |
| 121 | 121 | fclose($fp); |
| 122 | 122 | } |
@@ -125,16 +125,16 @@ discard block |
||
| 125 | 125 | return $this->publicKey; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - public function setPublicKey($publicKey){ |
|
| 128 | + public function setPublicKey($publicKey) { |
|
| 129 | 129 | $this->publicKey = $publicKey; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - private function convertPKCS1toPKCS8($pkcs1){ |
|
| 132 | + private function convertPKCS1toPKCS8($pkcs1) { |
|
| 133 | 133 | $start_key = $pkcs1; |
| 134 | 134 | $start_key = str_replace('-----BEGIN RSA PUBLIC KEY-----', '', $start_key); |
| 135 | 135 | $start_key = trim(str_replace('-----END RSA PUBLIC KEY-----', '', $start_key)); |
| 136 | - $key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' . str_replace("\n", '', $start_key); |
|
| 137 | - $key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($key, 64, "\n", true) . "\n-----END PUBLIC KEY-----"; |
|
| 136 | + $key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A'.str_replace("\n", '', $start_key); |
|
| 137 | + $key = "-----BEGIN PUBLIC KEY-----\n".wordwrap($key, 64, "\n", true)."\n-----END PUBLIC KEY-----"; |
|
| 138 | 138 | return $key; |
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | \ No newline at end of file |
@@ -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); |
@@ -109,7 +113,7 @@ discard block |
||
| 109 | 113 | if(!$this->publicKey) { |
| 110 | 114 | if (!$refresh && file_exists($this->config["rsa_pubkey_path"])) { |
| 111 | 115 | $this->publicKey = file_get_contents($this->config["rsa_pubkey_path"]); |
| 112 | - }else{ |
|
| 116 | + } else{ |
|
| 113 | 117 | $data = array(); |
| 114 | 118 | $data["mch_id"] = $this->config["mch_id"]; |
| 115 | 119 | $data["sign_type"] = $this->config["sign_type"]; |
@@ -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"]; |