@@ -33,9 +33,9 @@ discard block |
||
33 | 33 | /** |
34 | 34 | * @param $config |
35 | 35 | */ |
36 | - public function __construct($config=[]) |
|
36 | + public function __construct($config = []) |
|
37 | 37 | { |
38 | - if(!empty($config)){ |
|
38 | + if (!empty($config)) { |
|
39 | 39 | $this->config = $config; |
40 | 40 | $this->loadConfigGateway(); |
41 | 41 | } |
@@ -47,11 +47,11 @@ discard block |
||
47 | 47 | */ |
48 | 48 | private function loadConfigGateway() |
49 | 49 | { |
50 | - $gateway = $this->config['gateway'];// 正式环境 |
|
51 | - if($this->config['sandbox'] === false){ |
|
52 | - $this->gateway = isset($gateway[$this->gateway_type]) ? $gateway[$this->gateway_type] : $gateway['default'];// 沙箱环境 |
|
53 | - }else{ |
|
54 | - $this->gateway = $gateway['sandbox'];// 沙箱环境 |
|
50 | + $gateway = $this->config['gateway']; // 正式环境 |
|
51 | + if ($this->config['sandbox'] === false) { |
|
52 | + $this->gateway = isset($gateway[$this->gateway_type]) ? $gateway[$this->gateway_type] : $gateway['default']; // 沙箱环境 |
|
53 | + } else { |
|
54 | + $this->gateway = $gateway['sandbox']; // 沙箱环境 |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | return $this; |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | try { |
84 | 84 | $data = $this->loadData($data); |
85 | 85 | $sign = $this->generateSign($data); |
86 | - $gateway = $this->gateway . $this->api; |
|
86 | + $gateway = $this->gateway . $this->api; |
|
87 | 87 | |
88 | 88 | if ('cli' == php_sapi_name()) { |
89 | 89 | echo 'api:' . $gateway . PHP_EOL; |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | { |
120 | 120 | try { |
121 | 121 | $data = $this->loadData($data); |
122 | - $params = $this->generateSign($data,true); |
|
123 | - $gateway = $this->gateway . $this->api; |
|
122 | + $params = $this->generateSign($data, true); |
|
123 | + $gateway = $this->gateway . $this->api; |
|
124 | 124 | |
125 | 125 | $data = json_encode($data); |
126 | 126 | if ('cli' == php_sapi_name()) { |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | CURLOPT_TIMEOUT => 60, |
135 | 135 | CURLOPT_CONNECTTIMEOUT => 30 |
136 | 136 | ]; |
137 | - $response = Http::get($gateway,$params,$options); |
|
137 | + $response = Http::get($gateway, $params, $options); |
|
138 | 138 | $this->writeLog('response:' . $response); |
139 | 139 | return $response; |
140 | 140 | } catch (Exception $e) { |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | * @param bool $openForm |
186 | 186 | * @return string|array |
187 | 187 | */ |
188 | - public function generateSign($body,$openForm=false) |
|
188 | + public function generateSign($body, $openForm = false) |
|
189 | 189 | { |
190 | 190 | $body = (!is_string($body)) ? json_encode($body) : $body; |
191 | 191 | $appid = $this->config['appid']; |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | $str = bin2hex(hash('sha256', $body, true)); |
196 | 196 | $signature = base64_encode(hash_hmac('sha256', "$appid$timestamp$nonce$str", $appkey, true)); |
197 | 197 | $authorization = "OPEN-BODY-SIG AppId=\"$appid\", Timestamp=\"$timestamp\", Nonce=\"$nonce\", Signature=\"$signature\""; |
198 | - if($openForm){ |
|
198 | + if ($openForm) { |
|
199 | 199 | return [ |
200 | 200 | 'appId'=>$appid, |
201 | 201 | 'timestamp'=>$timestamp, |
@@ -222,8 +222,8 @@ discard block |
||
222 | 222 | * @param $message |
223 | 223 | * @return void |
224 | 224 | */ |
225 | - public function writeLog($message,$fileName='chinaums') |
|
225 | + public function writeLog($message, $fileName = 'chinaums') |
|
226 | 226 | { |
227 | - FileTool::writeLog($message,$fileName); |
|
227 | + FileTool::writeLog($message, $fileName); |
|
228 | 228 | } |
229 | 229 | } |