public IHttpActionResult Post(SmsViewModel value) { if (!Pool <MobileRegex> .Instance.IsMatch(value.UserName)) { return(Ok <string>(Messages.error_ValidateMobileFormat)); } var accountDTO = this._accountAppService.FindAccount(value.UserName); if (value.Action == "Login" || value.Action == "ForgotPwd" || value.Action == "ModifyMobile") { if (accountDTO == null) { return(Ok <string>(Messages.error_ValidateMobileNotReisterExisting)); } if (!accountDTO.IsEnabled) { return(Ok <string>(Messages.error_ValidateMobileFreeze)); } } else if (value.Action == "Register") { if (accountDTO != null) { return(Ok <string>(Messages.error_ValidateMobileReisterExisting)); } } else { throw new ArgumentNullException(); } SmsDTO smsDTO = this._smsAppService.FindSms(value.UserName); if (smsDTO != null && (DateTime.Now - smsDTO.CreateDate).TotalMinutes < 1) { return(Ok <string>(Messages.error_ValidateSmsTimeCount)); } var smsCode = CharHelper.GetRandomSmsCode(6); //向指定的用户发送短信 var codeTag = value.Action == "Login" ? 30351 : value.Action == "ModifyPwd" ? 8412 : value.Action == "ModifyMobile" ? 8413 : 8411; CodeSms codeSms = new DistributedServices.Seedwork.Sms.CodeSms(value.UserName, codeTag, string.Format("#app#={0}&#code#={0}&#hour#={0}", "来运吧物流", smsCode, 1)); SmsSendServer.SendSmsResult result = codeSms.Send(); if (result.ToString().Equals("Fail")) { return(Ok <string>(codeSms.ErrorMsg)); } var ip = UrlHelper.GetClientIP(); var resultSmsDTO = this._smsAppService.AddNewSms(new Application.MainBoundedContext.DTO.SmsDTO() { Code = smsCode, CreateDate = DateTime.Now, IP = ip, Mobile = value.UserName, ValidateState = 0, Type = value.SmsType }); return(Json <dynamic>(new { data = resultSmsDTO, total = 1 })); }