public static bool CreateSMSMessageHistory(string recNum, string userName, string code, string currentIP, MessageHistorySMSType smsType, out string msg) { UnitOfWork unitOfWork = new UnitOfWork(); var repository = unitOfWork.Repository <MessageHistory>(); MessageHistory entity = new MessageHistory(); entity.Code = code; // Helper.EncryptPassword(userName, code.ToLower()); entity.MobileNumber = recNum; entity.UserName = userName; if (smsType == MessageHistorySMSType.FindPassword) { entity.Title = "找回密码"; } else if (smsType == MessageHistorySMSType.Registration) { entity.Title = "用户注册"; } else if (smsType == MessageHistorySMSType.UserCreation) { entity.Title = "用户密码"; } else if (smsType == MessageHistorySMSType.ResetPassword) { entity.Title = "重置密码"; } entity.CreateDatetime = DateTime.Now; entity.IP = currentIP; entity.IsUsed = false; entity.MessageType = MessageHistoryType.SMS; entity.SMSType = smsType; if (!repository.Insert(entity, out msg, true)) { return(false); } return(true); }
private static bool _checkSMS_Business_Limit(string mobileNumber, string currentIP, MessageHistorySMSType messageHistorySMSType, out string msg) { UnitOfWork unitOfWork = new UnitOfWork(); var _repository = unitOfWork.Repository <MessageHistory>(); var lastEntity = _repository.Get(filter: msh => msh.MobileNumber == mobileNumber && msh.SMSType == messageHistorySMSType, orderBy: q => q.OrderByDescending(item => item.CreateDatetime.Value)).FirstOrDefault(); //发送间隔小于60秒 if (lastEntity != null) { if ((DateTime.Now - lastEntity.CreateDatetime.Value).TotalSeconds < 60) { msg = "发送太频繁"; return(false); } } //同一IP 1小时发送超过5条 if (_repository.Get(filter: msh => msh.IP == currentIP && msh.CreateDatetime.Value.Hour == DateTime.Now.Hour && msh.SMSType == messageHistorySMSType).Count() > 5) { msg = "发送太频繁"; return(false); } //超过额度 if (_repository.Get(filter: msh => msh.CreateDatetime.Value.Hour == DateTime.Now.Hour && msh.SMSType == messageHistorySMSType ).Count() > 100) { msg = "超过额度"; return(false); } msg = ""; return(true); }