public bool Handle(EventBus.Events.SMSSendEvent evt) { var service = new SysShortMessageService(); var sendSmsdto = evt.Map <EventBus.Events.SMSSendEvent, RequestSendSMSDTO>(); var result = service.SendMsg(sendSmsdto); //短信发送失败不重试。 if (result.Status == EnumApiStatus.BizError) { return(false); } else { return(true); } }
public ApiResult SendSmsCodeLogin([FromBody] RequestMsgCodeMobileDto request) { #region 校验:是否是允许的短信类型 if (request.TemplateID != "6") { return(EnumApiStatus.BizError.ToApiResultForApiStatus("不支持的类型")); } #endregion var shortMessageService = new SysShortMessageService(); //获取模板 var template = shortMessageService.GetTemplate(request.TemplateID); if (template == null) { return(EnumApiStatus.BizError.ToApiResultForApiStatus($"短信模板不存在,TemplateID={request.TemplateID}")); } int outMinute = 30; int codeNum = new Random().Next(100000, 999999); request.IDNumber = request.IDNumber.Substring(0, request.IDNumber.Length - 4) + "****"; //短信内容 string msgContent = string.Format(template.TemplateContent, codeNum.ToString(), outMinute.ToString(), "aaa", request.IDNumber); //短信参数 //string msgParms = string.Format("{0},{1},{2},{3}", // Service.Infrastructure.SecurityHelper.LoginUser.UserCNName, // request.IDNumber, // codeNum, // outMinute); var msgParms = new List <string>(); msgParms.Add(codeNum.ToString()); msgParms.Add(outMinute.ToString()); msgParms.Add("aaa"); msgParms.Add(request.IDNumber); //模板编号 var TemplateID = template.TemplateID; var evt = new RequestSendSMSDTO() { MsgParms = msgParms, Content = msgContent, TemplateID = TemplateID, Title = codeNum.ToString(), Mobile = request.Mobile, OutTime = DateTime.Now.AddMinutes(outMinute), }; var result = shortMessageService.SendMsg(evt); if (result.Status != EnumApiStatus.BizOK) { return(EnumApiStatus.BizError.ToApiResultForApiStatus(result.Msg)); } return(EnumApiStatus.BizOK.ToApiResultForApiStatus("验证码发送成功")); }
public ApiResult SendSmsCode([FromBody] RequestMsgCodeMobileDto request) { var appToken = CurrentOperatorApp; var userService = new BLL.User.Implements.UserService(); var shortMessageService = new SysShortMessageService(); #region 校验:图像验证码 if (!string.IsNullOrEmpty(request.VerifyCode)) { if (!userService.CheckVerifyCode(request.VerifyCode, appToken.Token)) { return(EnumApiStatus.BizError.ToApiResultForApiStatus("验证码过期或不正确")); } } #endregion #region 校验:用户注册短信 对不起此手机号已经注册 if (request.TemplateID == "1") { var userInfo = userService.GetUserInfoByMobile(request.Mobile, request.userType); if (userInfo != null) { return(EnumApiStatus.BizError.ToApiResultForApiStatus("对不起此手机号已经注册")); } } #endregion #region 校验: 找回密码短信 对不起此手机号尚未注册 if (request.TemplateID == "2") { var userInfo = userService.GetUserInfoByMobile(request.Mobile, request.userType); if (userInfo == null) { return(EnumApiStatus.BizError.ToApiResultForApiStatus("对不起此手机号尚未注册")); } } #endregion #region 校验:绑定手机号码短信 对不起此手机号已经注册 if (request.TemplateID == "4") { var res = userService.ExistsMobile(request.Mobile); if (res == true) { return(EnumApiStatus.BizError.ToApiResultForApiStatus("对不起此手机号已经注册")); } } #endregion #region 默认值:机构编号 if (string.IsNullOrEmpty(request.OrgID)) { request.OrgID = appToken.OrgID; } #endregion //获取模板 var template = shortMessageService.GetTemplate(request.TemplateID); if (template == null) { return(EnumApiStatus.BizError.ToApiResultForApiStatus($"短信模板不存在 TemplateID={request.TemplateID}")); } var outMinute = 30; var codeNum = new Random().Next(100000, 999999); var msgContent = string.Format(template.TemplateContent, codeNum, outMinute); //var msgParms = string.Format("{0},{1}", codeNum, outMinute); var msgParms = new List <string>(); msgParms.Add(codeNum.ToString()); msgParms.Add(outMinute.ToString()); var evt = new RequestSendSMSDTO() { MsgParms = msgParms, Content = msgContent, TemplateID = template.TemplateID, Mobile = request.Mobile, Title = codeNum.ToString(), OutTime = DateTime.Now.AddMinutes(outMinute), }; var result = shortMessageService.SendMsg(evt); if (result.Status != EnumApiStatus.BizOK) { return(EnumApiStatus.BizError.ToApiResultForApiStatus(result.Msg)); } return(EnumApiStatus.BizOK.ToApiResultForApiStatus("验证码发送成功")); }