You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.3 KiB
40 lines
1.3 KiB
using BBWY.Common.Models;
|
|
using BBWY.Server.Business;
|
|
using BBWY.Server.Model;
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Primitives;
|
|
|
|
namespace JD.API.Filters
|
|
{
|
|
public class YunDingFilterAttribute : ActionFilterAttribute
|
|
{
|
|
private IConfiguration configuration;
|
|
private YunDingBusiness yunDingBusiness;
|
|
|
|
|
|
public YunDingFilterAttribute(IConfiguration configuration, YunDingBusiness yunDingBusiness)
|
|
{
|
|
this.configuration = configuration;
|
|
this.yunDingBusiness = yunDingBusiness;
|
|
}
|
|
|
|
public override void OnActionExecuted(ActionExecutedContext context)
|
|
{
|
|
|
|
}
|
|
|
|
public override void OnActionExecuting(ActionExecutingContext context)
|
|
{
|
|
var platform = (Enums.Platform)int.Parse(configuration.GetSection("ValidatePlatformKey").Value);
|
|
if (platform == Enums.Platform.京东)
|
|
{
|
|
if (!context.HttpContext.Request.Headers.TryGetValue("YunDingKey", out StringValues yundingKey))
|
|
throw new BusinessException("YunDingKey获取失败");
|
|
|
|
if (yunDingBusiness.GetKey() != yundingKey.ToString())
|
|
throw new BusinessException("YunDingKey验证失败");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|