Exemple #1
0
        public Boolean ProcessRequest(string Method, string UserId, string Time, string skey)
        {
            APIResult obj    = new APIResult();
            string    method = Method;
            string    userId = UserId;
            string    IP     = GetClientIp();
            Pro       p      = new Pro();
            Boolean   b      = false;

            if (method == "get")
            {
                p            = General(IP, 0, userId);
                Session["i"] = p.i;
                Session["s"] = p.s;
                Session["t"] = p.t;
                b            = true;
            }
            if (method == "check")
            {
                string time = Time;
                string key  = skey;
                b = CheckKey(IP, General(IP, Convert.ToInt32(time), userId));
            }
            return(b);
        }
Exemple #2
0
        /// <summary>
        /// 检查密钥是否能用
        /// </summary>
        /// <returns></returns>
        public Boolean CheckKey(string IP, Pro p)
        {
            if (string.IsNullOrEmpty(IP))
            {
                IP = GetClientIp();
            }
            Pro newp = General(IP, Convert.ToInt32(p.t), p.i);

            if (p.s == newp.s)
            {
                int hh = Math.Abs(ConvertDateTimeInt(DateTime.Now) - (Convert.ToInt32(p.t) - obv));
                if (Math.Abs(ConvertDateTimeInt(DateTime.Now) - (Convert.ToInt32(p.t) - obv)) <= ev)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #3
0
        /// <summary>
        /// 生成密钥
        /// </summary>
        /// <param name="IP"></param>
        /// <param name="timestamp"></param>
        /// <param name="Id"></param>
        /// <returns></returns>
        public Pro General(string IP, int timestamp, string Id)
        {
            if (string.IsNullOrEmpty(Id))
            {
                return(null);
            }
            if (timestamp == 0)
            {
                timestamp = ConvertDateTimeInt(DateTime.Now) + obv;
            }
            if (string.IsNullOrEmpty(IP))
            {
                IP = GetClientIp();
            }
            string str = "|" + Id + "," + keys + "-" + IP + "]" + timestamp;
            Pro    p   = new Pro();

            p.i = Id;
            p.s = GetMD5(str);
            p.t = timestamp.ToString();
            return(p);
        }