/// <summary> /// 发送短信 /// </summary> public void SendSMS(string mobile, string content, string userId) { if (string.IsNullOrEmpty(mobile) || string.IsNullOrEmpty(content)) { return; } var biz = new CacheDataBusiness(); var filterArray = biz.QueryCoreConfigFromRedis("SMS.Filter.Words").Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries); foreach (var word in filterArray) { content = content.Replace(word, ""); } var key = biz.QueryCoreConfigFromRedis("CFSMS.Key"); var pwd = biz.QueryCoreConfigFromRedis("CFSMS.Password"); var sender = SMSSenderFactory.GetSMSSenderInstance(new SMSConfigInfo { AgentName = "CFSMS", UserName = key, Password = pwd, Attach = "", }); var r = string.Empty; r = sender.SendSMS(mobile, content, ""); //保存到发送记录 new InnerMailManager().AddMoibleSMSSendRecord(new E_SiteMessage_MoibleSMSSendRecord { CreateTime = DateTime.Now, Mobile = mobile, SendStatus = r, SMSContent = content, UserId = userId, }); }
/// <summary> /// 依据SMSDTO对象内容发送短信 /// </summary> /// <param name="smsDto">SMSDTO对象</param> private void SendSMS(SMSDTO smsDto) { var smsId = smsDto.Id; loger.Info("开始发送--SMSId:{0}".FormatWith(smsId)); var sms = new SMS { SMSId = smsDto.Id, AppId = smsDto.AppId, SMSContent = smsDto.Content, SMSErrMsg = "", SMSMobile = smsDto.Mobile, SMSReceivedTime = DateTime.Now, SMSSentTime = DateTime.Now, SMSStatus = SMSStatus.Received.ToString() }; var smsFacade = new SMSFacade(); //发送短信 bool result = false; string mobile = smsDto.Mobile; string content = smsDto.Content; //申讯短信内容需加签名 if (ConfigMgr.SmsChannel == 2) { if (smsDto.AppId == "100204")//OEM项目,负责人:张业华 { content += "【登机宝】"; } else { content += "【今日天下通】"; } } var sender = SMSSenderFactory.CreateSender(ConfigMgr.SmsChannel); try { result = sender.SendSMS(mobile, content); } catch (Exception ex) { sms.SMSErrMsg = ex.Message; loger.Error("短信发送异常--SMSId:{0}--Exception:{1}".FormatWith(new object[] { smsId, ex })); } if (result) { sms.SMSErrMsg = ""; } //保存数据库 sms.SMSStatus = result ? SMSStatus.Sent.ToString() : SMSStatus.Fail.ToString(); sms.SMSSentTime = DateTime.Now; try { smsFacade.UpdateSMS(sms); } catch (Exception ex) { loger.Error("数据库更新SMS记录失败--SMSId:{0}--Exception:{1}".FormatWith(new object[] { smsId, ex })); } loger.Info("结束发送--SMSId:{0}--发送结果{1}".FormatWith(new object[] { smsId, result? "成功":"失败" })); }