@@ -5,9 +5,9 @@ discard block |
||
| 5 | 5 | */ |
| 6 | 6 | namespace zhangv\wechat; |
| 7 | 7 | |
| 8 | -class HttpClient{ |
|
| 8 | +class HttpClient { |
|
| 9 | 9 | |
| 10 | - const GET = 'get',POST = 'post', DELETE = 'delete',PUT = 'put'; |
|
| 10 | + const GET = 'get', POST = 'post', DELETE = 'delete', PUT = 'put'; |
|
| 11 | 11 | private $instance = null; |
| 12 | 12 | private $errNo = null; |
| 13 | 13 | private $info = null; |
@@ -17,12 +17,12 @@ discard block |
||
| 17 | 17 | $this->initInstance($timeout); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - public function initInstance($timeout){ |
|
| 21 | - if(!$this->instance) { |
|
| 20 | + public function initInstance($timeout) { |
|
| 21 | + if (!$this->instance) { |
|
| 22 | 22 | $this->instance = curl_init(); |
| 23 | 23 | if ($timeout < 1) { |
| 24 | 24 | curl_setopt($this->instance, CURLOPT_TIMEOUT_MS, intval($timeout * 1000)); |
| 25 | - } else { |
|
| 25 | + }else { |
|
| 26 | 26 | curl_setopt($this->instance, CURLOPT_TIMEOUT, intval($timeout)); |
| 27 | 27 | } |
| 28 | 28 | curl_setopt($this->instance, CURLOPT_RETURNTRANSFER, true); |
@@ -31,26 +31,26 @@ discard block |
||
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - public function get($url,$params = array(),$headers = array(),$opts = array()) { |
|
| 34 | + public function get($url, $params = array(), $headers = array(), $opts = array()) { |
|
| 35 | 35 | if (!$this->instance) $this->initInstance($this->timeout); |
| 36 | - if($params && count($params) > 0) $url .= '?' . http_build_query($params); |
|
| 36 | + if ($params && count($params) > 0) $url .= '?'.http_build_query($params); |
|
| 37 | 37 | curl_setopt($this->instance, CURLOPT_URL, $url); |
| 38 | 38 | curl_setopt($this->instance, CURLOPT_HTTPGET, true); |
| 39 | 39 | curl_setopt($this->instance, CURLOPT_HTTPHEADER, $headers); |
| 40 | - curl_setopt_array($this->instance,$opts); |
|
| 40 | + curl_setopt_array($this->instance, $opts); |
|
| 41 | 41 | $result = $this->execute(); |
| 42 | 42 | curl_close($this->instance); |
| 43 | 43 | $this->instance = null; |
| 44 | 44 | return $result; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - public function post($url, $params = array(),$headers = array(),$opts = array()) { |
|
| 47 | + public function post($url, $params = array(), $headers = array(), $opts = array()) { |
|
| 48 | 48 | if (!$this->instance) $this->initInstance($this->timeout); |
| 49 | 49 | curl_setopt($this->instance, CURLOPT_URL, $url); |
| 50 | 50 | curl_setopt($this->instance, CURLOPT_POST, true); |
| 51 | 51 | curl_setopt($this->instance, CURLOPT_POSTFIELDS, $params); |
| 52 | 52 | curl_setopt($this->instance, CURLOPT_HTTPHEADER, $headers); |
| 53 | - curl_setopt_array($this->instance,$opts); |
|
| 53 | + curl_setopt_array($this->instance, $opts); |
|
| 54 | 54 | $result = $this->execute(); |
| 55 | 55 | curl_close($this->instance); |
| 56 | 56 | $this->instance = null; |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | curl_setopt_array($this->instance, $optArray); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - public function getInfo(){ |
|
| 73 | + public function getInfo() { |
|
| 74 | 74 | return $this->info; |
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | \ No newline at end of file |
@@ -32,8 +32,12 @@ discard block |
||
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | public function get($url,$params = array(),$headers = array(),$opts = array()) { |
| 35 | - if (!$this->instance) $this->initInstance($this->timeout); |
|
| 36 | - if($params && count($params) > 0) $url .= '?' . http_build_query($params); |
|
| 35 | + if (!$this->instance) { |
|
| 36 | + $this->initInstance($this->timeout); |
|
| 37 | + } |
|
| 38 | + if($params && count($params) > 0) { |
|
| 39 | + $url .= '?' . http_build_query($params); |
|
| 40 | + } |
|
| 37 | 41 | curl_setopt($this->instance, CURLOPT_URL, $url); |
| 38 | 42 | curl_setopt($this->instance, CURLOPT_HTTPGET, true); |
| 39 | 43 | curl_setopt($this->instance, CURLOPT_HTTPHEADER, $headers); |
@@ -45,7 +49,9 @@ discard block |
||
| 45 | 49 | } |
| 46 | 50 | |
| 47 | 51 | public function post($url, $params = array(),$headers = array(),$opts = array()) { |
| 48 | - if (!$this->instance) $this->initInstance($this->timeout); |
|
| 52 | + if (!$this->instance) { |
|
| 53 | + $this->initInstance($this->timeout); |
|
| 54 | + } |
|
| 49 | 55 | curl_setopt($this->instance, CURLOPT_URL, $url); |
| 50 | 56 | curl_setopt($this->instance, CURLOPT_POST, true); |
| 51 | 57 | curl_setopt($this->instance, CURLOPT_POSTFIELDS, $params); |
@@ -65,8 +71,12 @@ discard block |
||
| 65 | 71 | } |
| 66 | 72 | |
| 67 | 73 | public function setOpt($optArray) { |
| 68 | - if (!$this->instance) return; |
|
| 69 | - if (!is_array($optArray)) throw new \Exception("Argument is not an array!"); |
|
| 74 | + if (!$this->instance) { |
|
| 75 | + return; |
|
| 76 | + } |
|
| 77 | + if (!is_array($optArray)) { |
|
| 78 | + throw new \Exception("Argument is not an array!"); |
|
| 79 | + } |
|
| 70 | 80 | curl_setopt_array($this->instance, $optArray); |
| 71 | 81 | } |
| 72 | 82 | |
@@ -17,50 +17,50 @@ discard block |
||
| 17 | 17 | private $httpClient = null; |
| 18 | 18 | private $accessToken = null; |
| 19 | 19 | |
| 20 | - public function __construct($appId,$appSecret) { |
|
| 20 | + public function __construct($appId, $appSecret) { |
|
| 21 | 21 | $this->appId = $appId; |
| 22 | 22 | $this->appSecret = $appSecret; |
| 23 | 23 | $this->httpClient = new HttpClient(); |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - public function setHttpClient($httpClient){ |
|
| 26 | + public function setHttpClient($httpClient) { |
|
| 27 | 27 | $this->httpClient = $httpClient; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - public function setAccessToken($accessToken){ |
|
| 30 | + public function setAccessToken($accessToken) { |
|
| 31 | 31 | $this->accessToken = $accessToken; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - public function authorizeURI($redirectURI,$scope = 'snsapi_userinfo',$state = ''){ |
|
| 34 | + public function authorizeURI($redirectURI, $scope = 'snsapi_userinfo', $state = '') { |
|
| 35 | 35 | $redirectURI = urlencode($redirectURI); |
| 36 | 36 | return "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$this->appId}&redirect_uri={$redirectURI}&response_type=code&scope=$scope&state=$state#wechat_redirect"; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - public function authorize($code){ |
|
| 39 | + public function authorize($code) { |
|
| 40 | 40 | $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$this->appId}&secret={$this->appSecret}&code=$code&grant_type=authorization_code"; |
| 41 | 41 | $this->responseJSON = $this->httpClient->get($url); |
| 42 | 42 | return json_decode($this->responseJSON); |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - public function getUserInfo($openId){ |
|
| 45 | + public function getUserInfo($openId) { |
|
| 46 | 46 | $url = "https://api.weixin.qq.com/sns/userinfo?access_token={$this->accessToken}&openid=$openId&lang=zh_CN"; |
| 47 | 47 | $this->responseJSON = $this->httpClient->get($url); |
| 48 | 48 | return json_decode($this->responseJSON); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - public function refreshToken($refreshToken){ |
|
| 51 | + public function refreshToken($refreshToken) { |
|
| 52 | 52 | $url = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid={$this->appId}&grant_type=refresh_token&refresh_token=$refreshToken"; |
| 53 | 53 | $this->responseJSON = $this->httpClient->get($url); |
| 54 | 54 | return $this->responseJSON; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - public function verifyToken($accessToken,$openId){ |
|
| 57 | + public function verifyToken($accessToken, $openId) { |
|
| 58 | 58 | $url = "https://api.weixin.qq.com/sns/auth?access_token=$accessToken&openid=$openId"; |
| 59 | 59 | $this->responseJSON = $this->httpClient->get($url); |
| 60 | 60 | return $this->responseJSON; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - public function getAccessToken(){ |
|
| 63 | + public function getAccessToken() { |
|
| 64 | 64 | $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->appId}&secret={$this->appSecret}"; |
| 65 | 65 | $this->responseJSON = $this->httpClient->get($url); |
| 66 | 66 | $json = json_decode($this->responseJSON); |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | return $this->accessToken; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - public function getTicket(){ |
|
| 71 | + public function getTicket() { |
|
| 72 | 72 | $accessToken = $this->getAccessToken(); |
| 73 | 73 | // $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$accessToken"; |
| 74 | 74 | $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$accessToken"; |
@@ -655,7 +655,7 @@ |
||
| 655 | 655 | * @return array |
| 656 | 656 | */ |
| 657 | 657 | public function report($interface_url,$execution_time,$return_code,$result_code,$user_ip,$out_trade_no = null,$time = null,$device_info = null, |
| 658 | - $return_msg = null,$err_code = null,$err_code_des = null){ |
|
| 658 | + $return_msg = null,$err_code = null,$err_code_des = null){ |
|
| 659 | 659 | $data = array(); |
| 660 | 660 | $data["appid"] = $this->config["app_id"]; |
| 661 | 661 | $data["interface_url"] = $interface_url; |
@@ -8,9 +8,9 @@ discard block |
||
| 8 | 8 | use \Exception; |
| 9 | 9 | |
| 10 | 10 | class WechatPay { |
| 11 | - const TRADETYPE_JSAPI = 'JSAPI',TRADETYPE_NATIVE = 'NATIVE',TRADETYPE_APP = 'APP',TRADETYPE_MWEB = 'MWEB'; |
|
| 11 | + const TRADETYPE_JSAPI = 'JSAPI', TRADETYPE_NATIVE = 'NATIVE', TRADETYPE_APP = 'APP', TRADETYPE_MWEB = 'MWEB'; |
|
| 12 | 12 | const SIGNTYPE_MD5 = 'MD5', SIGNTYPE_HMACSHA256 = 'HMAC-SHA256'; |
| 13 | - const CHECKNAME_FORCECHECK = 'FORCE_CHECK',CHECKNAME_NOCHECK = 'NO_CHECK'; |
|
| 13 | + const CHECKNAME_FORCECHECK = 'FORCE_CHECK', CHECKNAME_NOCHECK = 'NO_CHECK'; |
|
| 14 | 14 | |
| 15 | 15 | const URL_UNIFIEDORDER = "https://api.mch.weixin.qq.com/pay/unifiedorder"; |
| 16 | 16 | const URL_ORDERQUERY = "https://api.mch.weixin.qq.com/pay/orderquery"; |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | const URL_GETPUBLICKEY = 'https://fraud.mch.weixin.qq.com/risk/getpublickey'; |
| 42 | 42 | public static $BANKCODE = ['工商银行' => '1002', '农业银行' => '1005', '中国银行' => '1026', '建设银行' => '1003', '招商银行' => '1001', |
| 43 | 43 | '邮储银行' => '1066', '交通银行' => '1020', '浦发银行' => '1004', '民生银行' => '1006', '兴业银行' => '1009', '平安银行' => '1010', |
| 44 | - '中信银行' => '1021', '华夏银行' => '1025', '广发银行' => '1027', '光大银行' => '1022', '北京银行' => '1032', '宁波银行' => '1056',]; |
|
| 44 | + '中信银行' => '1021', '华夏银行' => '1025', '广发银行' => '1027', '光大银行' => '1022', '北京银行' => '1032', '宁波银行' => '1056', ]; |
|
| 45 | 45 | |
| 46 | 46 | public $getSignKeyUrl = "https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey"; |
| 47 | 47 | public $sandbox = false; |
@@ -80,18 +80,18 @@ discard block |
||
| 80 | 80 | $this->httpClient = new HttpClient(5); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - public function getWechatOAuth(){ |
|
| 84 | - if(!$this->wechatOAuth){ |
|
| 85 | - $this->wechatOAuth = new WechatOAuth($this->config['app_id'],$this->config['app_secret']); |
|
| 83 | + public function getWechatOAuth() { |
|
| 84 | + if (!$this->wechatOAuth) { |
|
| 85 | + $this->wechatOAuth = new WechatOAuth($this->config['app_id'], $this->config['app_secret']); |
|
| 86 | 86 | } |
| 87 | 87 | return $this->wechatOAuth; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - public function setConfig($config){ |
|
| 90 | + public function setConfig($config) { |
|
| 91 | 91 | $this->config = $config; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - public function setHttpClient($httpClient){ |
|
| 94 | + public function setHttpClient($httpClient) { |
|
| 95 | 95 | $this->httpClient = $httpClient; |
| 96 | 96 | } |
| 97 | 97 | |
@@ -106,15 +106,15 @@ discard block |
||
| 106 | 106 | * @param $ext array |
| 107 | 107 | * @return string |
| 108 | 108 | */ |
| 109 | - public function getPrepayId($body,$out_trade_no,$total_fee,$openid,$spbill_create_ip = null,$ext = null) { |
|
| 110 | - $data = ($ext && is_array($ext))?$ext:array(); |
|
| 109 | + public function getPrepayId($body, $out_trade_no, $total_fee, $openid, $spbill_create_ip = null, $ext = null) { |
|
| 110 | + $data = ($ext && is_array($ext)) ? $ext : array(); |
|
| 111 | 111 | $data["body"] = $body; |
| 112 | 112 | $data["out_trade_no"] = $out_trade_no; |
| 113 | 113 | $data["total_fee"] = $total_fee; |
| 114 | - $data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["REMOTE_ADDR"]; |
|
| 114 | + $data["spbill_create_ip"] = $spbill_create_ip ?: $_SERVER["REMOTE_ADDR"]; |
|
| 115 | 115 | $data["notify_url"] = $this->config["notify_url"]; |
| 116 | 116 | $data["trade_type"] = WechatPay::TRADETYPE_JSAPI; |
| 117 | - $data["openid"] = $openid; |
|
| 117 | + $data["openid"] = $openid; |
|
| 118 | 118 | $result = $this->unifiedOrder($data); |
| 119 | 119 | return $result["prepay_id"]; |
| 120 | 120 | } |
@@ -129,8 +129,8 @@ discard block |
||
| 129 | 129 | * @param $ext array |
| 130 | 130 | * @return string |
| 131 | 131 | */ |
| 132 | - public function getPrepayIdAPP($body,$out_trade_no,$total_fee,$spbill_create_ip,$ext = null) { |
|
| 133 | - $data = ($ext && is_array($ext))?$ext:array(); |
|
| 132 | + public function getPrepayIdAPP($body, $out_trade_no, $total_fee, $spbill_create_ip, $ext = null) { |
|
| 133 | + $data = ($ext && is_array($ext)) ? $ext : array(); |
|
| 134 | 134 | $data["body"] = $body; |
| 135 | 135 | $data["out_trade_no"] = $out_trade_no; |
| 136 | 136 | $data["total_fee"] = $total_fee; |
@@ -152,12 +152,12 @@ discard block |
||
| 152 | 152 | * @param $ext array |
| 153 | 153 | * @return null |
| 154 | 154 | */ |
| 155 | - public function getCodeUrl($body,$out_trade_no,$total_fee,$product_id,$spbill_create_ip = null,$ext = null){ |
|
| 156 | - $data = ($ext && is_array($ext))?$ext:array(); |
|
| 155 | + public function getCodeUrl($body, $out_trade_no, $total_fee, $product_id, $spbill_create_ip = null, $ext = null) { |
|
| 156 | + $data = ($ext && is_array($ext)) ? $ext : array(); |
|
| 157 | 157 | $data["body"] = $body; |
| 158 | 158 | $data["out_trade_no"] = $out_trade_no; |
| 159 | 159 | $data["total_fee"] = $total_fee; |
| 160 | - $data["spbill_create_ip"] = $spbill_create_ip?:$_SERVER["SERVER_ADDR"]; |
|
| 160 | + $data["spbill_create_ip"] = $spbill_create_ip ?: $_SERVER["SERVER_ADDR"]; |
|
| 161 | 161 | $data["notify_url"] = $this->config["notify_url"]; |
| 162 | 162 | $data["trade_type"] = self::TRADETYPE_NATIVE; |
| 163 | 163 | $data["product_id"] = $product_id; |
@@ -175,15 +175,15 @@ discard block |
||
| 175 | 175 | * @return string |
| 176 | 176 | * @throws Exception |
| 177 | 177 | */ |
| 178 | - public function getMwebUrl($body,$out_trade_no,$total_fee,$ext = null){ |
|
| 179 | - $data = ($ext && is_array($ext))?$ext:array(); |
|
| 178 | + public function getMwebUrl($body, $out_trade_no, $total_fee, $ext = null) { |
|
| 179 | + $data = ($ext && is_array($ext)) ? $ext : array(); |
|
| 180 | 180 | $data["body"] = $body; |
| 181 | 181 | $data["out_trade_no"] = $out_trade_no; |
| 182 | 182 | $data["total_fee"] = $total_fee; |
| 183 | - $data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:''; |
|
| 183 | + $data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : ''; |
|
| 184 | 184 | $data["notify_url"] = $this->config["notify_url"]; |
| 185 | 185 | $data["trade_type"] = self::TRADETYPE_MWEB; |
| 186 | - if(!isset($this->config['h5_scene_info'])) throw new \Exception('h5_scene_info should be configured'); |
|
| 186 | + if (!isset($this->config['h5_scene_info'])) throw new \Exception('h5_scene_info should be configured'); |
|
| 187 | 187 | $data["scene_info"] = json_encode($this->config['h5_scene_info']); |
| 188 | 188 | $result = $this->unifiedOrder($data); |
| 189 | 189 | return $result["mweb_url"]; |
@@ -198,21 +198,21 @@ discard block |
||
| 198 | 198 | private function unifiedOrder($params) { |
| 199 | 199 | $data = array(); |
| 200 | 200 | $data["appid"] = $this->config["app_id"]; |
| 201 | - $data["device_info"] = (isset($params['device_info'])&&trim($params['device_info'])!='')?$params['device_info']:null; |
|
| 201 | + $data["device_info"] = (isset($params['device_info']) && trim($params['device_info']) != '') ? $params['device_info'] : null; |
|
| 202 | 202 | $data["body"] = $params['body']; |
| 203 | - $data["detail"] = isset($params['detail'])?$params['detail']:null;//optional |
|
| 204 | - $data["attach"] = isset($params['attach'])?$params['attach']:null;//optional |
|
| 205 | - $data["out_trade_no"] = isset($params['out_trade_no'])?$params['out_trade_no']:null; |
|
| 206 | - $data["fee_type"] = isset($params['fee_type'])?$params['fee_type']:'CNY'; |
|
| 203 | + $data["detail"] = isset($params['detail']) ? $params['detail'] : null; //optional |
|
| 204 | + $data["attach"] = isset($params['attach']) ? $params['attach'] : null; //optional |
|
| 205 | + $data["out_trade_no"] = isset($params['out_trade_no']) ? $params['out_trade_no'] : null; |
|
| 206 | + $data["fee_type"] = isset($params['fee_type']) ? $params['fee_type'] : 'CNY'; |
|
| 207 | 207 | $data["total_fee"] = $params['total_fee']; |
| 208 | 208 | $data["spbill_create_ip"] = $params['spbill_create_ip']; |
| 209 | - $data["time_start"] = isset($params['time_start'])?$params['time_start']:null;//optional |
|
| 210 | - $data["time_expire"] = isset($params['time_expire'])?$params['time_expire']:null;//optional |
|
| 211 | - $data["goods_tag"] = isset($params['goods_tag'])?$params['goods_tag']:null; |
|
| 209 | + $data["time_start"] = isset($params['time_start']) ? $params['time_start'] : null; //optional |
|
| 210 | + $data["time_expire"] = isset($params['time_expire']) ? $params['time_expire'] : null; //optional |
|
| 211 | + $data["goods_tag"] = isset($params['goods_tag']) ? $params['goods_tag'] : null; |
|
| 212 | 212 | $data["notify_url"] = $this->config["notify_url"]; |
| 213 | 213 | $data["trade_type"] = $params['trade_type']; |
| 214 | - $data["product_id"] = isset($params['product_id'])?$params['product_id']:null;//required when trade_type = NATIVE |
|
| 215 | - $data["openid"] = isset($params['openid'])?$params['openid']:null;//required when trade_type = JSAPI |
|
| 214 | + $data["product_id"] = isset($params['product_id']) ? $params['product_id'] : null; //required when trade_type = NATIVE |
|
| 215 | + $data["openid"] = isset($params['openid']) ? $params['openid'] : null; //required when trade_type = JSAPI |
|
| 216 | 216 | $result = $this->post(self::URL_UNIFIEDORDER, $data); |
| 217 | 217 | return $result; |
| 218 | 218 | } |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | * @param $transaction_id string 微信订单号 |
| 224 | 224 | * @return array |
| 225 | 225 | */ |
| 226 | - public function queryOrderByTransactionId($transaction_id){ |
|
| 226 | + public function queryOrderByTransactionId($transaction_id) { |
|
| 227 | 227 | $data = array(); |
| 228 | 228 | $data["appid"] = $this->config["app_id"]; |
| 229 | 229 | $data["transaction_id"] = $transaction_id; |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | * @param $out_trade_no string 商户订单号 |
| 238 | 238 | * @return array |
| 239 | 239 | */ |
| 240 | - public function queryOrderByOutTradeNo($out_trade_no){ |
|
| 240 | + public function queryOrderByOutTradeNo($out_trade_no) { |
|
| 241 | 241 | $data = array(); |
| 242 | 242 | $data["appid"] = $this->config["app_id"]; |
| 243 | 243 | $data["out_trade_no"] = $out_trade_no; |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | * @param $offset int 偏移 |
| 253 | 253 | * @return array |
| 254 | 254 | */ |
| 255 | - public function queryRefundByTransactionId($transaction_id,$offset = 0){ |
|
| 255 | + public function queryRefundByTransactionId($transaction_id, $offset = 0) { |
|
| 256 | 256 | $data = array(); |
| 257 | 257 | $data["appid"] = $this->config["app_id"]; |
| 258 | 258 | $data["transaction_id"] = $transaction_id; |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | * @param $offset int 偏移 |
| 268 | 268 | * @return array |
| 269 | 269 | */ |
| 270 | - public function queryRefundByOutTradeNo($out_trade_no,$offset = 0){ |
|
| 270 | + public function queryRefundByOutTradeNo($out_trade_no, $offset = 0) { |
|
| 271 | 271 | $data = array(); |
| 272 | 272 | $data["appid"] = $this->config["app_id"]; |
| 273 | 273 | $data["out_trade_no"] = $out_trade_no; |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | * @param $offset int 偏移 |
| 283 | 283 | * @return array |
| 284 | 284 | */ |
| 285 | - public function queryRefundByRefundId($refund_id,$offset = 0){ |
|
| 285 | + public function queryRefundByRefundId($refund_id, $offset = 0) { |
|
| 286 | 286 | $data = array(); |
| 287 | 287 | $data["appid"] = $this->config["app_id"]; |
| 288 | 288 | $data["refund_id"] = $refund_id; |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | * @param $offset int 偏移 |
| 298 | 298 | * @return array |
| 299 | 299 | */ |
| 300 | - public function queryRefundByOutRefundNo($out_refund_no,$offset = 0){ |
|
| 300 | + public function queryRefundByOutRefundNo($out_refund_no, $offset = 0) { |
|
| 301 | 301 | $data = array(); |
| 302 | 302 | $data["appid"] = $this->config["app_id"]; |
| 303 | 303 | $data["out_refund_no"] = $out_refund_no; |
@@ -311,11 +311,11 @@ discard block |
||
| 311 | 311 | * @param $out_trade_no string 商户订单号 |
| 312 | 312 | * @return array |
| 313 | 313 | */ |
| 314 | - public function closeOrder($out_trade_no){ |
|
| 314 | + public function closeOrder($out_trade_no) { |
|
| 315 | 315 | $data = array(); |
| 316 | 316 | $data["appid"] = $this->config["app_id"]; |
| 317 | 317 | $data["out_trade_no"] = $out_trade_no; |
| 318 | - $result = $this->post(self::URL_CLOSEORDER, $data,false); |
|
| 318 | + $result = $this->post(self::URL_CLOSEORDER, $data, false); |
|
| 319 | 319 | return $result; |
| 320 | 320 | } |
| 321 | 321 | |
@@ -330,14 +330,14 @@ discard block |
||
| 330 | 330 | * @param $ext array 扩展数组 |
| 331 | 331 | * @return array |
| 332 | 332 | */ |
| 333 | - public function refundByOutTradeNo($out_trade_no,$out_refund_no,$total_fee,$refund_fee,$ext = array()){ |
|
| 334 | - $data = ($ext && is_array($ext))?$ext:array(); |
|
| 333 | + public function refundByOutTradeNo($out_trade_no, $out_refund_no, $total_fee, $refund_fee, $ext = array()) { |
|
| 334 | + $data = ($ext && is_array($ext)) ? $ext : array(); |
|
| 335 | 335 | $data["appid"] = $this->config["app_id"]; |
| 336 | 336 | $data["out_trade_no"] = $out_trade_no; |
| 337 | 337 | $data["out_refund_no"] = $out_refund_no; |
| 338 | 338 | $data["total_fee"] = $total_fee; |
| 339 | 339 | $data["refund_fee"] = $refund_fee; |
| 340 | - $result = $this->post(self::URL_REFUND, $data,true); |
|
| 340 | + $result = $this->post(self::URL_REFUND, $data, true); |
|
| 341 | 341 | return $result; |
| 342 | 342 | } |
| 343 | 343 | |
@@ -352,14 +352,14 @@ discard block |
||
| 352 | 352 | * @param $ext array 扩展数组 |
| 353 | 353 | * @return array |
| 354 | 354 | */ |
| 355 | - public function refundByTransactionId($transaction_id,$out_refund_no,$total_fee,$refund_fee,$ext = array()){ |
|
| 356 | - $data = ($ext && is_array($ext))?$ext:array(); |
|
| 355 | + public function refundByTransactionId($transaction_id, $out_refund_no, $total_fee, $refund_fee, $ext = array()) { |
|
| 356 | + $data = ($ext && is_array($ext)) ? $ext : array(); |
|
| 357 | 357 | $data["appid"] = $this->config["app_id"]; |
| 358 | 358 | $data["transaction_id"] = $transaction_id; |
| 359 | 359 | $data["out_refund_no"] = $out_refund_no; |
| 360 | 360 | $data["total_fee"] = $total_fee; |
| 361 | 361 | $data["refund_fee"] = $refund_fee; |
| 362 | - $result = $this->post(self::URL_REFUND, $data,true); |
|
| 362 | + $result = $this->post(self::URL_REFUND, $data, true); |
|
| 363 | 363 | return $result; |
| 364 | 364 | } |
| 365 | 365 | |
@@ -369,11 +369,11 @@ discard block |
||
| 369 | 369 | * @param $out_trade_no string 商户订单号 |
| 370 | 370 | * @return array |
| 371 | 371 | */ |
| 372 | - public function reverseByOutTradeNo($out_trade_no){ |
|
| 372 | + public function reverseByOutTradeNo($out_trade_no) { |
|
| 373 | 373 | $data = array(); |
| 374 | 374 | $data["appid"] = $this->config["app_id"]; |
| 375 | 375 | $data["out_trade_no"] = $out_trade_no; |
| 376 | - $result = $this->post(self::URL_REVERSE, $data,true); |
|
| 376 | + $result = $this->post(self::URL_REVERSE, $data, true); |
|
| 377 | 377 | return $result; |
| 378 | 378 | } |
| 379 | 379 | |
@@ -383,11 +383,11 @@ discard block |
||
| 383 | 383 | * @param $transaction_id string 微信订单号 |
| 384 | 384 | * @return array |
| 385 | 385 | */ |
| 386 | - public function reverseByTransactionId($transaction_id){ |
|
| 386 | + public function reverseByTransactionId($transaction_id) { |
|
| 387 | 387 | $data = array(); |
| 388 | 388 | $data["appid"] = $this->config["app_id"]; |
| 389 | 389 | $data["transaction_id"] = $transaction_id; |
| 390 | - $result = $this->post(self::URL_REVERSE, $data,true); |
|
| 390 | + $result = $this->post(self::URL_REVERSE, $data, true); |
|
| 391 | 391 | return $result; |
| 392 | 392 | } |
| 393 | 393 | |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | * @param $bill_type string 类型 |
| 398 | 398 | * @return array |
| 399 | 399 | */ |
| 400 | - public function downloadBill($bill_date,$bill_type = 'ALL'){ |
|
| 400 | + public function downloadBill($bill_date, $bill_type = 'ALL') { |
|
| 401 | 401 | $data = array(); |
| 402 | 402 | $data["appid"] = $this->config["app_id"]; |
| 403 | 403 | $data["bill_date"] = $bill_date; |
@@ -423,14 +423,14 @@ discard block |
||
| 423 | 423 | * @throws Exception |
| 424 | 424 | * @ref https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3 |
| 425 | 425 | */ |
| 426 | - public function sendRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark,$scene_id = '',$riskinfo = '',$consume_mch_id = ''){ |
|
| 426 | + public function sendRedPack($mch_billno, $send_name, $re_openid, $total_amount, $total_num, $wishing, $act_name, $remark, $scene_id = '', $riskinfo = '', $consume_mch_id = '') { |
|
| 427 | 427 | $data = array(); |
| 428 | 428 | $data["wxappid"] = $this->config["app_id"]; |
| 429 | 429 | $data["mch_billno"] = $mch_billno; |
| 430 | 430 | $data["send_name"] = $send_name; |
| 431 | 431 | $data["re_openid"] = $re_openid; |
| 432 | 432 | $data["total_amount"] = $total_amount; |
| 433 | - if($total_amount > 20000 && trim($scene_id)=='') throw new \Exception("scene_id is required when total_amount beyond 20000"); |
|
| 433 | + if ($total_amount > 20000 && trim($scene_id) == '') throw new \Exception("scene_id is required when total_amount beyond 20000"); |
|
| 434 | 434 | $data["total_num"] = $total_num; |
| 435 | 435 | $data["wishing"] = $wishing; |
| 436 | 436 | $data["act_name"] = $act_name; |
@@ -459,14 +459,14 @@ discard block |
||
| 459 | 459 | * @throws Exception |
| 460 | 460 | * @ref https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5&index=4 |
| 461 | 461 | */ |
| 462 | - public function sendGroupRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark,$scene_id = '',$riskinfo = '',$consume_mch_id = ''){ |
|
| 462 | + public function sendGroupRedPack($mch_billno, $send_name, $re_openid, $total_amount, $total_num, $wishing, $act_name, $remark, $scene_id = '', $riskinfo = '', $consume_mch_id = '') { |
|
| 463 | 463 | $data = array(); |
| 464 | - $data["wxappid"] = $this->config["app_id"];//NOTE: WXappid |
|
| 464 | + $data["wxappid"] = $this->config["app_id"]; //NOTE: WXappid |
|
| 465 | 465 | $data["mch_billno"] = $mch_billno; |
| 466 | 466 | $data["send_name"] = $send_name; |
| 467 | 467 | $data["re_openid"] = $re_openid; |
| 468 | 468 | $data["total_amount"] = $total_amount; |
| 469 | - if($total_amount > 20000 && trim($scene_id)=='') throw new \Exception("scene_id is required when total_amount beyond 20000(200rmb)"); |
|
| 469 | + if ($total_amount > 20000 && trim($scene_id) == '') throw new \Exception("scene_id is required when total_amount beyond 20000(200rmb)"); |
|
| 470 | 470 | $data["total_num"] = $total_num; |
| 471 | 471 | $data["amt_type"] = 'ALL_RAND'; //红包金额设置方式 ALL_RAND—全部随机 |
| 472 | 472 | $data["wishing"] = $wishing; |
@@ -486,7 +486,7 @@ discard block |
||
| 486 | 486 | * @throws Exception |
| 487 | 487 | * @ref https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_6&index=5 |
| 488 | 488 | */ |
| 489 | - public function getHbInfo($mch_billno){ |
|
| 489 | + public function getHbInfo($mch_billno) { |
|
| 490 | 490 | $data = array(); |
| 491 | 491 | $data["mch_billno"] = $mch_billno; |
| 492 | 492 | $data["appid"] = $this->config["app_id"]; |
@@ -503,14 +503,14 @@ discard block |
||
| 503 | 503 | * @param int $limit 条数 |
| 504 | 504 | * @return array |
| 505 | 505 | */ |
| 506 | - public function batchQueryComment($begin_time,$end_time,$offset = 0,$limit = 200){ |
|
| 506 | + public function batchQueryComment($begin_time, $end_time, $offset = 0, $limit = 200) { |
|
| 507 | 507 | $data = array(); |
| 508 | 508 | $data["appid"] = $this->config["app_id"]; |
| 509 | 509 | $data["begin_time"] = $begin_time; |
| 510 | 510 | $data["end_time"] = $end_time; |
| 511 | 511 | $data["offset"] = $offset; |
| 512 | 512 | $data["limit"] = $limit; |
| 513 | - $data["sign"] = $this->sign($data,WechatPay::SIGNTYPE_HMACSHA256); |
|
| 513 | + $data["sign"] = $this->sign($data, WechatPay::SIGNTYPE_HMACSHA256); |
|
| 514 | 514 | $result = $this->post(self::URL_BATCHQUERYCOMMENT, $data, true); //cert is required |
| 515 | 515 | return $result; |
| 516 | 516 | } |
@@ -523,21 +523,21 @@ discard block |
||
| 523 | 523 | */ |
| 524 | 524 | public function getPackage($prepay_id, $trade_type = WechatPay::TRADETYPE_JSAPI) { |
| 525 | 525 | $data = array(); |
| 526 | - if ($trade_type == WechatPay::TRADETYPE_JSAPI){ |
|
| 526 | + if ($trade_type == WechatPay::TRADETYPE_JSAPI) { |
|
| 527 | 527 | $data["package"] = "prepay_id=$prepay_id"; |
| 528 | 528 | $data["timeStamp"] = time(); |
| 529 | 529 | $data["nonceStr"] = $this->getNonceStr(); |
| 530 | 530 | $data["appId"] = $this->config["app_id"]; |
| 531 | 531 | $data["signType"] = "MD5"; |
| 532 | 532 | $data["paySign"] = $this->sign($data); |
| 533 | - } else if ($trade_type == WechatPay::TRADETYPE_APP){ |
|
| 533 | + }else if ($trade_type == WechatPay::TRADETYPE_APP) { |
|
| 534 | 534 | $data["package"] = "Sign=WXPay"; |
| 535 | 535 | $data['prepayid'] = $prepay_id; |
| 536 | 536 | $data['partnerid'] = $this->config["mch_id"]; |
| 537 | 537 | $data["timestamp"] = time(); |
| 538 | 538 | $data["noncestr"] = $this->getNonceStr(); |
| 539 | 539 | $data["appid"] = $this->config["app_id"]; |
| 540 | - $data["sign"] = $this->sign($data); |
|
| 540 | + $data["sign"] = $this->sign($data); |
|
| 541 | 541 | } |
| 542 | 542 | return $data; |
| 543 | 543 | } |
@@ -553,15 +553,15 @@ discard block |
||
| 553 | 553 | * @param array $ext |
| 554 | 554 | * @return array |
| 555 | 555 | */ |
| 556 | - public function microPay($body,$out_trade_no,$total_fee,$spbill_create_ip,$auth_code,$ext = array()){ |
|
| 557 | - $data = ($ext && is_array($ext))?$ext:array(); |
|
| 556 | + public function microPay($body, $out_trade_no, $total_fee, $spbill_create_ip, $auth_code, $ext = array()) { |
|
| 557 | + $data = ($ext && is_array($ext)) ? $ext : array(); |
|
| 558 | 558 | $data["appid"] = $this->config["app_id"]; |
| 559 | 559 | $data["body"] = $body; |
| 560 | 560 | $data["out_trade_no"] = $out_trade_no; |
| 561 | 561 | $data["total_fee"] = $total_fee; |
| 562 | 562 | $data["spbill_create_ip"] = $spbill_create_ip; |
| 563 | 563 | $data["auth_code"] = $auth_code; |
| 564 | - $result = $this->post(self::URL_MICROPAY,$data,false); |
|
| 564 | + $result = $this->post(self::URL_MICROPAY, $data, false); |
|
| 565 | 565 | return $result; |
| 566 | 566 | } |
| 567 | 567 | |
@@ -572,17 +572,17 @@ discard block |
||
| 572 | 572 | * @return null |
| 573 | 573 | * @throws Exception |
| 574 | 574 | */ |
| 575 | - public function onPaidNotify($notify_data,callable $callback = null){ |
|
| 576 | - if(!is_array($notify_data)){ |
|
| 575 | + public function onPaidNotify($notify_data, callable $callback = null) { |
|
| 576 | + if (!is_array($notify_data)) { |
|
| 577 | 577 | $notify_data = $this->xml2array($notify_data); |
| 578 | 578 | } |
| 579 | - if($this->validateSign($notify_data)){ |
|
| 580 | - if($callback && is_callable($callback)){ |
|
| 581 | - return call_user_func_array( $callback , [$notify_data] ); |
|
| 582 | - }else{ |
|
| 579 | + if ($this->validateSign($notify_data)) { |
|
| 580 | + if ($callback && is_callable($callback)) { |
|
| 581 | + return call_user_func_array($callback, [$notify_data]); |
|
| 582 | + }else { |
|
| 583 | 583 | $this->responseNotify(); |
| 584 | 584 | } |
| 585 | - }else{ |
|
| 585 | + }else { |
|
| 586 | 586 | throw new \Exception('Invalid paid notify data'); |
| 587 | 587 | } |
| 588 | 588 | } |
@@ -594,17 +594,17 @@ discard block |
||
| 594 | 594 | * @return null |
| 595 | 595 | * @throws Exception |
| 596 | 596 | */ |
| 597 | - public function onRefundedNotify($notify_data,callable $callback = null){ |
|
| 598 | - if(!is_array($notify_data)){ |
|
| 597 | + public function onRefundedNotify($notify_data, callable $callback = null) { |
|
| 598 | + if (!is_array($notify_data)) { |
|
| 599 | 599 | $notify_data = $this->xml2array($notify_data); |
| 600 | 600 | } |
| 601 | - if($this->validateSign($notify_data)){ |
|
| 602 | - if($callback && is_callable($callback)){ |
|
| 603 | - return call_user_func_array( $callback , $notify_data ); |
|
| 604 | - }else{ |
|
| 601 | + if ($this->validateSign($notify_data)) { |
|
| 602 | + if ($callback && is_callable($callback)) { |
|
| 603 | + return call_user_func_array($callback, $notify_data); |
|
| 604 | + }else { |
|
| 605 | 605 | $this->responseNotify(); |
| 606 | 606 | } |
| 607 | - }else{ |
|
| 607 | + }else { |
|
| 608 | 608 | throw new \Exception('Invalid refunded notify data'); |
| 609 | 609 | } |
| 610 | 610 | } |
@@ -628,7 +628,7 @@ discard block |
||
| 628 | 628 | * @param $return_code string 返回状态码 SUCCESS/FAIL |
| 629 | 629 | * @param $return_msg string 返回信息 |
| 630 | 630 | */ |
| 631 | - public function responseNotify($return_code="SUCCESS", $return_msg= 'OK') { |
|
| 631 | + public function responseNotify($return_code = "SUCCESS", $return_msg = 'OK') { |
|
| 632 | 632 | $data = array(); |
| 633 | 633 | $data["return_code"] = $return_code; |
| 634 | 634 | if ($return_msg) { |
@@ -654,8 +654,8 @@ discard block |
||
| 654 | 654 | * @param null $err_code_des |
| 655 | 655 | * @return array |
| 656 | 656 | */ |
| 657 | - public function report($interface_url,$execution_time,$return_code,$result_code,$user_ip,$out_trade_no = null,$time = null,$device_info = null, |
|
| 658 | - $return_msg = null,$err_code = null,$err_code_des = null){ |
|
| 657 | + public function report($interface_url, $execution_time, $return_code, $result_code, $user_ip, $out_trade_no = null, $time = null, $device_info = null, |
|
| 658 | + $return_msg = null, $err_code = null, $err_code_des = null) { |
|
| 659 | 659 | $data = array(); |
| 660 | 660 | $data["appid"] = $this->config["app_id"]; |
| 661 | 661 | $data["interface_url"] = $interface_url; |
@@ -663,12 +663,12 @@ discard block |
||
| 663 | 663 | $data["return_code"] = $return_code; |
| 664 | 664 | $data["result_code"] = $result_code; |
| 665 | 665 | $data["user_ip"] = $user_ip; |
| 666 | - if($out_trade_no) $data["out_trade_no"] = $out_trade_no; |
|
| 667 | - if($time) $data["time"] = $time; |
|
| 668 | - if($device_info) $data["device_info"] = $device_info; |
|
| 669 | - if($return_msg) $data["return_msg"] = $return_msg; |
|
| 670 | - if($err_code) $data["err_code"] = $err_code; |
|
| 671 | - if($err_code_des) $data["err_code_des"] = $err_code_des; |
|
| 666 | + if ($out_trade_no) $data["out_trade_no"] = $out_trade_no; |
|
| 667 | + if ($time) $data["time"] = $time; |
|
| 668 | + if ($device_info) $data["device_info"] = $device_info; |
|
| 669 | + if ($return_msg) $data["return_msg"] = $return_msg; |
|
| 670 | + if ($err_code) $data["err_code"] = $err_code; |
|
| 671 | + if ($err_code_des) $data["err_code_des"] = $err_code_des; |
|
| 672 | 672 | $result = $this->post(self::URL_REPORT, $data, false); //cert is NOT required |
| 673 | 673 | return $result; |
| 674 | 674 | } |
@@ -679,11 +679,11 @@ discard block |
||
| 679 | 679 | * @param $longurl |
| 680 | 680 | * @return string |
| 681 | 681 | */ |
| 682 | - public function shortUrl($longurl){ |
|
| 682 | + public function shortUrl($longurl) { |
|
| 683 | 683 | $data = array(); |
| 684 | 684 | $data["appid"] = $this->config["app_id"]; |
| 685 | 685 | $data["long_url"] = $longurl; |
| 686 | - $result = $this->post(self::URL_SHORTURL,$data,false); |
|
| 686 | + $result = $this->post(self::URL_SHORTURL, $data, false); |
|
| 687 | 687 | return $result['short_url']; |
| 688 | 688 | } |
| 689 | 689 | |
@@ -692,11 +692,11 @@ discard block |
||
| 692 | 692 | * @param $auth_code |
| 693 | 693 | * @return mixed |
| 694 | 694 | */ |
| 695 | - public function authCodeToOpenId($auth_code){ |
|
| 695 | + public function authCodeToOpenId($auth_code) { |
|
| 696 | 696 | $data = array(); |
| 697 | 697 | $data["appid"] = $this->config["app_id"]; |
| 698 | 698 | $data["auth_code"] = $auth_code; |
| 699 | - $result = $this->post(self::URL_AUTHCODETOOPENID,$data,false); |
|
| 699 | + $result = $this->post(self::URL_AUTHCODETOOPENID, $data, false); |
|
| 700 | 700 | return $result['openid']; |
| 701 | 701 | } |
| 702 | 702 | |
@@ -713,19 +713,19 @@ discard block |
||
| 713 | 713 | * @return array |
| 714 | 714 | * @throws Exception |
| 715 | 715 | */ |
| 716 | - public function transferWallet($partner_trade_no,$openid,$amount,$desc,$spbill_create_ip = null,$re_user_name = null,$check_name = WechatPay::CHECKNAME_FORCECHECK){ |
|
| 716 | + public function transferWallet($partner_trade_no, $openid, $amount, $desc, $spbill_create_ip = null, $re_user_name = null, $check_name = WechatPay::CHECKNAME_FORCECHECK) { |
|
| 717 | 717 | $data = array(); |
| 718 | - if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required'); |
|
| 718 | + if ($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required'); |
|
| 719 | 719 | $data["mch_appid"] = $this->config["app_id"]; |
| 720 | 720 | $data["mchid"] = $this->config["mch_id"]; |
| 721 | 721 | $data["partner_trade_no"] = $partner_trade_no; |
| 722 | 722 | $data["openid"] = $openid; |
| 723 | 723 | $data["amount"] = $amount; |
| 724 | 724 | $data["desc"] = $desc; |
| 725 | - $data['spbill_create_ip'] = $spbill_create_ip?:$_SERVER['SERVER_ADDR']; |
|
| 725 | + $data['spbill_create_ip'] = $spbill_create_ip ?: $_SERVER['SERVER_ADDR']; |
|
| 726 | 726 | $data["check_name"] = $check_name; |
| 727 | 727 | $data["re_user_name"] = $re_user_name; |
| 728 | - $result = $this->post(self::URL_TRANSFER_WALLET,$data,true); |
|
| 728 | + $result = $this->post(self::URL_TRANSFER_WALLET, $data, true); |
|
| 729 | 729 | return $result; |
| 730 | 730 | } |
| 731 | 731 | |
@@ -735,12 +735,12 @@ discard block |
||
| 735 | 735 | * @param $partner_trade_no |
| 736 | 736 | * @return array |
| 737 | 737 | */ |
| 738 | - public function queryTransferWallet($partner_trade_no){ |
|
| 738 | + public function queryTransferWallet($partner_trade_no) { |
|
| 739 | 739 | $data = array(); |
| 740 | 740 | $data["appid"] = $this->config["app_id"]; |
| 741 | 741 | $data["mch_id"] = $this->config["mch_id"]; |
| 742 | 742 | $data["partner_trade_no"] = $partner_trade_no; |
| 743 | - $result = $this->post(self::URL_QUERY_TRANSFER_WALLET,$data,true); |
|
| 743 | + $result = $this->post(self::URL_QUERY_TRANSFER_WALLET, $data, true); |
|
| 744 | 744 | return $result; |
| 745 | 745 | } |
| 746 | 746 | |
@@ -756,8 +756,8 @@ discard block |
||
| 756 | 756 | * @return array |
| 757 | 757 | * @throws Exception |
| 758 | 758 | */ |
| 759 | - public function transferBankCard($partner_trade_no,$bank_no,$true_name,$bank_code,$amount,$desc){ |
|
| 760 | - if(!in_array($bank_code,array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code - $bank_code"); |
|
| 759 | + public function transferBankCard($partner_trade_no, $bank_no, $true_name, $bank_code, $amount, $desc) { |
|
| 760 | + if (!in_array($bank_code, array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code - $bank_code"); |
|
| 761 | 761 | $data = array(); |
| 762 | 762 | $data["partner_trade_no"] = $partner_trade_no; |
| 763 | 763 | $enc_bank_no = $this->rsaEncrypt($bank_no); |
@@ -767,7 +767,7 @@ discard block |
||
| 767 | 767 | $data["bank_code"] = $bank_code; |
| 768 | 768 | $data["desc"] = $desc; |
| 769 | 769 | $data["amount"] = $amount; |
| 770 | - $result = $this->post(self::URL_TRANSFER_BANKCARD,$data,true); |
|
| 770 | + $result = $this->post(self::URL_TRANSFER_BANKCARD, $data, true); |
|
| 771 | 771 | return $result; |
| 772 | 772 | } |
| 773 | 773 | |
@@ -781,14 +781,14 @@ discard block |
||
| 781 | 781 | * @param array $ext |
| 782 | 782 | * @return array |
| 783 | 783 | */ |
| 784 | - public function sendCoupon($coupon_stock_id,$open_id,$partner_trade_no,$op_user_id = '',$ext = []){ |
|
| 784 | + public function sendCoupon($coupon_stock_id, $open_id, $partner_trade_no, $op_user_id = '', $ext = []) { |
|
| 785 | 785 | $data = array(); |
| 786 | 786 | $data["partner_trade_no"] = $partner_trade_no; |
| 787 | 787 | $data["coupon_stock_id"] = $coupon_stock_id; |
| 788 | 788 | $data["openid_count"] = 1; |
| 789 | 789 | $data["open_id"] = $open_id; |
| 790 | 790 | $data["op_user_id"] = $op_user_id; |
| 791 | - $result = $this->post(self::URL_SEND_COUPON,$data,true); |
|
| 791 | + $result = $this->post(self::URL_SEND_COUPON, $data, true); |
|
| 792 | 792 | return $result; |
| 793 | 793 | } |
| 794 | 794 | |
@@ -799,11 +799,11 @@ discard block |
||
| 799 | 799 | * @param string $op_user_id |
| 800 | 800 | * @return array |
| 801 | 801 | */ |
| 802 | - public function queryCouponStock($coupon_stock_id,$op_user_id = ''){ |
|
| 802 | + public function queryCouponStock($coupon_stock_id, $op_user_id = '') { |
|
| 803 | 803 | $data = array(); |
| 804 | 804 | $data["coupon_stock_id"] = $coupon_stock_id; |
| 805 | 805 | $data["op_user_id"] = $op_user_id; |
| 806 | - $result = $this->post(self::URL_QUERY_COUPON_STOCK,$data,false); |
|
| 806 | + $result = $this->post(self::URL_QUERY_COUPON_STOCK, $data, false); |
|
| 807 | 807 | return $result; |
| 808 | 808 | } |
| 809 | 809 | |
@@ -817,13 +817,13 @@ discard block |
||
| 817 | 817 | * @param array $ext |
| 818 | 818 | * @return array |
| 819 | 819 | */ |
| 820 | - public function queryCouponsInfo($coupon_id,$open_id,$stock_id,$op_user_id = '',$ext = []){ |
|
| 820 | + public function queryCouponsInfo($coupon_id, $open_id, $stock_id, $op_user_id = '', $ext = []) { |
|
| 821 | 821 | $data = array(); |
| 822 | 822 | $data["coupon_id"] = $coupon_id; |
| 823 | 823 | $data["stock_id"] = $stock_id; |
| 824 | 824 | $data["open_id"] = $open_id; |
| 825 | 825 | $data["op_user_id"] = $op_user_id; |
| 826 | - $result = $this->post(self::URL_QUERY_COUPON_INFO,$data,false); |
|
| 826 | + $result = $this->post(self::URL_QUERY_COUPON_INFO, $data, false); |
|
| 827 | 827 | return $result; |
| 828 | 828 | } |
| 829 | 829 | |
@@ -833,7 +833,7 @@ discard block |
||
| 833 | 833 | * @param $refresh |
| 834 | 834 | * @return string |
| 835 | 835 | */ |
| 836 | - public function getPublicKey($refresh = false){ |
|
| 836 | + public function getPublicKey($refresh = false) { |
|
| 837 | 837 | if (!$refresh && file_exists($this->config["rsa_pubkey_path"])) { |
| 838 | 838 | $pubkey = file_get_contents($this->config["rsa_pubkey_path"]); |
| 839 | 839 | return $pubkey; |
@@ -841,7 +841,7 @@ discard block |
||
| 841 | 841 | $data = array(); |
| 842 | 842 | $data["mch_id"] = $this->config["mch_id"]; |
| 843 | 843 | $data["sign_type"] = $this->config["sign_type"]; |
| 844 | - $result = $this->post(self::URL_GETPUBLICKEY,$data,true); |
|
| 844 | + $result = $this->post(self::URL_GETPUBLICKEY, $data, true); |
|
| 845 | 845 | $pubkey = $result['pub_key']; |
| 846 | 846 | $pubkey = $this->convertPKCS1toPKCS8($pubkey); |
| 847 | 847 | $fp = fopen($this->config["rsa_pubkey_path"], "w"); |
@@ -850,20 +850,20 @@ discard block |
||
| 850 | 850 | return $pubkey; |
| 851 | 851 | } |
| 852 | 852 | |
| 853 | - private function convertPKCS1toPKCS8($pkcs1){ |
|
| 853 | + private function convertPKCS1toPKCS8($pkcs1) { |
|
| 854 | 854 | $start_key = $pkcs1; |
| 855 | 855 | $start_key = str_replace('-----BEGIN RSA PUBLIC KEY-----', '', $start_key); |
| 856 | 856 | $start_key = trim(str_replace('-----END RSA PUBLIC KEY-----', '', $start_key)); |
| 857 | - $key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' . str_replace("\n", '', $start_key); |
|
| 858 | - $key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($key, 64, "\n", true) . "\n-----END PUBLIC KEY-----"; |
|
| 857 | + $key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A'.str_replace("\n", '', $start_key); |
|
| 858 | + $key = "-----BEGIN PUBLIC KEY-----\n".wordwrap($key, 64, "\n", true)."\n-----END PUBLIC KEY-----"; |
|
| 859 | 859 | return $key; |
| 860 | 860 | } |
| 861 | 861 | |
| 862 | - public function rsaEncrypt($data){ |
|
| 862 | + public function rsaEncrypt($data) { |
|
| 863 | 863 | $pubkey = $this->getPublicKey(); |
| 864 | 864 | $encrypted = null; |
| 865 | 865 | $pubkey = openssl_get_publickey($pubkey); |
| 866 | - if (openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING)) |
|
| 866 | + if (openssl_public_encrypt($data, $encrypted, $pubkey, OPENSSL_PKCS1_OAEP_PADDING)) |
|
| 867 | 867 | $data = base64_encode($encrypted); |
| 868 | 868 | else |
| 869 | 869 | throw new Exception('Unable to encrypt data'); |
@@ -876,12 +876,12 @@ discard block |
||
| 876 | 876 | * @param $partner_trade_no |
| 877 | 877 | * @return array |
| 878 | 878 | */ |
| 879 | - public function queryTransferBankCard($partner_trade_no){ |
|
| 879 | + public function queryTransferBankCard($partner_trade_no) { |
|
| 880 | 880 | $data = array(); |
| 881 | 881 | $data["appid"] = $this->config["app_id"]; |
| 882 | 882 | $data["mch_id"] = $this->config["mch_id"]; |
| 883 | 883 | $data["partner_trade_no"] = $partner_trade_no; |
| 884 | - $result = $this->post(self::URL_QUERY_TRANSFER_WALLET,$data,true); |
|
| 884 | + $result = $this->post(self::URL_QUERY_TRANSFER_WALLET, $data, true); |
|
| 885 | 885 | return $result; |
| 886 | 886 | } |
| 887 | 887 | |
@@ -890,14 +890,14 @@ discard block |
||
| 890 | 890 | * @ref https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=23_1 |
| 891 | 891 | * @return array |
| 892 | 892 | */ |
| 893 | - public function getSignKey(){ |
|
| 893 | + public function getSignKey() { |
|
| 894 | 894 | $data = array(); |
| 895 | 895 | $data["mch_id"] = $this->config["mch_id"]; |
| 896 | - $result = $this->post($this->getSignKeyUrl,$data,false); |
|
| 896 | + $result = $this->post($this->getSignKeyUrl, $data, false); |
|
| 897 | 897 | return $result['sandbox_signkey']; |
| 898 | 898 | } |
| 899 | 899 | |
| 900 | - public function getSignPackage($url){ |
|
| 900 | + public function getSignPackage($url) { |
|
| 901 | 901 | $jsapiTicket = $this->getJSAPITicket(); |
| 902 | 902 | $timestamp = time(); |
| 903 | 903 | $nonceStr = $this->getNonceStr(); |
@@ -915,8 +915,8 @@ discard block |
||
| 915 | 915 | return $signPackage; |
| 916 | 916 | } |
| 917 | 917 | |
| 918 | - public function getJSAPITicket(){ |
|
| 919 | - if(isset($this->config['jsapi_ticket']) && file_exists($this->config['jsapi_ticket'])){ |
|
| 918 | + public function getJSAPITicket() { |
|
| 919 | + if (isset($this->config['jsapi_ticket']) && file_exists($this->config['jsapi_ticket'])) { |
|
| 920 | 920 | $data = json_decode(file_get_contents($this->config['jsapi_ticket'])); |
| 921 | 921 | if (!$data || $data->expire_time < time()) { |
| 922 | 922 | $data = $this->getWechatOAuth()->getTicket(); |
@@ -929,10 +929,10 @@ discard block |
||
| 929 | 929 | } |
| 930 | 930 | } |
| 931 | 931 | |
| 932 | - private function post($url, $data,$cert = true) { |
|
| 933 | - if(!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"]; |
|
| 934 | - if(!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr(); |
|
| 935 | - if(!isset($data['sign'])) $data['sign'] = $this->sign($data); |
|
| 932 | + private function post($url, $data, $cert = true) { |
|
| 933 | + if (!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"]; |
|
| 934 | + if (!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr(); |
|
| 935 | + if (!isset($data['sign'])) $data['sign'] = $this->sign($data); |
|
| 936 | 936 | $this->requestXML = $this->responseXML = null; |
| 937 | 937 | $this->requestArray = $this->responseArray = null; |
| 938 | 938 | |
@@ -944,53 +944,53 @@ discard block |
||
| 944 | 944 | CURLOPT_RETURNTRANSFER => true, |
| 945 | 945 | CURLOPT_TIMEOUT => 10 |
| 946 | 946 | ]; |
| 947 | - if($cert == true){ |
|
| 947 | + if ($cert == true) { |
|
| 948 | 948 | $opts[CURLOPT_SSLCERTTYPE] = 'PEM'; |
| 949 | 949 | $opts[CURLOPT_SSLCERT] = $this->config['ssl_cert_path']; |
| 950 | 950 | $opts[CURLOPT_SSLKEYTYPE] = 'PEM'; |
| 951 | 951 | $opts[CURLOPT_SSLKEY] = $this->config['ssl_key_path']; |
| 952 | 952 | } |
| 953 | 953 | $processResponse = true; |
| 954 | - if(in_array($url,[self::URL_DOWNLOADBILL])){ |
|
| 954 | + if (in_array($url, [self::URL_DOWNLOADBILL])) { |
|
| 955 | 955 | $processResponse = false; |
| 956 | 956 | } |
| 957 | - if($this->sandbox == true){ |
|
| 957 | + if ($this->sandbox == true) { |
|
| 958 | 958 | $host = "https://api.mch.weixin.qq.com"; |
| 959 | - $url = str_replace($host,'',$url); |
|
| 959 | + $url = str_replace($host, '', $url); |
|
| 960 | 960 | $url = "{$host}/sandboxnew{$url}"; |
| 961 | 961 | } |
| 962 | - $content = $this->httpClient->post($url,$this->requestXML,[],$opts); |
|
| 963 | - if(!$content) throw new Exception("Empty response with {$this->requestXML}"); |
|
| 962 | + $content = $this->httpClient->post($url, $this->requestXML, [], $opts); |
|
| 963 | + if (!$content) throw new Exception("Empty response with {$this->requestXML}"); |
|
| 964 | 964 | |
| 965 | 965 | $this->responseXML = $content; |
| 966 | - if($processResponse) |
|
| 966 | + if ($processResponse) |
|
| 967 | 967 | return $this->processResponseXML($this->responseXML); |
| 968 | 968 | else return $this->responseXML; |
| 969 | 969 | |
| 970 | 970 | } |
| 971 | 971 | |
| 972 | - private function processResponseXML($responseXML){ |
|
| 972 | + private function processResponseXML($responseXML) { |
|
| 973 | 973 | $result = $this->xml2array($responseXML); |
| 974 | 974 | $this->responseArray = $result; |
| 975 | - if(empty($result['return_code'])){ |
|
| 975 | + if (empty($result['return_code'])) { |
|
| 976 | 976 | throw new Exception("No return code presents in {$this->responseXML}"); |
| 977 | 977 | } |
| 978 | 978 | $this->returnCode = $result["return_code"]; |
| 979 | - $this->returnMsg = isset($result['return_msg'])?$result['return_msg']:''; |
|
| 979 | + $this->returnMsg = isset($result['return_msg']) ? $result['return_msg'] : ''; |
|
| 980 | 980 | |
| 981 | 981 | if ($this->returnCode == "SUCCESS") { |
| 982 | - if(isset($result['result_code']) && $result['result_code'] == "FAIL"){ |
|
| 982 | + if (isset($result['result_code']) && $result['result_code'] == "FAIL") { |
|
| 983 | 983 | $this->resultCode = $result['result_code']; |
| 984 | 984 | $this->errCode = $result['err_code']; |
| 985 | 985 | $this->errCodeDes = $result['err_code_des']; |
| 986 | 986 | throw new Exception("[$this->errCode]$this->errCodeDes"); |
| 987 | - }else{ |
|
| 987 | + }else { |
|
| 988 | 988 | return $result; |
| 989 | 989 | } |
| 990 | - } else { |
|
| 991 | - if($result["return_code"] == "FAIL"){ |
|
| 990 | + }else { |
|
| 991 | + if ($result["return_code"] == "FAIL") { |
|
| 992 | 992 | throw new Exception($this->returnMsg); |
| 993 | - }else{ |
|
| 993 | + }else { |
|
| 994 | 994 | $this->resultCode = $result['result_code']; |
| 995 | 995 | $this->errCode = $result['err_code']; |
| 996 | 996 | $this->errCodeDes = $result['err_code_des']; |
@@ -999,28 +999,28 @@ discard block |
||
| 999 | 999 | } |
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | - public function sign($data,$sign_type = WechatPay::SIGNTYPE_MD5) { |
|
| 1002 | + public function sign($data, $sign_type = WechatPay::SIGNTYPE_MD5) { |
|
| 1003 | 1003 | ksort($data); |
| 1004 | 1004 | $string1 = ""; |
| 1005 | 1005 | foreach ($data as $k => $v) { |
| 1006 | - if ($v && trim($v)!='') { |
|
| 1006 | + if ($v && trim($v) != '') { |
|
| 1007 | 1007 | $string1 .= "$k=$v&"; |
| 1008 | 1008 | } |
| 1009 | 1009 | } |
| 1010 | - $stringSignTemp = $string1 . "key=" . $this->config["api_key"]; |
|
| 1011 | - if($sign_type == WechatPay::SIGNTYPE_MD5){ |
|
| 1010 | + $stringSignTemp = $string1."key=".$this->config["api_key"]; |
|
| 1011 | + if ($sign_type == WechatPay::SIGNTYPE_MD5) { |
|
| 1012 | 1012 | $sign = strtoupper(md5($stringSignTemp)); |
| 1013 | - }elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){ |
|
| 1014 | - $sign = strtoupper(hash_hmac('sha256',$stringSignTemp,$this->config["api_key"])); |
|
| 1013 | + }elseif ($sign_type == WechatPay::SIGNTYPE_HMACSHA256) { |
|
| 1014 | + $sign = strtoupper(hash_hmac('sha256', $stringSignTemp, $this->config["api_key"])); |
|
| 1015 | 1015 | }else throw new \Exception("Not supported sign type - $sign_type"); |
| 1016 | 1016 | return $sign; |
| 1017 | 1017 | } |
| 1018 | 1018 | |
| 1019 | 1019 | private function array2xml($array) { |
| 1020 | - $xml = "<xml>" . PHP_EOL; |
|
| 1020 | + $xml = "<xml>".PHP_EOL; |
|
| 1021 | 1021 | foreach ($array as $k => $v) { |
| 1022 | - if($v && trim($v)!='') |
|
| 1023 | - $xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL; |
|
| 1022 | + if ($v && trim($v) != '') |
|
| 1023 | + $xml .= "<$k><![CDATA[$v]]></$k>".PHP_EOL; |
|
| 1024 | 1024 | } |
| 1025 | 1025 | $xml .= "</xml>"; |
| 1026 | 1026 | return $xml; |
@@ -1029,11 +1029,11 @@ discard block |
||
| 1029 | 1029 | private function xml2array($xml) { |
| 1030 | 1030 | $array = array(); |
| 1031 | 1031 | $tmp = null; |
| 1032 | - try{ |
|
| 1032 | + try { |
|
| 1033 | 1033 | $tmp = (array) simplexml_load_string($xml); |
| 1034 | - }catch(\Exception $e){} |
|
| 1035 | - if($tmp && is_array($tmp)){ |
|
| 1036 | - foreach ( $tmp as $k => $v) { |
|
| 1034 | + } catch (\Exception $e) {} |
|
| 1035 | + if ($tmp && is_array($tmp)) { |
|
| 1036 | + foreach ($tmp as $k => $v) { |
|
| 1037 | 1037 | $array[$k] = (string) $v; |
| 1038 | 1038 | } |
| 1039 | 1039 | } |
@@ -1041,7 +1041,7 @@ discard block |
||
| 1041 | 1041 | } |
| 1042 | 1042 | |
| 1043 | 1043 | private function getNonceStr() { |
| 1044 | - return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"),0,32); |
|
| 1044 | + return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"), 0, 32); |
|
| 1045 | 1045 | } |
| 1046 | 1046 | |
| 1047 | 1047 | } |
| 1048 | 1048 | \ No newline at end of file |
@@ -183,7 +183,9 @@ discard block |
||
| 183 | 183 | $data["spbill_create_ip"] = isset($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:''; |
| 184 | 184 | $data["notify_url"] = $this->config["notify_url"]; |
| 185 | 185 | $data["trade_type"] = self::TRADETYPE_MWEB; |
| 186 | - if(!isset($this->config['h5_scene_info'])) throw new \Exception('h5_scene_info should be configured'); |
|
| 186 | + if(!isset($this->config['h5_scene_info'])) { |
|
| 187 | + throw new \Exception('h5_scene_info should be configured'); |
|
| 188 | + } |
|
| 187 | 189 | $data["scene_info"] = json_encode($this->config['h5_scene_info']); |
| 188 | 190 | $result = $this->unifiedOrder($data); |
| 189 | 191 | return $result["mweb_url"]; |
@@ -430,7 +432,9 @@ discard block |
||
| 430 | 432 | $data["send_name"] = $send_name; |
| 431 | 433 | $data["re_openid"] = $re_openid; |
| 432 | 434 | $data["total_amount"] = $total_amount; |
| 433 | - if($total_amount > 20000 && trim($scene_id)=='') throw new \Exception("scene_id is required when total_amount beyond 20000"); |
|
| 435 | + if($total_amount > 20000 && trim($scene_id)=='') { |
|
| 436 | + throw new \Exception("scene_id is required when total_amount beyond 20000"); |
|
| 437 | + } |
|
| 434 | 438 | $data["total_num"] = $total_num; |
| 435 | 439 | $data["wishing"] = $wishing; |
| 436 | 440 | $data["act_name"] = $act_name; |
@@ -466,7 +470,9 @@ discard block |
||
| 466 | 470 | $data["send_name"] = $send_name; |
| 467 | 471 | $data["re_openid"] = $re_openid; |
| 468 | 472 | $data["total_amount"] = $total_amount; |
| 469 | - if($total_amount > 20000 && trim($scene_id)=='') throw new \Exception("scene_id is required when total_amount beyond 20000(200rmb)"); |
|
| 473 | + if($total_amount > 20000 && trim($scene_id)=='') { |
|
| 474 | + throw new \Exception("scene_id is required when total_amount beyond 20000(200rmb)"); |
|
| 475 | + } |
|
| 470 | 476 | $data["total_num"] = $total_num; |
| 471 | 477 | $data["amt_type"] = 'ALL_RAND'; //红包金额设置方式 ALL_RAND—全部随机 |
| 472 | 478 | $data["wishing"] = $wishing; |
@@ -579,10 +585,10 @@ discard block |
||
| 579 | 585 | if($this->validateSign($notify_data)){ |
| 580 | 586 | if($callback && is_callable($callback)){ |
| 581 | 587 | return call_user_func_array( $callback , [$notify_data] ); |
| 582 | - }else{ |
|
| 588 | + } else{ |
|
| 583 | 589 | $this->responseNotify(); |
| 584 | 590 | } |
| 585 | - }else{ |
|
| 591 | + } else{ |
|
| 586 | 592 | throw new \Exception('Invalid paid notify data'); |
| 587 | 593 | } |
| 588 | 594 | } |
@@ -601,10 +607,10 @@ discard block |
||
| 601 | 607 | if($this->validateSign($notify_data)){ |
| 602 | 608 | if($callback && is_callable($callback)){ |
| 603 | 609 | return call_user_func_array( $callback , $notify_data ); |
| 604 | - }else{ |
|
| 610 | + } else{ |
|
| 605 | 611 | $this->responseNotify(); |
| 606 | 612 | } |
| 607 | - }else{ |
|
| 613 | + } else{ |
|
| 608 | 614 | throw new \Exception('Invalid refunded notify data'); |
| 609 | 615 | } |
| 610 | 616 | } |
@@ -663,12 +669,24 @@ discard block |
||
| 663 | 669 | $data["return_code"] = $return_code; |
| 664 | 670 | $data["result_code"] = $result_code; |
| 665 | 671 | $data["user_ip"] = $user_ip; |
| 666 | - if($out_trade_no) $data["out_trade_no"] = $out_trade_no; |
|
| 667 | - if($time) $data["time"] = $time; |
|
| 668 | - if($device_info) $data["device_info"] = $device_info; |
|
| 669 | - if($return_msg) $data["return_msg"] = $return_msg; |
|
| 670 | - if($err_code) $data["err_code"] = $err_code; |
|
| 671 | - if($err_code_des) $data["err_code_des"] = $err_code_des; |
|
| 672 | + if($out_trade_no) { |
|
| 673 | + $data["out_trade_no"] = $out_trade_no; |
|
| 674 | + } |
|
| 675 | + if($time) { |
|
| 676 | + $data["time"] = $time; |
|
| 677 | + } |
|
| 678 | + if($device_info) { |
|
| 679 | + $data["device_info"] = $device_info; |
|
| 680 | + } |
|
| 681 | + if($return_msg) { |
|
| 682 | + $data["return_msg"] = $return_msg; |
|
| 683 | + } |
|
| 684 | + if($err_code) { |
|
| 685 | + $data["err_code"] = $err_code; |
|
| 686 | + } |
|
| 687 | + if($err_code_des) { |
|
| 688 | + $data["err_code_des"] = $err_code_des; |
|
| 689 | + } |
|
| 672 | 690 | $result = $this->post(self::URL_REPORT, $data, false); //cert is NOT required |
| 673 | 691 | return $result; |
| 674 | 692 | } |
@@ -715,7 +733,9 @@ discard block |
||
| 715 | 733 | */ |
| 716 | 734 | public function transferWallet($partner_trade_no,$openid,$amount,$desc,$spbill_create_ip = null,$re_user_name = null,$check_name = WechatPay::CHECKNAME_FORCECHECK){ |
| 717 | 735 | $data = array(); |
| 718 | - if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) throw new Exception('Real name is required'); |
|
| 736 | + if($check_name == WechatPay::CHECKNAME_FORCECHECK && !$re_user_name) { |
|
| 737 | + throw new Exception('Real name is required'); |
|
| 738 | + } |
|
| 719 | 739 | $data["mch_appid"] = $this->config["app_id"]; |
| 720 | 740 | $data["mchid"] = $this->config["mch_id"]; |
| 721 | 741 | $data["partner_trade_no"] = $partner_trade_no; |
@@ -757,7 +777,9 @@ discard block |
||
| 757 | 777 | * @throws Exception |
| 758 | 778 | */ |
| 759 | 779 | public function transferBankCard($partner_trade_no,$bank_no,$true_name,$bank_code,$amount,$desc){ |
| 760 | - if(!in_array($bank_code,array_values(self::$BANKCODE))) throw new Exception("Unsupported bank code - $bank_code"); |
|
| 780 | + if(!in_array($bank_code,array_values(self::$BANKCODE))) { |
|
| 781 | + throw new Exception("Unsupported bank code - $bank_code"); |
|
| 782 | + } |
|
| 761 | 783 | $data = array(); |
| 762 | 784 | $data["partner_trade_no"] = $partner_trade_no; |
| 763 | 785 | $enc_bank_no = $this->rsaEncrypt($bank_no); |
@@ -846,7 +868,9 @@ discard block |
||
| 846 | 868 | $pubkey = $this->convertPKCS1toPKCS8($pubkey); |
| 847 | 869 | $fp = fopen($this->config["rsa_pubkey_path"], "w"); |
| 848 | 870 | fwrite($fp, $pubkey); |
| 849 | - if ($fp) fclose($fp); |
|
| 871 | + if ($fp) { |
|
| 872 | + fclose($fp); |
|
| 873 | + } |
|
| 850 | 874 | return $pubkey; |
| 851 | 875 | } |
| 852 | 876 | |
@@ -863,10 +887,11 @@ discard block |
||
| 863 | 887 | $pubkey = $this->getPublicKey(); |
| 864 | 888 | $encrypted = null; |
| 865 | 889 | $pubkey = openssl_get_publickey($pubkey); |
| 866 | - if (openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING)) |
|
| 867 | - $data = base64_encode($encrypted); |
|
| 868 | - else |
|
| 869 | - throw new Exception('Unable to encrypt data'); |
|
| 890 | + if (openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING)) { |
|
| 891 | + $data = base64_encode($encrypted); |
|
| 892 | + } else { |
|
| 893 | + throw new Exception('Unable to encrypt data'); |
|
| 894 | + } |
|
| 870 | 895 | return $data; |
| 871 | 896 | } |
| 872 | 897 | |
@@ -922,7 +947,9 @@ discard block |
||
| 922 | 947 | $data = $this->getWechatOAuth()->getTicket(); |
| 923 | 948 | $fp = fopen($this->config["jsapi_ticket"], "w"); |
| 924 | 949 | fwrite($fp, $data); |
| 925 | - if ($fp) fclose($fp); |
|
| 950 | + if ($fp) { |
|
| 951 | + fclose($fp); |
|
| 952 | + } |
|
| 926 | 953 | $data = json_decode($data); |
| 927 | 954 | } |
| 928 | 955 | return $data->jsapi_ticket; |
@@ -930,9 +957,15 @@ discard block |
||
| 930 | 957 | } |
| 931 | 958 | |
| 932 | 959 | private function post($url, $data,$cert = true) { |
| 933 | - if(!isset($data['mch_id']) && !isset($data['mchid'])) $data["mch_id"] = $this->config["mch_id"]; |
|
| 934 | - if(!isset($data['nonce_str'])) $data["nonce_str"] = $this->getNonceStr(); |
|
| 935 | - if(!isset($data['sign'])) $data['sign'] = $this->sign($data); |
|
| 960 | + if(!isset($data['mch_id']) && !isset($data['mchid'])) { |
|
| 961 | + $data["mch_id"] = $this->config["mch_id"]; |
|
| 962 | + } |
|
| 963 | + if(!isset($data['nonce_str'])) { |
|
| 964 | + $data["nonce_str"] = $this->getNonceStr(); |
|
| 965 | + } |
|
| 966 | + if(!isset($data['sign'])) { |
|
| 967 | + $data['sign'] = $this->sign($data); |
|
| 968 | + } |
|
| 936 | 969 | $this->requestXML = $this->responseXML = null; |
| 937 | 970 | $this->requestArray = $this->responseArray = null; |
| 938 | 971 | |
@@ -960,12 +993,16 @@ discard block |
||
| 960 | 993 | $url = "{$host}/sandboxnew{$url}"; |
| 961 | 994 | } |
| 962 | 995 | $content = $this->httpClient->post($url,$this->requestXML,[],$opts); |
| 963 | - if(!$content) throw new Exception("Empty response with {$this->requestXML}"); |
|
| 996 | + if(!$content) { |
|
| 997 | + throw new Exception("Empty response with {$this->requestXML}"); |
|
| 998 | + } |
|
| 964 | 999 | |
| 965 | 1000 | $this->responseXML = $content; |
| 966 | - if($processResponse) |
|
| 967 | - return $this->processResponseXML($this->responseXML); |
|
| 968 | - else return $this->responseXML; |
|
| 1001 | + if($processResponse) { |
|
| 1002 | + return $this->processResponseXML($this->responseXML); |
|
| 1003 | + } else { |
|
| 1004 | + return $this->responseXML; |
|
| 1005 | + } |
|
| 969 | 1006 | |
| 970 | 1007 | } |
| 971 | 1008 | |
@@ -984,13 +1021,13 @@ discard block |
||
| 984 | 1021 | $this->errCode = $result['err_code']; |
| 985 | 1022 | $this->errCodeDes = $result['err_code_des']; |
| 986 | 1023 | throw new Exception("[$this->errCode]$this->errCodeDes"); |
| 987 | - }else{ |
|
| 1024 | + } else{ |
|
| 988 | 1025 | return $result; |
| 989 | 1026 | } |
| 990 | 1027 | } else { |
| 991 | 1028 | if($result["return_code"] == "FAIL"){ |
| 992 | 1029 | throw new Exception($this->returnMsg); |
| 993 | - }else{ |
|
| 1030 | + } else{ |
|
| 994 | 1031 | $this->resultCode = $result['result_code']; |
| 995 | 1032 | $this->errCode = $result['err_code']; |
| 996 | 1033 | $this->errCodeDes = $result['err_code_des']; |
@@ -1010,17 +1047,20 @@ discard block |
||
| 1010 | 1047 | $stringSignTemp = $string1 . "key=" . $this->config["api_key"]; |
| 1011 | 1048 | if($sign_type == WechatPay::SIGNTYPE_MD5){ |
| 1012 | 1049 | $sign = strtoupper(md5($stringSignTemp)); |
| 1013 | - }elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){ |
|
| 1050 | + } elseif($sign_type == WechatPay::SIGNTYPE_HMACSHA256){ |
|
| 1014 | 1051 | $sign = strtoupper(hash_hmac('sha256',$stringSignTemp,$this->config["api_key"])); |
| 1015 | - }else throw new \Exception("Not supported sign type - $sign_type"); |
|
| 1052 | + } else { |
|
| 1053 | + throw new \Exception("Not supported sign type - $sign_type"); |
|
| 1054 | + } |
|
| 1016 | 1055 | return $sign; |
| 1017 | 1056 | } |
| 1018 | 1057 | |
| 1019 | 1058 | private function array2xml($array) { |
| 1020 | 1059 | $xml = "<xml>" . PHP_EOL; |
| 1021 | 1060 | foreach ($array as $k => $v) { |
| 1022 | - if($v && trim($v)!='') |
|
| 1023 | - $xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL; |
|
| 1061 | + if($v && trim($v)!='') { |
|
| 1062 | + $xml .= "<$k><![CDATA[$v]]></$k>" . PHP_EOL; |
|
| 1063 | + } |
|
| 1024 | 1064 | } |
| 1025 | 1065 | $xml .= "</xml>"; |
| 1026 | 1066 | return $xml; |
@@ -1031,7 +1071,7 @@ discard block |
||
| 1031 | 1071 | $tmp = null; |
| 1032 | 1072 | try{ |
| 1033 | 1073 | $tmp = (array) simplexml_load_string($xml); |
| 1034 | - }catch(\Exception $e){} |
|
| 1074 | + } catch(\Exception $e){} |
|
| 1035 | 1075 | if($tmp && is_array($tmp)){ |
| 1036 | 1076 | foreach ( $tmp as $k => $v) { |
| 1037 | 1077 | $array[$k] = (string) $v; |
@@ -1,10 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | //公众号支付 |
| 3 | -require_once __DIR__ ."/../src/WechatPay.php"; |
|
| 3 | +require_once __DIR__."/../src/WechatPay.php"; |
|
| 4 | 4 | use zhangv\wechat\WechatPay; |
| 5 | 5 | $cfg = include './config.php'; |
| 6 | 6 | |
| 7 | -if(empty( $_REQUEST['openid'])) { |
|
| 7 | +if (empty($_REQUEST['openid'])) { |
|
| 8 | 8 | $redirect = "http://{$_SERVER['HTTP_HOST']}/wechat-pay/demo/wxoauth.php"; |
| 9 | 9 | header('Location: '.$redirect); |
| 10 | 10 | exit; |
@@ -3,9 +3,9 @@ |
||
| 3 | 3 | |
| 4 | 4 | $cfg = require './config.php'; |
| 5 | 5 | $payment = new WechatPay($cfg); |
| 6 | -$payment->onPaidNotify($xml,function($notifydata) use ($payment){ |
|
| 6 | +$payment->onPaidNotify($xml, function($notifydata) use ($payment){ |
|
| 7 | 7 | //do stuff |
| 8 | 8 | print_r($notifydata); |
| 9 | - $payment->responseNotify('SUCCESS','OK'); |
|
| 9 | + $payment->responseNotify('SUCCESS', 'OK'); |
|
| 10 | 10 | }); |
| 11 | 11 | |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | //APP支付 - 获取预支付交易回话标识 |
| 3 | 3 | //注意:APP支付使用的是开放平台的APPID |
| 4 | -require_once __DIR__ ."/../src/WechatPay.php"; |
|
| 4 | +require_once __DIR__."/../src/WechatPay.php"; |
|
| 5 | 5 | use zhangv\wechat\WechatPay; |
| 6 | 6 | |
| 7 | 7 | $cfg = include './config.php'; |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | //扫码支付 |
| 3 | -require_once __DIR__ ."/../src/WechatPay.php"; |
|
| 3 | +require_once __DIR__."/../src/WechatPay.php"; |
|
| 4 | 4 | use zhangv\wechat\WechatPay; |
| 5 | 5 | |
| 6 | 6 | $cfg = include './config.php'; |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | $desc = "desc$stamp"; |
| 12 | 12 | $productid = "testproduct"; |
| 13 | 13 | $amt = 1; |
| 14 | -$codeurl = $payment->getCodeUrl($desc, $orderid, $amt,$productid); |
|
| 14 | +$codeurl = $payment->getCodeUrl($desc, $orderid, $amt, $productid); |
|
| 15 | 15 | |
| 16 | 16 | ?> |
| 17 | 17 | <script type="text/javascript" src="js/jquery.js"></script> |
@@ -1,23 +1,23 @@ |
||
| 1 | 1 | <?php |
| 2 | -require_once __DIR__ ."/../src/WechatOAuth.php"; |
|
| 3 | -require_once __DIR__ ."/../src/HttpClient.php"; |
|
| 2 | +require_once __DIR__."/../src/WechatOAuth.php"; |
|
| 3 | +require_once __DIR__."/../src/HttpClient.php"; |
|
| 4 | 4 | use zhangv\wechat\WechatOAuth; |
| 5 | 5 | |
| 6 | -if (isset($_GET['code'])){ |
|
| 6 | +if (isset($_GET['code'])) { |
|
| 7 | 7 | $cfg = require './config.php'; |
| 8 | 8 | |
| 9 | 9 | $code = trim($_GET['code']); |
| 10 | 10 | $state = trim($_GET['state']); |
| 11 | - $oauth = new WechatOAuth($cfg['app_id'],$cfg['app_secret']); |
|
| 11 | + $oauth = new WechatOAuth($cfg['app_id'], $cfg['app_secret']); |
|
| 12 | 12 | $at = $oauth->authorize($code); |
| 13 | 13 | |
| 14 | - if(!$at || empty($at->openid)){ |
|
| 14 | + if (!$at || empty($at->openid)) { |
|
| 15 | 15 | die('授权失败'); |
| 16 | - }else{ |
|
| 16 | + }else { |
|
| 17 | 17 | $accesstoken = $at->access_token; |
| 18 | 18 | $openid = $at->openid; |
| 19 | 19 | header('Location: '."http://{$_SERVER['HTTP_HOST']}/wechat-pay/demo/pay.php?openid=$openid"); |
| 20 | 20 | } |
| 21 | -}else{ |
|
| 21 | +}else { |
|
| 22 | 22 | die('授权失败,请重试。'); |
| 23 | 23 | } |
| 24 | 24 | \ No newline at end of file |
@@ -13,11 +13,11 @@ |
||
| 13 | 13 | |
| 14 | 14 | if(!$at || empty($at->openid)){ |
| 15 | 15 | die('授权失败'); |
| 16 | - }else{ |
|
| 16 | + } else{ |
|
| 17 | 17 | $accesstoken = $at->access_token; |
| 18 | 18 | $openid = $at->openid; |
| 19 | 19 | header('Location: '."http://{$_SERVER['HTTP_HOST']}/wechat-pay/demo/pay.php?openid=$openid"); |
| 20 | 20 | } |
| 21 | -}else{ |
|
| 21 | +} else{ |
|
| 22 | 22 | die('授权失败,请重试。'); |
| 23 | 23 | } |
| 24 | 24 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -require_once __DIR__ ."/../src/WechatOAuth.php"; |
|
| 3 | -require_once __DIR__ ."/../src/HttpClient.php"; |
|
| 2 | +require_once __DIR__."/../src/WechatOAuth.php"; |
|
| 3 | +require_once __DIR__."/../src/HttpClient.php"; |
|
| 4 | 4 | use zhangv\wechat\WechatOAuth; |
| 5 | 5 | |
| 6 | 6 | $cfg = require './config.php'; |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | $redirect = "http://{$_SERVER['HTTP_HOST']}/wechat-pay/demo/wxoauthcallback.php"; |
| 9 | 9 | $scope = 'snsapi_userinfo'; |
| 10 | 10 | $state = ""; |
| 11 | -$oauth =new WechatOAuth($appid,$cfg['app_secret']); |
|
| 12 | -$url = $oauth->authorizeURI($redirect,$scope); |
|
| 11 | +$oauth = new WechatOAuth($appid, $cfg['app_secret']); |
|
| 12 | +$url = $oauth->authorizeURI($redirect, $scope); |
|
| 13 | 13 | |
| 14 | 14 | header('Location: '.$redirect); |
| 15 | 15 | \ No newline at end of file |