From 217bb851277fa2401bb7c310486dfbc6376c00e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=81=B0=E7=81=B0?= Date: Sat, 24 Jul 2021 16:27:13 +0000 Subject: [PATCH] =?UTF-8?q?!81=20=E4=BF=AE=E5=A4=8D=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=E8=BD=AC=E5=8F=91=E8=8E=B7=E5=8F=96ip=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E9=95=BF=E5=BA=A6=E8=BF=87=E9=95=BF=E9=97=AE=E9=A2=98=E3=80=82?= =?UTF-8?q?=20*=20!80=20=E4=BF=AE=E5=A4=8D=E5=9F=9F=E5=90=8D=E8=BD=AC?= =?UTF-8?q?=E5=8F=91=E8=8E=B7=E5=8F=96ip=E5=9C=B0=E5=9D=80=E9=95=BF?= =?UTF-8?q?=E5=BA=A6=E8=BF=87=E9=95=BF=E9=97=AE=E9=A2=98=E3=80=82=20*=20!7?= =?UTF-8?q?8=20=E4=BF=AE=E5=A4=8Dmysql=E6=95=B0=E6=8D=AE=E5=BA=93=E9=81=97?= =?UTF-8?q?=E7=95=99=E9=97=AE=E9=A2=98=20*=20!76=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=85=A8=E5=B1=80=E9=94=99=E8=AF=AF=E8=BF=94=E5=9B=9E=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E8=AF=AD=20*=20!74=20=E4=BF=AE=E5=A4=8D=E5=95=86?= =?UTF-8?q?=E5=93=81=E6=89=B9=E9=87=8F=E5=A4=84=E7=90=86=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=E5=B9=B6=E4=BC=98=E5=8C=96=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E7=95=8C=E9=9D=A2=E3=80=82#I3X8PP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CoreCms.Net.Middlewares/IPLogMildd.cs | 5 ++++- .../Bill/CoreCmsBillPaymentsServices.cs | 3 ++- .../IntelligentForms/CoreCmsFormServices.cs | 2 +- CoreCms.Net.Services/Message/CoreCmsSmsServices.cs | 5 +++-- CoreCms.Net.Services/Order/CoreCmsOrderServices.cs | 2 +- CoreCms.Net.Services/User/CoreCmsUserServices.cs | 3 ++- .../Controllers/Com/LoginController.cs | 10 ++++++++-- CoreCms.Net.Web.WebApi/Controllers/UserController.cs | 8 +++++--- ...opmysql20210720带演示数据(骆驼命名与实体名对应) .sql | 1 - 9 files changed, 26 insertions(+), 13 deletions(-) diff --git a/CoreCms.Net.Middlewares/IPLogMildd.cs b/CoreCms.Net.Middlewares/IPLogMildd.cs index 7025ea0..1bf81cd 100644 --- a/CoreCms.Net.Middlewares/IPLogMildd.cs +++ b/CoreCms.Net.Middlewares/IPLogMildd.cs @@ -95,7 +95,10 @@ namespace CoreCms.Net.Middlewares var ip = context.Request.Headers["X-Forwarded-For"].ObjectToString(); if (string.IsNullOrEmpty(ip)) { - ip = context.Connection.RemoteIpAddress.ObjectToString(); + if (context.Connection.RemoteIpAddress != null) + { + ip = context.Connection.RemoteIpAddress.MapToIPv4().ObjectToString(); + } } return ip; } diff --git a/CoreCms.Net.Services/Bill/CoreCmsBillPaymentsServices.cs b/CoreCms.Net.Services/Bill/CoreCmsBillPaymentsServices.cs index d56a01e..2778385 100644 --- a/CoreCms.Net.Services/Bill/CoreCmsBillPaymentsServices.cs +++ b/CoreCms.Net.Services/Bill/CoreCmsBillPaymentsServices.cs @@ -409,7 +409,8 @@ namespace CoreCms.Net.Services billPayments.type = type; billPayments.status = (int)GlobalEnumVars.BillPaymentsStatus.NoPay; billPayments.paymentCode = paymentCode; - billPayments.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + billPayments.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; + billPayments.parameters = @params != null ? JsonConvert.SerializeObject(@params) : ""; billPayments.createTime = DateTime.Now; diff --git a/CoreCms.Net.Services/IntelligentForms/CoreCmsFormServices.cs b/CoreCms.Net.Services/IntelligentForms/CoreCmsFormServices.cs index 1585c03..b282d86 100644 --- a/CoreCms.Net.Services/IntelligentForms/CoreCmsFormServices.cs +++ b/CoreCms.Net.Services/IntelligentForms/CoreCmsFormServices.cs @@ -385,7 +385,7 @@ namespace CoreCms.Net.Services formSubmitModel.payStatus = false; formSubmitModel.status = false; formSubmitModel.createTime = DateTime.Now; - formSubmitModel.ip = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString(); + formSubmitModel.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; var formSubmitId = await _formSubmitServices.InsertReturnIdentityAsync(formSubmitModel); diff --git a/CoreCms.Net.Services/Message/CoreCmsSmsServices.cs b/CoreCms.Net.Services/Message/CoreCmsSmsServices.cs index 40d51bc..f24fa93 100644 --- a/CoreCms.Net.Services/Message/CoreCmsSmsServices.cs +++ b/CoreCms.Net.Services/Message/CoreCmsSmsServices.cs @@ -87,7 +87,7 @@ namespace CoreCms.Net.Services oldLog.code = type; oldLog.createTime = DateTime.Now; oldLog.mobile = mobile; - oldLog.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + oldLog.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; oldLog.isUsed = false; var obj = new { @@ -238,7 +238,8 @@ namespace CoreCms.Net.Services oldLog.parameters = JsonConvert.SerializeObject(parameters); oldLog.contentBody = str; oldLog.createTime = DateTime.Now; - oldLog.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + oldLog.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? + _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; oldLog.isUsed = isUsed; await _dal.InsertAsync(oldLog); diff --git a/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs b/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs index d854a6d..1d2becb 100644 --- a/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs +++ b/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs @@ -532,7 +532,7 @@ namespace CoreCms.Net.Services order.orderDiscountAmount = cartDto.orderPromotionMoney > 0 ? cartDto.orderPromotionMoney : 0; order.goodsDiscountAmount = cartDto.goodsPromotionMoney > 0 ? cartDto.goodsPromotionMoney : 0; order.couponDiscountAmount = cartDto.couponPromotionMoney; - order.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + order.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; //以上保存了订单主体表信息,以下生成订单明细表 var items = FormatOrderItems(cartDto.list, order.orderId); if (!items.Any()) diff --git a/CoreCms.Net.Services/User/CoreCmsUserServices.cs b/CoreCms.Net.Services/User/CoreCmsUserServices.cs index 7d6dc48..dc0e0b9 100644 --- a/CoreCms.Net.Services/User/CoreCmsUserServices.cs +++ b/CoreCms.Net.Services/User/CoreCmsUserServices.cs @@ -630,7 +630,8 @@ namespace CoreCms.Net.Services var log = new CoreCmsUserLog(); log.userId = userInfo.id; log.state = isReg ? (int)GlobalEnumVars.UserLogTypes.注册 : (int)GlobalEnumVars.UserLogTypes.登录; - log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? + _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; log.createTime = DateTime.Now; log.parameters = isReg ? GlobalEnumVars.UserLogTypes.注册.ToString() : GlobalEnumVars.UserLogTypes.登录.ToString(); await _userLogServices.InsertAsync(log); diff --git a/CoreCms.Net.Web.Admin/Controllers/Com/LoginController.cs b/CoreCms.Net.Web.Admin/Controllers/Com/LoginController.cs index ec9e7d6..9474772 100644 --- a/CoreCms.Net.Web.Admin/Controllers/Com/LoginController.cs +++ b/CoreCms.Net.Web.Admin/Controllers/Com/LoginController.cs @@ -137,7 +137,9 @@ namespace CoreCms.Net.Web.Admin.Controllers //插入登录日志 var log = new SysLoginRecord(); log.username = model.userName; - log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? + _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; + log.os = RuntimeInformation.OSDescription; if (_httpContextAccessor.HttpContext != null) log.browser = _httpContextAccessor.HttpContext.Request.Headers[HeaderNames.UserAgent]; @@ -152,7 +154,9 @@ namespace CoreCms.Net.Web.Admin.Controllers //插入登录日志 var log = new SysLoginRecord(); log.username = model.userName; - log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? + _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; + log.os = RuntimeInformation.OSDescription; if (_httpContextAccessor.HttpContext != null) log.browser = _httpContextAccessor.HttpContext.Request.Headers[HeaderNames.UserAgent]; @@ -212,7 +216,9 @@ namespace CoreCms.Net.Web.Admin.Controllers if (_httpContextAccessor.HttpContext != null) { if (_httpContextAccessor.HttpContext.Connection.RemoteIpAddress != null) + { log.ip = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString(); + } log.os = RuntimeInformation.OSDescription; log.browser = _httpContextAccessor.HttpContext.Request.Headers[HeaderNames.UserAgent]; } diff --git a/CoreCms.Net.Web.WebApi/Controllers/UserController.cs b/CoreCms.Net.Web.WebApi/Controllers/UserController.cs index 890b86f..a19a88a 100644 --- a/CoreCms.Net.Web.WebApi/Controllers/UserController.cs +++ b/CoreCms.Net.Web.WebApi/Controllers/UserController.cs @@ -208,7 +208,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers var log = new CoreCmsUserLog(); log.userId = user.id; log.state = (int)GlobalEnumVars.UserLogTypes.登录; - log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; log.createTime = DateTime.Now; log.parameters = GlobalEnumVars.UserLogTypes.登录.ToString(); await _userLogServices.InsertAsync(log); @@ -316,7 +316,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers var log = new CoreCmsUserLog(); log.userId = user.id; log.state = (int)GlobalEnumVars.UserLogTypes.登录; - log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; log.createTime = DateTime.Now; log.parameters = GlobalEnumVars.UserLogTypes.登录.ToString(); await _userLogServices.InsertAsync(log); @@ -522,7 +522,9 @@ namespace CoreCms.Net.Web.WebApi.Controllers var log = new CoreCmsUserLog(); log.userId = id; log.state = (int)GlobalEnumVars.UserLogTypes.注册; - log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? + _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; + log.createTime = DateTime.Now; log.parameters = GlobalEnumVars.UserLogTypes.注册.ToString(); await _userLogServices.InsertAsync(log); diff --git a/数据库/MySql/coreshopmysql20210720带演示数据(骆驼命名与实体名对应) .sql b/数据库/MySql/coreshopmysql20210720带演示数据(骆驼命名与实体名对应) .sql index f21e5a2..9044764 100644 --- a/数据库/MySql/coreshopmysql20210720带演示数据(骆驼命名与实体名对应) .sql +++ b/数据库/MySql/coreshopmysql20210720带演示数据(骆驼命名与实体名对应) .sql @@ -8190,7 +8190,6 @@ INSERT INTO `SysMenu` (`id`, `parentId`, `identificationCode`, `menuName`, `menu (52, 51, 'goods', '商品列表', '', 'good/goods/index', 'good/goods/list', 0, 1, 'good:goods:index', NULL, NULL, b'0', b'0', '2020-07-17 01:08:11', '2020-07-17 16:18:55'), (53, 51, 'goodscategory', '商品分类', '', 'good/goodscategory/index', 'good/goodscategory/list', 0, 10, 'good:goodscategory:index', NULL, NULL, b'0', b'0', '2020-07-17 01:08:11', '2020-07-17 16:18:58'), (54, 51, 'goodsbrand', '品牌列表', '', 'good/goodsbrand/index', 'good/goodsbrand/list', 0, 20, 'good:goodsbrand:index', NULL, NULL, b'0', b'0', '2020-07-17 01:08:11', '2020-07-17 16:19:02'), -(55, 51, 'goodstype', '商品类型', '', 'good/goodstype/index', 'good/goodstype/list', 0, 30, 'good:goodstype:index', NULL, NULL, b'0', b'0', '2020-07-17 01:08:11', '2020-07-17 16:19:05'), (56, 51, 'goodscomment', '商品评价', '', 'good/goodscomment/index', 'good/goodscomment/list', 0, 40, 'good:goodscomment:index', NULL, NULL, b'0', b'0', '2020-07-17 01:08:11', '2020-07-17 16:19:16'), (57, 51, 'goodsparams', '参数列表', '', 'good/goodsparams/index', 'good/goodsparams/list', 0, 35, 'good:goodsparams:index', NULL, NULL, b'0', b'0', '2020-07-17 01:08:11', '2020-07-17 16:19:12'), (58, 51, 'goodsTypeSpec', '商品属性', '', 'good/goodsTypeSpec/index', 'good/goodsTypeSpec/list', 0, 32, 'good:goodsTypeSpec:index', NULL, NULL, b'0', b'0', '2020-07-17 01:08:11', '2020-07-17 16:19:09'),