public ResponseAccountInvitationSend SendMessage([FromBody] RequestAccountInvitationSend request) { try { UserBLL bll = new UserBLL(); return(bll.SendMessage(request)); } catch (Exception ex) { throw new HttpResponseException( Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
/// <summary> /// 发送短信 /// </summary> /// <param name="request"></param> /// <returns></returns> public ResponseAccountInvitationSend SendMessage(RequestAccountInvitationSend request) { var res = new ResponseAccountInvitationSend(); using (cnn = GetConnection()) { var ts = cnn.BeginTransaction(); try { if (string.IsNullOrEmpty(request.MobilePhone)) { throw new Exception("手机号不能为空"); } // string code = GenerateRandomNumber(5); string vcode = GenerateRandomNumber(4); IClientProfile profile = DefaultProfile.GetProfile("", "", ""); IAcsClient client = new DefaultAcsClient(profile); SingleSendSmsRequest req = new SingleSendSmsRequest(); req.SignName = "章小算"; //"管理控制台中配置的短信签名(状态必须是验证通过)" req.TemplateCode = "SMS_115165077"; //管理控制台中配置的审核通过的短信模板的模板CODE(状态必须是验证通过)" req.RecNum = request.MobilePhone; //"接收号码,多个号码可以逗号分隔" req.ParamString = "{\"code\":\"" + vcode + "\"}"; //切记前面的code字段,只能是英文,不能是中文!!短信模板中的变量;数字需要转换为字符串;个人用户每个变量长度必须小于15个字符。" SingleSendSmsResponse httpResponse = client.GetAcsResponse(req); TKS_FAS_MobileVerification context = new TKS_FAS_MobileVerification(); context.Id = Guid.NewGuid().ToString("N"); context.Mobile = request.MobilePhone; context.VerCode = vcode; context.CodeType = VerificationType.WX_Regist.ToString(); context.Status = "OP"; context.CreateDate = DateTime.Now; cnn.Insert <TKS_FAS_MobileVerification>(context, ts); ts.Commit(); res.IsSuccess = true; res.Message = ""; } catch (Exception ex) { res.IsSuccess = false; res.Message = ex.Message; } } return(res); }