V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
d0m2o08
V2EX  ›  程序员

带时间戳的 api,允许时间戳有误差,这个要怎么实现?

  •  
  •   d0m2o08 · Jan 11, 2021 · 1472 views
    This topic created in 1933 days ago, the information mentioned may be changed or developed.
    请教各位 v2 的吴彦祖

    假设请求的参数是

    xxx.xx/api?cmd=aa&timestamp=时间戳&sign=签名

    服务端允许时间戳误差 30 秒,时间戳这块应该怎么校验呢
    SingeeKing
        1
    SingeeKing  
    PRO
       Jan 11, 2021   ❤️ 1
    now := time.Now().Unix()

    if timestamp < now - 30 || timestamp > now+5 {
    return nil, err
    }
    d0m2o08
        2
    d0m2o08  
    OP
       Jan 11, 2021
    @SingeeKing 原来是先校验时间戳是否合法,再校验签名,多谢吴彦祖😁😁
    huobazi
        3
    huobazi  
       Jan 11, 2021
    楼主都自己都描述的很清楚了,把汉字翻译成代码就可以了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5604 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 07:09 · PVG 15:09 · LAX 00:09 · JFK 03:09
    ♥ Do have faith in what you're doing.