解决新装后插入用户无法登陆的问题
This commit is contained in:
@@ -15,9 +15,9 @@ class Application {
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $providers = [
|
private $providers = [
|
||||||
'qq' => 'Qq',
|
'qq' => 'Qq',
|
||||||
'weibo' => 'Weibo',
|
'weibo' => 'Weibo',
|
||||||
'wechat' => 'Wechat',
|
'wechat' => 'Wechat',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,15 +26,14 @@ class Application {
|
|||||||
*/
|
*/
|
||||||
protected $services = [];
|
protected $services = [];
|
||||||
|
|
||||||
public function __construct($options = [])
|
public function __construct($options = []) {
|
||||||
{
|
|
||||||
$options = array_intersect_key($options, $this->providers);
|
$options = array_intersect_key($options, $this->providers);
|
||||||
$options = array_merge($this->config, is_array($options) ? $options : []);
|
$options = array_merge($this->config, is_array($options) ? $options : []);
|
||||||
foreach ($options as $key => &$option) {
|
foreach ($options as $key => &$option) {
|
||||||
$option['app_id'] = isset($option['app_id']) ? $option['app_id'] : '';
|
$option['app_id'] = isset($option['app_id']) ? $option['app_id'] : '';
|
||||||
$option['app_secret'] = isset($option['app_secret']) ? $option['app_secret'] : '';
|
$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;
|
$this->config = $options;
|
||||||
//注册服务器提供者
|
//注册服务器提供者
|
||||||
@@ -44,8 +43,7 @@ class Application {
|
|||||||
/**
|
/**
|
||||||
* 注册服务提供者
|
* 注册服务提供者
|
||||||
*/
|
*/
|
||||||
private function registerProviders()
|
private function registerProviders() {
|
||||||
{
|
|
||||||
foreach ($this->providers as $k => $v) {
|
foreach ($this->providers as $k => $v) {
|
||||||
$this->services[$k] = function () use ($k, $v) {
|
$this->services[$k] = function () use ($k, $v) {
|
||||||
$options = $this->config[$k];
|
$options = $this->config[$k];
|
||||||
@@ -55,13 +53,11 @@ class Application {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __set($key, $value)
|
public function __set($key, $value) {
|
||||||
{
|
|
||||||
$this->services[$key] = $value;
|
$this->services[$key] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __get($key)
|
public function __get($key) {
|
||||||
{
|
|
||||||
return isset($this->services[$key]) ? $this->services[$key]($this) : null;
|
return isset($this->services[$key]) ? $this->services[$key]($this) : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,8 @@ class Qq {
|
|||||||
"oauth_consumer_key" => $this->config['app_id'],
|
"oauth_consumer_key" => $this->config['app_id'],
|
||||||
"openid" => $openid,
|
"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);
|
$userinfo = (array) json_decode($ret, true);
|
||||||
if (!$userinfo || !isset($userinfo['ret']) || $userinfo['ret'] !== 0) {
|
if (!$userinfo || !isset($userinfo['ret']) || $userinfo['ret'] !== 0) {
|
||||||
return [];
|
return [];
|
||||||
@@ -108,7 +109,8 @@ class Qq {
|
|||||||
"redirect_uri" => $this->config['callback'],
|
"redirect_uri" => $this->config['callback'],
|
||||||
"code" => $code,
|
"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 = [];
|
$params = [];
|
||||||
parse_str($ret, $params);
|
parse_str($ret, $params);
|
||||||
return $params ? $params : [];
|
return $params ? $params : [];
|
||||||
@@ -120,7 +122,8 @@ class Qq {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function getOpenId($access_token = '') {
|
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) {
|
if (strpos($response, "callback") !== false) {
|
||||||
$lpos = strpos($response, "(");
|
$lpos = strpos($response, "(");
|
||||||
$rpos = strrpos($response, ")");
|
$rpos = strrpos($response, ")");
|
||||||
|
|||||||
@@ -70,7 +70,8 @@ class Weibo {
|
|||||||
"access_token" => $access_token,
|
"access_token" => $access_token,
|
||||||
"uid" => $uid,
|
"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);
|
$userinfo = (array) json_decode($ret, true);
|
||||||
if (!$userinfo || isset($userinfo['error_code'])) {
|
if (!$userinfo || isset($userinfo['error_code'])) {
|
||||||
return [];
|
return [];
|
||||||
@@ -107,7 +108,8 @@ class Weibo {
|
|||||||
"redirect_uri" => $this->config['callback'],
|
"redirect_uri" => $this->config['callback'],
|
||||||
"code" => $code,
|
"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);
|
$ret = (array) json_decode($response, true);
|
||||||
return $ret ? $ret : [];
|
return $ret ? $ret : [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
<style type="text/css">
|
<div style="text-align: center; padding: 10px 0;">
|
||||||
.third-login{margin: 0;}
|
<a class="btn btn-primary" href="{:addons_url('syslogin/index/login', ['platform' => 'qq'])}"><i class="fa fa-qq"></i> QQ登录</a>
|
||||||
.third-login li{list-style: none;}
|
<a class="btn btn-primary" href="{:addons_url('syslogin/index/login', ['platform' => 'wechat'])}"><i class="fa fa-wechat"></i> 微信登录</a>
|
||||||
</style>
|
<a class="btn btn-primary" href="{:addons_url('syslogin/index/login', ['platform' => 'weibo'])}"><i class="fa fa-weibo"></i> 微博登录</a>
|
||||||
<ul class="third-login">
|
</div>
|
||||||
<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>
|
|
||||||
@@ -462,7 +462,7 @@ CREATE TABLE `sent_member` (
|
|||||||
`reg_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '注册时间',
|
`reg_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '注册时间',
|
||||||
`last_login_ip` bigint(20) NOT NULL DEFAULT '0' COMMENT '最后登录IP',
|
`last_login_ip` bigint(20) NOT NULL DEFAULT '0' COMMENT '最后登录IP',
|
||||||
`last_login_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '最后登录时间',
|
`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`),
|
PRIMARY KEY (`uid`),
|
||||||
KEY `status` (`status`)
|
KEY `status` (`status`)
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='会员表';
|
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='会员表';
|
||||||
|
|||||||
Reference in New Issue
Block a user