@@ -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 { |