@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | $this->saveState(); |
28 | 28 | //登录参数 |
29 | 29 | $oauthToken = $this->call('oauth/request_token', ['oauth_callback' => $this->config['callback']], 'POST'); |
30 | - return self::API_BASE . 'oauth/authenticate?oauth_token=' . $oauthToken['oauth_token']; |
|
30 | + return self::API_BASE.'oauth/authenticate?oauth_token='.$oauthToken['oauth_token']; |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | if (isset($this->token['oauth_token_secret'])) { |
67 | 67 | $this->tokenSecret = $this->token['oauth_token_secret']; |
68 | 68 | } else { |
69 | - throw new \Exception("获取Twitter ACCESS_TOKEN 出错:" . json_encode($this->token)); |
|
69 | + throw new \Exception("获取Twitter ACCESS_TOKEN 出错:".json_encode($this->token)); |
|
70 | 70 | } |
71 | 71 | } |
72 | 72 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | $method = strtoupper($method); |
87 | 87 | $request = [ |
88 | 88 | 'method' => $method, |
89 | - 'uri' => self::API_BASE . $api, |
|
89 | + 'uri' => self::API_BASE.$api, |
|
90 | 90 | ]; |
91 | 91 | $oauthParams = $this->getOAuthParams($params); |
92 | 92 | $oauthParams['oauth_signature'] = $this->signature($request, $oauthParams); |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | { |
132 | 132 | ksort($params); |
133 | 133 | $sign_str = Str::buildParams($params, true); |
134 | - $sign_str = $request['method'] . '&' . rawurlencode($request['uri']) . '&' . rawurlencode($sign_str); |
|
135 | - $sign_key = $this->config['app_secret'] . '&' . $this->tokenSecret; |
|
134 | + $sign_str = $request['method'].'&'.rawurlencode($request['uri']).'&'.rawurlencode($sign_str); |
|
135 | + $sign_key = $this->config['app_secret'].'&'.$this->tokenSecret; |
|
136 | 136 | |
137 | 137 | return rawurlencode(base64_encode(hash_hmac('sha1', $sign_str, $sign_key, true))); |
138 | 138 | } |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | { |
148 | 148 | $return = 'OAuth '; |
149 | 149 | foreach ($params as $k => $param) { |
150 | - $return .= $k . '="' . $param . '", '; |
|
150 | + $return .= $k.'="'.$param.'", '; |
|
151 | 151 | } |
152 | 152 | return rtrim($return, ', '); |
153 | 153 | } |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * 解析access_token方法请求后的返回值 |
169 | 169 | * @param string $token 获取access_token的方法的返回值 |
170 | 170 | */ |
171 | - protected function parseToken($token){ |
|
171 | + protected function parseToken($token) { |
|
172 | 172 | return $token; |
173 | 173 | } |
174 | 174 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | if (!$config) { |
86 | 86 | throw new \Exception('传入的配置不能为空'); |
87 | 87 | } |
88 | - if(isset($_GET['referer']) && $config['callback']){ |
|
88 | + if (isset($_GET['referer']) && $config['callback']) { |
|
89 | 89 | $config['callback'] .= ((strpos($config['callback'], '?') !== false) ? '&' : '?').'referer='.$_GET['referer']; |
90 | 90 | } |
91 | 91 | //默认参数 |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | 'proxy' => '', |
99 | 99 | 'state' => '', |
100 | 100 | 'type' => '', |
101 | - 'is_sandbox' => false,//是否是沙箱环境 |
|
101 | + 'is_sandbox' => false, //是否是沙箱环境 |
|
102 | 102 | ]; |
103 | - $this->config = array_merge($_config, $config); |
|
104 | - foreach($this->config as $key=>$val){ |
|
105 | - if(property_exists($this,$key)) $this->$key=$val; |
|
103 | + $this->config = array_merge($_config, $config); |
|
104 | + foreach ($this->config as $key=>$val) { |
|
105 | + if (property_exists($this, $key)) $this->$key = $val; |
|
106 | 106 | } |
107 | 107 | $this->timestamp = time(); |
108 | 108 | } |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | * Updater: |
139 | 139 | * @return $this |
140 | 140 | */ |
141 | - public function mustCheckState(){ |
|
141 | + public function mustCheckState() { |
|
142 | 142 | $this->checkState = true; |
143 | 143 | return $this; |
144 | 144 | } |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | * @Author: TinyMeng <[email protected]> |
149 | 149 | * @return array |
150 | 150 | */ |
151 | - public function getConfig(){ |
|
151 | + public function getConfig() { |
|
152 | 152 | return $this->config; |
153 | 153 | } |
154 | 154 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @param $token |
158 | 158 | * @return $this |
159 | 159 | */ |
160 | - public function setToken($token){ |
|
160 | + public function setToken($token) { |
|
161 | 161 | $this->token = $token; |
162 | 162 | return $this; |
163 | 163 | } |
@@ -166,14 +166,14 @@ discard block |
||
166 | 166 | * 存储state |
167 | 167 | * @Author: TinyMeng <[email protected]> |
168 | 168 | */ |
169 | - public function saveState(){ |
|
169 | + public function saveState() { |
|
170 | 170 | if ($this->checkState === true) { |
171 | 171 | //是否开启session |
172 | 172 | if (session_status() !== PHP_SESSION_ACTIVE) { |
173 | 173 | session_start(); |
174 | 174 | } |
175 | - if(empty($this->config['state'])){ |
|
176 | - $this->config['state'] = Str::random();//生成随机state |
|
175 | + if (empty($this->config['state'])) { |
|
176 | + $this->config['state'] = Str::random(); //生成随机state |
|
177 | 177 | } |
178 | 178 | //存储到session |
179 | 179 | $_SESSION['tinymeng_oauth_state'] = $this->config['state']; |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | * @Author: TinyMeng <[email protected]> |
186 | 186 | * @throws \Exception |
187 | 187 | */ |
188 | - public function checkState(){ |
|
188 | + public function checkState() { |
|
189 | 189 | if ($this->checkState === true) { |
190 | 190 | if (session_status() !== PHP_SESSION_ACTIVE) { |
191 | 191 | session_start(); |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | * Updater: |
203 | 203 | * @return array |
204 | 204 | */ |
205 | - protected function accessTokenParams(){ |
|
205 | + protected function accessTokenParams() { |
|
206 | 206 | $params = [ |
207 | 207 | 'client_id' => $this->config['app_id'], |
208 | 208 | 'client_secret' => $this->config['app_secret'], |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | * @author: JiaMeng <[email protected]> |
219 | 219 | * Updater: |
220 | 220 | */ |
221 | - protected function getToken(){ |
|
221 | + protected function getToken() { |
|
222 | 222 | if (empty($this->token)) { |
223 | 223 | /** 验证state参数 */ |
224 | 224 | $this->checkState(); |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | $params = $this->accessTokenParams(); |
228 | 228 | |
229 | 229 | /** 获取access_token */ |
230 | - $token = $this->POST($this->AccessTokenURL, $params); |
|
230 | + $token = $this->POST($this->AccessTokenURL, $params); |
|
231 | 231 | /** 解析token值(子类实现此方法) */ |
232 | 232 | $this->token = $this->parseToken($token); |
233 | 233 | } |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | */ |
245 | 245 | protected function get($url, $params = [], $headers = []) |
246 | 246 | { |
247 | - return \tinymeng\tools\HttpRequest::httpGet($url, $params,$headers); |
|
247 | + return \tinymeng\tools\HttpRequest::httpGet($url, $params, $headers); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
@@ -258,8 +258,8 @@ discard block |
||
258 | 258 | */ |
259 | 259 | protected function post($url, $params = [], $headers = []) |
260 | 260 | { |
261 | - $headers[] = 'Accept: application/json';//GitHub需要的header |
|
262 | - return \tinymeng\tools\HttpRequest::httpPost($url, $params,$headers); |
|
261 | + $headers[] = 'Accept: application/json'; //GitHub需要的header |
|
262 | + return \tinymeng\tools\HttpRequest::httpPost($url, $params, $headers); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | * M代表男性,F代表女性 |
268 | 268 | * @param $gender |
269 | 269 | */ |
270 | - public function getGender($gender){ |
|
271 | - return strtolower(substr($gender , 0 , 1)) == 'm' ? ConstCode::GENDER_MAN : ConstCode::GENDER_WOMEN; |
|
270 | + public function getGender($gender) { |
|
271 | + return strtolower(substr($gender, 0, 1)) == 'm' ? ConstCode::GENDER_MAN : ConstCode::GENDER_WOMEN; |
|
272 | 272 | } |
273 | 273 | } |
@@ -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 | /** |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | 'gender' => isset($result['gender']) ? $this->getGender($result['gender']) : ConstCode::GENDER, |
69 | 69 | 'avatar' => $result['picture'], |
70 | 70 | ); |
71 | - if(isset($result['email'])){ |
|
71 | + if (isset($result['email'])) { |
|
72 | 72 | $userInfo['email'] = $result['email']; |
73 | 73 | } |
74 | 74 | return $userInfo; |
@@ -79,14 +79,14 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function getUserInfo() |
81 | 81 | { |
82 | - if($this->type == 'app'){//App登录 |
|
83 | - if(!isset($_REQUEST['code']) ){ |
|
82 | + if ($this->type == 'app') {//App登录 |
|
83 | + if (!isset($_REQUEST['code'])) { |
|
84 | 84 | throw new \Exception("Google APP登录 需要传输code参数! "); |
85 | 85 | } |
86 | 86 | } |
87 | 87 | $this->getToken(); |
88 | - $headers = ['Authorization : Bearer ' . $this->token['access_token']]; |
|
89 | - $data = $this->get(self::API_BASE . 'oauth2/v2/userinfo', '', $headers); |
|
88 | + $headers = ['Authorization : Bearer '.$this->token['access_token']]; |
|
89 | + $data = $this->get(self::API_BASE.'oauth2/v2/userinfo', '', $headers); |
|
90 | 90 | return json_decode($data, true); |
91 | 91 | } |
92 | 92 |
@@ -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'=> $this->token['access_token'] ?? '', |
107 | 107 | 'union_id'=> $this->token['unionid'] ?? '', |
108 | 108 | 'channel' => $this->oauth_type, |
109 | - 'nickname'=> $result['nickname']??'', |
|
109 | + 'nickname'=> $result['nickname'] ?? '', |
|
110 | 110 | '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 { |
@@ -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 { |
@@ -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 | } |
@@ -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 | |
34 | 34 | const TYPE_QQ_APP = 21; //qqAPP |
@@ -47,24 +47,24 @@ discard block |
||
47 | 47 | * @param bool $type 类型:app applets |
48 | 48 | * @return int |
49 | 49 | */ |
50 | - static public function getTypeConst($channel,$type="") |
|
50 | + static public function getTypeConst($channel, $type = "") |
|
51 | 51 | { |
52 | - switch ($channel){ |
|
52 | + switch ($channel) { |
|
53 | 53 | case self::TYPE_QQ: |
54 | - if($type == 'app'){ |
|
55 | - $typeConst = self::TYPE_QQ_APP;//qqApp |
|
56 | - }else{ |
|
54 | + if ($type == 'app') { |
|
55 | + $typeConst = self::TYPE_QQ_APP; //qqApp |
|
56 | + } else { |
|
57 | 57 | $typeConst = $channel; |
58 | 58 | } |
59 | 59 | break; |
60 | 60 | case self::TYPE_WECHAT: |
61 | - if($type == 'app'){ |
|
62 | - $typeConst = self::TYPE_WECHAT_APP;//微信App |
|
63 | - }else if($type == 'applets'){ |
|
64 | - $typeConst = self::TYPE_WECHAT_APPLETS;//微信小程序 |
|
65 | - }else if(Tool::isWeiXin()){ |
|
66 | - $typeConst = self::TYPE_WECHAT_MOBILE;//微信mobile |
|
67 | - }else{ |
|
61 | + if ($type == 'app') { |
|
62 | + $typeConst = self::TYPE_WECHAT_APP; //微信App |
|
63 | + } else if ($type == 'applets') { |
|
64 | + $typeConst = self::TYPE_WECHAT_APPLETS; //微信小程序 |
|
65 | + } else if (Tool::isWeiXin()) { |
|
66 | + $typeConst = self::TYPE_WECHAT_MOBILE; //微信mobile |
|
67 | + } else { |
|
68 | 68 | $typeConst = $channel; |
69 | 69 | } |
70 | 70 | break; |