fix: 修改微信用户和验证码登录,改为永不因不活跃过期,token时间1年有效。
This commit is contained in:
@@ -71,12 +71,16 @@ public class SmsAuthStrategy implements IAuthStrategy {
|
||||
});
|
||||
loginUser.setClientKey(client.getClientKey());
|
||||
loginUser.setDeviceType(client.getDeviceType());
|
||||
|
||||
// 短信登录用户:token 有效期1年,允许多设备同时在线(与微信小程序一致)
|
||||
// - timeout: 1年 = 31536000秒
|
||||
// - activeTimeout: -1 表示永不因不活跃而过期
|
||||
// - isConcurrent: true 允许多设备同时在线
|
||||
SaLoginParameter model = new SaLoginParameter();
|
||||
model.setDeviceType(client.getDeviceType());
|
||||
// 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置
|
||||
// 例如: 后台用户30分钟过期 app用户1天过期
|
||||
model.setTimeout(client.getTimeout());
|
||||
model.setActiveTimeout(client.getActiveTimeout());
|
||||
model.setTimeout(31536000L); // 1年 = 365天 * 24小时 * 60分钟 * 60秒
|
||||
model.setActiveTimeout(-1); // 永不因不活跃过期
|
||||
model.setIsConcurrent(true); // 允许多设备同时在线
|
||||
model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
|
||||
// 生成token
|
||||
LoginHelper.login(loginUser, model);
|
||||
|
||||
@@ -93,30 +93,23 @@ public class WechatAuthStrategy implements IAuthStrategy {
|
||||
loginUser.setDeviceType(client.getDeviceType());
|
||||
|
||||
// 4. 配置登录参数
|
||||
// 微信小程序用户:设置更长的 token 有效期,避免频繁过期重新登录
|
||||
// - timeout: token 绝对有效期(默认30天)
|
||||
// - activeTimeout: 活跃超时时间(默认7天),用户7天不活跃才过期
|
||||
// 优先使用 client 配置的值,如果配置不合理(太短)则使用默认的长效配置
|
||||
// 微信小程序用户:token 有效期1年,允许多设备同时在线
|
||||
// - timeout: 1年 = 31536000秒
|
||||
// - activeTimeout: -1 表示永不因不活跃而过期(用户1年内随时可用)
|
||||
// - isConcurrent: true 允许多设备同时在线
|
||||
SaLoginParameter model = new SaLoginParameter();
|
||||
model.setDeviceType(client.getDeviceType());
|
||||
// 微信小程序默认配置:绝对有效期30天(2592000秒),活跃超时7天(604800秒)
|
||||
long defaultTimeout = 2592000L; // 30天
|
||||
long defaultActiveTimeout = 604800L; // 7天
|
||||
// 如果 client 配置的超时时间太短(小于1天),使用默认的长效配置
|
||||
Long timeout = client.getTimeout();
|
||||
Long activeTimeout = client.getActiveTimeout();
|
||||
if (timeout == null || timeout < 86400) { // 小于1天(86400秒)
|
||||
timeout = defaultTimeout;
|
||||
}
|
||||
if (activeTimeout == null || activeTimeout < 86400) { // 小于1天
|
||||
activeTimeout = defaultActiveTimeout;
|
||||
}
|
||||
model.setTimeout(timeout);
|
||||
model.setActiveTimeout(activeTimeout);
|
||||
// 微信小程序:token有效期1年,永不因不活跃过期
|
||||
model.setTimeout(31536000L); // 1年 = 365天 * 24小时 * 60分钟 * 60秒
|
||||
model.setActiveTimeout(-1); // 永不因不活跃过期
|
||||
// isConcurrent: 是否允许同一账号多地同时登录
|
||||
// true = 允许多设备同时在线(手机+平板)
|
||||
// false = 同一设备类型只能一个在线,新登录踢掉旧的(换手机场景)
|
||||
model.setIsConcurrent(true); // 允许多设备同时在线
|
||||
model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
|
||||
|
||||
log.info("微信登录token配置: clientId={}, timeout={}秒({}天), activeTimeout={}秒({}天)",
|
||||
client.getClientId(), timeout, timeout / 86400, activeTimeout, activeTimeout / 86400);
|
||||
log.info("微信登录token配置: clientId={}, timeout=1年, activeTimeout=永不过期, isConcurrent={}",
|
||||
client.getClientId(), true);
|
||||
|
||||
// 5. 执行登录,生成 token
|
||||
LoginHelper.login(loginUser, model);
|
||||
|
||||
Reference in New Issue
Block a user