添加重复请求通知
parent
718294f776
commit
1d90aba7cd
|
|
@ -8,6 +8,7 @@ namespace IRaCIS.Core.Application.BusinessFilter.LegacyController
|
||||||
{
|
{
|
||||||
using Database.Api;
|
using Database.Api;
|
||||||
using DocumentFormat.OpenXml.InkML;
|
using DocumentFormat.OpenXml.InkML;
|
||||||
|
using IRaCIS.Core.Application.Helper.OtherTool;
|
||||||
using IRaCIS.Core.Application.Service.Common;
|
using IRaCIS.Core.Application.Service.Common;
|
||||||
using IRaCIS.Core.Infrastructure;
|
using IRaCIS.Core.Infrastructure;
|
||||||
using IRaCIS.Core.Infrastructure.Extention;
|
using IRaCIS.Core.Infrastructure.Extention;
|
||||||
|
|
@ -17,6 +18,7 @@ namespace IRaCIS.Core.Application.BusinessFilter.LegacyController
|
||||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
@ -35,7 +37,7 @@ namespace IRaCIS.Core.Application.BusinessFilter.LegacyController
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="logger">logger</param>
|
/// <param name="logger">logger</param>
|
||||||
/// <param name="accessor">loggerHelper</param>
|
/// <param name="accessor">loggerHelper</param>
|
||||||
public class RequestDuplicationFilter(ILogger<RequestDuplicationFilter> logger, IHttpContextAccessor accessor, IUserInfo _userInfo, IStringLocalizer _localizer, IOptionsMonitor<RequestDuplicationOptions> RequestDuplicationOptionsMonitor) : ExceptionFilterAttribute, IAsyncActionFilter
|
public class RequestDuplicationFilter(ILogger<RequestDuplicationFilter> logger, IHttpContextAccessor accessor, IUserInfo _userInfo, IStringLocalizer _localizer, IOptionsMonitor<RequestDuplicationOptions> RequestDuplicationOptionsMonitor, IConfiguration _config) : ExceptionFilterAttribute, IAsyncActionFilter
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 传入的参数
|
/// 传入的参数
|
||||||
|
|
@ -118,11 +120,51 @@ namespace IRaCIS.Core.Application.BusinessFilter.LegacyController
|
||||||
RequestDuplicationOptionsMonitor.CurrentValue.DuplicationWindowMs);
|
RequestDuplicationOptionsMonitor.CurrentValue.DuplicationWindowMs);
|
||||||
if (!isAdded)
|
if (!isAdded)
|
||||||
{
|
{
|
||||||
|
SendRequestDuplicationWeComNotice(requestPath);
|
||||||
|
logger.LogError($"重复请求出现错误:{this.Intoparam}");
|
||||||
throw new BusinessValidationFailedException(_localizer["RequestDuplicationFilter_RequestDuplication"], ApiResponseCodeEnum.BusinessValidationFailed);
|
throw new BusinessValidationFailedException(_localizer["RequestDuplicationFilter_RequestDuplication"], ApiResponseCodeEnum.BusinessValidationFailed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SendRequestDuplicationWeComNotice(string requestPath)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bool isOpenWeComNotice = _config.GetValue<bool>("WeComNoticeConfig:IsOpenWeComNotice");
|
||||||
|
|
||||||
|
if (isOpenWeComNotice)
|
||||||
|
{
|
||||||
|
string webhook = _config["WeComNoticeConfig:WebhookUrl"] ?? string.Empty;
|
||||||
|
|
||||||
|
var uri = new Uri(_config["SystemEmailSendConfig:SiteUrl"]);
|
||||||
|
var baseUrl = uri.GetLeftPart(UriPartial.Authority);
|
||||||
|
|
||||||
|
var userList = _config.GetSection("WeComNoticeConfig:APINoticeUserList").Get<string[]>();
|
||||||
|
|
||||||
|
var request = accessor?.HttpContext?.Request;
|
||||||
|
|
||||||
|
_ = WeComNotifier.SendAlertAsync(
|
||||||
|
webhook: webhook,
|
||||||
|
alert: new WeComAlert
|
||||||
|
{
|
||||||
|
Env = baseUrl,
|
||||||
|
UserName = _userInfo.UserName.IsNotNullOrEmpty() ? $"{_userInfo.UserName}({_userInfo.UserTypeShortName})" : "匿名",
|
||||||
|
Api = $"{request?.Method} {requestPath}",
|
||||||
|
Message = "重复请求拦截",
|
||||||
|
JsonData = this.Intoparam,
|
||||||
|
Stack = string.Empty,
|
||||||
|
AtUsers = userList ?? []
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.LogError($"重复请求过滤器里发送企业微信出现错误:{ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string GenerateParameterHash(string parameters)
|
public string GenerateParameterHash(string parameters)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(parameters))
|
if (string.IsNullOrEmpty(parameters))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue