@@ -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 | } |
@@ -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 | } |
@@ -51,9 +51,9 @@ discard block |
||
| 51 | 51 | 'scope' => $this->config['scope'], |
| 52 | 52 | 'state' => $this->config['state'], |
| 53 | 53 | 'display' => $this->display, |
| 54 | - 'allow_signup' => true,//是否会在OAuth流程中为未经身份验证的用户提供注册GitHub的选项。默认是true。false在策略禁止注册的情况下使用。 |
|
| 54 | + 'allow_signup' => true, //是否会在OAuth流程中为未经身份验证的用户提供注册GitHub的选项。默认是true。false在策略禁止注册的情况下使用。 |
|
| 55 | 55 | ]; |
| 56 | - return $this->AuthorizeURL . '?' . http_build_query($params); |
|
| 56 | + return $this->AuthorizeURL.'?'.http_build_query($params); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | $headers = [ |
| 114 | 114 | 'User-Agent: '.$this->config['application_name'], |
| 115 | 115 | '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 ', |
| 116 | - 'Authorization: token ' . $this->token['access_token'], |
|
| 116 | + 'Authorization: token '.$this->token['access_token'], |
|
| 117 | 117 | 'Accept: application/json' |
| 118 | 118 | ]; |
| 119 | 119 | $response = $this->get($this->UserInfoURL, [], $headers); |
@@ -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 | const TYPE_BAIDU = 13; //百度 |
| 34 | 34 | const TYPE_CODING = 14; //Coding |
@@ -53,24 +53,24 @@ discard block |
||
| 53 | 53 | * @param bool $type 类型:app applets |
| 54 | 54 | * @return int |
| 55 | 55 | */ |
| 56 | - static public function getTypeConst($channel,$type="") |
|
| 56 | + static public function getTypeConst($channel, $type = "") |
|
| 57 | 57 | { |
| 58 | - switch ($channel){ |
|
| 58 | + switch ($channel) { |
|
| 59 | 59 | case self::TYPE_QQ: |
| 60 | - if($type == 'app'){ |
|
| 61 | - $typeConst = self::TYPE_QQ_APP;//qqApp |
|
| 62 | - }else{ |
|
| 60 | + if ($type == 'app') { |
|
| 61 | + $typeConst = self::TYPE_QQ_APP; //qqApp |
|
| 62 | + } else { |
|
| 63 | 63 | $typeConst = $channel; |
| 64 | 64 | } |
| 65 | 65 | break; |
| 66 | 66 | case self::TYPE_WECHAT: |
| 67 | - if($type == 'app'){ |
|
| 68 | - $typeConst = self::TYPE_WECHAT_APP;//微信App |
|
| 69 | - }else if($type == 'applets'){ |
|
| 70 | - $typeConst = self::TYPE_WECHAT_APPLETS;//微信小程序 |
|
| 71 | - }else if(Tool::isWeiXin()){ |
|
| 72 | - $typeConst = self::TYPE_WECHAT_MOBILE;//微信mobile |
|
| 73 | - }else{ |
|
| 67 | + if ($type == 'app') { |
|
| 68 | + $typeConst = self::TYPE_WECHAT_APP; //微信App |
|
| 69 | + } else if ($type == 'applets') { |
|
| 70 | + $typeConst = self::TYPE_WECHAT_APPLETS; //微信小程序 |
|
| 71 | + } else if (Tool::isWeiXin()) { |
|
| 72 | + $typeConst = self::TYPE_WECHAT_MOBILE; //微信mobile |
|
| 73 | + } else { |
|
| 74 | 74 | $typeConst = $channel; |
| 75 | 75 | } |
| 76 | 76 | break; |
@@ -10,20 +10,20 @@ |
||
| 10 | 10 | //引入配置文件 |
| 11 | 11 | $params = require('config/params.php'); |
| 12 | 12 | |
| 13 | -try{ |
|
| 14 | - $name="qq";//登录类型,例:qq / google |
|
| 13 | +try { |
|
| 14 | + $name = "qq"; //登录类型,例:qq / google |
|
| 15 | 15 | $oauth = new oauth2($params); |
| 16 | 16 | if (empty($_GET['code'])) { |
| 17 | 17 | /** 登录 */ |
| 18 | 18 | $result = $oauth->login($name); |
| 19 | 19 | // var_dump($result['url']);die; |
| 20 | 20 | //重定向到第三方登录页 |
| 21 | - header('Location: ' . $result['url']); |
|
| 22 | - }else{ |
|
| 21 | + header('Location: '.$result['url']); |
|
| 22 | + } else { |
|
| 23 | 23 | /** 登录回调 */ |
| 24 | 24 | $result = $this->callback($name); |
| 25 | - var_dump($result);die; |
|
| 25 | + var_dump($result); die; |
|
| 26 | 26 | } |
| 27 | -}catch(Exception $e){ |
|
| 27 | +} catch (Exception $e) { |
|
| 28 | 28 | echo 'Oauth登录失败!'.$e->getMessage(); |
| 29 | 29 | } |
| 30 | 30 | \ No newline at end of file |
@@ -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 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | /** |
| 6 | 6 | * |
| 7 | 7 | */ |
| 8 | -class oauth2{ |
|
| 8 | +class oauth2 { |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * 全部配置文件 |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | /** |
| 27 | 27 | * @param $conf |
| 28 | 28 | */ |
| 29 | - public function __construct($conf){ |
|
| 29 | + public function __construct($conf) { |
|
| 30 | 30 | $this->configAll = $conf; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -37,15 +37,15 @@ discard block |
||
| 37 | 37 | * Updater: |
| 38 | 38 | * @param $name |
| 39 | 39 | */ |
| 40 | - public function getConfig($name){ |
|
| 41 | - $this->config = $this->configAll[$name]??[]; |
|
| 42 | - if($name == 'wechat'){ |
|
| 43 | - if(!Tool::isMobile()){ |
|
| 44 | - $this->config = $this->config['pc'];//微信pc扫码登录 |
|
| 45 | - }elseif(Tool::isWeiXin()){ |
|
| 46 | - $this->config = $this->config['mobile'];//微信浏览器中打开 |
|
| 47 | - }else{ |
|
| 48 | - echo '请使用微信打开!';exit();//手机浏览器打开 |
|
| 40 | + public function getConfig($name) { |
|
| 41 | + $this->config = $this->configAll[$name] ?? []; |
|
| 42 | + if ($name == 'wechat') { |
|
| 43 | + if (!Tool::isMobile()) { |
|
| 44 | + $this->config = $this->config['pc']; //微信pc扫码登录 |
|
| 45 | + }elseif (Tool::isWeiXin()) { |
|
| 46 | + $this->config = $this->config['mobile']; //微信浏览器中打开 |
|
| 47 | + } else { |
|
| 48 | + echo '请使用微信打开!'; exit(); //手机浏览器打开 |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | //可以设置代理服务器,一般用于调试国外平台 |
@@ -57,15 +57,15 @@ discard block |
||
| 57 | 57 | * Author: JiaMeng <[email protected]> |
| 58 | 58 | * Updater: |
| 59 | 59 | */ |
| 60 | - public function login($name,$state=""){ |
|
| 60 | + public function login($name, $state = "") { |
|
| 61 | 61 | /** 获取配置 */ |
| 62 | - if($name == 'wx') $name = 'wechat'; |
|
| 62 | + if ($name == 'wx') $name = 'wechat'; |
|
| 63 | 63 | $this->getConfig($name); |
| 64 | 64 | $this->config['state'] = $state; |
| 65 | 65 | |
| 66 | 66 | /** 初始化实例类 */ |
| 67 | 67 | $oauth = OAuth::$name($this->config); |
| 68 | - if(Tool::isMobile() || Tool::isWeiXin()){ |
|
| 68 | + if (Tool::isMobile() || Tool::isWeiXin()) { |
|
| 69 | 69 | /** |
| 70 | 70 | * 对于微博,如果登录界面要适用于手机,则需要设定->setDisplay('mobile') |
| 71 | 71 | * 对于微信,如果是公众号登录,则需要设定->setDisplay('mobile'),否则是WEB网站扫码登录 |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | public function callback($name) |
| 95 | 95 | { |
| 96 | 96 | /** 获取配置 */ |
| 97 | - if($name == 'wx') $name = 'wechat'; |
|
| 97 | + if ($name == 'wx') $name = 'wechat'; |
|
| 98 | 98 | $this->getConfig($name); |
| 99 | 99 | |
| 100 | 100 | /** 初始化实例类 */ |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | 'state' => $this->config['state'], |
| 35 | 35 | 'scope' => $this->config['scope'], |
| 36 | 36 | ]; |
| 37 | - return $this->AuthorizeURL . '?' . http_build_query($params); |
|
| 37 | + return $this->AuthorizeURL.'?'.http_build_query($params); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | $params = [ |
| 74 | 74 | 'access_token'=>$this->token['access_token'], |
| 75 | 75 | ]; |
| 76 | - $data = $this->get($this->UserInfoURL,$params); |
|
| 76 | + $data = $this->get($this->UserInfoURL, $params); |
|
| 77 | 77 | return json_decode($data, true); |
| 78 | 78 | } |
| 79 | 79 | |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | /** |
| 92 | 92 | * Description: 获取AccessToken |
| 93 | 93 | */ |
| 94 | - protected function getToken(){
|
|
| 94 | + protected function getToken() {
|
|
| 95 | 95 | if (empty($this->token)) {
|
| 96 | 96 | /** 验证state参数 */ |
| 97 | 97 | $this->CheckState(); |
@@ -100,8 +100,8 @@ discard block |
||
| 100 | 100 | $params = $this->accessTokenParams(); |
| 101 | 101 | |
| 102 | 102 | /** 获取access_token */ |
| 103 | - $this->AccessTokenURL = $this->AccessTokenURL . '?' . http_build_query($params); |
|
| 104 | - $token = $this->post($this->AccessTokenURL); |
|
| 103 | + $this->AccessTokenURL = $this->AccessTokenURL.'?'.http_build_query($params); |
|
| 104 | + $token = $this->post($this->AccessTokenURL); |
|
| 105 | 105 | /** 解析token值(子类实现此方法) */ |
| 106 | 106 | $this->token = $this->parseToken($token); |
| 107 | 107 | } |
@@ -22,21 +22,21 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | class Douyin extends Gateway |
| 24 | 24 | { |
| 25 | - protected $ApiBase = 'https://open.douyin.com'; |
|
| 25 | + protected $ApiBase = 'https://open.douyin.com'; |
|
| 26 | 26 | protected $AuthorizeURL = 'https://open.douyin.com/platform/oauth/connect/'; |
| 27 | - protected $AuthorizeSilenceURL = 'https://open.douyin.com/oauth/authorize/v2/';//抖音静默授权 |
|
| 27 | + protected $AuthorizeSilenceURL = 'https://open.douyin.com/oauth/authorize/v2/'; //抖音静默授权 |
|
| 28 | 28 | protected $AccessTokenURL = 'oauth/access_token/'; |
| 29 | 29 | protected $UserInfoURL = 'oauth/userinfo/'; |
| 30 | 30 | |
| 31 | 31 | protected $jsCode2Session = 'https://minigame.zijieapi.com/mgplatform/api/apps/jscode2session'; |
| 32 | 32 | |
| 33 | 33 | protected $API_BASE_ARRAY = [ |
| 34 | - 'douyin'=>'https://open.douyin.com/',//抖音 |
|
| 35 | - 'toutiao'=>'https://open.snssdk.com/',//头条 |
|
| 36 | - 'xigua'=>'https://open-api.ixigua.com/',//西瓜 |
|
| 34 | + 'douyin'=>'https://open.douyin.com/', //抖音 |
|
| 35 | + 'toutiao'=>'https://open.snssdk.com/', //头条 |
|
| 36 | + 'xigua'=>'https://open-api.ixigua.com/', //西瓜 |
|
| 37 | 37 | ]; |
| 38 | 38 | |
| 39 | - public $oauth_type = ConstCode::TYPE_DOUYIN;//抖音 |
|
| 39 | + public $oauth_type = ConstCode::TYPE_DOUYIN; //抖音 |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * @param $config |
@@ -66,17 +66,17 @@ discard block |
||
| 66 | 66 | 'redirect_uri' => $this->config['callback'], |
| 67 | 67 | 'response_type' => $this->config['response_type'], |
| 68 | 68 | 'scope' => $this->config['scope'], |
| 69 | - 'optionalScope' => $this->config['optionalScope']??'', |
|
| 69 | + 'optionalScope' => $this->config['optionalScope'] ?? '', |
|
| 70 | 70 | 'state' => $this->config['state'], |
| 71 | 71 | ]; |
| 72 | - if($params['state'] == 'login_id'){ |
|
| 72 | + if ($params['state'] == 'login_id') { |
|
| 73 | 73 | /** |
| 74 | 74 | * 抖音静默获取授权码 |
| 75 | 75 | * https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/openapi/account-permission/douyin-default-get-permission-code |
| 76 | 76 | */ |
| 77 | - return $this->AuthorizeSilenceURL . '?' . http_build_query($params); |
|
| 78 | - }else{ |
|
| 79 | - return $this->AuthorizeURL . '?' . http_build_query($params); |
|
| 77 | + return $this->AuthorizeSilenceURL.'?'.http_build_query($params); |
|
| 78 | + } else { |
|
| 79 | + return $this->AuthorizeURL.'?'.http_build_query($params); |
|
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | |
@@ -115,10 +115,10 @@ discard block |
||
| 115 | 115 | 'access_token'=> $this->token['access_token'] ?? '', |
| 116 | 116 | 'union_id'=> $this->token['unionid'] ?? '', |
| 117 | 117 | 'channel' => $this->oauth_type, |
| 118 | - 'nickname'=> $result['nickname']??'', |
|
| 118 | + 'nickname'=> $result['nickname'] ?? '', |
|
| 119 | 119 | 'gender' => $result['gender'] ?? ConstCode::GENDER, |
| 120 | - 'type' => ConstCode::getTypeConst($this->oauth_type,$this->type), |
|
| 121 | - 'avatar' => $result['avatar']??'', |
|
| 120 | + 'type' => ConstCode::getTypeConst($this->oauth_type, $this->type), |
|
| 121 | + 'avatar' => $result['avatar'] ?? '', |
|
| 122 | 122 | 'native' => $result, |
| 123 | 123 | ]; |
| 124 | 124 | return $userInfo; |
@@ -133,15 +133,15 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | public function getUserInfo() |
| 135 | 135 | { |
| 136 | - if($this->type == 'app'){//App登录 |
|
| 137 | - if(!isset($_REQUEST['access_token']) ){ |
|
| 136 | + if ($this->type == 'app') {//App登录 |
|
| 137 | + if (!isset($_REQUEST['access_token'])) { |
|
| 138 | 138 | throw new OAuthException("Douyin APP登录 需要传输access_token参数! "); |
| 139 | 139 | } |
| 140 | 140 | $this->token['access_token'] = $_REQUEST['access_token']; |
| 141 | - }elseif ($this->type == 'applets'){ |
|
| 141 | + }elseif ($this->type == 'applets') { |
|
| 142 | 142 | //小程序 |
| 143 | 143 | return $this->applets(); |
| 144 | - }else { |
|
| 144 | + } else { |
|
| 145 | 145 | /** 获取token信息 */ |
| 146 | 146 | $this->getToken(); |
| 147 | 147 | } |
@@ -160,12 +160,12 @@ discard block |
||
| 160 | 160 | * @return array|mixed|null |
| 161 | 161 | * @throws OAuthException |
| 162 | 162 | */ |
| 163 | - public function applets(){ |
|
| 163 | + public function applets() { |
|
| 164 | 164 | /** 获取参数 */ |
| 165 | 165 | $params = $this->jscode2sessionParams(); |
| 166 | 166 | |
| 167 | 167 | /** 获取access_token */ |
| 168 | - $token = $this->get($this->jsCode2Session, $params); |
|
| 168 | + $token = $this->get($this->jsCode2Session, $params); |
|
| 169 | 169 | /** 解析token值(子类实现此方法) */ |
| 170 | 170 | $this->token = $this->parseToken($token); |
| 171 | 171 | return $this->token; |
@@ -178,10 +178,10 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | private function switchAccessTokenURL() |
| 180 | 180 | { |
| 181 | - switch ($this->oauth_type){ |
|
| 182 | - case ConstCode::TYPE_DOUYIN:$this->ApiBase = $this->API_BASE_ARRAY['douyin'];break; |
|
| 183 | - case ConstCode::TYPE_TOUTIAO:$this->ApiBase = $this->API_BASE_ARRAY['toutiao'];break; |
|
| 184 | - case ConstCode::TYPE_XIGUA:$this->ApiBase = $this->API_BASE_ARRAY['xigua'];break; |
|
| 181 | + switch ($this->oauth_type) { |
|
| 182 | + case ConstCode::TYPE_DOUYIN:$this->ApiBase = $this->API_BASE_ARRAY['douyin']; break; |
|
| 183 | + case ConstCode::TYPE_TOUTIAO:$this->ApiBase = $this->API_BASE_ARRAY['toutiao']; break; |
|
| 184 | + case ConstCode::TYPE_XIGUA:$this->ApiBase = $this->API_BASE_ARRAY['xigua']; break; |
|
| 185 | 185 | default:throw new OAuthException("获取抖音 OAUTH_TYPE 参数出错:{$this->oauth_type}"); |
| 186 | 186 | } |
| 187 | 187 | $this->AccessTokenURL = $this->ApiBase.$this->AccessTokenURL; |
@@ -218,8 +218,8 @@ discard block |
||
| 218 | 218 | 'appid' => $this->config['app_id'], |
| 219 | 219 | 'secret' => $this->config['app_secret'], |
| 220 | 220 | ]; |
| 221 | - if(isset($_REQUEST['code'])) $params['code'] = $_REQUEST['code']; |
|
| 222 | - if(isset($_REQUEST['anonymous_code'])) $params['anonymous_code'] = $_REQUEST['anonymous_code']; |
|
| 221 | + if (isset($_REQUEST['code'])) $params['code'] = $_REQUEST['code']; |
|
| 222 | + if (isset($_REQUEST['anonymous_code'])) $params['anonymous_code'] = $_REQUEST['anonymous_code']; |
|
| 223 | 223 | |
| 224 | 224 | return $params; |
| 225 | 225 | } |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | $data = json_decode($token, true); |
| 238 | 238 | if (isset($data['data']['access_token'])) { |
| 239 | 239 | return $data['data']; |
| 240 | - }elseif (isset($data['session_key'])){ |
|
| 240 | + }elseif (isset($data['session_key'])) { |
|
| 241 | 241 | //小程序登录 |
| 242 | 242 | return $data; |
| 243 | 243 | } else { |