zoukankan      html  css  js  c++  java
  • 根据时间戳及密钥判断当前token值是否有效

    需要的方法:

    /// <summary>
    /// 将c# DateTime时间格式转换为Unix时间戳格式
    /// </summary>
    /// <param name="time">时间</param>
    /// <returns>double</returns>
    public static double ConvertDateTimeToTimeStamp()
    {
    double intResult = 0;
    DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
    intResult = (DateTime.Now - startTime).TotalSeconds;
    return intResult;
    }

    /// <summary>
    /// 毫秒时间戳
    /// </summary>
    /// <returns></returns>
    public static double TimeSpanByTotalMilliseconds()
    {
    return (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000;
    }

    传入参数 :{"TimeStampRange":"时间戳","sign":"签名"}  协商的固定参数:SignKey:密钥

    string plan=thirdLogin.Unionid + thirdLogin.TimeStampRange.ToString() + SignKey;

    if (EncrypHelper.GetMD5(plan) != thirdLogin.Sign || (Math.Abs(TimeHelper.TimeSpanByTotalMilliseconds() - thirdLogin.TimeStampRange) > 300000)){}

    1.将用户标识列,时间戳和密钥拼接的字段进行MD5加密,判断传入的sign是否正确

    2.判断传入的时间戳是否超过了10分钟,精确到毫秒。

    注释:Math.Abs获取其绝对值

  • 相关阅读:
    C++防止头文件反复包括
    yppasswd, ypchfn, ypchsh
    yes
    Yacc
    xxd
    xpdf -Portable Document Format(PDF)文件阅读器
    xinetd
    xargs
    x25, PF_X25
    write -在一个文件描述符上执行写操作
  • 原文地址:https://www.cnblogs.com/BounceGuo/p/9603610.html
Copyright © 2011-2022 走看看