mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-13 21:53:41 +08:00
fix:
登录校验bug修复 多客户端登录,返回相同的token
This commit is contained in:
@@ -67,16 +67,24 @@ public class LoginServiceImpl implements LoginService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String login(Long uid) {
|
public String login(Long uid) {
|
||||||
//获取用户token
|
|
||||||
String token = jwtUtils.createToken(uid);
|
|
||||||
//存储到redis
|
|
||||||
String key = RedisKey.getKey(RedisKey.USER_TOKEN_STRING, uid);
|
String key = RedisKey.getKey(RedisKey.USER_TOKEN_STRING, uid);
|
||||||
redisUtils.set(key, token, TOKEN_EXPIRE_DAYS, TimeUnit.DAYS);//token过期用redis中心化控制,初期采用5天过期,剩1天自动续期的方案。后续可以用双token实现
|
String token = redisUtils.getStr(key);
|
||||||
|
if (StrUtil.isNotBlank(token)) {
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
//获取用户token
|
||||||
|
token = jwtUtils.createToken(uid);
|
||||||
|
RedisUtils.set(key, token, TOKEN_EXPIRE_DAYS, TimeUnit.DAYS);//token过期用redis中心化控制,初期采用5天过期,剩1天自动续期的方案。后续可以用双token实现
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getValidUid(String token) {
|
public Long getValidUid(String token) {
|
||||||
return jwtUtils.getUidOrNull(token);
|
boolean verify = verify(token);
|
||||||
|
return verify ? jwtUtils.getUidOrNull(token) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ public class NettyWebSocketServerHandler extends SimpleChannelInboundHandler<Tex
|
|||||||
// 处理异常
|
// 处理异常
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||||
log.warn("异常发生,异常消息 ={}" + cause.getMessage());
|
log.warn("异常发生,异常消息 ={}" , cause.getMessage());
|
||||||
ctx.channel().close();
|
ctx.channel().close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user