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.
41 lines
1.3 KiB
41 lines
1.3 KiB
3 years ago
|
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
|
||
|
{
|
||
3 years ago
|
public class YunDingFilter : ActionFilterAttribute
|
||
3 years ago
|
{
|
||
|
private IConfiguration configuration;
|
||
|
private YunDingBusiness yunDingBusiness;
|
||
|
|
||
|
|
||
3 years ago
|
public YunDingFilter(IConfiguration configuration, YunDingBusiness yunDingBusiness)
|
||
3 years ago
|
{
|
||
|
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))
|
||
3 years ago
|
throw new BusinessException("身份验证失败");
|
||
3 years ago
|
|
||
|
if (yunDingBusiness.GetKey() != yundingKey.ToString())
|
||
3 years ago
|
throw new BusinessException("身份验证失败");
|
||
3 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|