From 6763c23b7edb44758613256273c184f6855f1f06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Sat, 4 Jun 2022 15:28:09 +0800 Subject: [PATCH 1/4] update appsettings.json --- ZR.Admin.WebApi/appsettings.json | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/ZR.Admin.WebApi/appsettings.json b/ZR.Admin.WebApi/appsettings.json index 20fecc6..6f0aa27 100644 --- a/ZR.Admin.WebApi/appsettings.json +++ b/ZR.Admin.WebApi/appsettings.json @@ -56,20 +56,12 @@ }, //接口请求限制 "IpRateLimiting": { - //例如设置了5次每分钟访问限流。当False时:项目中每个接口都加入计数,不管你访问哪个接口,只要在一分钟内累计够5次,将禁止访问。 - //True:当一分钟请求了5次GetData接口,则该接口将在时间段内禁止访问,但是还可以访问PostData()5次,总得来说是每个接口都有5次在这一分钟,互不干扰。 "EnableEndpointRateLimiting": true, - //false,拒绝的API调用不会添加到调用次数计数器上;如 客户端每秒发出3个请求并且您设置了每秒一个调用的限制,则每分钟或每天计数器等其他限制将仅记录第一个调用,即成功的API调用。如果您希望被拒绝的API调用计入其他时间的显示(分钟,小时等) - //,则必须设置StackBlockedRequests为true。 "StackBlockedRequests": false, "RealIpHeader": "X-Real-IP", - //取白名单的客户端ID。如果此标头中存在客户端ID并且与ClientWhitelist中指定的值匹配,则不应用速率限制。 "ClientIdHeader": "X-ClientId", "HttpStatusCode": 429, - //端点白名单 "EndpointWhitelist": [ "post:/system/dict/data/types", "*:/msghub/negotiate", "*:/LogOut" ], - //客户端白名单 - //"ClientWhitelist": [ "dev-id-1", "dev-id-2" ], "QuotaExceededResponse": { "Content": "{{\"code\":429,\"msg\":\"访问过于频繁,请稍后重试\"}}", "ContentType": "application/json", @@ -95,27 +87,6 @@ "Period": "3s", "Limit": 1 } - //{ - // "Endpoint": "*", - // //时间段,格式:{数字}{单位};可使用单位:s, m, h, d - // "Period": "1s", - // "Limit": 2 - //} - //{ - // "Endpoint": "*", - // "Period": "15m", - // "Limit": 100 - //}, - //{ - // "Endpoint": "*", - // "Period": "12h", - // "Limit": 1000 - //}, - //{ - // "Endpoint": "*", - // "Period": "7d", - // "Limit": 10000 - //} ], "IpRateLimitPolicies": { //ip规则 From ddbcfcc8d6e5b82216aef004b2f2b307259fa9d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Sat, 4 Jun 2022 18:29:13 +0800 Subject: [PATCH 2/4] update SysMenuService.cs --- ZR.Service/System/SysMenuService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZR.Service/System/SysMenuService.cs b/ZR.Service/System/SysMenuService.cs index 105b710..9154000 100644 --- a/ZR.Service/System/SysMenuService.cs +++ b/ZR.Service/System/SysMenuService.cs @@ -86,7 +86,7 @@ namespace ZR.Service var list = MenuRepository.GetList(f => f.parentId == menuId).OrderBy(f => f.orderNum).ToList(); Context.ThenMapper(list, item => { - item.SubNum = Context.Queryable().SetContext(x => x.parentId, () => item.MenuId, item).Count(); + item.SubNum = Context.Queryable().SetContext(x => x.parentId, () => item.MenuId, item).Count; }); return list; } From c6be4db66c5b70baaafe34d10a77073fd45ef5a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Sun, 5 Jun 2022 13:15:28 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=9C=A8=E7=BA=BF=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=96=B0=E5=A2=9E=E7=94=A8=E6=88=B7=E5=9C=B0?= =?UTF-8?q?=E7=90=86=E4=BD=8D=E7=BD=AE=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Admin.WebApi/Hubs/MessageHub.cs | 13 ++++++++++--- ZR.Admin.WebApi/Hubs/OnlineUsers.cs | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ZR.Admin.WebApi/Hubs/MessageHub.cs b/ZR.Admin.WebApi/Hubs/MessageHub.cs index b5bf330..f549968 100644 --- a/ZR.Admin.WebApi/Hubs/MessageHub.cs +++ b/ZR.Admin.WebApi/Hubs/MessageHub.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Infrastructure; using Infrastructure.Constant; using Infrastructure.Model; +using IPTools.Core; using Microsoft.AspNetCore.SignalR; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Framework; @@ -19,7 +20,7 @@ namespace ZR.Admin.WebApi.Hubs //创建用户集合,用于存储所有链接的用户数据 private static readonly List clientUsers = new(); private readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); - private ISysNoticeService SysNoticeService; + private readonly ISysNoticeService SysNoticeService; public MessageHub(ISysNoticeService noticeService) { @@ -43,12 +44,18 @@ namespace ZR.Admin.WebApi.Hubs { var name = Context.User.Identity.Name; var ip = HttpContextExtension.GetClientUserIp(App.HttpContext); + var ip_info = IpTool.Search(ip); + LoginUser loginUser = JwtUtil.GetLoginUser(App.HttpContext); var user = clientUsers.Any(u => u.ConnnectionId == Context.ConnectionId); //判断用户是否存在,否则添加集合 if (!user && Context.User.Identity.IsAuthenticated) { - clientUsers.Add(new OnlineUsers(Context.ConnectionId, name, loginUser?.UserId, ip)); + OnlineUsers users = new(Context.ConnectionId, name, loginUser?.UserId, ip) + { + Location = ip_info.City + }; + clientUsers.Add(users); Console.WriteLine($"{DateTime.Now}:{name},{Context.ConnectionId}连接服务端success,当前已连接{clientUsers.Count}个"); //Clients.All.SendAsync("welcome", $"欢迎您:{name},当前时间:{DateTime.Now}"); Clients.All.SendAsync(HubsConstant.MoreNotice, SendNotice()); @@ -69,10 +76,10 @@ namespace ZR.Admin.WebApi.Hubs //判断用户是否存在,否则添加集合 if (user != null) { - Console.WriteLine($"用户{user?.Name}离开了,当前已连接{clientUsers.Count}个"); clientUsers.Remove(user); Clients.All.SendAsync(HubsConstant.OnlineNum, clientUsers.Count); Clients.All.SendAsync(HubsConstant.OnlineUser, clientUsers); + Console.WriteLine($"用户{user?.Name}离开了,当前已连接{clientUsers.Count}个"); } return base.OnDisconnectedAsync(exception); } diff --git a/ZR.Admin.WebApi/Hubs/OnlineUsers.cs b/ZR.Admin.WebApi/Hubs/OnlineUsers.cs index a6292e0..cbb0c75 100644 --- a/ZR.Admin.WebApi/Hubs/OnlineUsers.cs +++ b/ZR.Admin.WebApi/Hubs/OnlineUsers.cs @@ -17,6 +17,7 @@ namespace ZR.Model public string Name { get; set; } public DateTime LoginTime { get; set; } public string UserIP { get; set; } + public string Location { get; set; } public OnlineUsers(string clientid, string name, long? userid, string userip) { From ef9baadf92932baa614f2096778d85dd6cc65c05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Sun, 5 Jun 2022 14:52:18 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Admin.WebApi/ZR.Admin.WebApi.csproj | 8 ++++---- ZR.CodeGenerator/ZR.CodeGenerator.csproj | 2 +- ZR.Common/ZR.Common.csproj | 6 +++--- ZR.Model/ZR.Model.csproj | 4 ++-- ZR.Repository/ZR.Repository.csproj | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj b/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj index c366c9e..33f4e72 100644 --- a/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj +++ b/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj @@ -14,10 +14,10 @@ - + - + @@ -25,8 +25,8 @@ - - + + diff --git a/ZR.CodeGenerator/ZR.CodeGenerator.csproj b/ZR.CodeGenerator/ZR.CodeGenerator.csproj index a44309b..91c2fde 100644 --- a/ZR.CodeGenerator/ZR.CodeGenerator.csproj +++ b/ZR.CodeGenerator/ZR.CodeGenerator.csproj @@ -12,6 +12,6 @@ - + diff --git a/ZR.Common/ZR.Common.csproj b/ZR.Common/ZR.Common.csproj index eaeea2f..f3df98d 100644 --- a/ZR.Common/ZR.Common.csproj +++ b/ZR.Common/ZR.Common.csproj @@ -6,9 +6,9 @@ - - - + + + diff --git a/ZR.Model/ZR.Model.csproj b/ZR.Model/ZR.Model.csproj index 20edbb3..9650c06 100644 --- a/ZR.Model/ZR.Model.csproj +++ b/ZR.Model/ZR.Model.csproj @@ -5,9 +5,9 @@ - + - + diff --git a/ZR.Repository/ZR.Repository.csproj b/ZR.Repository/ZR.Repository.csproj index eefd262..70bc436 100644 --- a/ZR.Repository/ZR.Repository.csproj +++ b/ZR.Repository/ZR.Repository.csproj @@ -14,7 +14,7 @@ - +