Completed
Push — master ( 9bc9b6...ec4bbc )
by Wei
04:31
created
src/service/App.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -36,8 +36,8 @@  discard block
 block discarded – undo
36 36
 	 * @param $ext array
37 37
 	 * @return string
38 38
 	 */
39
-	public function getPrepayId($body,$out_trade_no,$total_fee,$spbill_create_ip,$ext = null) {
40
-		$data = ($ext && is_array($ext))?$ext:array();
39
+	public function getPrepayId($body, $out_trade_no, $total_fee, $spbill_create_ip, $ext = null) {
40
+		$data = ($ext && is_array($ext)) ? $ext : array();
41 41
 		$data["body"]         = $body;
42 42
 		$data["out_trade_no"] = $out_trade_no;
43 43
 		$data["total_fee"]    = $total_fee;
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 		$data["timestamp"] = time();
63 63
 		$data["noncestr"]  = $this->getNonceStr();
64 64
 		$data["appid"] = $this->config["app_id"];
65
-		$data["sign"]   = $this->sign($data);
65
+		$data["sign"] = $this->sign($data);
66 66
 		return $data;
67 67
 	}
68 68
 }
69 69
\ No newline at end of file
Please login to merge, or discard this patch.
src/util/WechatOAuth.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 namespace zhangv\wechat\pay\util;
9 9
 
10 10
 class WechatOAuth {
11
-	const TICKETTYPE_JSAPI = 'jsapi',TICKETTYPE_WXCARD = 'wx_card';
11
+	const TICKETTYPE_JSAPI = 'jsapi', TICKETTYPE_WXCARD = 'wx_card';
12 12
 	public $responseJSON = null;
13 13
 	public $errCode = null;
14 14
 	public $errMsg = null;
@@ -18,46 +18,46 @@  discard block
 block discarded – undo
18 18
 	private $httpClient = null;
19 19
 	private $accessToken = null;
20 20
 
21
-	public function __construct($appId,$appSecret) {
21
+	public function __construct($appId, $appSecret) {
22 22
 		$this->appId = $appId;
23 23
 		$this->appSecret = $appSecret;
24 24
 		$this->httpClient = new HttpClient();
25 25
 	}
26 26
 
27
-	public function setHttpClient($httpClient){
27
+	public function setHttpClient($httpClient) {
28 28
 		$this->httpClient = $httpClient;
29 29
 	}
30 30
 
31
-	public function authorizeURI($redirectURI,$scope = 'snsapi_userinfo',$state = ''){
31
+	public function authorizeURI($redirectURI, $scope = 'snsapi_userinfo', $state = '') {
32 32
 		$redirectURI = urlencode($redirectURI);
33 33
 		return "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$this->appId}&redirect_uri={$redirectURI}&response_type=code&scope=$scope&state=$state#wechat_redirect";
34 34
 	}
35 35
 
36
-	public function authorize($code){
36
+	public function authorize($code) {
37 37
 		$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$this->appId}&secret={$this->appSecret}&code=$code&grant_type=authorization_code";
38 38
 		$this->responseJSON = $this->httpClient->get($url);
39 39
 		return json_decode($this->responseJSON);
40 40
 	}
41 41
 
42
-	public function getUserInfo($openId){
42
+	public function getUserInfo($openId) {
43 43
 		$url = "https://api.weixin.qq.com/sns/userinfo?access_token={$this->accessToken}&openid=$openId&lang=zh_CN";
44 44
 		$this->responseJSON = $this->httpClient->get($url);
45 45
 		return json_decode($this->responseJSON);
46 46
 	}
47 47
 
48
-	public function refreshToken($refreshToken){
48
+	public function refreshToken($refreshToken) {
49 49
 		$url = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid={$this->appId}&grant_type=refresh_token&refresh_token=$refreshToken";
50 50
 		$this->responseJSON = $this->httpClient->get($url);
51 51
 		return json_decode($this->responseJSON);
52 52
 	}
53 53
 
54
-	public function verifyToken($accessToken,$openId){
54
+	public function verifyToken($accessToken, $openId) {
55 55
 		$url = "https://api.weixin.qq.com/sns/auth?access_token=$accessToken&openid=$openId";
56 56
 		$this->responseJSON = $this->httpClient->get($url);
57 57
 		return json_decode($this->responseJSON);
58 58
 	}
59 59
 
60
-	public function getAccessToken(){
60
+	public function getAccessToken() {
61 61
 		$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->appId}&secret={$this->appSecret}";
62 62
 		$this->responseJSON = $this->httpClient->get($url);
63 63
 		$json = json_decode($this->responseJSON);
@@ -65,27 +65,27 @@  discard block
 block discarded – undo
65 65
 		return $this->accessToken;
66 66
 	}
67 67
 
68
-	public function getTicket($type = WechatOAuth::TICKETTYPE_JSAPI, $accessToken = null){
69
-		if(!$accessToken) $accessToken = $this->getAccessToken();
68
+	public function getTicket($type = WechatOAuth::TICKETTYPE_JSAPI, $accessToken = null) {
69
+		if (!$accessToken) $accessToken = $this->getAccessToken();
70 70
 		// $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$accessToken";
71 71
 		$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type={$type}&access_token=$accessToken";
72 72
 		$this->responseJSON = $this->httpClient->get($url);
73 73
 		return json_decode($this->responseJSON);
74 74
 	}
75 75
 
76
-	public function getSession($code){
76
+	public function getSession($code) {
77 77
 		$url = "https://api.weixin.qq.com/sns/jscode2session?appid={$this->appId}&secret={$this->appSecret}&js_code=$code&grant_type=authorization_code";
78 78
 		$this->responseJSON = $this->httpClient->get($url);
79 79
 		return json_decode($this->responseJSON);
80 80
 	}
81 81
 
82
-	public function getSignPackage($url = null, $ticket = null){
83
-		if(!$url){
82
+	public function getSignPackage($url = null, $ticket = null) {
83
+		if (!$url) {
84 84
 			$url = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ||
85 85
 				(!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)) ? "https://" : "http://";
86 86
 			$url .= "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
87 87
 		}
88
-		if(!$ticket) $ticket = $this->getTicket();
88
+		if (!$ticket) $ticket = $this->getTicket();
89 89
 		$timestamp = time();
90 90
 		$nonceStr = $this->getNonceStr();
91 91
 		$rawString = "jsapi_ticket=$ticket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
@@ -103,6 +103,6 @@  discard block
 block discarded – undo
103 103
 	}
104 104
 
105 105
 	private function getNonceStr() {
106
-		return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"),0,32);
106
+		return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"), 0, 32);
107 107
 	}
108 108
 }
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -66,7 +66,9 @@  discard block
 block discarded – undo
66 66
 	}
67 67
 
68 68
 	public function getTicket($type = WechatOAuth::TICKETTYPE_JSAPI, $accessToken = null){
69
-		if(!$accessToken) $accessToken = $this->getAccessToken();
69
+		if(!$accessToken) {
70
+			$accessToken = $this->getAccessToken();
71
+		}
70 72
 		// $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$accessToken";
71 73
 		$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type={$type}&access_token=$accessToken";
72 74
 		$this->responseJSON = $this->httpClient->get($url);
@@ -85,7 +87,9 @@  discard block
 block discarded – undo
85 87
 				(!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)) ? "https://" : "http://";
86 88
 			$url .= "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
87 89
 		}
88
-		if(!$ticket) $ticket = $this->getTicket();
90
+		if(!$ticket) {
91
+			$ticket = $this->getTicket();
92
+		}
89 93
 		$timestamp = time();
90 94
 		$nonceStr = $this->getNonceStr();
91 95
 		$rawString = "jsapi_ticket=$ticket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
Please login to merge, or discard this patch.
src/util/HttpClient.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -7,9 +7,9 @@  discard block
 block discarded – undo
7 7
  */
8 8
 namespace zhangv\wechat\pay\util;
9 9
 
10
-class HttpClient{
10
+class HttpClient {
11 11
 
12
-	const GET = 'get',POST = 'post', DELETE = 'delete',PUT = 'put';
12
+	const GET = 'get', POST = 'post', DELETE = 'delete', PUT = 'put';
13 13
 	private $instance = null;
14 14
 	private $errNo = null;
15 15
 	private $info = null;
@@ -19,8 +19,8 @@  discard block
 block discarded – undo
19 19
 		$this->initInstance($timeout);
20 20
 	}
21 21
 
22
-	public function initInstance($timeout){
23
-		if(!$this->instance) {
22
+	public function initInstance($timeout) {
23
+		if (!$this->instance) {
24 24
 			$this->instance = curl_init();
25 25
 			curl_setopt($this->instance, CURLOPT_TIMEOUT, intval($timeout));
26 26
 			curl_setopt($this->instance, CURLOPT_RETURNTRANSFER, true);
@@ -29,26 +29,26 @@  discard block
 block discarded – undo
29 29
 		}
30 30
 	}
31 31
 
32
-	public function get($url,$params = array(),$headers = array(),$opts = array()) {
32
+	public function get($url, $params = array(), $headers = array(), $opts = array()) {
33 33
 		if (!$this->instance)	$this->initInstance($this->timeout);
34
-		if($params && count($params) > 0) $url .= '?' . http_build_query($params);
34
+		if ($params && count($params) > 0) $url .= '?'.http_build_query($params);
35 35
 		curl_setopt($this->instance, CURLOPT_URL, $url);
36 36
 		curl_setopt($this->instance, CURLOPT_HTTPGET, true);
37 37
 		curl_setopt($this->instance, CURLOPT_HTTPHEADER, $headers);
38
-		curl_setopt_array($this->instance,$opts);
38
+		curl_setopt_array($this->instance, $opts);
39 39
 		$result = $this->execute();
40 40
 		curl_close($this->instance);
41 41
 		$this->instance = null;
42 42
 		return $result;
43 43
 	}
44 44
 
45
-	public function post($url, $params = array(),$headers = array(),$opts = array()) {
45
+	public function post($url, $params = array(), $headers = array(), $opts = array()) {
46 46
 		if (!$this->instance)	$this->initInstance($this->timeout);
47 47
 		curl_setopt($this->instance, CURLOPT_URL, $url);
48 48
 		curl_setopt($this->instance, CURLOPT_POST, true);
49 49
 		curl_setopt($this->instance, CURLOPT_POSTFIELDS, $params);
50 50
 		curl_setopt($this->instance, CURLOPT_HTTPHEADER, $headers);
51
-		curl_setopt_array($this->instance,$opts);
51
+		curl_setopt_array($this->instance, $opts);
52 52
 		$result = $this->execute();
53 53
 		curl_close($this->instance);
54 54
 		$this->instance = null;
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 		return $result;
63 63
 	}
64 64
 
65
-	public function getInfo(){
65
+	public function getInfo() {
66 66
 		return $this->info;
67 67
 	}
68 68
 }
69 69
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -28,8 +28,12 @@  discard block
 block discarded – undo
28 28
 	}
29 29
 
30 30
 	public function get($url,$params = array(),$headers = array(),$opts = array()) {
31
-		if (!$this->instance)	$this->initInstance($this->timeout);
32
-		if($params && count($params) > 0) $url .= '?' . http_build_query($params);
31
+		if (!$this->instance) {
32
+			$this->initInstance($this->timeout);
33
+		}
34
+		if($params && count($params) > 0) {
35
+			$url .= '?' . http_build_query($params);
36
+		}
33 37
 		curl_setopt($this->instance, CURLOPT_URL, $url);
34 38
 		curl_setopt($this->instance, CURLOPT_HTTPGET, true);
35 39
 		curl_setopt($this->instance, CURLOPT_HTTPHEADER, $headers);
@@ -41,7 +45,9 @@  discard block
 block discarded – undo
41 45
 	}
42 46
 
43 47
 	public function post($url, $params = array(),$headers = array(),$opts = array()) {
44
-		if (!$this->instance)	$this->initInstance($this->timeout);
48
+		if (!$this->instance) {
49
+			$this->initInstance($this->timeout);
50
+		}
45 51
 		curl_setopt($this->instance, CURLOPT_URL, $url);
46 52
 		curl_setopt($this->instance, CURLOPT_POST, true);
47 53
 		curl_setopt($this->instance, CURLOPT_POSTFIELDS, $params);
Please login to merge, or discard this patch.
src/service/Jsapi.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -38,16 +38,16 @@
 block discarded – undo
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
 	}
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -46,7 +46,9 @@
 block discarded – undo
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"];
Please login to merge, or discard this patch.
src/service/Mchpay.php 2 patches
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -25,19 +25,19 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,15 +79,15 @@  discard block
 block discarded – undo
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
 
86
-	public function rsaEncrypt($data,$pubkey = null){
87
-		if(!$pubkey) $pubkey = $this->getPublicKey();
86
+	public function rsaEncrypt($data, $pubkey = null) {
87
+		if (!$pubkey) $pubkey = $this->getPublicKey();
88 88
 		$encrypted = null;
89 89
 		$pubkey = openssl_get_publickey($pubkey);
90
-		if (@openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING))
90
+		if (@openssl_public_encrypt($data, $encrypted, $pubkey, OPENSSL_PKCS1_OAEP_PADDING))
91 91
 			$data = base64_encode($encrypted);
92 92
 		else
93 93
 			throw new Exception('Unable to encrypt data');
@@ -100,12 +100,12 @@  discard block
 block discarded – undo
100 100
 	 * @param $partner_trade_no
101 101
 	 * @return array
102 102
 	 */
103
-	public function queryTransferBankCard($partner_trade_no){
103
+	public function queryTransferBankCard($partner_trade_no) {
104 104
 		$data = array();
105 105
 		$data["appid"] = $this->config["app_id"];
106 106
 		$data["mch_id"] = $this->config["mch_id"];
107 107
 		$data["partner_trade_no"] = $partner_trade_no;
108
-		$result = $this->post(self::URL_QUERY_TRANSFER_WALLET,$data,true);
108
+		$result = $this->post(self::URL_QUERY_TRANSFER_WALLET, $data, true);
109 109
 		return $result;
110 110
 	}
111 111
 
@@ -116,18 +116,18 @@  discard block
 block discarded – undo
116 116
 	 * @return string
117 117
 	 * @throws Exception
118 118
 	 */
119
-	public function getPublicKey($refresh = false){
120
-		if(!$this->publicKey) {
119
+	public function getPublicKey($refresh = false) {
120
+		if (!$this->publicKey) {
121 121
 			if (!$refresh && file_exists($this->config["rsa_pubkey_path"])) {
122 122
 				$this->publicKey = file_get_contents($this->config["rsa_pubkey_path"]);
123
-			}else{
123
+			}else {
124 124
 				$data = array();
125 125
 				$data["mch_id"] = $this->config["mch_id"];
126 126
 				$data["sign_type"] = $this->config["sign_type"];
127 127
 				$result = $this->post(self::URL_GETPUBLICKEY, $data, true);
128 128
 				$pubkey = $result['pub_key'];
129 129
 				$this->publicKey = $this->convertPKCS1toPKCS8($pubkey);
130
-				if($fp = @fopen($this->config["rsa_pubkey_path"], "w")) {
130
+				if ($fp = @fopen($this->config["rsa_pubkey_path"], "w")) {
131 131
 					fwrite($fp, $this->publicKey);
132 132
 					fclose($fp);
133 133
 				}
@@ -136,16 +136,16 @@  discard block
 block discarded – undo
136 136
 		return $this->publicKey;
137 137
 	}
138 138
 
139
-	public function setPublicKey($publicKey){
139
+	public function setPublicKey($publicKey) {
140 140
 		$this->publicKey = $publicKey;
141 141
 	}
142 142
 
143
-	private function convertPKCS1toPKCS8($pkcs1){
143
+	private function convertPKCS1toPKCS8($pkcs1) {
144 144
 		$start_key = $pkcs1;
145 145
 		$start_key = str_replace('-----BEGIN RSA PUBLIC KEY-----', '', $start_key);
146 146
 		$start_key = trim(str_replace('-----END RSA PUBLIC KEY-----', '', $start_key));
147
-		$key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' . str_replace("\n", '', $start_key);
148
-		$key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($key, 64, "\n", true) . "\n-----END PUBLIC KEY-----";
147
+		$key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A'.str_replace("\n", '', $start_key);
148
+		$key = "-----BEGIN PUBLIC KEY-----\n".wordwrap($key, 64, "\n", true)."\n-----END PUBLIC KEY-----";
149 149
 		return $key;
150 150
 	}
151 151
 }
152 152
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +15 added lines, -8 removed lines patch added patch discarded remove patch
@@ -27,7 +27,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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);
@@ -84,13 +88,16 @@  discard block
 block discarded – undo
84 88
 	}
85 89
 
86 90
 	public function rsaEncrypt($data,$pubkey = null){
87
-		if(!$pubkey) $pubkey = $this->getPublicKey();
91
+		if(!$pubkey) {
92
+			$pubkey = $this->getPublicKey();
93
+		}
88 94
 		$encrypted = null;
89 95
 		$pubkey = openssl_get_publickey($pubkey);
90
-		if (@openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING))
91
-			$data = base64_encode($encrypted);
92
-		else
93
-			throw new Exception('Unable to encrypt data');
96
+		if (@openssl_public_encrypt($data, $encrypted, $pubkey,OPENSSL_PKCS1_OAEP_PADDING)) {
97
+					$data = base64_encode($encrypted);
98
+		} else {
99
+					throw new Exception('Unable to encrypt data');
100
+		}
94 101
 		return $data;
95 102
 	}
96 103
 
@@ -120,7 +127,7 @@  discard block
 block discarded – undo
120 127
 		if(!$this->publicKey) {
121 128
 			if (!$refresh && file_exists($this->config["rsa_pubkey_path"])) {
122 129
 				$this->publicKey = file_get_contents($this->config["rsa_pubkey_path"]);
123
-			}else{
130
+			} else{
124 131
 				$data = array();
125 132
 				$data["mch_id"] = $this->config["mch_id"];
126 133
 				$data["sign_type"] = $this->config["sign_type"];
Please login to merge, or discard this patch.