@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | if (!$config) { |
86 | 86 | throw new \Exception('传入的配置不能为空'); |
87 | 87 | } |
88 | - if(isset($_GET['referer']) && $config['callback']){ |
|
88 | + if (isset($_GET['referer']) && $config['callback']) { |
|
89 | 89 | $config['callback'] .= ((strpos($config['callback'], '?') !== false) ? '&' : '?').'referer='.$_GET['referer']; |
90 | 90 | } |
91 | 91 | //默认参数 |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | 'proxy' => '', |
99 | 99 | 'state' => '', |
100 | 100 | 'type' => '', |
101 | - 'is_sandbox' => false,//是否是沙箱环境 |
|
101 | + 'is_sandbox' => false, //是否是沙箱环境 |
|
102 | 102 | ]; |
103 | - $this->config = array_merge($_config, $config); |
|
104 | - foreach($this->config as $key=>$val){ |
|
105 | - if(property_exists($this,$key)) $this->$key=$val; |
|
103 | + $this->config = array_merge($_config, $config); |
|
104 | + foreach ($this->config as $key=>$val) { |
|
105 | + if (property_exists($this, $key)) $this->$key = $val; |
|
106 | 106 | } |
107 | 107 | $this->timestamp = time(); |
108 | 108 | } |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | * Updater: |
139 | 139 | * @return $this |
140 | 140 | */ |
141 | - public function mustCheckState(){ |
|
141 | + public function mustCheckState() { |
|
142 | 142 | $this->checkState = true; |
143 | 143 | return $this; |
144 | 144 | } |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | * @Author: TinyMeng <[email protected]> |
149 | 149 | * @return array |
150 | 150 | */ |
151 | - public function getConfig(){ |
|
151 | + public function getConfig() { |
|
152 | 152 | return $this->config; |
153 | 153 | } |
154 | 154 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @param $token |
158 | 158 | * @return $this |
159 | 159 | */ |
160 | - public function setToken($token){ |
|
160 | + public function setToken($token) { |
|
161 | 161 | $this->token = $token; |
162 | 162 | return $this; |
163 | 163 | } |
@@ -166,14 +166,14 @@ discard block |
||
166 | 166 | * 存储state |
167 | 167 | * @Author: TinyMeng <[email protected]> |
168 | 168 | */ |
169 | - public function saveState(){ |
|
169 | + public function saveState() { |
|
170 | 170 | if ($this->checkState === true) { |
171 | 171 | //是否开启session |
172 | 172 | if (session_status() !== PHP_SESSION_ACTIVE) { |
173 | 173 | session_start(); |
174 | 174 | } |
175 | - if(empty($this->config['state'])){ |
|
176 | - $this->config['state'] = Str::random();//生成随机state |
|
175 | + if (empty($this->config['state'])) { |
|
176 | + $this->config['state'] = Str::random(); //生成随机state |
|
177 | 177 | } |
178 | 178 | //存储到session |
179 | 179 | $_SESSION['tinymeng_oauth_state'] = $this->config['state']; |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | * @Author: TinyMeng <[email protected]> |
186 | 186 | * @throws \Exception |
187 | 187 | */ |
188 | - public function CheckState(){ |
|
188 | + public function CheckState() { |
|
189 | 189 | if ($this->checkState === true) { |
190 | 190 | if (session_status() !== PHP_SESSION_ACTIVE) { |
191 | 191 | session_start(); |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | * Updater: |
203 | 203 | * @return array |
204 | 204 | */ |
205 | - protected function accessTokenParams(){ |
|
205 | + protected function accessTokenParams() { |
|
206 | 206 | $params = [ |
207 | 207 | 'client_id' => $this->config['app_id'], |
208 | 208 | 'client_secret' => $this->config['app_secret'], |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | * @author: JiaMeng <[email protected]> |
219 | 219 | * Updater: |
220 | 220 | */ |
221 | - protected function getToken(){ |
|
221 | + protected function getToken() { |
|
222 | 222 | if (empty($this->token)) { |
223 | 223 | /** 验证state参数 */ |
224 | 224 | $this->CheckState(); |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | $params = $this->accessTokenParams(); |
228 | 228 | |
229 | 229 | /** 获取access_token */ |
230 | - $token = $this->POST($this->AccessTokenURL, $params); |
|
230 | + $token = $this->POST($this->AccessTokenURL, $params); |
|
231 | 231 | /** 解析token值(子类实现此方法) */ |
232 | 232 | $this->token = $this->parseToken($token); |
233 | 233 | } |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | */ |
245 | 245 | protected function get($url, $params = [], $headers = []) |
246 | 246 | { |
247 | - return \tinymeng\tools\HttpRequest::httpGet($url, $params,$headers); |
|
247 | + return \tinymeng\tools\HttpRequest::httpGet($url, $params, $headers); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
@@ -258,8 +258,8 @@ discard block |
||
258 | 258 | */ |
259 | 259 | protected function post($url, $params = [], $headers = []) |
260 | 260 | { |
261 | - $headers[] = 'Accept: application/json';//GitHub需要的header |
|
262 | - return \tinymeng\tools\HttpRequest::httpPost($url, $params,$headers); |
|
261 | + $headers[] = 'Accept: application/json'; //GitHub需要的header |
|
262 | + return \tinymeng\tools\HttpRequest::httpPost($url, $params, $headers); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | * M代表男性,F代表女性 |
268 | 268 | * @param $gender |
269 | 269 | */ |
270 | - public function getGender($gender){ |
|
271 | - return strtolower(substr($gender , 0 , 1)) == 'm' ? ConstCode::GENDER_MAN : ConstCode::GENDER_WOMEN; |
|
270 | + public function getGender($gender) { |
|
271 | + return strtolower(substr($gender, 0, 1)) == 'm' ? ConstCode::GENDER_MAN : ConstCode::GENDER_WOMEN; |
|
272 | 272 | } |
273 | 273 | } |