You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

激活URL服务器端有效期计算异常排查求助

激活URL过期时间计算不一致问题排查

问题现象

邮件激活URL设置为90天过期,本地测试计算结果正确(对应时间戳1695364328794的过期时间为2023年12月21日),但部署到服务器后,用户在2023年9月22日(GMT+10:00)点击URL时,系统显示过期时间为2023年9月24日,仅2天就失效。服务器部署的代码与本地测试代码完全一致。

服务器日志

Plain Text Output=webChannel=GMD_XXX;fundIdentifier=XXXX;email=XXX-X.XXX@XX.com;userName=Linkexpire.Xie;timestamp=1695364328794;
Data fom encryptedToken --> fundIdentifier:XXXX -- userName:Linkexpire.Xie -- webChannel:GMD_XXX -- timeStamp:**1695364328794** -- email:XX-XX.XX@XX.com
The UID is : XXXX
userName to be searched is Linkexpire.Xie and fundName is van
Filter is cn=Linkexpire.Xie
isValidToken-->true
eclaimsAccountStatusENABLED
Inside IN-ACTIVE
The Activation URL will expire on 24/09/23

本地测试代码

package com;

import java.util.Calendar;
import java.util.Date;
import java.text.SimpleDateFormat;

public class TestApplication {
    
    public static void main(String[] args) {

      String timestamp = "1695364328794"; //Friday, September 22, 2023 4:32:08.794 PM

      validateActivationURLExpiry(timestamp);
    }

    public static void validateActivationURLExpiry(String timestamp)  {
        long timestampValue = Long.parseLong(timestamp);
        System.out.println("timestampValue:" + timestampValue);
        Date now = new Date();
        String expiryInDays = "90";
        int expiryInDay = Integer.parseInt(expiryInDays);

        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(timestampValue);
        calendar.add(Calendar.DAY_OF_YEAR, expiryInDay);
        long timestampValueAfter90Days = calendar.getTime().getTime();
        System.out.println("timestampValueAfter90Days:" + timestampValueAfter90Days);       

        // 输出URL过期日期
        Date date = new Date(timestampValueAfter90Days);
        SimpleDateFormat df2 = new SimpleDateFormat("dd/MM/yy");
        String dateText = df2.format(date);
        System.out.println("The Activation URL will expire on " + dateText);

        if (now.getTime() > timestampValueAfter90Days) {
            System.out.println("URL has expired already ");
            //throw new UserManagementException(new Exception("URL has expired already "));
        }
    }   
}

本地测试结果

timestampValue:1695364328794
timestampValueAfter90Days:1703136728794
The Activation URL will expire on 21/12/23

排查建议

  • 检查服务器时区与过期天数配置
    优先确认服务器系统时区是否和本地一致,Calendar.getInstance()默认使用系统时区,时区偏差会导致日期计算错误。同时检查服务器上的配置文件(若过期天数不是硬编码),确认expiryInDays是否被正确设置为90,若误设为2会直接导致2天过期。

  • 核对服务器部署的代码版本
    排除部署失误导致的代码版本不一致,重新检查服务器端代码中calendar.add(Calendar.DAY_OF_YEAR, expiryInDay)这一行,确认使用的是DAY_OF_YEAR而非其他字段(如DAY_OF_MONTH),且expiryInDay的取值逻辑正确。

  • 验证时间戳生成与解析环节
    确认激活URL生成时的时间戳是否正确,服务器解析Token时是否准确还原了时间戳。虽然日志显示时间戳与本地一致,但仍需排查生成环节是否存在时间单位错误(如把秒级时间戳当成毫秒级处理)。

内容的提问来源于stack exchange,提问作者Redwood Thomas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 08:35:14