@@ -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)'; |
@@ -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 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | 'scope' => $this->config['scope'], |
| 55 | 55 | 'display' => $this->display, |
| 56 | 56 | ]; |
| 57 | - return $this->AuthorizeURL . '?' . http_build_query($params); |
|
| 57 | + return $this->AuthorizeURL.'?'.http_build_query($params); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | 'nickname'=> $result['nickname'], |
| 77 | 77 | 'gender' => isset($result['gender']) ? $this->getGender($result['gender']) : ConstCode::GENDER, |
| 78 | 78 | 'avatar' => $result['figureurl_qq_2'] ? $result['figureurl_qq_2'] : $result['figureurl_qq_1'], |
| 79 | - 'birthday'=> date('Y-m-d',strtotime($result['year'])), |
|
| 79 | + 'birthday'=> date('Y-m-d', strtotime($result['year'])), |
|
| 80 | 80 | ]; |
| 81 | 81 | return $userInfo; |
| 82 | 82 | } |
@@ -110,12 +110,12 @@ discard block |
||
| 110 | 110 | */ |
| 111 | 111 | public function openid() |
| 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("腾讯QQ,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 | } |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | if (isset($data['access_token'])) { |
| 142 | 142 | return $data; |
| 143 | 143 | } else { |
| 144 | - throw new \Exception("获取腾讯QQ ACCESS_TOKEN 出错:" . $token); |
|
| 144 | + throw new \Exception("获取腾讯QQ ACCESS_TOKEN 出错:".$token); |
|
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | * @return mixed|string |
| 153 | 153 | * @throws \Exception |
| 154 | 154 | */ |
| 155 | - private function getOpenID(){ |
|
| 155 | + private function getOpenID() { |
|
| 156 | 156 | $query = [ |
| 157 | 157 | 'access_token' => $this->token['access_token'] |
| 158 | 158 | ]; |
@@ -161,12 +161,12 @@ discard block |
||
| 161 | 161 | $query['unionid'] = 1; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - $data = $this->get(self::API_BASE . 'oauth2.0/me',$query); |
|
| 165 | - $data = json_decode(trim(substr($data, 9), " );\n"), true); |
|
| 164 | + $data = $this->get(self::API_BASE.'oauth2.0/me', $query); |
|
| 165 | + $data = json_decode(trim(substr($data, 9), " );\n"), true); |
|
| 166 | 166 | if (isset($data['openid'])) { |
| 167 | 167 | return $data; |
| 168 | 168 | } else { |
| 169 | - throw new \Exception("获取用户openid出错:" . $data['error_description']); |
|
| 169 | + throw new \Exception("获取用户openid出错:".$data['error_description']); |
|
| 170 | 170 | } |
| 171 | 171 | } |
| 172 | 172 | |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | * M代表男性,F代表女性 |
| 176 | 176 | * @param $gender |
| 177 | 177 | */ |
| 178 | - public function getGender($gender){ |
|
| 178 | + public function getGender($gender) { |
|
| 179 | 179 | return $gender == '男' ? ConstCode::GENDER_MAN : ConstCode::GENDER_WOMEN; |
| 180 | 180 | } |
| 181 | 181 | |
@@ -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 | * @param $config |
@@ -65,17 +65,17 @@ discard block |
||
| 65 | 65 | 'redirect_uri' => $this->config['callback'], |
| 66 | 66 | 'response_type' => $this->config['response_type'], |
| 67 | 67 | 'scope' => $this->config['scope'], |
| 68 | - 'optionalScope' => $this->config['optionalScope']??'', |
|
| 68 | + 'optionalScope' => $this->config['optionalScope'] ?? '', |
|
| 69 | 69 | 'state' => $this->config['state'], |
| 70 | 70 | ]; |
| 71 | - if($params['state'] == 'login_id'){ |
|
| 71 | + if ($params['state'] == 'login_id') { |
|
| 72 | 72 | /** |
| 73 | 73 | * 抖音静默获取授权码 |
| 74 | 74 | * https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/openapi/account-permission/douyin-default-get-permission-code |
| 75 | 75 | */ |
| 76 | - return $this->AuthorizeSilenceURL . '?' . http_build_query($params); |
|
| 77 | - }else{ |
|
| 78 | - return $this->AuthorizeURL . '?' . http_build_query($params); |
|
| 76 | + return $this->AuthorizeSilenceURL.'?'.http_build_query($params); |
|
| 77 | + } else { |
|
| 78 | + return $this->AuthorizeURL.'?'.http_build_query($params); |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
@@ -114,11 +114,11 @@ discard block |
||
| 114 | 114 | 'access_token'=> $this->token['access_token'] ?? '', |
| 115 | 115 | 'union_id'=> $this->token['unionid'] ?? '', |
| 116 | 116 | 'channel' => $this->oauth_type, |
| 117 | - 'nickname'=> $result['nickname']??'', |
|
| 117 | + 'nickname'=> $result['nickname'] ?? '', |
|
| 118 | 118 | 'gender' => $result['gender'] ?? ConstCode::GENDER, |
| 119 | - 'avatar' => $result['avatar']??'', |
|
| 119 | + 'avatar' => $result['avatar'] ?? '', |
|
| 120 | 120 | ]; |
| 121 | - $userInfo['type'] = ConstCode::getTypeConst($userInfo['channel'],$this->type); |
|
| 121 | + $userInfo['type'] = ConstCode::getTypeConst($userInfo['channel'], $this->type); |
|
| 122 | 122 | return $userInfo; |
| 123 | 123 | } |
| 124 | 124 | |
@@ -131,15 +131,15 @@ discard block |
||
| 131 | 131 | */ |
| 132 | 132 | public function getUserInfo() |
| 133 | 133 | { |
| 134 | - if($this->type == 'app'){//App登录 |
|
| 135 | - if(!isset($_REQUEST['access_token']) ){ |
|
| 134 | + if ($this->type == 'app') {//App登录 |
|
| 135 | + if (!isset($_REQUEST['access_token'])) { |
|
| 136 | 136 | throw new \Exception("Douyin APP登录 需要传输access_token参数! "); |
| 137 | 137 | } |
| 138 | 138 | $this->token['access_token'] = $_REQUEST['access_token']; |
| 139 | - }elseif ($this->type == 'applets'){ |
|
| 139 | + }elseif ($this->type == 'applets') { |
|
| 140 | 140 | //小程序 |
| 141 | 141 | return $this->applets(); |
| 142 | - }else { |
|
| 142 | + } else { |
|
| 143 | 143 | /** 获取token信息 */ |
| 144 | 144 | $this->getToken(); |
| 145 | 145 | } |
@@ -158,12 +158,12 @@ discard block |
||
| 158 | 158 | * @return array|mixed|null |
| 159 | 159 | * @throws \Exception |
| 160 | 160 | */ |
| 161 | - public function applets(){ |
|
| 161 | + public function applets() { |
|
| 162 | 162 | /** 获取参数 */ |
| 163 | 163 | $params = $this->jscode2sessionParams(); |
| 164 | 164 | |
| 165 | 165 | /** 获取access_token */ |
| 166 | - $token = $this->get($this->jsCode2Session, $params); |
|
| 166 | + $token = $this->get($this->jsCode2Session, $params); |
|
| 167 | 167 | /** 解析token值(子类实现此方法) */ |
| 168 | 168 | $this->token = $this->parseToken($token); |
| 169 | 169 | return $this->token; |
@@ -176,10 +176,10 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | private function switchAccessTokenURL() |
| 178 | 178 | { |
| 179 | - switch ($this->oauth_type){ |
|
| 180 | - case ConstCode::TYPE_DOUYIN:$this->ApiBase = $this->API_BASE_ARRAY['douyin'];break; |
|
| 181 | - case ConstCode::TYPE_TOUTIAO:$this->ApiBase = $this->API_BASE_ARRAY['toutiao'];break; |
|
| 182 | - case ConstCode::TYPE_XIGUA:$this->ApiBase = $this->API_BASE_ARRAY['xigua'];break; |
|
| 179 | + switch ($this->oauth_type) { |
|
| 180 | + case ConstCode::TYPE_DOUYIN:$this->ApiBase = $this->API_BASE_ARRAY['douyin']; break; |
|
| 181 | + case ConstCode::TYPE_TOUTIAO:$this->ApiBase = $this->API_BASE_ARRAY['toutiao']; break; |
|
| 182 | + case ConstCode::TYPE_XIGUA:$this->ApiBase = $this->API_BASE_ARRAY['xigua']; break; |
|
| 183 | 183 | default:throw new \Exception("获取抖音 OAUTH_TYPE 参数出错:{$this->oauth_type}"); |
| 184 | 184 | } |
| 185 | 185 | $this->AccessTokenURL = $this->ApiBase.$this->AccessTokenURL; |
@@ -216,8 +216,8 @@ discard block |
||
| 216 | 216 | 'appid' => $this->config['app_id'], |
| 217 | 217 | 'secret' => $this->config['app_secret'], |
| 218 | 218 | ]; |
| 219 | - if(isset($_REQUEST['code'])) $params['code'] = $_REQUEST['code']; |
|
| 220 | - if(isset($_REQUEST['anonymous_code'])) $params['anonymous_code'] = $_REQUEST['anonymous_code']; |
|
| 219 | + if (isset($_REQUEST['code'])) $params['code'] = $_REQUEST['code']; |
|
| 220 | + if (isset($_REQUEST['anonymous_code'])) $params['anonymous_code'] = $_REQUEST['anonymous_code']; |
|
| 221 | 221 | |
| 222 | 222 | return $params; |
| 223 | 223 | } |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | $data = json_decode($token, true); |
| 236 | 236 | if (isset($data['data']['access_token'])) { |
| 237 | 237 | return $data['data']; |
| 238 | - }elseif (isset($data['session_key'])){ |
|
| 238 | + }elseif (isset($data['session_key'])) { |
|
| 239 | 239 | //小程序登录 |
| 240 | 240 | return $data; |
| 241 | 241 | } 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传参 |
@@ -131,10 +131,10 @@ discard block |
||
| 131 | 131 | throw new \Exception("Wechat APP登录 需要传输access_token参数! "); |
| 132 | 132 | } |
| 133 | 133 | $this->token['access_token'] = $_REQUEST['access_token']; |
| 134 | - }elseif ($this->type == 'applets'){ |
|
| 134 | + } elseif ($this->type == 'applets'){ |
|
| 135 | 135 | //小程序 |
| 136 | 136 | return $this->applets(); |
| 137 | - }else { |
|
| 137 | + } else { |
|
| 138 | 138 | /** 获取token信息 */ |
| 139 | 139 | $this->getToken(); |
| 140 | 140 | } |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | $data = json_decode($token, true); |
| 216 | 216 | if (isset($data['access_token'])) { |
| 217 | 217 | return $data; |
| 218 | - }elseif (isset($data['session_key'])){ |
|
| 218 | + } elseif (isset($data['session_key'])){ |
|
| 219 | 219 | //小程序登录 |
| 220 | 220 | return $data; |
| 221 | 221 | } else { |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | $this->saveState(); |
| 42 | 42 | |
| 43 | 43 | //获取代理链接 |
| 44 | - if(isset($this->config['proxy_url'])){ |
|
| 44 | + if (isset($this->config['proxy_url'])) { |
|
| 45 | 45 | return $this->getProxyURL(); |
| 46 | 46 | } |
| 47 | 47 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | 'scope' => $this->config['scope'], |
| 55 | 55 | 'state' => $this->config['state'], |
| 56 | 56 | ]; |
| 57 | - return $this->AuthorizeURL . '?' . http_build_query($params) . '#wechat_redirect'; |
|
| 57 | + return $this->AuthorizeURL.'?'.http_build_query($params).'#wechat_redirect'; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | 'state' => $this->config['state'], |
| 73 | 73 | 'redirect_uri' => $this->config['callback'], |
| 74 | 74 | ]; |
| 75 | - return $this->config['proxy_url'] . '?' . http_build_query($params); |
|
| 75 | + return $this->config['proxy_url'].'?'.http_build_query($params); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -109,12 +109,12 @@ discard block |
||
| 109 | 109 | 'union_id'=> $this->token['unionid'] ?? '', |
| 110 | 110 | 'access_token'=> $this->token['access_token'] ?? '', |
| 111 | 111 | 'channel' => ConstCode::TYPE_WECHAT, |
| 112 | - 'nickname'=> $result['nickname']??'', |
|
| 112 | + 'nickname'=> $result['nickname'] ?? '', |
|
| 113 | 113 | 'gender' => $result['sex'] ?? ConstCode::GENDER, |
| 114 | - 'avatar' => $result['headimgurl']??'', |
|
| 115 | - 'session_key' => $result['session_key']??'', |
|
| 114 | + 'avatar' => $result['headimgurl'] ?? '', |
|
| 115 | + 'session_key' => $result['session_key'] ?? '', |
|
| 116 | 116 | ]; |
| 117 | - $userInfo['type'] = ConstCode::getTypeConst($userInfo['channel'],$this->type); |
|
| 117 | + $userInfo['type'] = ConstCode::getTypeConst($userInfo['channel'], $this->type); |
|
| 118 | 118 | return $userInfo; |
| 119 | 119 | } |
| 120 | 120 | |
@@ -127,15 +127,15 @@ discard block |
||
| 127 | 127 | */ |
| 128 | 128 | public function getUserInfo() |
| 129 | 129 | { |
| 130 | - if($this->type == 'app'){//App登录 |
|
| 131 | - if(!isset($_REQUEST['access_token']) ){ |
|
| 130 | + if ($this->type == 'app') {//App登录 |
|
| 131 | + if (!isset($_REQUEST['access_token'])) { |
|
| 132 | 132 | throw new \Exception("Wechat APP登录 需要传输access_token参数! "); |
| 133 | 133 | } |
| 134 | 134 | $this->token['access_token'] = $_REQUEST['access_token']; |
| 135 | - }elseif ($this->type == 'applets'){ |
|
| 135 | + }elseif ($this->type == 'applets') { |
|
| 136 | 136 | //小程序 |
| 137 | 137 | return $this->applets(); |
| 138 | - }else { |
|
| 138 | + } else { |
|
| 139 | 139 | /** 获取token信息 */ |
| 140 | 140 | $this->getToken(); |
| 141 | 141 | } |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | 'openid'=>$this->openid(), |
| 147 | 147 | 'lang'=>'zh_CN', |
| 148 | 148 | ]; |
| 149 | - $data = $this->get(self::API_BASE . 'userinfo', $params); |
|
| 149 | + $data = $this->get(self::API_BASE.'userinfo', $params); |
|
| 150 | 150 | return json_decode($data, true); |
| 151 | 151 | } |
| 152 | 152 | |
@@ -154,13 +154,13 @@ discard block |
||
| 154 | 154 | * @return array|mixed|null |
| 155 | 155 | * @throws \Exception |
| 156 | 156 | */ |
| 157 | - public function applets(){ |
|
| 157 | + public function applets() { |
|
| 158 | 158 | /** 获取参数 */ |
| 159 | 159 | $params = $this->accessTokenParams(); |
| 160 | 160 | $params['js_code'] = $params['code']; |
| 161 | 161 | |
| 162 | 162 | /** 获取access_token */ |
| 163 | - $token = $this->get($this->jsCode2Session, $params); |
|
| 163 | + $token = $this->get($this->jsCode2Session, $params); |
|
| 164 | 164 | /** 解析token值(子类实现此方法) */ |
| 165 | 165 | $this->token = $this->parseToken($token); |
| 166 | 166 | return $this->token; |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | $data = json_decode($token, true); |
| 217 | 217 | if (isset($data['access_token'])) { |
| 218 | 218 | return $data; |
| 219 | - }elseif (isset($data['session_key'])){ |
|
| 219 | + }elseif (isset($data['session_key'])) { |
|
| 220 | 220 | //小程序登录 |
| 221 | 221 | return $data; |
| 222 | 222 | } else { |
@@ -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 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | 'scope' => $this->config['scope'], |
| 34 | 34 | 'state' => $this->config['state'] ?: Str::random(), |
| 35 | 35 | ]; |
| 36 | - return $this->AuthorizeURL . '?' . http_build_query($params); |
|
| 36 | + return $this->AuthorizeURL.'?'.http_build_query($params); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | 'channel' => ConstCode::TYPE_LINE, |
| 58 | 58 | 'nickname' => $result['displayName'], |
| 59 | 59 | 'gender' => ConstCode::GENDER, //line不返回性别信息 |
| 60 | - 'avatar' => isset($result['pictureUrl']) ? $result['pictureUrl'] . '/large' : '', |
|
| 60 | + 'avatar' => isset($result['pictureUrl']) ? $result['pictureUrl'].'/large' : '', |
|
| 61 | 61 | ]; |
| 62 | 62 | return $userInfo; |
| 63 | 63 | } |
@@ -90,10 +90,10 @@ discard block |
||
| 90 | 90 | $method = strtoupper($method); |
| 91 | 91 | $request = [ |
| 92 | 92 | 'method' => $method, |
| 93 | - 'uri' => self::API_BASE . $api, |
|
| 93 | + 'uri' => self::API_BASE.$api, |
|
| 94 | 94 | ]; |
| 95 | 95 | |
| 96 | - $headers = ['Authorization' => $this->token['token_type'] . ' ' . $this->token['access_token']]; |
|
| 96 | + $headers = ['Authorization' => $this->token['token_type'].' '.$this->token['access_token']]; |
|
| 97 | 97 | |
| 98 | 98 | $data = $this->$method($request['uri'], $params, $headers); |
| 99 | 99 | |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | protected static function init($gateway, $config) |
| 36 | 36 | { |
| 37 | - if(empty($config)){ |
|
| 37 | + if (empty($config)) { |
|
| 38 | 38 | throw new \Exception("第三方登录 [$gateway] config配置不能为空"); |
| 39 | 39 | } |
| 40 | 40 | $baseConfig = [ |
@@ -44,14 +44,14 @@ discard block |
||
| 44 | 44 | 'scope' => '', |
| 45 | 45 | 'type' => '', |
| 46 | 46 | ]; |
| 47 | - if($gateway == 'weixin'){ |
|
| 47 | + if ($gateway == 'weixin') { |
|
| 48 | 48 | /** 兼容 tinymeng/oauth v1.0.0完美升级 */ |
| 49 | 49 | $gateway = 'wechat'; |
| 50 | 50 | } |
| 51 | 51 | $gateway = Str::uFirst($gateway); |
| 52 | - $class = __NAMESPACE__ . '\\Gateways\\' . $gateway; |
|
| 52 | + $class = __NAMESPACE__.'\\Gateways\\'.$gateway; |
|
| 53 | 53 | if (class_exists($class)) { |
| 54 | - $app = new $class(array_replace_recursive($baseConfig,$config)); |
|
| 54 | + $app = new $class(array_replace_recursive($baseConfig, $config)); |
|
| 55 | 55 | if ($app instanceof GatewayInterface) { |
| 56 | 56 | return $app; |
| 57 | 57 | } |