@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | 'scope' => $this->config['scope'], |
42 | 42 | 'state' => $this->config['state'], |
43 | 43 | ]; |
44 | - return self::AUTHORIZE_URL . '?' . http_build_query($params); |
|
44 | + return self::AUTHORIZE_URL.'?'.http_build_query($params); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | 'avatar' => $result['picture'], |
71 | 71 | 'native' => $result, |
72 | 72 | ); |
73 | - if(isset($result['email'])){ |
|
73 | + if (isset($result['email'])) { |
|
74 | 74 | $userInfo['email'] = $result['email']; |
75 | 75 | } |
76 | 76 | return $userInfo; |
@@ -81,14 +81,14 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function getUserInfo() |
83 | 83 | { |
84 | - if($this->type == 'app'){//App登录 |
|
85 | - if(!isset($_REQUEST['code']) ){ |
|
84 | + if ($this->type == 'app') {//App登录 |
|
85 | + if (!isset($_REQUEST['code'])) { |
|
86 | 86 | throw new OAuthException("Google APP登录 需要传输code参数! "); |
87 | 87 | } |
88 | 88 | } |
89 | 89 | $this->getToken(); |
90 | - $headers = ['Authorization: Bearer ' . $this->token['access_token']]; |
|
91 | - $data = $this->get(self::API_BASE . 'oauth2/v2/userinfo', '', $headers); |
|
90 | + $headers = ['Authorization: Bearer '.$this->token['access_token']]; |
|
91 | + $data = $this->get(self::API_BASE.'oauth2/v2/userinfo', '', $headers); |
|
92 | 92 | return json_decode($data, true); |
93 | 93 | } |
94 | 94 |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | if (!$config) { |
113 | 113 | throw new OAuthException('传入的配置不能为空'); |
114 | 114 | } |
115 | - if(isset($_GET['referer']) && $config['callback']){ |
|
115 | + if (isset($_GET['referer']) && $config['callback']) { |
|
116 | 116 | $config['callback'] .= ((strpos($config['callback'], '?') !== false) ? '&' : '?').'referer='.$_GET['referer']; |
117 | 117 | } |
118 | 118 | //默认参数 |
@@ -125,11 +125,11 @@ discard block |
||
125 | 125 | 'proxy' => '', |
126 | 126 | 'state' => '', |
127 | 127 | 'type' => '', |
128 | - 'is_sandbox' => false,//是否是沙箱环境 |
|
128 | + 'is_sandbox' => false, //是否是沙箱环境 |
|
129 | 129 | ]; |
130 | - $this->config = array_merge($_config, $config); |
|
131 | - foreach($this->config as $key=>$val){ |
|
132 | - if(property_exists($this,$key)) $this->$key=$val; |
|
130 | + $this->config = array_merge($_config, $config); |
|
131 | + foreach ($this->config as $key=>$val) { |
|
132 | + if (property_exists($this, $key)) $this->$key = $val; |
|
133 | 133 | } |
134 | 134 | $this->timestamp = time(); |
135 | 135 | } |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * Updater: |
166 | 166 | * @return $this |
167 | 167 | */ |
168 | - public function mustCheckState(){ |
|
168 | + public function mustCheckState() { |
|
169 | 169 | $this->checkState = true; |
170 | 170 | return $this; |
171 | 171 | } |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | * @Author: TinyMeng <[email protected]> |
176 | 176 | * @return array |
177 | 177 | */ |
178 | - public function getConfig(){ |
|
178 | + public function getConfig() { |
|
179 | 179 | return $this->config; |
180 | 180 | } |
181 | 181 | |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | * @param $token |
185 | 185 | * @return $this |
186 | 186 | */ |
187 | - public function setToken($token){ |
|
187 | + public function setToken($token) { |
|
188 | 188 | $this->token = $token; |
189 | 189 | return $this; |
190 | 190 | } |
@@ -193,14 +193,14 @@ discard block |
||
193 | 193 | * 存储state |
194 | 194 | * @Author: TinyMeng <[email protected]> |
195 | 195 | */ |
196 | - public function saveState(){ |
|
196 | + public function saveState() { |
|
197 | 197 | if ($this->checkState === true) { |
198 | 198 | //是否开启session |
199 | 199 | if (session_status() !== PHP_SESSION_ACTIVE) { |
200 | 200 | session_start(); |
201 | 201 | } |
202 | - if(empty($this->config['state'])){ |
|
203 | - $this->config['state'] = Str::random();//生成随机state |
|
202 | + if (empty($this->config['state'])) { |
|
203 | + $this->config['state'] = Str::random(); //生成随机state |
|
204 | 204 | } |
205 | 205 | //存储到session |
206 | 206 | $_SESSION['tinymeng_oauth_state'] = $this->config['state']; |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | * @Author: TinyMeng <[email protected]> |
213 | 213 | * @throws OAuthException |
214 | 214 | */ |
215 | - public function checkState(){ |
|
215 | + public function checkState() { |
|
216 | 216 | if ($this->checkState === true) { |
217 | 217 | if (session_status() !== PHP_SESSION_ACTIVE) { |
218 | 218 | session_start(); |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * @author: JiaMeng <[email protected]> |
230 | 230 | * @return string |
231 | 231 | */ |
232 | - public function getCode(){ |
|
232 | + public function getCode() { |
|
233 | 233 | return isset($_REQUEST['code']) ? $_REQUEST['code'] : ''; |
234 | 234 | } |
235 | 235 | |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * Updater: |
240 | 240 | * @return array |
241 | 241 | */ |
242 | - protected function accessTokenParams(){ |
|
242 | + protected function accessTokenParams() { |
|
243 | 243 | $params = [ |
244 | 244 | 'client_id' => $this->config['app_id'], |
245 | 245 | 'client_secret' => $this->config['app_secret'], |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | * @author: JiaMeng <[email protected]> |
256 | 256 | * Updater: |
257 | 257 | */ |
258 | - protected function getToken(){ |
|
258 | + protected function getToken() { |
|
259 | 259 | if (empty($this->token)) { |
260 | 260 | /** 验证state参数 */ |
261 | 261 | $this->checkState(); |
@@ -264,10 +264,10 @@ discard block |
||
264 | 264 | $params = $this->accessTokenParams(); |
265 | 265 | |
266 | 266 | /** 获取access_token */ |
267 | - $token = $this->post($this->AccessTokenURL, $params,$this->getHeaders()); |
|
267 | + $token = $this->post($this->AccessTokenURL, $params, $this->getHeaders()); |
|
268 | 268 | /** 解析token值(子类实现此方法) */ |
269 | 269 | $this->token = $this->parseToken($token); |
270 | - }else{ |
|
270 | + } else { |
|
271 | 271 | return $this->token; |
272 | 272 | } |
273 | 273 | } |
@@ -277,8 +277,8 @@ discard block |
||
277 | 277 | * M代表男性,F代表女性 |
278 | 278 | * @param $gender |
279 | 279 | */ |
280 | - public function getGender($gender){ |
|
281 | - return strtolower(substr($gender , 0 , 1)) == 'm' ? ConstCode::GENDER_MAN : ConstCode::GENDER_WOMEN; |
|
280 | + public function getGender($gender) { |
|
281 | + return strtolower(substr($gender, 0, 1)) == 'm' ? ConstCode::GENDER_MAN : ConstCode::GENDER_WOMEN; |
|
282 | 282 | } |
283 | 283 | |
284 | 284 |
@@ -129,7 +129,9 @@ discard block |
||
129 | 129 | ]; |
130 | 130 | $this->config = array_merge($_config, $config); |
131 | 131 | foreach($this->config as $key=>$val){ |
132 | - if(property_exists($this,$key)) $this->$key=$val; |
|
132 | + if(property_exists($this,$key)) { |
|
133 | + $this->$key=$val; |
|
134 | + } |
|
133 | 135 | } |
134 | 136 | $this->timestamp = time(); |
135 | 137 | } |
@@ -267,7 +269,7 @@ discard block |
||
267 | 269 | $token = $this->post($this->AccessTokenURL, $params,$this->getHeaders()); |
268 | 270 | /** 解析token值(子类实现此方法) */ |
269 | 271 | $this->token = $this->parseToken($token); |
270 | - }else{ |
|
272 | + } else{ |
|
271 | 273 | return $this->token; |
272 | 274 | } |
273 | 275 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | */ |
36 | 36 | protected function get($url, $params = [], $headers = []) |
37 | 37 | { |
38 | - return HttpRequest::httpGet($url, $params,$headers); |
|
38 | + return HttpRequest::httpGet($url, $params, $headers); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | */ |
50 | 50 | protected function post($url, $params = [], $headers = []) |
51 | 51 | { |
52 | - return HttpRequest::httpPost($url, $params,$headers); |
|
52 | + return HttpRequest::httpPost($url, $params, $headers); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 |
@@ -24,11 +24,11 @@ discard block |
||
24 | 24 | exit("<script language='javascript'>window.location.href='./';</script>"); |
25 | 25 | |
26 | 26 | } elseif (isset($arr['code'])) { |
27 | - exit('登录失败,返回错误原因:' . $arr['msg']); |
|
27 | + exit('登录失败,返回错误原因:'.$arr['msg']); |
|
28 | 28 | } else { |
29 | 29 | exit('获取登录数据失败'); |
30 | 30 | } |
31 | - }catch (\Exception $exception){ |
|
31 | + } catch (\Exception $exception) { |
|
32 | 32 | echo $exception->getFile(); |
33 | 33 | echo $exception->getLine(); |
34 | 34 | echo $exception->getMessage(); |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | if (isset($arr['code']) && $arr['code'] == 0) { |
40 | 40 | exit("<script language='javascript'>window.location.href='{$arr['url']}';</script>"); |
41 | 41 | } elseif (isset($arr['code'])) { |
42 | - exit('登录接口返回:' . $arr['msg']); |
|
42 | + exit('登录接口返回:'.$arr['msg']); |
|
43 | 43 | } else { |
44 | 44 | exit('获取登录地址失败'); |
45 | 45 | } |
@@ -28,7 +28,7 @@ |
||
28 | 28 | } else { |
29 | 29 | exit('获取登录数据失败'); |
30 | 30 | } |
31 | - }catch (\Exception $exception){ |
|
31 | + } catch (\Exception $exception){ |
|
32 | 32 | echo $exception->getFile(); |
33 | 33 | echo $exception->getLine(); |
34 | 34 | echo $exception->getMessage(); |