diff --git a/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 b/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 index edcdbedc..89985642 100644 Binary files a/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 and b/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 differ diff --git a/src/WMS.Web.Api/Startup.cs b/src/WMS.Web.Api/Startup.cs index c925da8d..45f44030 100644 --- a/src/WMS.Web.Api/Startup.cs +++ b/src/WMS.Web.Api/Startup.cs @@ -82,6 +82,8 @@ namespace WMS.Web.Api //统一异常处理中间件 app.UseMiddleware(); app.UseMiddleware(); + app.UseMiddleware(); + app.UseRouting(); app.UseEndpoints(endpoints => { diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml index 76086fa6..62fc8141 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml @@ -719,6 +719,12 @@ + + + 娴嬭瘯閲嶅鎻愪氦杩囨护鍣 + + + 鍑哄簱浠诲姟鍗曟墜鍔ㄥ悓姝ラ噾铦舵暟鎹 diff --git a/src/WMS.Web.Repositories/DependencyInjection/PlatformActionMiddleware.cs b/src/WMS.Web.Repositories/DependencyInjection/PlatformActionMiddleware.cs new file mode 100644 index 00000000..d7652bbf --- /dev/null +++ b/src/WMS.Web.Repositories/DependencyInjection/PlatformActionMiddleware.cs @@ -0,0 +1,85 @@ +锘縰sing Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.Extensions.Caching.Memory; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Net; +using System.Text; +using WMS.Web.Core.Internal.Results; +using WMS.Web.Domain.Services.Public; +using Microsoft.AspNetCore.Http; +using Newtonsoft.Json; +using System.IO; +using System.Threading.Tasks; + +namespace WMS.Web.Repositories.DependencyInjection +{ + /// + /// 闃查噸澶嶆彁浜 + /// + public class PlatformActionMiddleware + { + private readonly RequestDelegate next; + private readonly ILogger _logger; + private readonly RedisClientService _redisClientService; + /// + /// 缁熶竴閿欒澶勭悊涓棿浠 + /// + public PlatformActionMiddleware(RequestDelegate next, ILogger logger, RedisClientService redisClientService) + { + this.next = next; + _logger = logger; + _redisClientService = redisClientService; + } + private string bodyStr = ""; + + /// + /// 婵娲 + /// + /// + /// + public async Task Invoke(HttpContext context) + { + //榛樿 璇锋眰body鍙兘璇诲彇涓娆 鎵浠ュ湪杩欓噷闇瑕佹墜鍔ㄦ妸浠栬缃垚璇诲彇澶氭 骞朵笖 涓嶈兘浣跨敤using 閲婃斁 + context.Request.EnableBuffering(); + StreamReader requestReader = new StreamReader(context.Request.Body, Encoding.UTF8); + bodyStr = await requestReader.ReadToEndAsync(); + context.Request.Body.Seek(0, SeekOrigin.Begin); + + string httpMethod = WebUtility.HtmlEncode(context.Request.Method); + if (httpMethod == "POST") + { + //浣跨敤璇锋眰璺緞浣滀负鍞竴key + string path = context.Request.Path; + string authorization = context.Request.Headers["Authorization"]; + string cacheToken = $"{authorization}_{path}"; + string keyValue = string.IsNullOrEmpty(bodyStr) ? "yc" : bodyStr; + + if (path != null) + { + //var cache = iZen.Utils.Core.iCache.CacheManager.GetCacheValue(cacheToken); + string cv = _redisClientService.GetStringKey(cacheToken); + if (cv == null && bodyStr != cv) + { + //iZen.Utils.Core.iCache.CacheManager.SetChacheValueSeconds(cacheToken, keyValue, 1); + //璁剧疆缂撳瓨10绉掕繃鏈 + _redisClientService.SetStringKey(cacheToken, keyValue, TimeSpan.FromSeconds(10)); + + } + else + { + context.Response.StatusCode = 401; + var result = JsonConvert.SerializeObject(new { status = 4012343, data = string.Empty, message = "閲嶅鎻愪氦" }); + context.Response.ContentType = "application/json;charset=utf-8"; + await context.Response.WriteAsync(result); + return; + } + + } + } + await next(context); + + } + } +}