更新api
This commit is contained in:
@@ -9,8 +9,6 @@ using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
|
||||
|
||||
|
||||
namespace COMCMS.Web.Filter
|
||||
{
|
||||
public class CheckFilterAttribute : ActionFilterAttribute
|
||||
@@ -33,7 +31,13 @@ namespace COMCMS.Web.Filter
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception(error);
|
||||
ReJson re = new ReJson(40000, error);
|
||||
context.Result = new ContentResult()
|
||||
{
|
||||
Content = re.ToJson(),
|
||||
ContentType = "application/json"
|
||||
};
|
||||
//throw new Exception(error);
|
||||
}
|
||||
|
||||
var notVali = ValiSignature(context.HttpContext);
|
||||
@@ -49,35 +53,60 @@ namespace COMCMS.Web.Filter
|
||||
}
|
||||
}
|
||||
|
||||
#region 详细验证
|
||||
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)
|
||||
string method = Request.Method.ToUpper();
|
||||
if (method == "GET")
|
||||
{
|
||||
if (k != "signature")
|
||||
var queryStrings = Request.Query;
|
||||
List<string> keys = new List<string>();
|
||||
//string[] keys = HttpContext.Current.Request.QueryString.AllKeys;
|
||||
if (queryStrings == null)
|
||||
{
|
||||
string v = Request.Query[k];
|
||||
pars.Add(k, v);
|
||||
return new ReJson(40000, "参数错误!");
|
||||
}
|
||||
else
|
||||
foreach (var item in queryStrings.Keys)
|
||||
{
|
||||
signature = Request.Query[k];
|
||||
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 为空!");
|
||||
@@ -98,5 +127,8 @@ namespace COMCMS.Web.Filter
|
||||
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user