Skip to content

Commit

Permalink
修复token续期不生效问题
Browse files Browse the repository at this point in the history
  • Loading branch information
elunez committed Jan 2, 2024
1 parent 2a87911 commit 3b6b514
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,15 @@ public Claims getClaims(String token) {
*/
public void checkRenewal(String token) {
// 判断是否续期token,计算token的过期时间
long time = redisUtils.getExpire(properties.getOnlineKey() + token) * 1000;
String loginKey = loginKey(token);
long time = redisUtils.getExpire(loginKey) * 1000;
Date expireDate = DateUtil.offset(new Date(), DateField.MILLISECOND, (int) time);
// 判断当前时间与过期时间的时间差
long differ = expireDate.getTime() - System.currentTimeMillis();
// 如果在续期检查的范围内,则续期
if (differ <= properties.getDetect()) {
long renew = time + properties.getRenew();
redisUtils.expire(properties.getOnlineKey() + token, renew, TimeUnit.MILLISECONDS);
redisUtils.expire(loginKey, renew, TimeUnit.MILLISECONDS);
}
}

Expand Down

0 comments on commit 3b6b514

Please sign in to comment.