Browse Source

后端控制登录短信的发送时机

娄底高职分支
hwh2023 8 months ago
parent
commit
d3926c2cb0
3 changed files with 166 additions and 65 deletions
  1. +104
    -65
      Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/UserApi.cs
  2. +23
    -0
      Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.Base/SystemModule/Log/LogBLL.cs
  3. +39
    -0
      Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.Base/SystemModule/Log/LogService.cs

+ 104
- 65
Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/UserApi.cs View File

@@ -47,6 +47,7 @@ namespace Learun.Application.WebApi

}
private UserIBLL userIBLL = new UserBLL();
//private logibll userIBLL = new UserBLL();
private PostIBLL postIBLL = new PostBLL();
private RoleIBLL roleIBLL = new RoleBLL();
private StuInfoBasicIBLL stuInfoBasicIBLL = new StuInfoBasicBLL();
@@ -230,6 +231,8 @@ namespace Learun.Application.WebApi
{
pwd = true;
}
//是否发送短信了
bool whethersendsms = false;
if (!pwd)
{
//增加短信发送验证
@@ -242,39 +245,59 @@ namespace Learun.Application.WebApi
{
res.userInfo.majorno = majorinfo.ID ?? "";
}
try
#region 判断是否需要发短信
string queryjson = "{\"keywords\":\"" + userEntity.F_Mobile + "\"}";
LogEntity lastsendlog = LogBLL.GetlikeList(queryjson);
if (lastsendlog != null)
{
//学生增加短信发送验证
string raRndNum = Learun.Util.CommonHelper.RndNum(6);
var listStr = new List<string>();
var str1 = $"欢迎使用智慧校园,您本次登录的验证码是 " + raRndNum + "。";
listStr.Add(str1);
var result = yixintongSms.SendSmsToSingle(userEntity.F_Mobile, SmsType.LoginBind, listStr);
if (result.Result.code == "0")
var aa = ((DateTime)lastsendlog.F_OperateTime - DateTime.Now).TotalMinutes;
//大于30天就要发短信了
if (Math.Abs(aa) > 30 * 24 * 60 )
{
redisCache.Write<string>("studentuserlogin_" + userEntity.F_Mobile, raRndNum, new TimeSpan(0, 5, 0));
//日志
logEntity = new LogEntity();
logEntity.F_CategoryId = 3;
logEntity.F_OperateTypeId = "sms";
logEntity.F_OperateType = "sms";
logEntity.F_OperateAccount = "system";
logEntity.F_ExecuteResult = 200;
logEntity.F_ExecuteResultJson = "短信发送成功:" + result.Result.message;
logEntity.F_Description = "短信发送:" + userEntity.F_Mobile;
logEntity.WriteLog();
whethersendsms = true;
}
else
}
else
{
whethersendsms = true;
}
#endregion
try
{
if (whethersendsms)
{
logEntity = new LogEntity();
logEntity.F_CategoryId = 4;
logEntity.F_OperateTypeId = "sms";
logEntity.F_OperateType = "sms";
logEntity.F_OperateAccount = "system";
logEntity.F_ExecuteResult = 400;
logEntity.F_ExecuteResultJson = "短信发送失败:" + result.Result.message + result.Result.errorType;
logEntity.F_Description = "短信发送:" + userEntity.F_Mobile;
logEntity.WriteLog();
//学生增加短信发送验证
string raRndNum = Learun.Util.CommonHelper.RndNum(6);
var listStr = new List<string>();
var str1 = $"欢迎使用智慧校园,您本次登录的验证码是 " + raRndNum + "。";
listStr.Add(str1);
var result = yixintongSms.SendSmsToSingle(userEntity.F_Mobile, SmsType.LoginBind, listStr);
if (result.Result.code == "0")
{
redisCache.Write<string>("studentuserlogin_" + userEntity.F_Mobile, raRndNum, new TimeSpan(0, 5, 0));
//日志
logEntity = new LogEntity();
logEntity.F_CategoryId = 3;
logEntity.F_OperateTypeId = "sms";
logEntity.F_OperateType = "sms";
logEntity.F_OperateAccount = "system";
logEntity.F_ExecuteResult = 200;
logEntity.F_ExecuteResultJson = "短信发送成功:" + result.Result.message;
logEntity.F_Description = "短信发送:" + userEntity.F_Mobile;
logEntity.WriteLog();
}
else
{
logEntity = new LogEntity();
logEntity.F_CategoryId = 4;
logEntity.F_OperateTypeId = "sms";
logEntity.F_OperateType = "sms";
logEntity.F_OperateAccount = "system";
logEntity.F_ExecuteResult = 400;
logEntity.F_ExecuteResultJson = "短信发送失败:" + result.Result.message + result.Result.errorType;
logEntity.F_Description = "短信发送:" + userEntity.F_Mobile;
logEntity.WriteLog();
}
}
}
catch (Exception e)
@@ -293,45 +316,60 @@ namespace Learun.Application.WebApi
var teacherentity = empInfoIBLL.GetEmpInfoEntityByEmpNo(userEntity.F_Account);
if (teacherentity != null)
{
//res.userInfo.grade = studententity.Grade;
//var majorinfo = majorIbll.GetCdMajorEntityByMajorNo(studententity.MajorNo);
//if (majorinfo != null)
//{
// res.userInfo.majorno = majorinfo.ID ?? "";
//}
try

#region 判断是否需要发短信
string queryjson = "{\"keywords\":\"" + userEntity.F_Mobile + "\"}";
LogEntity lastsendlog = LogBLL.GetlikeList(queryjson);
if (lastsendlog != null)
{
//学生增加短信发送验证
string raRndNum = Learun.Util.CommonHelper.RndNum(6);
var listStr = new List<string>();
var str1 = $"欢迎使用智慧校园,您本次登录的验证码是 " + raRndNum + "。";
listStr.Add(str1);
var result = yixintongSms.SendSmsToSingle(userEntity.F_Mobile, SmsType.LoginBind, listStr);
if (result.Result.code == "0")
var aa = ((DateTime)lastsendlog.F_OperateTime - DateTime.Now).TotalMinutes;
//大于30天就要发短信了
if (Math.Abs(aa) > 7 * 24 * 60 )
{
redisCache.Write<string>("studentuserlogin_" + userEntity.F_Mobile, raRndNum, new TimeSpan(0, 5, 0));
//日志
logEntity = new LogEntity();
logEntity.F_CategoryId = 3;
logEntity.F_OperateTypeId = "sms";
logEntity.F_OperateType = "sms";
logEntity.F_OperateAccount = "system";
logEntity.F_ExecuteResult = 200;
logEntity.F_ExecuteResultJson = "短信发送成功:" + result.Result.message;
logEntity.F_Description = "短信发送:" + userEntity.F_Mobile;
logEntity.WriteLog();
whethersendsms = true;
}
else
}
else
{
whethersendsms = true;
}
#endregion
try
{
if (whethersendsms)
{
logEntity = new LogEntity();
logEntity.F_CategoryId = 4;
logEntity.F_OperateTypeId = "sms";
logEntity.F_OperateType = "sms";
logEntity.F_OperateAccount = "system";
logEntity.F_ExecuteResult = 400;
logEntity.F_ExecuteResultJson = "短信发送失败:" + result.Result.message + result.Result.errorType;
logEntity.F_Description = "短信发送:" + userEntity.F_Mobile;
logEntity.WriteLog();
//学生增加短信发送验证
string raRndNum = Learun.Util.CommonHelper.RndNum(6);
var listStr = new List<string>();
var str1 = $"欢迎使用智慧校园,您本次登录的验证码是 " + raRndNum + "。";
listStr.Add(str1);
var result = yixintongSms.SendSmsToSingle(userEntity.F_Mobile, SmsType.LoginBind, listStr);
if (result.Result.code == "0")
{
redisCache.Write<string>("studentuserlogin_" + userEntity.F_Mobile, raRndNum, new TimeSpan(0, 5, 0));
//日志
logEntity = new LogEntity();
logEntity.F_CategoryId = 3;
logEntity.F_OperateTypeId = "sms";
logEntity.F_OperateType = "sms";
logEntity.F_OperateAccount = "system";
logEntity.F_ExecuteResult = 200;
logEntity.F_ExecuteResultJson = "短信发送成功:" + result.Result.message;
logEntity.F_Description = "短信发送:" + userEntity.F_Mobile;
logEntity.WriteLog();
}
else
{
logEntity = new LogEntity();
logEntity.F_CategoryId = 4;
logEntity.F_OperateTypeId = "sms";
logEntity.F_OperateType = "sms";
logEntity.F_OperateAccount = "system";
logEntity.F_ExecuteResult = 400;
logEntity.F_ExecuteResultJson = "短信发送失败:" + result.Result.message + result.Result.errorType;
logEntity.F_Description = "短信发送:" + userEntity.F_Mobile;
logEntity.WriteLog();
}
}
}
catch (Exception e)
@@ -358,7 +396,8 @@ namespace Learun.Application.WebApi
baseinfo = res.userInfo,
post = postIBLL.GetListByPostIds(res.userInfo.postIds),
role = roleIBLL.GetListByRoleIds(res.userInfo.roleIds),
pwd = pwd
pwd = pwd,
sendresult=whethersendsms
};
return Success(jsonData);
}


+ 23
- 0
Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.Base/SystemModule/Log/LogBLL.cs View File

@@ -64,6 +64,29 @@ namespace Learun.Application.Base.SystemModule
}
}
}
/// <summary>
/// 日志列表
/// </summary>
/// <param name="queryJson">查询参数</param>
/// <returns></returns>
public static LogEntity GetlikeList(string queryJson)
{
try
{
return service.GetlikeList(queryJson);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
public static IEnumerable<LogEntity> GetGroupLog(string userid)
{
try


+ 39
- 0
Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.Base/SystemModule/Log/LogService.cs View File

@@ -282,6 +282,45 @@ namespace Learun.Application.Base.SystemModule
}
}
}
/// <summary>
/// 日志列表
/// </summary>
/// <param name="queryJson">查询参数</param>
/// <returns></returns>
public LogEntity GetlikeList(string queryJson)
{
try
{
var list = new LogEntity();
var expression = LinqExtensions.True<LogEntity>();
var queryParam = queryJson.ToJObject();

string keywords = queryParam["keywords"].ToString();

//expression = expression.And(t => t.F_OperateTime >= date1 && t.F_OperateTime < date2);
var strSql = new StringBuilder();
strSql.Append(" select top 1 t.* ");
strSql.Append(" from LR_Base_Log t ");
if (!string.IsNullOrEmpty(keywords))
{
strSql.Append($" where f_executeresultjson like '%发送短信成功%' and f_description like '%" + keywords + "%'");
}
strSql.Append(" order by f_operatetime desc");
list = this.BaseRepository().FindList<LogEntity>(strSql.ToString()).FirstOrDefault();
return list;
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion

public LogEntity GetUserLogList(string userId)


Loading…
Cancel
Save