elunez/eladmin

Token续期

kefault opened this issue · 2 comments

public void checkRenewal(String token) {
    // 判断是否续期token,计算token的过期时间
    long time = redisUtils.getExpire(properties.getOnlineKey() + token) * 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);
    }
}



/**
 * 获取登录用户RedisKey
 * @param token /
 * @return key
 */
public String loginKey(String token) {
    Claims claims = getClaims(token);
    String md5Token = DigestUtil.md5Hex(token);
    return properties.getOnlineKey() + claims.getSubject() + "-" + md5Token;
}

Token续期这里涉及到的redis key是不是有问题?

我也发现了,long time返回的是-2000

elunez commented

已修复