diff --git a/CoreCms.Net.Configuration/SystemSettingConstVars.cs b/CoreCms.Net.Configuration/SystemSettingConstVars.cs
index 7fd4b7f9..ab79c2d1 100644
--- a/CoreCms.Net.Configuration/SystemSettingConstVars.cs
+++ b/CoreCms.Net.Configuration/SystemSettingConstVars.cs
@@ -645,6 +645,20 @@ namespace CoreCms.Net.Configuration
///
public const string SmsSignature = "smsSignature";
+ ///
+ /// 短信单ip每日发送量
+ ///
+ public const string SmsIpSendNumber = "smsIpSendNumber";
+
+ ///
+ /// 短信发送IP白名单
+ ///
+ public const string SmsIpSendWhiteList= "smsIpSendWhiteList";
+
+ ///
+ /// 短信发送IP黑名单
+ ///
+ public const string SmsIpSendBlackList = "smsIpSendBlackList";
///
/// 账户注册-短信内容模板
diff --git a/CoreCms.Net.Configuration/SystemSettingDictionary.cs b/CoreCms.Net.Configuration/SystemSettingDictionary.cs
index bced0376..3a95573c 100644
--- a/CoreCms.Net.Configuration/SystemSettingDictionary.cs
+++ b/CoreCms.Net.Configuration/SystemSettingDictionary.cs
@@ -214,6 +214,9 @@ namespace CoreCms.Net.Configuration
di.Add(SystemSettingConstVars.SmsPassword, new DictionaryKeyValues() { sKey = "密码", sValue = "" });
di.Add(SystemSettingConstVars.SmsApiUrl, new DictionaryKeyValues() { sKey = "Api地址", sValue = "http://sms.corecms.net:9999/sms.aspx" });
di.Add(SystemSettingConstVars.SmsSignature, new DictionaryKeyValues() { sKey = "短信签名", sValue = "" });
+ di.Add(SystemSettingConstVars.SmsIpSendNumber, new DictionaryKeyValues() { sKey = "单Ip每日发送量", sValue = "20" });
+ di.Add(SystemSettingConstVars.SmsIpSendWhiteList, new DictionaryKeyValues() { sKey = "发送IP白名单", sValue = "127.0.0.1|192.168.1.1|192.168.0.1" });
+ di.Add(SystemSettingConstVars.SmsIpSendBlackList, new DictionaryKeyValues() { sKey = "发送IP黑名单", sValue = "8.8.8.8|2.2.2.2" });
//附件存储
di.Add(SystemSettingConstVars.FilesStorageType, new DictionaryKeyValues() { sKey = "存储方式", sValue = "LocalStorage" });
diff --git a/CoreCms.Net.Model/CoreCms.Net.Model.xml b/CoreCms.Net.Model/CoreCms.Net.Model.xml
index aedbf5cf..de32affa 100644
--- a/CoreCms.Net.Model/CoreCms.Net.Model.xml
+++ b/CoreCms.Net.Model/CoreCms.Net.Model.xml
@@ -12467,6 +12467,21 @@
短信签名
+
+
+ 短信单ip每日发送量
+
+
+
+
+ 短信发送IP白名单
+
+
+
+
+ 短信发送IP黑名单
+
+
短信发送回调结果
diff --git a/CoreCms.Net.Model/ViewModels/Sms/SMSOptions.cs b/CoreCms.Net.Model/ViewModels/Sms/SMSOptions.cs
index 0b557372..19b152fb 100644
--- a/CoreCms.Net.Model/ViewModels/Sms/SMSOptions.cs
+++ b/CoreCms.Net.Model/ViewModels/Sms/SMSOptions.cs
@@ -45,6 +45,24 @@ namespace CoreCms.Net.Model.ViewModels.Sms
/// 短信签名
///
public string Signature { get; set; }
+
+ ///
+ /// 短信单ip每日发送量
+ ///
+ public int SmsIpSendNumber { get; set; } = 20;
+
+ ///
+ /// 短信发送IP白名单
+ ///
+ public string SmsIpSendWhiteList { get; set; }
+
+
+ ///
+ /// 短信发送IP黑名单
+ ///
+ public string SmsIpSendBlackList { get; set; }
+
+
}
///
diff --git a/CoreCms.Net.Services/Message/CoreCmsSmsServices.cs b/CoreCms.Net.Services/Message/CoreCmsSmsServices.cs
index 01d72fdf..92fcc799 100644
--- a/CoreCms.Net.Services/Message/CoreCmsSmsServices.cs
+++ b/CoreCms.Net.Services/Message/CoreCmsSmsServices.cs
@@ -9,6 +9,8 @@
***********************************************************************/
using System;
+using System.Collections.Generic;
+using System.Linq;
using System.Threading.Tasks;
using CoreCms.Net.Configuration;
using CoreCms.Net.IRepository;
@@ -78,8 +80,37 @@ namespace CoreCms.Net.Services
Random rd = new Random();
int codeNumber = rd.Next(100000, 999999);
- //获取是否存在
+
var dt = DateTime.Now;
+
+ //获取当前ip今日的发送记录
+ var ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1";
+ if (string.IsNullOrEmpty(ip))
+ {
+ jm.msg = "短信发送IP获取失败";
+ return jm;
+ }
+ var black = smsOptions.SmsIpSendBlackList.Split('|').ToList();
+ if (black.Count > 0 && black.Contains(ip))
+ {
+ jm.msg = "此IP被禁止短信业务";
+ return jm;
+ }
+ var white = smsOptions.SmsIpSendWhiteList.Split('|').ToList();
+ if (white.Count <= 0 || !white.Contains(ip))
+ {
+ var startDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0, DateTimeKind.Utc);
+ var endDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59, DateTimeKind.Utc);
+
+ var sendCount = await _dal.GetCountAsync(p => p.ip.Equals(ip) && p.createTime > startDateTime && p.createTime < endDateTime);
+ if (smsOptions.SmsIpSendNumber > 0 && sendCount > smsOptions.SmsIpSendNumber)
+ {
+ jm.msg = "此IP被已超过每日短信发送限额。";
+ return jm;
+ }
+ }
+
+ //获取是否存在
var endDt = dt.AddMinutes(10);
var oldLog = await _dal.QueryByClauseAsync(p => p.code == type && p.mobile == mobile && p.createTime > dt && p.createTime < endDt, p => p.id, OrderByType.Desc);
@@ -87,9 +118,9 @@ namespace CoreCms.Net.Services
{
oldLog = new CoreCmsSms();
oldLog.code = type;
- oldLog.createTime = DateTime.Now;
+ oldLog.createTime = dt;
oldLog.mobile = mobile;
- oldLog.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1";
+ oldLog.ip = ip;
oldLog.isUsed = false;
var obj = new
{
@@ -206,6 +237,36 @@ namespace CoreCms.Net.Services
jm.msg = "短信功能未开启";
return jm;
}
+ var dt = DateTime.Now;
+
+ //获取当前ip今日的发送记录
+ var ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "";
+ if (string.IsNullOrEmpty(ip))
+ {
+ jm.msg = "短信发送IP获取失败";
+ return jm;
+ }
+ var black = smsOptions.SmsIpSendBlackList.Split('|').ToList();
+ if (black.Count > 0 && black.Contains(ip))
+ {
+ jm.msg = "此IP被禁止短信业务";
+ return jm;
+ }
+ var white = smsOptions.SmsIpSendWhiteList.Split('|').ToList();
+ if (white.Count <= 0 || !white.Contains(ip))
+ {
+ var startDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0,
+ DateTimeKind.Utc);
+ var endDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59,
+ DateTimeKind.Utc);
+
+ var sendCount = await _dal.GetCountAsync(p => p.ip.Equals(ip) && p.createTime > startDateTime && p.createTime < endDateTime);
+ if (smsOptions.SmsIpSendNumber > 0 && sendCount > smsOptions.SmsIpSendNumber)
+ {
+ jm.msg = "此IP被已超过每日短信发送限额。";
+ return jm;
+ }
+ }
if (string.IsNullOrEmpty(mobile))
{
@@ -215,7 +276,6 @@ namespace CoreCms.Net.Services
var isUsed = false;
if (code == GlobalEnumVars.SmsMessageTypes.Reg.ToString() || code == GlobalEnumVars.SmsMessageTypes.Login.ToString() || code == GlobalEnumVars.SmsMessageTypes.Veri.ToString())
{
- var dt = DateTime.Now;
var newCreateTime = DateTime.Now.AddSeconds(-60);
var smsInfo = await _dal.QueryByClauseAsync(p =>
p.mobile == mobile && p.code == code && p.createTime < newCreateTime && p.isUsed == false);
@@ -227,7 +287,7 @@ namespace CoreCms.Net.Services
jm.msg = "两次发送时间间隔小于60秒";
return jm;
}
- parameters = JObject.Parse(smsInfo.parameters); ;
+ parameters = JObject.Parse(smsInfo.parameters);
}
else
{
@@ -360,8 +420,8 @@ namespace CoreCms.Net.Services
oldLog.code = code;
oldLog.parameters = JsonConvert.SerializeObject(parameters);
oldLog.contentBody = str;
- oldLog.createTime = DateTime.Now;
- oldLog.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1";
+ oldLog.createTime = dt;
+ oldLog.ip = ip;
oldLog.isUsed = isUsed;
await _dal.InsertAsync(oldLog);
diff --git a/CoreCms.Net.Services/Shop/CoreCmsSettingServices.cs b/CoreCms.Net.Services/Shop/CoreCmsSettingServices.cs
index f64ccc60..02213a4e 100644
--- a/CoreCms.Net.Services/Shop/CoreCmsSettingServices.cs
+++ b/CoreCms.Net.Services/Shop/CoreCmsSettingServices.cs
@@ -220,6 +220,9 @@ namespace CoreCms.Net.Services
sms.Password = GetValue(SystemSettingConstVars.SmsPassword, configs, settings);
sms.Signature = GetValue(SystemSettingConstVars.SmsSignature, configs, settings);
sms.ApiUrl = GetValue(SystemSettingConstVars.SmsApiUrl, configs, settings);
+ sms.SmsIpSendNumber= GetValue(SystemSettingConstVars.SmsIpSendNumber, configs, settings).ObjectToInt(20);
+ sms.SmsIpSendWhiteList = GetValue(SystemSettingConstVars.SmsIpSendWhiteList, configs, settings);
+ sms.SmsIpSendBlackList = GetValue(SystemSettingConstVars.SmsIpSendBlackList, configs, settings);
return sms;
}
diff --git a/CoreCms.Net.Web.Admin/wwwroot/views/shop/message/smssetting/index.html b/CoreCms.Net.Web.Admin/wwwroot/views/shop/message/smssetting/index.html
index 6182ea8b..bb3f5472 100644
--- a/CoreCms.Net.Web.Admin/wwwroot/views/shop/message/smssetting/index.html
+++ b/CoreCms.Net.Web.Admin/wwwroot/views/shop/message/smssetting/index.html
@@ -19,69 +19,94 @@
.layui-tab-content { padding: 15px 0; }