private ReJson ValiSignature(HttpContext context) { var Request = context.Request; var queryStrings = Request.Query; List <string> keys = new List <string>(); //string[] keys = HttpContext.Current.Request.QueryString.AllKeys; if (queryStrings == null) { throw new Exception("queryStrings Is Null"); } foreach (var item in queryStrings.Keys) { keys.Add(item); } SortedDictionary <string, string> pars = new SortedDictionary <string, string>(); string signature = ""; foreach (var k in keys) { if (k != "signature") { string v = Request.Query[k]; pars.Add(k, v); } else { signature = Request.Query[k]; } } //没有签名返回错误 if (string.IsNullOrEmpty(signature)) { throw new Exception("signature Is Null"); } if (!MySign.CheckSign(pars, signature)) { return(new ReJson(40004, "signature 错误!")); } //判断是否超时 string timeStamp = pars["timeStamp"]; //判断时间有效性 DateTime postTime = Utils.StampToDateTime(timeStamp); if (postTime < DateTime.Now.AddSeconds(-120))//30秒有效期 { return(new ReJson(40004, "signature 错误!", 1)); } return(null); }
public bool CheckSignature(SortedDictionary <string, string> pars, string signature) { if (!MySign.CheckSign(pars, signature)) { reJson.code = 40004; reJson.message = "signature 错误!"; return(false); } //判断是否超时 string timeStamp = pars["timeStamp"]; //判断时间有效性 DateTime postTime = Utils.StampToDateTime(timeStamp); if (postTime < DateTime.UtcNow.AddSeconds(-120))//30秒有效期 { reJson.code = 40004; reJson.message = "数据请求超时!"; reJson.isReload = 1; return(false); } return(true); }
private ReJson ValiSignature(HttpContext context) { var Request = context.Request; SortedDictionary <string, string> pars = new SortedDictionary <string, string>(); string signature = ""; string method = Request.Method.ToUpper(); if (method == "GET") { var queryStrings = Request.Query; List <string> keys = new List <string>(); //string[] keys = HttpContext.Current.Request.QueryString.AllKeys; if (queryStrings == null) { return(new ReJson(40000, "参数错误!")); } foreach (var item in queryStrings.Keys) { keys.Add(item); } foreach (var k in keys) { if (k != "signature") { string v = Request.Query[k]; pars.Add(k, v); } else { signature = Request.Query[k]; } } } else if (method == "POST") { var stream = context.Request.Form; foreach (var item in stream) { if (item.Key != "signature") { pars.Add(item.Key, item.Value); } else { signature = item.Value; } } } else { return(new ReJson(50000, "不支持的HTTP方法!")); } //没有签名返回错误 if (string.IsNullOrEmpty(signature)) { return(new ReJson(40004, "signature 为空!")); } if (!MySign.CheckSign(pars, signature)) { return(new ReJson(40004, "signature 错误!")); } //判断是否超时 string timeStamp = pars["timeStamp"]; //判断时间有效性 DateTime postTime = Utils.StampToDateTime(timeStamp); if (postTime < DateTime.UtcNow.AddSeconds(-120))//30秒有效期 { return(new ReJson(40004, "signature 错误!", 1)); } return(null); }