解决新装后插入用户无法登陆的问题

This commit is contained in:
2020-04-20 13:13:09 +08:00
parent 1a68cddd1c
commit ed57619b65
5 changed files with 24 additions and 27 deletions

View File

@@ -15,9 +15,9 @@ class Application {
* @var array
*/
private $providers = [
'qq' => 'Qq',
'weibo' => 'Weibo',
'wechat' => 'Wechat',
'qq' => 'Qq',
'weibo' => 'Weibo',
'wechat' => 'Wechat',
];
/**
@@ -26,15 +26,14 @@ class Application {
*/
protected $services = [];
public function __construct($options = [])
{
public function __construct($options = []) {
$options = array_intersect_key($options, $this->providers);
$options = array_merge($this->config, is_array($options) ? $options : []);
foreach ($options as $key => &$option) {
$option['app_id'] = isset($option['app_id']) ? $option['app_id'] : '';
$option['app_secret'] = isset($option['app_secret']) ? $option['app_secret'] : '';
// 如果未定义回调地址则自动生成
$option['callback'] = isset($option['callback']) && $option['callback'] ? $option['callback'] : addon_url('syslogin/index/callback', [':platform' => $key], false, true);
$option['callback'] = isset($option['callback']) && $option['callback'] ? $option['callback'] : addons_url('syslogin/index/callback', [':platform' => $key], false, true);
}
$this->config = $options;
//注册服务器提供者
@@ -44,8 +43,7 @@ class Application {
/**
* 注册服务提供者
*/
private function registerProviders()
{
private function registerProviders() {
foreach ($this->providers as $k => $v) {
$this->services[$k] = function () use ($k, $v) {
$options = $this->config[$k];
@@ -55,13 +53,11 @@ class Application {
}
}
public function __set($key, $value)
{
public function __set($key, $value) {
$this->services[$key] = $value;
}
public function __get($key)
{
public function __get($key) {
return isset($this->services[$key]) ? $this->services[$key]($this) : null;
}
}

View File

@@ -72,7 +72,8 @@ class Qq {
"oauth_consumer_key" => $this->config['app_id'],
"openid" => $openid,
];
$ret = Http::get(self::GET_USERINFO_URL, $queryarr);
$client = new \GuzzleHttp\Client();
$ret = $client->post(self::GET_USERINFO_URL, ['form_params' => $queryarr])->getBody()->getContents();
$userinfo = (array) json_decode($ret, true);
if (!$userinfo || !isset($userinfo['ret']) || $userinfo['ret'] !== 0) {
return [];
@@ -108,7 +109,8 @@ class Qq {
"redirect_uri" => $this->config['callback'],
"code" => $code,
);
$ret = Http::get(self::GET_ACCESS_TOKEN_URL, $queryarr);
$client = new \GuzzleHttp\Client();
$ret = $client->post(self::GET_ACCESS_TOKEN_URL, ['form_params' => $queryarr])->getBody()->getContents();
$params = [];
parse_str($ret, $params);
return $params ? $params : [];
@@ -120,7 +122,8 @@ class Qq {
* @return string
*/
private function getOpenId($access_token = '') {
$response = Http::get(self::GET_OPENID_URL, ['access_token' => $access_token]);
$client = new \GuzzleHttp\Client();
$response = $client->post(self::GET_OPENID_URL, ['form_params' => ['access_token' => $access_token]])->getBody()->getContents();
if (strpos($response, "callback") !== false) {
$lpos = strpos($response, "(");
$rpos = strrpos($response, ")");

View File

@@ -70,7 +70,8 @@ class Weibo {
"access_token" => $access_token,
"uid" => $uid,
];
$ret = Http::get(self::GET_USERINFO_URL, $queryarr);
$client = new \GuzzleHttp\Client();
$ret = $client->post(self::GET_USERINFO_URL, ['form_params' => $queryarr])->getBody()->getContents();
$userinfo = (array) json_decode($ret, true);
if (!$userinfo || isset($userinfo['error_code'])) {
return [];
@@ -107,7 +108,8 @@ class Weibo {
"redirect_uri" => $this->config['callback'],
"code" => $code,
);
$response = Http::post(self::GET_ACCESS_TOKEN_URL, $queryarr);
$client = new \GuzzleHttp\Client();
$response = $client->post(self::GET_ACCESS_TOKEN_URL, ['form_params' => $queryarr])->getBody()->getContents();
$ret = (array) json_decode($response, true);
return $ret ? $ret : [];
}

View File

@@ -1,9 +1,5 @@
<style type="text/css">
.third-login{margin: 0;}
.third-login li{list-style: none;}
</style>
<ul class="third-login">
<li><a href="{:addons_url('syslogin/index/login', ['platform' => 'qq'])}"><i class="fa fa-qq"></i> QQ登录</a></li>
<li><a href="{:addons_url('syslogin/index/login', ['platform' => 'wechat'])}"><i class="fa fa-wechat"></i> 微信登录</a></li>
<li><a href="{:addons_url('syslogin/index/login', ['platform' => 'weibo'])}"><i class="fa fa-weibo"></i> 微博登录</a></li>
</ul>
<div style="text-align: center; padding: 10px 0;">
<a class="btn btn-primary" href="{:addons_url('syslogin/index/login', ['platform' => 'qq'])}"><i class="fa fa-qq"></i> QQ登录</a>
<a class="btn btn-primary" href="{:addons_url('syslogin/index/login', ['platform' => 'wechat'])}"><i class="fa fa-wechat"></i> 微信登录</a>
<a class="btn btn-primary" href="{:addons_url('syslogin/index/login', ['platform' => 'weibo'])}"><i class="fa fa-weibo"></i> 微博登录</a>
</div>

View File

@@ -462,7 +462,7 @@ CREATE TABLE `sent_member` (
`reg_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '注册时间',
`last_login_ip` bigint(20) NOT NULL DEFAULT '0' COMMENT '最后登录IP',
`last_login_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '最后登录时间',
`status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '会员状态',
`status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '会员状态',
PRIMARY KEY (`uid`),
KEY `status` (`status`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='会员表';