更新api

This commit is contained in:
2018-12-03 16:16:18 +08:00
parent 3d4d9f2d3c
commit 9c1cce3505
6 changed files with 73 additions and 31 deletions
@@ -30,7 +30,7 @@ namespace COMCMS.Web.Controllers.api
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
[CheckFilter] [CheckFilter]
public object GetArticleList(int kid, int pagesize = 10, int page = 1, string random = "", string timeStamp = "", string signature = "") public object GetArticleList(int kid, int pagesize = 10, int page = 1)
{ {
var where = Article._.IsHide != 1; var where = Article._.IsHide != 1;
if (kid > 0) if (kid > 0)
@@ -83,7 +83,7 @@ namespace COMCMS.Web.Controllers.api
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
[CheckFilter] [CheckFilter]
public object GetArticleListWidthSub(int kid, int pagesize = 10, int page = 1, string key = "", string random = "", string timeStamp = "", string signature = "") public object GetArticleListWidthSub(int kid, int pagesize = 10, int page = 1, string key = "")
{ {
var where = Article._.IsHide != 1; var where = Article._.IsHide != 1;
@@ -154,7 +154,7 @@ namespace COMCMS.Web.Controllers.api
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
[CheckFilter] [CheckFilter]
public object GetArticleDetail(int id, string random = "", string timeStamp = "", string signature = "") public object GetArticleDetail(int id)
{ {
//获取商品 //获取商品
Article entity = Article.FindById(id); Article entity = Article.FindById(id);
@@ -173,7 +173,7 @@ namespace COMCMS.Web.Controllers.api
#region 获取文章栏目详情,并带下一级栏目 #region 获取文章栏目详情,并带下一级栏目
[HttpGet] [HttpGet]
[CheckFilter] [CheckFilter]
public object GetArticleCategory(int id, string random = "", string timeStamp = "", string signature = "") public object GetArticleCategory(int id)
{ {
ArticleCategory entity = ArticleCategory.FindById(id); ArticleCategory entity = ArticleCategory.FindById(id);
if (entity == null) if (entity == null)
+11 -1
View File
@@ -20,6 +20,7 @@ namespace COMCMS.Web.Controllers.api
{ {
// GET: api/<controller> // GET: api/<controller>
[HttpGet] [HttpGet]
[CheckFilter]
public object Get() public object Get()
{ {
Config cfg = Config.GetSystemConfig(); Config cfg = Config.GetSystemConfig();
@@ -37,10 +38,19 @@ namespace COMCMS.Web.Controllers.api
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
[CheckFilter] [CheckFilter]
public ReJson CheckSign(string id, string random = "", string timeStamp = "", string signature = "") public ReJson CheckSign(string id)
{ {
return new ReJson("验签成功!"); return new ReJson("验签成功!");
} }
//POST验证
[HttpPost]
[CheckFilter]
public ReJson ChekSignWidhPost(int id)
{
return new ReJson("验证通过!");
}
#endregion #endregion
//#region 测试出错 //#region 测试出错
@@ -22,7 +22,7 @@ namespace COMCMS.Web.Controllers.api
#region 微信小程序订单支付 #region 微信小程序订单支付
[HttpGet] [HttpGet]
[CheckFilter] [CheckFilter]
public ReJson DoPayOrder(string ordernum, string random = "", string timeStamp = "", string signature = "") public ReJson DoPayOrder(string ordernum)
{ {
//获取订单 //获取订单
Order entity = Order.Find(Order._.OrderNum == ordernum); Order entity = Order.Find(Order._.OrderNum == ordernum);
@@ -34,7 +34,7 @@ namespace COMCMS.Web.Controllers.api
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
[CheckFilter] [CheckFilter]
public object GetCategories(int level, int pid = 0, string random = "", string timeStamp = "", string signature = "") public object GetCategories(int level, int pid = 0)
{ {
var list = Category.GetListTree(pid, level, false, false); var list = Category.GetListTree(pid, level, false, false);
@@ -74,7 +74,7 @@ namespace COMCMS.Web.Controllers.api
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
[CheckFilter] [CheckFilter]
public object GetProductList(int kid, int page, int pageSize = 10, string random = "", string timeStamp = "", string signature = "") public object GetProductList(int kid, int page, int pageSize = 10)
{ {
var where = Product._.IsHide == 0; var where = Product._.IsHide == 0;
if (kid > 0) if (kid > 0)
+2 -2
View File
@@ -31,7 +31,7 @@ namespace COMCMS.Web.Controllers.api
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
[CheckFilter] [CheckFilter]
public ReJson UserLogin(string code, string random = "", string timeStamp = "", string signature = "") public ReJson UserLogin(string code)
{ {
if (string.IsNullOrEmpty(code)) if (string.IsNullOrEmpty(code))
{ {
@@ -141,7 +141,7 @@ namespace COMCMS.Web.Controllers.api
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
public ReJson SyncWeixinInfo(string sessionkey, string userInfo, int inviteid = 0, string random = "", string timeStamp = "", string signature = "") public ReJson SyncWeixinInfo(string sessionkey, string userInfo, int inviteid = 0)
{ {
if (string.IsNullOrEmpty(sessionkey)) if (string.IsNullOrEmpty(sessionkey))
{ {
+39 -7
View File
@@ -9,8 +9,6 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Filters;
namespace COMCMS.Web.Filter namespace COMCMS.Web.Filter
{ {
public class CheckFilterAttribute : ActionFilterAttribute 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); var notVali = ValiSignature(context.HttpContext);
@@ -49,23 +53,26 @@ namespace COMCMS.Web.Filter
} }
} }
#region 详细验证
private ReJson ValiSignature(HttpContext context) private ReJson ValiSignature(HttpContext context)
{ {
var Request = context.Request; 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; var queryStrings = Request.Query;
List<string> keys = new List<string>(); List<string> keys = new List<string>();
//string[] keys = HttpContext.Current.Request.QueryString.AllKeys; //string[] keys = HttpContext.Current.Request.QueryString.AllKeys;
if (queryStrings == null) if (queryStrings == null)
{ {
throw new Exception("queryStrings Is Null"); return new ReJson(40000, "参数错误!");
} }
foreach (var item in queryStrings.Keys) foreach (var item in queryStrings.Keys)
{ {
keys.Add(item); keys.Add(item);
} }
SortedDictionary<string, string> pars = new SortedDictionary<string, string>();
string signature = "";
foreach (var k in keys) foreach (var k in keys)
{ {
if (k != "signature") if (k != "signature")
@@ -78,6 +85,28 @@ namespace COMCMS.Web.Filter
signature = Request.Query[k]; 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)) if (string.IsNullOrEmpty(signature))
return new ReJson(40004, "signature 为空!"); return new ReJson(40004, "signature 为空!");
@@ -98,5 +127,8 @@ namespace COMCMS.Web.Filter
return null; return null;
} }
#endregion
} }
} }