@@ -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 | } |
@@ -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 |
@@ -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 |
@@ -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 | |
@@ -105,11 +105,11 @@ discard block |
||
105 | 105 | 'open_id' => $this->openid(), |
106 | 106 | 'union_id'=> isset($this->token['unionid']) ? $this->token['unionid'] : '', |
107 | 107 | 'channel' => $this->oauth_type, |
108 | - 'nickname'=> $result['nickname']??'', |
|
108 | + 'nickname'=> $result['nickname'] ?? '', |
|
109 | 109 | 'gender' => isset($result['gender']) ? $result['gender'] : ConstCode::GENDER, |
110 | - 'avatar' => $result['avatar']??'', |
|
110 | + 'avatar' => $result['avatar'] ?? '', |
|
111 | 111 | ]; |
112 | - $userInfo['type'] = ConstCode::getTypeConst($userInfo['channel'],$this->type); |
|
112 | + $userInfo['type'] = ConstCode::getTypeConst($userInfo['channel'], $this->type); |
|
113 | 113 | return $userInfo; |
114 | 114 | } |
115 | 115 | |
@@ -122,15 +122,15 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function getUserInfo() |
124 | 124 | { |
125 | - if($this->type == 'app'){//App登录 |
|
126 | - if(!isset($_REQUEST['access_token']) ){ |
|
125 | + if ($this->type == 'app') {//App登录 |
|
126 | + if (!isset($_REQUEST['access_token'])) { |
|
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 | } |
@@ -149,12 +149,12 @@ discard block |
||
149 | 149 | * @return array|mixed|null |
150 | 150 | * @throws \Exception |
151 | 151 | */ |
152 | - public function applets(){ |
|
152 | + public function applets() { |
|
153 | 153 | /** 获取参数 */ |
154 | 154 | $params = $this->jscode2sessionParams(); |
155 | 155 | |
156 | 156 | /** 获取access_token */ |
157 | - $token = $this->get($this->jsCode2Session, $params); |
|
157 | + $token = $this->get($this->jsCode2Session, $params); |
|
158 | 158 | /** 解析token值(子类实现此方法) */ |
159 | 159 | $this->token = $this->parseToken($token); |
160 | 160 | return $this->token; |
@@ -167,10 +167,10 @@ discard block |
||
167 | 167 | */ |
168 | 168 | private function switchAccessTokenURL() |
169 | 169 | { |
170 | - switch ($this->oauth_type){ |
|
171 | - case ConstCode::TYPE_DOUYIN:$this->ApiBase = $this->API_BASE_ARRAY['douyin'];break; |
|
172 | - case ConstCode::TYPE_TOUTIAO:$this->ApiBase = $this->API_BASE_ARRAY['toutiao'];break; |
|
173 | - case ConstCode::TYPE_XIGUA:$this->ApiBase = $this->API_BASE_ARRAY['xigua'];break; |
|
170 | + switch ($this->oauth_type) { |
|
171 | + case ConstCode::TYPE_DOUYIN:$this->ApiBase = $this->API_BASE_ARRAY['douyin']; break; |
|
172 | + case ConstCode::TYPE_TOUTIAO:$this->ApiBase = $this->API_BASE_ARRAY['toutiao']; break; |
|
173 | + case ConstCode::TYPE_XIGUA:$this->ApiBase = $this->API_BASE_ARRAY['xigua']; break; |
|
174 | 174 | default:throw new \Exception("获取抖音 OAUTH_TYPE 参数出错:{$this->oauth_type}"); |
175 | 175 | } |
176 | 176 | $this->AccessTokenURL = $this->ApiBase.$this->AccessTokenURL; |
@@ -207,8 +207,8 @@ 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'])) $params['code'] = $_REQUEST['code']; |
|
211 | + if (isset($_REQUEST['anonymous_code'])) $params['anonymous_code'] = $_REQUEST['anonymous_code']; |
|
212 | 212 | |
213 | 213 | return $params; |
214 | 214 | } |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | $data = json_decode($token, true); |
227 | 227 | if (isset($data['data']['access_token'])) { |
228 | 228 | return $data['data']; |
229 | - }elseif (isset($data['session_key'])){ |
|
229 | + }elseif (isset($data['session_key'])) { |
|
230 | 230 | //小程序登录 |
231 | 231 | return $data; |
232 | 232 | } else { |
@@ -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 | } |