Compare commits
No commits in common. "8cd8b7cf4301db9e5273e18d439ebd87c4f42101" and "826aff3d3619e065a6c8cadbed178d6affd2bc40" have entirely different histories.
8cd8b7cf43
...
826aff3d36
|
|
@ -8,7 +8,6 @@ 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;
|
||||||
|
|
@ -18,7 +17,6 @@ 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;
|
||||||
|
|
@ -37,7 +35,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, IConfiguration _config) : ExceptionFilterAttribute, IAsyncActionFilter
|
public class RequestDuplicationFilter(ILogger<RequestDuplicationFilter> logger, IHttpContextAccessor accessor, IUserInfo _userInfo, IStringLocalizer _localizer, IOptionsMonitor<RequestDuplicationOptions> RequestDuplicationOptionsMonitor) : ExceptionFilterAttribute, IAsyncActionFilter
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 传入的参数
|
/// 传入的参数
|
||||||
|
|
@ -120,51 +118,11 @@ 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