@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | if (!$config) { |
92 | 92 | throw new \Exception('传入的配置不能为空'); |
93 | 93 | } |
94 | - if(isset($_GET['referer']) && $config['callback']){ |
|
94 | + if (isset($_GET['referer']) && $config['callback']) { |
|
95 | 95 | $config['callback'] .= ((strpos($config['callback'], '?') !== false) ? '&' : '?').'referer='.$_GET['referer']; |
96 | 96 | } |
97 | 97 | //默认参数 |
@@ -104,11 +104,11 @@ discard block |
||
104 | 104 | 'proxy' => '', |
105 | 105 | 'state' => '', |
106 | 106 | 'type' => '', |
107 | - 'is_sandbox' => false,//是否是沙箱环境 |
|
107 | + 'is_sandbox' => false, //是否是沙箱环境 |
|
108 | 108 | ]; |
109 | - $this->config = array_merge($_config, $config); |
|
110 | - foreach($this->config as $key=>$val){ |
|
111 | - if(property_exists($this,$key)) $this->$key=$val; |
|
109 | + $this->config = array_merge($_config, $config); |
|
110 | + foreach ($this->config as $key=>$val) { |
|
111 | + if (property_exists($this, $key)) $this->$key = $val; |
|
112 | 112 | } |
113 | 113 | $this->timestamp = time(); |
114 | 114 | } |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * Updater: |
145 | 145 | * @return $this |
146 | 146 | */ |
147 | - public function mustCheckState(){ |
|
147 | + public function mustCheckState() { |
|
148 | 148 | $this->checkState = true; |
149 | 149 | return $this; |
150 | 150 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @Author: TinyMeng <[email protected]> |
155 | 155 | * @return array |
156 | 156 | */ |
157 | - public function getConfig(){ |
|
157 | + public function getConfig() { |
|
158 | 158 | return $this->config; |
159 | 159 | } |
160 | 160 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @param $token |
164 | 164 | * @return $this |
165 | 165 | */ |
166 | - public function setToken($token){ |
|
166 | + public function setToken($token) { |
|
167 | 167 | $this->token = $token; |
168 | 168 | return $this; |
169 | 169 | } |
@@ -172,14 +172,14 @@ discard block |
||
172 | 172 | * 存储state |
173 | 173 | * @Author: TinyMeng <[email protected]> |
174 | 174 | */ |
175 | - public function saveState(){ |
|
175 | + public function saveState() { |
|
176 | 176 | if ($this->checkState === true) { |
177 | 177 | //是否开启session |
178 | 178 | if (session_status() !== PHP_SESSION_ACTIVE) { |
179 | 179 | session_start(); |
180 | 180 | } |
181 | - if(empty($this->config['state'])){ |
|
182 | - $this->config['state'] = Str::random();//生成随机state |
|
181 | + if (empty($this->config['state'])) { |
|
182 | + $this->config['state'] = Str::random(); //生成随机state |
|
183 | 183 | } |
184 | 184 | //存储到session |
185 | 185 | $_SESSION['tinymeng_oauth_state'] = $this->config['state']; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * @Author: TinyMeng <[email protected]> |
192 | 192 | * @throws \Exception |
193 | 193 | */ |
194 | - public function checkState(){ |
|
194 | + public function checkState() { |
|
195 | 195 | if ($this->checkState === true) { |
196 | 196 | if (session_status() !== PHP_SESSION_ACTIVE) { |
197 | 197 | session_start(); |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | * @author: JiaMeng <[email protected]> |
209 | 209 | * @return string |
210 | 210 | */ |
211 | - public function getCode(){ |
|
211 | + public function getCode() { |
|
212 | 212 | return isset($_REQUEST['code']) ? $_REQUEST['code'] : ''; |
213 | 213 | } |
214 | 214 | |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | * Updater: |
219 | 219 | * @return array |
220 | 220 | */ |
221 | - protected function accessTokenParams(){ |
|
221 | + protected function accessTokenParams() { |
|
222 | 222 | $params = [ |
223 | 223 | 'client_id' => $this->config['app_id'], |
224 | 224 | 'client_secret' => $this->config['app_secret'], |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | * @author: JiaMeng <[email protected]> |
235 | 235 | * Updater: |
236 | 236 | */ |
237 | - protected function getToken(){ |
|
237 | + protected function getToken() { |
|
238 | 238 | if (empty($this->token)) { |
239 | 239 | /** 验证state参数 */ |
240 | 240 | $this->checkState(); |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | $params = $this->accessTokenParams(); |
244 | 244 | |
245 | 245 | /** 获取access_token */ |
246 | - $token = $this->POST($this->AccessTokenURL, $params); |
|
246 | + $token = $this->POST($this->AccessTokenURL, $params); |
|
247 | 247 | /** 解析token值(子类实现此方法) */ |
248 | 248 | $this->token = $this->parseToken($token); |
249 | 249 | } |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | */ |
261 | 261 | protected function get($url, $params = [], $headers = []) |
262 | 262 | { |
263 | - return \tinymeng\tools\HttpRequest::httpGet($url, $params,$headers); |
|
263 | + return \tinymeng\tools\HttpRequest::httpGet($url, $params, $headers); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
@@ -274,8 +274,8 @@ discard block |
||
274 | 274 | */ |
275 | 275 | protected function post($url, $params = [], $headers = []) |
276 | 276 | { |
277 | - $headers[] = 'Accept: application/json';//GitHub需要的header |
|
278 | - return \tinymeng\tools\HttpRequest::httpPost($url, $params,$headers); |
|
277 | + $headers[] = 'Accept: application/json'; //GitHub需要的header |
|
278 | + return \tinymeng\tools\HttpRequest::httpPost($url, $params, $headers); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * M代表男性,F代表女性 |
284 | 284 | * @param $gender |
285 | 285 | */ |
286 | - public function getGender($gender){ |
|
287 | - return strtolower(substr($gender , 0 , 1)) == 'm' ? ConstCode::GENDER_MAN : ConstCode::GENDER_WOMEN; |
|
286 | + public function getGender($gender) { |
|
287 | + return strtolower(substr($gender, 0, 1)) == 'm' ? ConstCode::GENDER_MAN : ConstCode::GENDER_WOMEN; |
|
288 | 288 | } |
289 | 289 | } |