| @@ -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 | |
| @@ -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 | } | 
| @@ -40,9 +40,9 @@ discard block | ||
| 40 | 40 | 'scope' => $this->config['scope'], | 
| 41 | 41 | 'state' => $this->config['state'], | 
| 42 | 42 | 'display' => $this->display, | 
| 43 | - 'allow_signup' => true,//是否会在OAuth流程中为未经身份验证的用户提供注册GitHub的选项。默认是true。false在策略禁止注册的情况下使用。 | |
| 43 | + 'allow_signup' => true, //是否会在OAuth流程中为未经身份验证的用户提供注册GitHub的选项。默认是true。false在策略禁止注册的情况下使用。 | |
| 44 | 44 | ]; | 
| 45 | - return $this->AuthorizeURL . '?' . http_build_query($params); | |
| 45 | + return $this->AuthorizeURL.'?'.http_build_query($params); | |
| 46 | 46 | } | 
| 47 | 47 | |
| 48 | 48 | /** | 
| @@ -98,11 +98,11 @@ discard block | ||
| 98 | 98 |      { | 
| 99 | 99 | $this->getToken(); | 
| 100 | 100 | |
| 101 | - $url = self::API_BASE . "user"; | |
| 101 | + $url = self::API_BASE."user"; | |
| 102 | 102 | $headers = [ | 
| 103 | 103 | 'User-Agent: '.$this->config['application_name'], | 
| 104 | 104 | '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 ', | 
| 105 | - 'Authorization: token ' . $this->token['access_token'], | |
| 105 | + 'Authorization: token '.$this->token['access_token'], | |
| 106 | 106 | 'Accept: application/json' | 
| 107 | 107 | ]; | 
| 108 | 108 | $response = $this->get($url, [], $headers); | 
| @@ -40,7 +40,7 @@ discard block | ||
| 40 | 40 | 'scope' => $this->config['scope'], | 
| 41 | 41 | 'state' => $this->config['state'], | 
| 42 | 42 | ]; | 
| 43 | - return self::AUTHORIZE_URL . '?' . http_build_query($params); | |
| 43 | + return self::AUTHORIZE_URL.'?'.http_build_query($params); | |
| 44 | 44 | } | 
| 45 | 45 | |
| 46 | 46 | /** | 
| @@ -67,7 +67,7 @@ discard block | ||
| 67 | 67 | 'gender' => isset($result['gender']) ? $this->getGender($result['gender']) : ConstCode::GENDER, | 
| 68 | 68 | 'avatar' => $result['picture'], | 
| 69 | 69 | ]; | 
| 70 | -        if(isset($result['email'])){ | |
| 70 | +        if (isset($result['email'])) { | |
| 71 | 71 | $userInfo['email'] = $result['email']; | 
| 72 | 72 | } | 
| 73 | 73 | return $userInfo; | 
| @@ -78,14 +78,14 @@ discard block | ||
| 78 | 78 | */ | 
| 79 | 79 | public function getUserInfo() | 
| 80 | 80 |      { | 
| 81 | -        if($this->type == 'app'){//App登录 | |
| 82 | -            if(!isset($_REQUEST['code']) ){ | |
| 81 | +        if ($this->type == 'app') {//App登录 | |
| 82 | +            if (!isset($_REQUEST['code'])) { | |
| 83 | 83 |                  throw new \Exception("Google APP登录 需要传输code参数! "); | 
| 84 | 84 | } | 
| 85 | 85 | } | 
| 86 | 86 | $this->getToken(); | 
| 87 | - $headers = ['Authorization : Bearer ' . $this->token['access_token']]; | |
| 88 | - $data = $this->get(self::API_BASE . 'oauth2/v2/userinfo', '', $headers); | |
| 87 | + $headers = ['Authorization : Bearer '.$this->token['access_token']]; | |
| 88 | + $data = $this->get(self::API_BASE.'oauth2/v2/userinfo', '', $headers); | |
| 89 | 89 | return json_decode($data, true); | 
| 90 | 90 | } | 
| 91 | 91 | |
| @@ -43,7 +43,7 @@ discard block | ||
| 43 | 43 | 'scope' => $this->config['scope'], | 
| 44 | 44 | 'state' => $this->config['state'] ?: Str::random(), | 
| 45 | 45 | ]; | 
| 46 | - return $this->AuthorizeURL . '?' . http_build_query($params); | |
| 46 | + return $this->AuthorizeURL.'?'.http_build_query($params); | |
| 47 | 47 | } | 
| 48 | 48 | |
| 49 | 49 | /** | 
| @@ -77,12 +77,12 @@ discard block | ||
| 77 | 77 | */ | 
| 78 | 78 | public function getUserInfo() | 
| 79 | 79 |      { | 
| 80 | -        if($this->type == 'app'){//App登录 | |
| 81 | -            if(!isset($_REQUEST['access_token']) ){ | |
| 80 | +        if ($this->type == 'app') {//App登录 | |
| 81 | +            if (!isset($_REQUEST['access_token'])) { | |
| 82 | 82 |                  throw new \Exception("Facebook APP登录 需要传输access_token参数! "); | 
| 83 | 83 | } | 
| 84 | 84 | $this->token['access_token'] = $_REQUEST['access_token']; | 
| 85 | -        }else { | |
| 85 | +        } else { | |
| 86 | 86 | $this->getToken(); | 
| 87 | 87 | } | 
| 88 | 88 | $fields = isset($this->config['fields']) ? $this->config['fields'] : 'id,name,gender,picture.width(400)'; | 
| @@ -102,7 +102,7 @@ discard block | ||
| 102 | 102 | $method = strtoupper($method); | 
| 103 | 103 | $request = [ | 
| 104 | 104 | 'method' => $method, | 
| 105 | - 'uri' => self::API_BASE . $api, | |
| 105 | + 'uri' => self::API_BASE.$api, | |
| 106 | 106 | ]; | 
| 107 | 107 | |
| 108 | 108 | $data = $this->$method($request['uri'], $params); | 
| @@ -82,7 +82,7 @@ | ||
| 82 | 82 |                  throw new \Exception("Facebook APP登录 需要传输access_token参数! "); | 
| 83 | 83 | } | 
| 84 | 84 | $this->token['access_token'] = $_REQUEST['access_token']; | 
| 85 | -        }else { | |
| 85 | +        } else { | |
| 86 | 86 | $this->getToken(); | 
| 87 | 87 | } | 
| 88 | 88 | $fields = isset($this->config['fields']) ? $this->config['fields'] : 'id,name,gender,picture.width(400)'; | 
| @@ -115,7 +115,7 @@ | ||
| 115 | 115 |                  throw new \Exception("Wechat APP登录 需要传输access_token参数! "); | 
| 116 | 116 | } | 
| 117 | 117 | $this->token['access_token'] = $_REQUEST['access_token']; | 
| 118 | -        }else { | |
| 118 | +        } else { | |
| 119 | 119 | /** 获取token信息 */ | 
| 120 | 120 | $this->getToken(); | 
| 121 | 121 | } | 
| @@ -58,7 +58,7 @@ discard block | ||
| 58 | 58 |              $this->AuthorizeURL = str_replace("alipay", "alipaydev", $this->AuthorizeURL); | 
| 59 | 59 | } | 
| 60 | 60 | |
| 61 | - return $this->AuthorizeURL . '?' . http_build_query($params); | |
| 61 | + return $this->AuthorizeURL.'?'.http_build_query($params); | |
| 62 | 62 | } | 
| 63 | 63 | |
| 64 | 64 | /** | 
| @@ -97,7 +97,7 @@ discard block | ||
| 97 | 97 | 'gender' => isset($result['gender']) ? $this->getGender($result['gender']) : ConstCode::GENDER, | 
| 98 | 98 | 'avatar' => $result['avatar'], | 
| 99 | 99 | ]; | 
| 100 | - $userInfo['type'] = ConstCode::getTypeConst($userInfo['channel'],$this->type); | |
| 100 | + $userInfo['type'] = ConstCode::getTypeConst($userInfo['channel'], $this->type); | |
| 101 | 101 | return $userInfo; | 
| 102 | 102 | } | 
| 103 | 103 | |
| @@ -110,12 +110,12 @@ discard block | ||
| 110 | 110 | */ | 
| 111 | 111 | public function getUserInfo() | 
| 112 | 112 |      { | 
| 113 | -        if($this->type == 'app'){//App登录 | |
| 114 | -            if(!isset($_REQUEST['access_token']) ){ | |
| 113 | +        if ($this->type == 'app') {//App登录 | |
| 114 | +            if (!isset($_REQUEST['access_token'])) { | |
| 115 | 115 |                  throw new \Exception("Wechat APP登录 需要传输access_token参数! "); | 
| 116 | 116 | } | 
| 117 | 117 | $this->token['access_token'] = $_REQUEST['access_token']; | 
| 118 | -        }else { | |
| 118 | +        } else { | |
| 119 | 119 | /** 获取token信息 */ | 
| 120 | 120 | $this->getToken(); | 
| 121 | 121 | } | 
| @@ -133,7 +133,7 @@ discard block | ||
| 133 | 133 | |
| 134 | 134 | $data = $this->post(self::API_BASE, $params); | 
| 135 | 135 | $data = mb_convert_encoding($data, 'utf-8', 'gbk'); | 
| 136 | - $result = json_decode($data, true); | |
| 136 | + $result = json_decode($data, true); | |
| 137 | 137 | return $result['alipay_user_info_share_response']; | 
| 138 | 138 | } | 
| 139 | 139 | |
| @@ -210,7 +210,7 @@ discard block | ||
| 210 | 210 |              throw new \Exception('支付宝RSA密钥未配置'); | 
| 211 | 211 | } | 
| 212 | 212 | $rsa = str_replace([PHP_EOL, $header, $footer], '', $rsa); | 
| 213 | - $rsaVal = $header . PHP_EOL . chunk_split($rsa, 64, PHP_EOL) . $footer; | |
| 213 | + $rsaVal = $header.PHP_EOL.chunk_split($rsa, 64, PHP_EOL).$footer; | |
| 214 | 214 | return $rsaVal; | 
| 215 | 215 | } | 
| 216 | 216 | |
| @@ -41,7 +41,7 @@ discard block | ||
| 41 | 41 | 'scope' => $this->config['scope'], | 
| 42 | 42 | 'display' => $this->display, | 
| 43 | 43 | ]; | 
| 44 | - return $this->AuthorizeURL . '?' . http_build_query($params); | |
| 44 | + return $this->AuthorizeURL.'?'.http_build_query($params); | |
| 45 | 45 | } | 
| 46 | 46 | |
| 47 | 47 | /** | 
| @@ -62,7 +62,7 @@ discard block | ||
| 62 | 62 | 'nickname'=> $result['nickname'], | 
| 63 | 63 | 'gender' => isset($result['gender']) ? $this->getGender($result['gender']) : ConstCode::GENDER, | 
| 64 | 64 | 'avatar' => $result['figureurl_qq_2'] ? $result['figureurl_qq_2'] : $result['figureurl_qq_1'], | 
| 65 | -            'birthday'=> date('Y-m-d',strtotime($result['year'])), | |
| 65 | +            'birthday'=> date('Y-m-d', strtotime($result['year'])), | |
| 66 | 66 | ]; | 
| 67 | 67 | return $userInfo; | 
| 68 | 68 | } | 
| @@ -83,7 +83,7 @@ discard block | ||
| 83 | 83 | 'access_token'=>$this->token['access_token'], | 
| 84 | 84 | 'format'=>'json', | 
| 85 | 85 | ]; | 
| 86 | - $data = $this->get(self::API_BASE . 'user/get_user_info', $params); | |
| 86 | + $data = $this->get(self::API_BASE.'user/get_user_info', $params); | |
| 87 | 87 | return json_decode($data, true); | 
| 88 | 88 | } | 
| 89 | 89 | |
| @@ -96,12 +96,12 @@ discard block | ||
| 96 | 96 | */ | 
| 97 | 97 | public function openid() | 
| 98 | 98 |      { | 
| 99 | -        if($this->type == 'app'){//App登录 | |
| 100 | -            if(!isset($_REQUEST['access_token'])){ | |
| 99 | +        if ($this->type == 'app') {//App登录 | |
| 100 | +            if (!isset($_REQUEST['access_token'])) { | |
| 101 | 101 |                  throw new \Exception("腾讯QQ,APP登录 需要传输access_token参数! "); | 
| 102 | 102 | } | 
| 103 | 103 | $this->token['access_token'] = $_REQUEST['access_token']; | 
| 104 | -        }else{ | |
| 104 | +        } else { | |
| 105 | 105 | /** 获取token */ | 
| 106 | 106 | $this->getToken(); | 
| 107 | 107 | } | 
| @@ -127,7 +127,7 @@ discard block | ||
| 127 | 127 |          if (isset($data['access_token'])) { | 
| 128 | 128 | return $data; | 
| 129 | 129 |          } else { | 
| 130 | -            throw new \Exception("获取腾讯QQ ACCESS_TOKEN 出错:" . $token); | |
| 130 | +            throw new \Exception("获取腾讯QQ ACCESS_TOKEN 出错:".$token); | |
| 131 | 131 | } | 
| 132 | 132 | } | 
| 133 | 133 | |
| @@ -138,7 +138,7 @@ discard block | ||
| 138 | 138 | * @return mixed|string | 
| 139 | 139 | * @throws \Exception | 
| 140 | 140 | */ | 
| 141 | -    private function getOpenID(){ | |
| 141 | +    private function getOpenID() { | |
| 142 | 142 | $query = [ | 
| 143 | 143 | 'access_token' => $this->token['access_token'] | 
| 144 | 144 | ]; | 
| @@ -147,12 +147,12 @@ discard block | ||
| 147 | 147 | $query['unionid'] = 1; | 
| 148 | 148 | } | 
| 149 | 149 | |
| 150 | - $data = $this->get(self::API_BASE . 'oauth2.0/me',$query); | |
| 151 | - $data = json_decode(trim(substr($data, 9), " );\n"), true); | |
| 150 | + $data = $this->get(self::API_BASE.'oauth2.0/me', $query); | |
| 151 | + $data = json_decode(trim(substr($data, 9), " );\n"), true); | |
| 152 | 152 |          if (isset($data['openid'])) { | 
| 153 | 153 | return $data; | 
| 154 | 154 |          } else { | 
| 155 | -            throw new \Exception("获取用户openid出错:" . $data['error_description']); | |
| 155 | +            throw new \Exception("获取用户openid出错:".$data['error_description']); | |
| 156 | 156 | } | 
| 157 | 157 | } | 
| 158 | 158 | |
| @@ -161,7 +161,7 @@ discard block | ||
| 161 | 161 | * M代表男性,F代表女性 | 
| 162 | 162 | * @param $gender | 
| 163 | 163 | */ | 
| 164 | -    public function getGender($gender){ | |
| 164 | +    public function getGender($gender) { | |
| 165 | 165 | return $gender == '男' ? ConstCode::GENDER_MAN : ConstCode::GENDER_WOMEN; | 
| 166 | 166 | } | 
| 167 | 167 | } | 
| @@ -101,7 +101,7 @@ | ||
| 101 | 101 |                  throw new \Exception("腾讯QQ,APP登录 需要传输access_token参数! "); | 
| 102 | 102 | } | 
| 103 | 103 | $this->token['access_token'] = $_REQUEST['access_token']; | 
| 104 | -        }else{ | |
| 104 | +        } else{ | |
| 105 | 105 | /** 获取token */ | 
| 106 | 106 | $this->getToken(); | 
| 107 | 107 | } | 
| @@ -64,7 +64,7 @@ discard block | ||
| 64 | 64 | * https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/openapi/account-permission/douyin-default-get-permission-code | 
| 65 | 65 | */ | 
| 66 | 66 | return $this->AuthorizeSilenceURL . '?' . http_build_query($params); | 
| 67 | -        }else{ | |
| 67 | +        } else{ | |
| 68 | 68 | return $this->AuthorizeURL . '?' . http_build_query($params); | 
| 69 | 69 | } | 
| 70 | 70 | } | 
| @@ -127,10 +127,10 @@ discard block | ||
| 127 | 127 |                  throw new \Exception("Douyin APP登录 需要传输access_token参数! "); | 
| 128 | 128 | } | 
| 129 | 129 | $this->token['access_token'] = $_REQUEST['access_token']; | 
| 130 | -        }elseif ($this->type == 'applets'){ | |
| 130 | +        } elseif ($this->type == 'applets'){ | |
| 131 | 131 | //小程序 | 
| 132 | 132 | return $this->applets(); | 
| 133 | -        }else { | |
| 133 | +        } else { | |
| 134 | 134 | /** 获取token信息 */ | 
| 135 | 135 | $this->getToken(); | 
| 136 | 136 | } | 
| @@ -207,8 +207,12 @@ discard block | ||
| 207 | 207 | 'appid' => $this->config['app_id'], | 
| 208 | 208 | 'secret' => $this->config['app_secret'], | 
| 209 | 209 | ]; | 
| 210 | - if(isset($_REQUEST['code'])) $params['code'] = $_REQUEST['code']; | |
| 211 | - if(isset($_REQUEST['anonymous_code'])) $params['anonymous_code'] = $_REQUEST['anonymous_code']; | |
| 210 | +        if(isset($_REQUEST['code'])) { | |
| 211 | + $params['code'] = $_REQUEST['code']; | |
| 212 | + } | |
| 213 | +        if(isset($_REQUEST['anonymous_code'])) { | |
| 214 | + $params['anonymous_code'] = $_REQUEST['anonymous_code']; | |
| 215 | + } | |
| 212 | 216 | |
| 213 | 217 | return $params; | 
| 214 | 218 | } | 
| @@ -226,7 +230,7 @@ discard block | ||
| 226 | 230 | $data = json_decode($token, true); | 
| 227 | 231 |          if (isset($data['data']['access_token'])) { | 
| 228 | 232 | return $data['data']; | 
| 229 | -        }elseif (isset($data['session_key'])){ | |
| 233 | +        } elseif (isset($data['session_key'])){ | |
| 230 | 234 | //小程序登录 | 
| 231 | 235 | return $data; | 
| 232 | 236 |          } else { | 
| @@ -21,21 +21,21 @@ discard block | ||
| 21 | 21 | */ | 
| 22 | 22 | class Douyin extends Gateway | 
| 23 | 23 |  { | 
| 24 | - protected $ApiBase = 'https://open.douyin.com'; | |
| 24 | + protected $ApiBase = 'https://open.douyin.com'; | |
| 25 | 25 | protected $AuthorizeURL = 'https://open.douyin.com/platform/oauth/connect/'; | 
| 26 | - protected $AuthorizeSilenceURL = 'https://open.douyin.com/oauth/authorize/v2/';//抖音静默授权 | |
| 26 | + protected $AuthorizeSilenceURL = 'https://open.douyin.com/oauth/authorize/v2/'; //抖音静默授权 | |
| 27 | 27 | protected $AccessTokenURL = 'oauth/access_token/'; | 
| 28 | 28 | protected $UserInfoURL = 'oauth/userinfo/'; | 
| 29 | 29 | |
| 30 | 30 | protected $jsCode2Session = 'https://minigame.zijieapi.com/mgplatform/api/apps/jscode2session'; | 
| 31 | 31 | |
| 32 | 32 | protected $API_BASE_ARRAY = [ | 
| 33 | - 'douyin'=>'https://open.douyin.com/',//抖音 | |
| 34 | - 'toutiao'=>'https://open.snssdk.com/',//头条 | |
| 35 | - 'xigua'=>'https://open-api.ixigua.com/',//西瓜 | |
| 33 | + 'douyin'=>'https://open.douyin.com/', //抖音 | |
| 34 | + 'toutiao'=>'https://open.snssdk.com/', //头条 | |
| 35 | + 'xigua'=>'https://open-api.ixigua.com/', //西瓜 | |
| 36 | 36 | ]; | 
| 37 | 37 | |
| 38 | - public $oauth_type = ConstCode::TYPE_DOUYIN;//抖音 | |
| 38 | + public $oauth_type = ConstCode::TYPE_DOUYIN; //抖音 | |
| 39 | 39 | |
| 40 | 40 | /** | 
| 41 | 41 | * Description: 得到跳转地址 | 
| @@ -55,17 +55,17 @@ discard block | ||
| 55 | 55 | 'redirect_uri' => $this->config['callback'], | 
| 56 | 56 | 'response_type' => $this->config['response_type'], | 
| 57 | 57 | 'scope' => $this->config['scope'], | 
| 58 | - 'optionalScope' => $this->config['optionalScope']??'', | |
| 58 | + 'optionalScope' => $this->config['optionalScope'] ?? '', | |
| 59 | 59 | 'state' => $this->config['state'], | 
| 60 | 60 | ]; | 
| 61 | -        if($params['state'] == 'login_id'){ | |
| 61 | +        if ($params['state'] == 'login_id') { | |
| 62 | 62 | /** | 
| 63 | 63 | * 抖音静默获取授权码 | 
| 64 | 64 | * https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/openapi/account-permission/douyin-default-get-permission-code | 
| 65 | 65 | */ | 
| 66 | - return $this->AuthorizeSilenceURL . '?' . http_build_query($params); | |
| 67 | -        }else{ | |
| 68 | - return $this->AuthorizeURL . '?' . http_build_query($params); | |
| 66 | + return $this->AuthorizeSilenceURL.'?'.http_build_query($params); | |
| 67 | +        } else { | |
| 68 | + return $this->AuthorizeURL.'?'.http_build_query($params); | |
| 69 | 69 | } | 
| 70 | 70 | } | 
| 71 | 71 | |
| @@ -106,11 +106,11 @@ discard block | ||
| 106 | 106 | 'access_token'=> isset($this->token['access_token']) ? $this->token['access_token'] : '', | 
| 107 | 107 | 'union_id'=> isset($this->token['unionid']) ? $this->token['unionid'] : '', | 
| 108 | 108 | 'channel' => $this->oauth_type, | 
| 109 | - 'nickname'=> $result['nickname']??'', | |
| 109 | + 'nickname'=> $result['nickname'] ?? '', | |
| 110 | 110 | 'gender' => isset($result['gender']) ? $result['gender'] : ConstCode::GENDER, | 
| 111 | - 'avatar' => $result['avatar']??'', | |
| 111 | + 'avatar' => $result['avatar'] ?? '', | |
| 112 | 112 | ]; | 
| 113 | - $userInfo['type'] = ConstCode::getTypeConst($userInfo['channel'],$this->type); | |
| 113 | + $userInfo['type'] = ConstCode::getTypeConst($userInfo['channel'], $this->type); | |
| 114 | 114 | return $userInfo; | 
| 115 | 115 | } | 
| 116 | 116 | |
| @@ -123,15 +123,15 @@ discard block | ||
| 123 | 123 | */ | 
| 124 | 124 | public function getUserInfo() | 
| 125 | 125 |      { | 
| 126 | -        if($this->type == 'app'){//App登录 | |
| 127 | -            if(!isset($_REQUEST['access_token']) ){ | |
| 126 | +        if ($this->type == 'app') {//App登录 | |
| 127 | +            if (!isset($_REQUEST['access_token'])) { | |
| 128 | 128 |                  throw new \Exception("Douyin APP登录 需要传输access_token参数! "); | 
| 129 | 129 | } | 
| 130 | 130 | $this->token['access_token'] = $_REQUEST['access_token']; | 
| 131 | -        }elseif ($this->type == 'applets'){ | |
| 131 | +        }elseif ($this->type == 'applets') { | |
| 132 | 132 | //小程序 | 
| 133 | 133 | return $this->applets(); | 
| 134 | -        }else { | |
| 134 | +        } else { | |
| 135 | 135 | /** 获取token信息 */ | 
| 136 | 136 | $this->getToken(); | 
| 137 | 137 | } | 
| @@ -150,12 +150,12 @@ discard block | ||
| 150 | 150 | * @return array|mixed|null | 
| 151 | 151 | * @throws \Exception | 
| 152 | 152 | */ | 
| 153 | -    public function applets(){ | |
| 153 | +    public function applets() { | |
| 154 | 154 | /** 获取参数 */ | 
| 155 | 155 | $params = $this->jscode2sessionParams(); | 
| 156 | 156 | |
| 157 | 157 | /** 获取access_token */ | 
| 158 | - $token = $this->get($this->jsCode2Session, $params); | |
| 158 | + $token = $this->get($this->jsCode2Session, $params); | |
| 159 | 159 | /** 解析token值(子类实现此方法) */ | 
| 160 | 160 | $this->token = $this->parseToken($token); | 
| 161 | 161 | return $this->token; | 
| @@ -168,10 +168,10 @@ discard block | ||
| 168 | 168 | */ | 
| 169 | 169 | private function switchAccessTokenURL() | 
| 170 | 170 |      { | 
| 171 | -        switch ($this->oauth_type){ | |
| 172 | - case ConstCode::TYPE_DOUYIN:$this->ApiBase = $this->API_BASE_ARRAY['douyin'];break; | |
| 173 | - case ConstCode::TYPE_TOUTIAO:$this->ApiBase = $this->API_BASE_ARRAY['toutiao'];break; | |
| 174 | - case ConstCode::TYPE_XIGUA:$this->ApiBase = $this->API_BASE_ARRAY['xigua'];break; | |
| 171 | +        switch ($this->oauth_type) { | |
| 172 | + case ConstCode::TYPE_DOUYIN:$this->ApiBase = $this->API_BASE_ARRAY['douyin']; break; | |
| 173 | + case ConstCode::TYPE_TOUTIAO:$this->ApiBase = $this->API_BASE_ARRAY['toutiao']; break; | |
| 174 | + case ConstCode::TYPE_XIGUA:$this->ApiBase = $this->API_BASE_ARRAY['xigua']; break; | |
| 175 | 175 |              default:throw new \Exception("获取抖音 OAUTH_TYPE 参数出错:{$this->oauth_type}"); | 
| 176 | 176 | } | 
| 177 | 177 | $this->AccessTokenURL = $this->ApiBase.$this->AccessTokenURL; | 
| @@ -208,8 +208,8 @@ discard block | ||
| 208 | 208 | 'appid' => $this->config['app_id'], | 
| 209 | 209 | 'secret' => $this->config['app_secret'], | 
| 210 | 210 | ]; | 
| 211 | - if(isset($_REQUEST['code'])) $params['code'] = $_REQUEST['code']; | |
| 212 | - if(isset($_REQUEST['anonymous_code'])) $params['anonymous_code'] = $_REQUEST['anonymous_code']; | |
| 211 | + if (isset($_REQUEST['code'])) $params['code'] = $_REQUEST['code']; | |
| 212 | + if (isset($_REQUEST['anonymous_code'])) $params['anonymous_code'] = $_REQUEST['anonymous_code']; | |
| 213 | 213 | |
| 214 | 214 | return $params; | 
| 215 | 215 | } | 
| @@ -227,7 +227,7 @@ discard block | ||
| 227 | 227 | $data = json_decode($token, true); | 
| 228 | 228 |          if (isset($data['data']['access_token'])) { | 
| 229 | 229 | return $data['data']; | 
| 230 | -        }elseif (isset($data['session_key'])){ | |
| 230 | +        }elseif (isset($data['session_key'])) { | |
| 231 | 231 | //小程序登录 | 
| 232 | 232 | return $data; | 
| 233 | 233 |          } else { | 
| @@ -38,7 +38,7 @@ discard block | ||
| 38 | 38 | 'scope' => $this->config['scope'], | 
| 39 | 39 | 'state' => $this->config['state'] ?: Str::random(), | 
| 40 | 40 | ]; | 
| 41 | - return $this->AuthorizeURL . '?' . http_build_query($params); | |
| 41 | + return $this->AuthorizeURL.'?'.http_build_query($params); | |
| 42 | 42 | } | 
| 43 | 43 | |
| 44 | 44 | /** | 
| @@ -74,13 +74,13 @@ discard block | ||
| 74 | 74 | */ | 
| 75 | 75 | public function getUserInfo() | 
| 76 | 76 |      { | 
| 77 | -        if($this->type == 'app'){//App登录 | |
| 78 | -            if(!isset($_REQUEST['access_token']) ){ | |
| 77 | +        if ($this->type == 'app') {//App登录 | |
| 78 | +            if (!isset($_REQUEST['access_token'])) { | |
| 79 | 79 |                  throw new \Exception("Naver APP登录 需要传输access_token参数! "); | 
| 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'); | 
| @@ -103,10 +103,10 @@ discard block | ||
| 103 | 103 | $method = strtoupper($method); | 
| 104 | 104 | $request = [ | 
| 105 | 105 | 'method' => $method, | 
| 106 | - 'uri' => self::API_BASE . $api, | |
| 106 | + 'uri' => self::API_BASE.$api, | |
| 107 | 107 | ]; | 
| 108 | 108 | |
| 109 | - $headers = ['Authorization' => $this->token['token_type'] . ' ' . $this->token['access_token']]; | |
| 109 | + $headers = ['Authorization' => $this->token['token_type'].' '.$this->token['access_token']]; | |
| 110 | 110 | |
| 111 | 111 | $data = $this->$method($request['uri'], $params, $headers); | 
| 112 | 112 | |
| @@ -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'); | 
| @@ -37,7 +37,7 @@ discard block | ||
| 37 | 37 | 'state' => $this->config['state'], | 
| 38 | 38 | 'display' => $this->display, | 
| 39 | 39 | ]; | 
| 40 | - return $this->AuthorizeURL . '?' . http_build_query($params); | |
| 40 | + return $this->AuthorizeURL.'?'.http_build_query($params); | |
| 41 | 41 | } | 
| 42 | 42 | |
| 43 | 43 | /** | 
| @@ -88,16 +88,16 @@ discard block | ||
| 88 | 88 | */ | 
| 89 | 89 | public function getUserInfo() | 
| 90 | 90 |      { | 
| 91 | -        if($this->type == 'app'){//App登录 | |
| 92 | -            if(!isset($_REQUEST['access_token']) || !isset($_REQUEST['uid'])){ | |
| 91 | +        if ($this->type == 'app') {//App登录 | |
| 92 | +            if (!isset($_REQUEST['access_token']) || !isset($_REQUEST['uid'])) { | |
| 93 | 93 |                  throw new \Exception("Sina APP登录 需要传输access_token和uid参数! "); | 
| 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 | - $this->AccessTokenURL = $this->AccessTokenURL. '?' . http_build_query($params);//get传参 | |
| 100 | + $this->AccessTokenURL = $this->AccessTokenURL.'?'.http_build_query($params); //get传参 | |
| 101 | 101 | $this->getToken(); | 
| 102 | 102 | } | 
| 103 | 103 | |
| @@ -117,11 +117,11 @@ discard block | ||
| 117 | 117 |      { | 
| 118 | 118 | $method = strtoupper($method); | 
| 119 | 119 | |
| 120 | -        if(isset($this->token['access_token'])){ | |
| 120 | +        if (isset($this->token['access_token'])) { | |
| 121 | 121 | $params['access_token'] = $this->token['access_token']; | 
| 122 | 122 | } | 
| 123 | 123 | |
| 124 | - $data = $this->$method(self::API_BASE . $api, $params); | |
| 124 | + $data = $this->$method(self::API_BASE.$api, $params); | |
| 125 | 125 | return json_decode($data, true); | 
| 126 | 126 | } | 
| 127 | 127 | |
| @@ -162,8 +162,8 @@ discard block | ||
| 162 | 162 | * @param $data | 
| 163 | 163 | * @return mixed | 
| 164 | 164 | */ | 
| 165 | -    public function statusesShare($data){ | |
| 166 | -        return $this->call('statuses/share.json', json_encode($data),'POST'); | |
| 165 | +    public function statusesShare($data) { | |
| 166 | +        return $this->call('statuses/share.json', json_encode($data), 'POST'); | |
| 167 | 167 | } | 
| 168 | 168 | |
| 169 | 169 | } | 
| @@ -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传参 |