@@ -80,7 +80,7 @@ |
||
| 80 | 80 | } |
| 81 | 81 | $this->token['token_type'] = 'Bearer'; |
| 82 | 82 | $this->token['access_token'] = $_REQUEST['access_token']; |
| 83 | - }else { |
|
| 83 | + } else { |
|
| 84 | 84 | $this->getToken(); |
| 85 | 85 | } |
| 86 | 86 | $data = $this->call('nid/me', $this->token, 'GET'); |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | 'scope' => $this->config['scope'], |
| 40 | 40 | 'state' => $this->config['state'] ?: Str::random(), |
| 41 | 41 | ]; |
| 42 | - return $this->AuthorizeURL . '?' . http_build_query($params); |
|
| 42 | + return $this->AuthorizeURL.'?'.http_build_query($params); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -76,13 +76,13 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | public function getUserInfo() |
| 78 | 78 | { |
| 79 | - if($this->type == 'app'){//App登录 |
|
| 80 | - if(!isset($_REQUEST['access_token']) ){ |
|
| 79 | + if ($this->type == 'app') {//App登录 |
|
| 80 | + if (!isset($_REQUEST['access_token'])) { |
|
| 81 | 81 | throw new OAuthException("Naver APP登录 需要传输access_token参数! "); |
| 82 | 82 | } |
| 83 | 83 | $this->token['token_type'] = 'Bearer'; |
| 84 | 84 | $this->token['access_token'] = $_REQUEST['access_token']; |
| 85 | - }else { |
|
| 85 | + } else { |
|
| 86 | 86 | $this->getToken(); |
| 87 | 87 | } |
| 88 | 88 | $data = $this->call('nid/me', $this->token, 'GET'); |
@@ -105,10 +105,10 @@ discard block |
||
| 105 | 105 | $method = strtoupper($method); |
| 106 | 106 | $request = [ |
| 107 | 107 | 'method' => $method, |
| 108 | - 'uri' => self::API_BASE . $api, |
|
| 108 | + 'uri' => self::API_BASE.$api, |
|
| 109 | 109 | ]; |
| 110 | 110 | |
| 111 | - $headers = ['Authorization' => $this->token['token_type'] . ' ' . $this->token['access_token']]; |
|
| 111 | + $headers = ['Authorization' => $this->token['token_type'].' '.$this->token['access_token']]; |
|
| 112 | 112 | |
| 113 | 113 | $data = $this->$method($request['uri'], $params, $headers); |
| 114 | 114 | |
@@ -94,7 +94,7 @@ |
||
| 94 | 94 | } |
| 95 | 95 | $this->token['access_token'] = $_REQUEST['access_token']; |
| 96 | 96 | $this->token['openid'] = $_REQUEST['uid']; |
| 97 | - }else{ |
|
| 97 | + } else{ |
|
| 98 | 98 | /** 获取参数 */ |
| 99 | 99 | $params = $this->accessTokenParams(); |
| 100 | 100 | $this->AccessTokenURL = $this->AccessTokenURL. '?' . http_build_query($params);//get传参 |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | 'state' => $this->config['state'], |
| 39 | 39 | 'display' => $this->display, |
| 40 | 40 | ]; |
| 41 | - return $this->AuthorizeURL . '?' . http_build_query($params); |
|
| 41 | + return $this->AuthorizeURL.'?'.http_build_query($params); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -91,16 +91,16 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | public function getUserInfo() |
| 93 | 93 | { |
| 94 | - if($this->type == 'app'){//App登录 |
|
| 95 | - if(!isset($_REQUEST['access_token']) || !isset($_REQUEST['uid'])){ |
|
| 94 | + if ($this->type == 'app') {//App登录 |
|
| 95 | + if (!isset($_REQUEST['access_token']) || !isset($_REQUEST['uid'])) { |
|
| 96 | 96 | throw new OAuthException("Sina APP登录 需要传输access_token和uid参数! "); |
| 97 | 97 | } |
| 98 | 98 | $this->token['access_token'] = $_REQUEST['access_token']; |
| 99 | 99 | $this->token['openid'] = $_REQUEST['uid']; |
| 100 | - }else{ |
|
| 100 | + } else { |
|
| 101 | 101 | /** 获取参数 */ |
| 102 | 102 | $params = $this->accessTokenParams(); |
| 103 | - $this->AccessTokenURL = $this->AccessTokenURL. '?' . http_build_query($params);//get传参 |
|
| 103 | + $this->AccessTokenURL = $this->AccessTokenURL.'?'.http_build_query($params); //get传参 |
|
| 104 | 104 | $this->getToken(); |
| 105 | 105 | } |
| 106 | 106 | |
@@ -120,11 +120,11 @@ discard block |
||
| 120 | 120 | { |
| 121 | 121 | $method = strtoupper($method); |
| 122 | 122 | |
| 123 | - if(isset($this->token['access_token'])){ |
|
| 123 | + if (isset($this->token['access_token'])) { |
|
| 124 | 124 | $params['access_token'] = $this->token['access_token']; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - $data = $this->$method(self::API_BASE . $api, $params); |
|
| 127 | + $data = $this->$method(self::API_BASE.$api, $params); |
|
| 128 | 128 | return json_decode($data, true); |
| 129 | 129 | } |
| 130 | 130 | |
@@ -165,8 +165,8 @@ discard block |
||
| 165 | 165 | * @param $data |
| 166 | 166 | * @return mixed |
| 167 | 167 | */ |
| 168 | - public function statusesShare($data){ |
|
| 169 | - return $this->call('statuses/share.json', json_encode($data),'POST'); |
|
| 168 | + public function statusesShare($data) { |
|
| 169 | + return $this->call('statuses/share.json', json_encode($data), 'POST'); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | } |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | if (in_array($k, $except)) { |
| 16 | 16 | continue; |
| 17 | 17 | } |
| 18 | - $param_str .= $k . '='; |
|
| 18 | + $param_str .= $k.'='; |
|
| 19 | 19 | $param_str .= $urlencode ? rawurlencode($v) : $v; |
| 20 | 20 | $param_str .= '&'; |
| 21 | 21 | } |
@@ -52,18 +52,18 @@ |
||
| 52 | 52 | case self::TYPE_QQ: |
| 53 | 53 | if($type == 'app'){ |
| 54 | 54 | $typeConst = self::TYPE_QQ_APP;//qqApp |
| 55 | - }else{ |
|
| 55 | + } else{ |
|
| 56 | 56 | $typeConst = $channel; |
| 57 | 57 | } |
| 58 | 58 | break; |
| 59 | 59 | case self::TYPE_WECHAT: |
| 60 | 60 | if($type == 'app'){ |
| 61 | 61 | $typeConst = self::TYPE_WECHAT_APP;//微信App |
| 62 | - }else if($type == 'applets'){ |
|
| 62 | + } else if($type == 'applets'){ |
|
| 63 | 63 | $typeConst = self::TYPE_WECHAT_APPLETS;//微信小程序 |
| 64 | - }else if(Tool::isWeiXin()){ |
|
| 64 | + } else if(Tool::isWeiXin()){ |
|
| 65 | 65 | $typeConst = self::TYPE_WECHAT_MOBILE;//微信mobile |
| 66 | - }else{ |
|
| 66 | + } else{ |
|
| 67 | 67 | $typeConst = $channel; |
| 68 | 68 | } |
| 69 | 69 | break; |
@@ -6,16 +6,16 @@ discard block |
||
| 6 | 6 | |
| 7 | 7 | use tinymeng\tools\Tool; |
| 8 | 8 | |
| 9 | -class ConstCode{ |
|
| 9 | +class ConstCode { |
|
| 10 | 10 | |
| 11 | 11 | /** 公共状态 */ |
| 12 | - const STATUS_DELETE = 0;//删除 |
|
| 13 | - const STATUS_NORMAL = 1;//正常 |
|
| 12 | + const STATUS_DELETE = 0; //删除 |
|
| 13 | + const STATUS_NORMAL = 1; //正常 |
|
| 14 | 14 | |
| 15 | 15 | /** 性别 */ |
| 16 | - const GENDER = 0;//未知 |
|
| 17 | - const GENDER_MAN = 1;//男 |
|
| 18 | - const GENDER_WOMEN = 2;//女 |
|
| 16 | + const GENDER = 0; //未知 |
|
| 17 | + const GENDER_MAN = 1; //男 |
|
| 18 | + const GENDER_WOMEN = 2; //女 |
|
| 19 | 19 | |
| 20 | 20 | /** 登录类型 */ |
| 21 | 21 | const TYPE_QQ = 1; //QQ |
@@ -27,8 +27,8 @@ discard block |
||
| 27 | 27 | const TYPE_FACEBOOK = 7; //faceBook |
| 28 | 28 | const TYPE_GOOGLE = 8; //google |
| 29 | 29 | const TYPE_TWITTER = 9; //飞鸽 |
| 30 | - const TYPE_LINE = 10;//line |
|
| 31 | - const TYPE_NAVER = 11;//naver |
|
| 30 | + const TYPE_LINE = 10; //line |
|
| 31 | + const TYPE_NAVER = 11; //naver |
|
| 32 | 32 | const TYPE_ALIYUN = 12; //阿里云 |
| 33 | 33 | const TYPE_BAIDU = 13; //百度 |
| 34 | 34 | const TYPE_CODING = 14; //Coding |
@@ -53,24 +53,24 @@ discard block |
||
| 53 | 53 | * @param bool $type 类型:app applets |
| 54 | 54 | * @return int |
| 55 | 55 | */ |
| 56 | - static public function getTypeConst($channel,$type="") |
|
| 56 | + static public function getTypeConst($channel, $type = "") |
|
| 57 | 57 | { |
| 58 | - switch ($channel){ |
|
| 58 | + switch ($channel) { |
|
| 59 | 59 | case self::TYPE_QQ: |
| 60 | - if($type == 'app'){ |
|
| 61 | - $typeConst = self::TYPE_QQ_APP;//qqApp |
|
| 62 | - }else{ |
|
| 60 | + if ($type == 'app') { |
|
| 61 | + $typeConst = self::TYPE_QQ_APP; //qqApp |
|
| 62 | + } else { |
|
| 63 | 63 | $typeConst = $channel; |
| 64 | 64 | } |
| 65 | 65 | break; |
| 66 | 66 | case self::TYPE_WECHAT: |
| 67 | - if($type == 'app'){ |
|
| 68 | - $typeConst = self::TYPE_WECHAT_APP;//微信App |
|
| 69 | - }else if($type == 'applets'){ |
|
| 70 | - $typeConst = self::TYPE_WECHAT_APPLETS;//微信小程序 |
|
| 71 | - }else if(Tool::isWeiXin()){ |
|
| 72 | - $typeConst = self::TYPE_WECHAT_MOBILE;//微信mobile |
|
| 73 | - }else{ |
|
| 67 | + if ($type == 'app') { |
|
| 68 | + $typeConst = self::TYPE_WECHAT_APP; //微信App |
|
| 69 | + } else if ($type == 'applets') { |
|
| 70 | + $typeConst = self::TYPE_WECHAT_APPLETS; //微信小程序 |
|
| 71 | + } else if (Tool::isWeiXin()) { |
|
| 72 | + $typeConst = self::TYPE_WECHAT_MOBILE; //微信mobile |
|
| 73 | + } else { |
|
| 74 | 74 | $typeConst = $channel; |
| 75 | 75 | } |
| 76 | 76 | break; |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | 'state' => $this->config['state'], |
| 40 | 40 | 'scope' => $this->config['scope'], |
| 41 | 41 | ]; |
| 42 | - return $this->AuthorizeURL . '?' . http_build_query($params); |
|
| 42 | + return $this->AuthorizeURL.'?'.http_build_query($params); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $this->openid(); |
| 80 | 80 | |
| 81 | 81 | $headers = ['Authorization: Bearer '.$this->token['access_token']]; |
| 82 | - $data = $this->get($this->UserInfoURL, [],$headers); |
|
| 82 | + $data = $this->get($this->UserInfoURL, [], $headers); |
|
| 83 | 83 | return json_decode($data, true); |
| 84 | 84 | } |
| 85 | 85 | |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * @author: JiaMeng <[email protected]> |
| 102 | 102 | * Updater: |
| 103 | 103 | */ |
| 104 | - protected function getToken(){ |
|
| 104 | + protected function getToken() { |
|
| 105 | 105 | if (empty($this->token)) { |
| 106 | 106 | /** 验证state参数 */ |
| 107 | 107 | $this->CheckState(); |
@@ -110,8 +110,8 @@ discard block |
||
| 110 | 110 | $params = $this->accessTokenParams(); |
| 111 | 111 | |
| 112 | 112 | /** 获取access_token */ |
| 113 | - $this->AccessTokenURL = $this->AccessTokenURL . '?' . http_build_query($params); |
|
| 114 | - $token = $this->post($this->AccessTokenURL); |
|
| 113 | + $this->AccessTokenURL = $this->AccessTokenURL.'?'.http_build_query($params); |
|
| 114 | + $token = $this->post($this->AccessTokenURL); |
|
| 115 | 115 | /** 解析token值(子类实现此方法) */ |
| 116 | 116 | $this->token = $this->parseToken($token); |
| 117 | 117 | } |
@@ -108,7 +108,9 @@ discard block |
||
| 108 | 108 | ]; |
| 109 | 109 | $this->config = array_merge($_config, $config); |
| 110 | 110 | foreach($this->config as $key=>$val){ |
| 111 | - if(property_exists($this,$key)) $this->$key=$val; |
|
| 111 | + if(property_exists($this,$key)) { |
|
| 112 | + $this->$key=$val; |
|
| 113 | + } |
|
| 112 | 114 | } |
| 113 | 115 | $this->timestamp = time(); |
| 114 | 116 | } |
@@ -246,7 +248,7 @@ discard block |
||
| 246 | 248 | $token = $this->POST($this->AccessTokenURL, $params); |
| 247 | 249 | /** 解析token值(子类实现此方法) */ |
| 248 | 250 | $this->token = $this->parseToken($token); |
| 249 | - }else{ |
|
| 251 | + } else{ |
|
| 250 | 252 | return $this->token; |
| 251 | 253 | } |
| 252 | 254 | } |
@@ -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 | |
@@ -51,9 +51,9 @@ discard block |
||
| 51 | 51 | 'scope' => $this->config['scope'], |
| 52 | 52 | 'state' => $this->config['state'], |
| 53 | 53 | 'display' => $this->display, |
| 54 | - 'allow_signup' => true,//是否会在OAuth流程中为未经身份验证的用户提供注册GitHub的选项。默认是true。false在策略禁止注册的情况下使用。 |
|
| 54 | + 'allow_signup' => true, //是否会在OAuth流程中为未经身份验证的用户提供注册GitHub的选项。默认是true。false在策略禁止注册的情况下使用。 |
|
| 55 | 55 | ]; |
| 56 | - return $this->AuthorizeURL . '?' . http_build_query($params); |
|
| 56 | + return $this->AuthorizeURL.'?'.http_build_query($params); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | $headers = [ |
| 114 | 114 | 'User-Agent: '.$this->config['application_name'], |
| 115 | 115 | 'UserModel-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36 ', |
| 116 | - 'Authorization: token ' . $this->token['access_token'], |
|
| 116 | + 'Authorization: token '.$this->token['access_token'], |
|
| 117 | 117 | 'Accept: application/json' |
| 118 | 118 | ]; |
| 119 | 119 | $response = $this->get($this->UserInfoURL, [], $headers); |
@@ -10,20 +10,20 @@ |
||
| 10 | 10 | //引入配置文件 |
| 11 | 11 | $params = require('config/params.php'); |
| 12 | 12 | |
| 13 | -try{ |
|
| 14 | - $name="qq";//登录类型,例:qq / google |
|
| 13 | +try { |
|
| 14 | + $name = "qq"; //登录类型,例:qq / google |
|
| 15 | 15 | $oauth = new oauth2($params); |
| 16 | 16 | if (empty($_GET['code'])) { |
| 17 | 17 | /** 登录 */ |
| 18 | 18 | $result = $oauth->login($name); |
| 19 | 19 | // var_dump($result['url']);die; |
| 20 | 20 | //重定向到第三方登录页 |
| 21 | - header('Location: ' . $result['url']); |
|
| 22 | - }else{ |
|
| 21 | + header('Location: '.$result['url']); |
|
| 22 | + } else { |
|
| 23 | 23 | /** 登录回调 */ |
| 24 | 24 | $result = $this->callback($name); |
| 25 | - var_dump($result);die; |
|
| 25 | + var_dump($result); die; |
|
| 26 | 26 | } |
| 27 | -}catch(Exception $e){ |
|
| 27 | +} catch (Exception $e) { |
|
| 28 | 28 | echo 'Oauth登录失败!'.$e->getMessage(); |
| 29 | 29 | } |
| 30 | 30 | \ No newline at end of file |
@@ -19,11 +19,11 @@ |
||
| 19 | 19 | // var_dump($result['url']);die; |
| 20 | 20 | //重定向到第三方登录页 |
| 21 | 21 | header('Location: ' . $result['url']); |
| 22 | - }else{ |
|
| 22 | + } else{ |
|
| 23 | 23 | /** 登录回调 */ |
| 24 | 24 | $result = $this->callback($name); |
| 25 | 25 | var_dump($result);die; |
| 26 | 26 | } |
| 27 | -}catch(Exception $e){ |
|
| 27 | +} catch(Exception $e){ |
|
| 28 | 28 | echo 'Oauth登录失败!'.$e->getMessage(); |
| 29 | 29 | } |
| 30 | 30 | \ No newline at end of file |
@@ -12,12 +12,12 @@ discard block |
||
| 12 | 12 | /** |
| 13 | 13 | * @Author: TinyMeng <[email protected]> |
| 14 | 14 | */ |
| 15 | - public function run(){ |
|
| 15 | + public function run() { |
|
| 16 | 16 | if (isset($_GET['code'])) { |
| 17 | 17 | $state = isset($_GET['state']) ? $_GET['state'] : ""; |
| 18 | - header('Location: ' . $_COOKIE['redirect_uri'] . '?code=' . $_GET['code'] . '&state=' . $state); |
|
| 18 | + header('Location: '.$_COOKIE['redirect_uri'].'?code='.$_GET['code'].'&state='.$state); |
|
| 19 | 19 | } else { |
| 20 | - if(!isset($_GET['appid']) || !isset($_GET['response_type']) || !isset($_GET['scope'])){ |
|
| 20 | + if (!isset($_GET['appid']) || !isset($_GET['response_type']) || !isset($_GET['scope'])) { |
|
| 21 | 21 | echo "参数缺失"; |
| 22 | 22 | return; |
| 23 | 23 | } |
@@ -26,20 +26,20 @@ discard block |
||
| 26 | 26 | $protocol = $this->is_HTTPS() ? 'https://' : 'http://'; |
| 27 | 27 | $params = array( |
| 28 | 28 | 'appid' => $_GET['appid'], |
| 29 | - 'redirect_uri' => $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['DOCUMENT_URI'], |
|
| 29 | + 'redirect_uri' => $protocol.$_SERVER['HTTP_HOST'].$_SERVER['DOCUMENT_URI'], |
|
| 30 | 30 | 'response_type' => $_GET['response_type'], |
| 31 | 31 | 'scope' => $_GET['scope'], |
| 32 | 32 | 'state' => $state, |
| 33 | 33 | ); |
| 34 | - if($_GET['scope'] == 'snsapi_login'){ |
|
| 34 | + if ($_GET['scope'] == 'snsapi_login') { |
|
| 35 | 35 | //扫码登录 |
| 36 | - $AuthorizeURL = $this->AuthorizeURL . '/connect/qrconnect'; |
|
| 37 | - }else{ |
|
| 38 | - $AuthorizeURL = $this->AuthorizeURL . '/connect/oauth2/authorize'; |
|
| 36 | + $AuthorizeURL = $this->AuthorizeURL.'/connect/qrconnect'; |
|
| 37 | + } else { |
|
| 38 | + $AuthorizeURL = $this->AuthorizeURL.'/connect/oauth2/authorize'; |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | setcookie('redirect_uri', urldecode($_GET['redirect_uri']), $_SERVER['REQUEST_TIME'] + 60, '/'); |
| 42 | - header('Location: ' . $AuthorizeURL . '?' . http_build_query($params) . '#wechat_redirect'); |
|
| 42 | + header('Location: '.$AuthorizeURL.'?'.http_build_query($params).'#wechat_redirect'); |
|
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * @Author: TinyMeng <[email protected]> |
| 49 | 49 | * @return bool |
| 50 | 50 | */ |
| 51 | - protected function is_HTTPS(){ |
|
| 51 | + protected function is_HTTPS() { |
|
| 52 | 52 | if (!isset($_SERVER['HTTPS'])) { |
| 53 | 53 | return false; |
| 54 | 54 | } |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | if($_GET['scope'] == 'snsapi_login'){ |
| 34 | 34 | //扫码登录 |
| 35 | 35 | $AuthorizeURL = $this->AuthorizeURL . '/connect/qrconnect'; |
| 36 | - }else{ |
|
| 36 | + } else{ |
|
| 37 | 37 | $AuthorizeURL = $this->AuthorizeURL . '/connect/oauth2/authorize'; |
| 38 | 38 | } |
| 39 | 39 | |