@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | protected function get($url, $params = [], $headers = []) |
23 | 23 | { |
24 | - return HttpRequest::httpGet($url, $params,$headers); |
|
24 | + return HttpRequest::httpGet($url, $params, $headers); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | */ |
36 | 36 | protected function post($url, $params = [], $headers = []) |
37 | 37 | { |
38 | - $headers[] = 'Accept: application/json';//GitHub需要的header |
|
39 | - return HttpRequest::httpPost($url, $params,$headers); |
|
38 | + $headers[] = 'Accept: application/json'; //GitHub需要的header |
|
39 | + return HttpRequest::httpPost($url, $params, $headers); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 |
@@ -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); |
|
267 | + $token = $this->post($this->AccessTokenURL, $params); |
|
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); |
268 | 270 | /** 解析token值(子类实现此方法) */ |
269 | 271 | $this->token = $this->parseToken($token); |
270 | - }else{ |
|
272 | + } else{ |
|
271 | 273 | return $this->token; |
272 | 274 | } |
273 | 275 | } |
@@ -30,11 +30,11 @@ |
||
30 | 30 | } |
31 | 31 | } else { |
32 | 32 | $arr = $oauth->login($type); |
33 | - if (isset($arr['code']) && $arr['code'] == 0) { |
|
34 | - exit("<script language='javascript'>window.location.href='{$arr['url']}';</script>"); |
|
35 | - } elseif (isset($arr['code'])) { |
|
36 | - exit('登录接口返回:' . $arr['msg']); |
|
37 | - } else { |
|
38 | - exit('获取登录地址失败'); |
|
39 | - } |
|
33 | + if (isset($arr['code']) && $arr['code'] == 0) { |
|
34 | + exit("<script language='javascript'>window.location.href='{$arr['url']}';</script>"); |
|
35 | + } elseif (isset($arr['code'])) { |
|
36 | + exit('登录接口返回:' . $arr['msg']); |
|
37 | + } else { |
|
38 | + exit('获取登录地址失败'); |
|
39 | + } |
|
40 | 40 | } |
@@ -24,7 +24,7 @@ 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 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | if (isset($arr['code']) && $arr['code'] == 0) { |
34 | 34 | exit("<script language='javascript'>window.location.href='{$arr['url']}';</script>"); |
35 | 35 | } elseif (isset($arr['code'])) { |
36 | - exit('登录接口返回:' . $arr['msg']); |
|
36 | + exit('登录接口返回:'.$arr['msg']); |
|
37 | 37 | } else { |
38 | 38 | exit('获取登录地址失败'); |
39 | 39 | } |
@@ -24,16 +24,16 @@ |
||
24 | 24 | <div class="list-group"> |
25 | 25 | <?php foreach ($_SESSION['user'] as $key => $value):?> |
26 | 26 | <div class="form-group"> |
27 | - <label><?php echo $key;?>:</label> |
|
28 | - <?php if(is_array($value)):?> |
|
27 | + <label><?php echo $key; ?>:</label> |
|
28 | + <?php if (is_array($value)):?> |
|
29 | 29 | <textarea rows="5" class="form-control" readonly="readonly"> |
30 | 30 | <?php echo json_encode($value); ?> |
31 | 31 | </textarea> |
32 | 32 | <?php else:?> |
33 | 33 | <input type="text" value="<?php echo $value; ?>" class="form-control" readonly="readonly"/> |
34 | - <?php endif;?> |
|
34 | + <?php endif; ?> |
|
35 | 35 | </div> |
36 | - <?php endforeach;?> |
|
36 | + <?php endforeach; ?> |
|
37 | 37 | </div> |
38 | 38 | </div> |
39 | 39 | </div> |
@@ -29,8 +29,11 @@ |
||
29 | 29 | <textarea rows="5" class="form-control" readonly="readonly"> |
30 | 30 | <?php echo json_encode($value); ?> |
31 | 31 | </textarea> |
32 | - <?php else:?> |
|
33 | - <input type="text" value="<?php echo $value; ?>" class="form-control" readonly="readonly"/> |
|
32 | + <?php else { |
|
33 | + :?> |
|
34 | + <input type="text" value="<?php echo $value; |
|
35 | +} |
|
36 | +?>" class="form-control" readonly="readonly"/> |
|
34 | 37 | <?php endif;?> |
35 | 38 | </div> |
36 | 39 | <?php endforeach;?> |