/// <summary> /// 当条件为真,则发送短信或邮件。否则只记录日志。 /// </summary> /// <param name="condition"></param> /// <param name="message"></param> public virtual void WarnIf(bool condition, string message) { if (condition) { string msg = String.Format("<b>{0}</b> {1} {2}<br/>", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), User, message); switch (LogConfig.LogWarnType) { case LogWarnType.OFF: break; case LogWarnType.Email: new Thread(new ThreadStart(() => { using (Email.EmailSender sender = new Email.EmailSender() { Subject = "[Event Log System]", EmailBody = msg }) { sender.AddReceiver(LogConfig.LogWarnEmail); sender.Send(); } })).Start(); break; case LogWarnType.SMS: new Thread(new ThreadStart(() => { SMSSender.Send(LogConfig.LogWarningSMSReciver, msg); })).Start(); break; } } InnerLogMethod(LogLevel.Warn, message); }
public static SendStatus SendSMS(string[] phoneNumbers, string message, SiteSettings settings, out string string_0) { string_0 = ""; SendStatus result; if (phoneNumbers == null || string.IsNullOrEmpty(message) || phoneNumbers.Length == 0 || message.Trim().Length == 0) { result = SendStatus.RequireMsg; } else { if (settings == null || !settings.SMSEnabled) { result = SendStatus.NoProvider; } else { SMSSender sMSSender = Messenger.CreateSMSSender(settings, out string_0); if (sMSSender == null) { result = SendStatus.ConfigError; } else { result = (sMSSender.Send(phoneNumbers, message, out string_0) ? SendStatus.Success : SendStatus.Fail); } } } return(result); }
private void HaiMeiSendMessage(SiteSettings settings, string cellphone) { try { string text = HiContext.Current.GenerateRandomNumber(4); ConfigData configData = new ConfigData(HiCryptographer.Decrypt(settings.SMSSettings)); SMSSender sMSSender = SMSSender.CreateInstance(settings.SMSSender, configData.SettingsXml); string text2 = string.Format(@"您好!您正在进行海美生活会员修改密码,本次的验证码为:{0},请勿向任何人提供您收到的短信验证码,并尽快完成验证。", text); string text3; bool flag = sMSSender.Send(cellphone, text2, out text3); if (flag) { //HiCache.Insert(HiContext.Current.User.UserId + "cellphone", text, 10800); EcShop.Entities.Members.Verify verfyinfo = new Entities.Members.Verify(); verfyinfo.VerifyCode = text; verfyinfo.CellPhone = cellphone.Trim(); EcShop.ControlPanel.Members.TelVerifyHelper.CreateVerify(verfyinfo); } this.message = "{\"success\":true,\"msg\":\"" + text3 + "\"}"; } catch (System.Exception) { this.message = "{\"success\":false,\"msg\":\"未知错误\"}"; } }
public bool SendSms(string phone, string text) { SMSSender sender = new SMSSender("*****@*****.**", "1qaZ2wsX", "name"); var result = sender.Send(phone, text); return(true); }
private void GetSmsCodeCommandExecute(object obj) { SMSSender sender = new SMSSender("*****@*****.**", "1qaZ2wsX", "name"); _generatedSmsCode = new Random().Next(9999); sender.Send(PhoneNumber, _generatedSmsCode.ToString()); }
public static void SendNotification(string title, string body, string to, NotificationMedia media) { if (media == NotificationMedia.Email) { EmailSender.Send(ConfigurationManager.AppSettings["ParkingApi.Messaging.Email.From"], to, title, body); } else { SMSSender.Send(to, body); } }
public OperationResult AfterStartServerAuthentication(string applicationUser, string tokenID, string baseNotifyMessage, string newPassword, TokenMovingFactorType tokenMovingFactorType, TokenSeedType tokenSeedType) { string[] _arrayNotifMsg = (baseNotifyMessage ?? "").Split(new char[] { '|' }); string[] _params = new string[_arrayNotifMsg.Length - 1]; Array.Copy(_arrayNotifMsg, 1, _params, 0, _params.Length); string notifMsg = ((_arrayNotifMsg[0] ?? "").Length > 1) ? _arrayNotifMsg[0] : SAFConfiguration.readParameterExternal("SMS.TEMPLATE.ON.STARTSERVERAUTH"); notifMsg = string.Format(notifMsg.Replace("{tm}", DateTime.Now.ToShortDateString()).Replace("{dt}", DateTime.Now.ToShortTimeString()), _params); return(SMSSender.Send(applicationUser, tokenID, null, notifMsg)); }
public static SendStatus SendSMS(string phoneNumber, string message, SiteSettings settings, out string msg) { msg = ""; if (((string.IsNullOrEmpty(phoneNumber) || string.IsNullOrEmpty(message)) || (phoneNumber.Trim().Length == 0)) || (message.Trim().Length == 0)) { return(SendStatus.RequireMsg); } if (!((settings != null) && settings.SMSEnabled)) { return(SendStatus.NoProvider); } SMSSender sender = CreateSMSSender(settings, out msg); if (sender == null) { return(SendStatus.ConfigError); } return(sender.Send(phoneNumber, message, out msg) ? SendStatus.Success : SendStatus.Fail); }
static void FactoryMethodUse() { // Wrong. var message = "Design Partner Study"; DesignParttenersK19.FactoryMethod.SMSSender smsSender = new SMSSender(); smsSender.Send(message); DesignParttenersK19.FactoryMethod.EmailSender emailSender = new EmailSender(); emailSender.Send(message); DesignParttenersK19.FactoryMethod.PushSender pushSender = new PushSender(); pushSender.Send(message); // Right. DesignParttenersK19.FactoryMethod.SenderCreator creator = new SenderCreator(); var sender = creator.Create(SenderType.Sms); sender.Send(message); }
bool Send(string number, string text) { SMSSender sender = new SMSSender("*****@*****.**", "1qaZ2wsX", "name"); var result = sender.Send(number, text); switch (result) { case -1: Console.WriteLine("Неправильный логин и / или пароль"); break; case -2: Console.WriteLine("Неправильный формат XML"); break; case -3: Console.WriteLine("Недостаточно кредитов на аккаунте пользователя"); break; case -4: Console.WriteLine("Нет верных номеров получателей"); break; case -5: Console.WriteLine("Ошибка подключения"); break; case -6: break; case -7: break; default: Console.WriteLine("СМС в количестве: {0} отправлено!", result); return(true); //break; } return(false); }
private void btnTestSend_Click(object sender, EventArgs e) { string text = default(string); ConfigData configData = this.LoadConfig(out text); string templateCode = this.txtTestSMSTemplateCode.Text.Trim();//短信模板编码 if (string.IsNullOrEmpty(text) || configData == null) { this.ShowMsg("请先选择发送方式并填写配置信息", false); } else if (!configData.IsValid) { string text2 = ""; foreach (string errorMsg in configData.ErrorMsgs) { text2 += Formatter.FormatErrorMessage(errorMsg); } this.ShowMsg(text2, false); } else if (string.IsNullOrEmpty(this.txtTestCellPhone.Text) || string.IsNullOrEmpty(this.txtTestSubject.Text) || this.txtTestCellPhone.Text.Trim().Length == 0 || this.txtTestSubject.Text.Trim().Length == 0) { this.ShowMsg("接收手机号和发送内容不能为空", false); } else if (!Regex.IsMatch(this.txtTestCellPhone.Text.Trim(), "^(13|14|15|18)\\d{9}$")) { this.ShowMsg("请填写正确的手机号码", false); } else if (string.IsNullOrEmpty(templateCode) || templateCode.Trim().Length == 0) { this.ShowMsg("请填写正确的模板code", false); } else { SMSSender sMSSender = SMSSender.CreateInstance(text, configData.SettingsXml); string msg = default(string); bool success = sMSSender.Send(this.txtTestCellPhone.Text.Trim(), templateCode, this.txtTestSubject.Text.Trim(), out msg); this.ShowMsg(msg, success); } }
static void Main(string[] args) { SMSSender sender = new SMSSender("*****@*****.**", "1qaZ2wsX", "name"); var result = sender.Send("+380123456712", "Test message"); switch (result) { case -1: Console.WriteLine("Неправильный логин и / или пароль"); break; case -2: Console.WriteLine("Неправильный формат XML"); break; case -3: Console.WriteLine("Недостаточно кредитов на аккаунте пользователя"); break; case -4: Console.WriteLine("Нет верных номеров получателей"); break; case -5: Console.WriteLine("Ошибка подключения"); break; case -6: break; case -7: break; default: Console.WriteLine("СМС в количестве: {0} отправлено!", result); break; } }
private void btnTestSend_Click(object sender, System.EventArgs e) { string text; ConfigData configData = this.LoadConfig(out text); if (string.IsNullOrEmpty(text) || configData == null) { this.ShowMsg("请先选择发送方式并填写配置信息", false); return; } if (!configData.IsValid) { string text2 = ""; foreach (string current in configData.ErrorMsgs) { text2 += Formatter.FormatErrorMessage(current); } this.ShowMsg(text2, false); return; } if (string.IsNullOrEmpty(this.txtTestCellPhone.Text) || string.IsNullOrEmpty(this.txtTestSubject.Text) || this.txtTestCellPhone.Text.Trim().Length == 0 || this.txtTestSubject.Text.Trim().Length == 0) { this.ShowMsg("接收手机号和发送内容不能为空", false); return; } if (!System.Text.RegularExpressions.Regex.IsMatch(this.txtTestCellPhone.Text.Trim(), "^(13|14|15|18)\\d{9}$")) { this.ShowMsg("请填写正确的手机号码", false); return; } SMSSender sMSSender = SMSSender.CreateInstance(text, configData.SettingsXml); string msg; bool success = sMSSender.Send(this.txtTestCellPhone.Text.Trim(), this.txtTestSubject.Text.Trim(), out msg); this.ShowMsg(msg, success); }
public OperationResult AfterCreate(string applicationUser, string applicationUseruserPhone, string applicationEmail, string tokenVendorID, string expirationDate, string supplierSerialNumber, string creationLotID, string pin, string baseNotifyMessage, int tokenInternalID, long businessEventID, TokenStatus tokenStatus) { TokenInfo tokenInfo = new TokenInfo(); OperationResult operationResult = OperationResult.Error; TokenInfo[] array = new TokenBusinessDAO().loadTokenUserByType(applicationUser, tokenVendorID); OperationResult result; if (array == null) { result = OperationResult.PostValidationRulesFail; } else { for (int i = 0; i < array.Length; i++) { if (tokenInternalID == array[i].tokenInfoCore.InternalID) { tokenInfo = array[i]; operationResult = OperationResult.Success; } else { switch (array[i].tokenInfoCore.TypeID) { case 1: if (array[i].Status == TokenStatus.Enabled) { operationResult = SAFBaseFunctions.tokenDisable(array[i].ApplicationUser, array[i].tokenInfoCore.InternalID.ToString(), string.Empty); } break; case 2: if (array[i].Status == TokenStatus.Enabled || array[i].Status == TokenStatus.Disabled) { operationResult = SAFBaseFunctions.tokenCancel(array[i].ApplicationUser, array[i].tokenInfoCore.InternalID.ToString(), string.Empty); } break; case 3: if (array[i].Status == TokenStatus.Enabled || array[i].Status == TokenStatus.Disabled) { operationResult = SAFBaseFunctions.tokenCancel(array[i].ApplicationUser, array[i].tokenInfoCore.InternalID.ToString(), string.Empty); } break; } } } if (operationResult != OperationResult.Success) { result = operationResult; } else { string text = SAFConfiguration.readParameterExternal((tokenStatus == TokenStatus.ReadyToDeploy) ? "OP.SMS.NOTIFY.ON.CREATE.DEPLOY" : "OP.SMS.NOTIFY.ON.CREATE"); text = ((text.Trim().Length < 1) ? null : text.Trim()); string smsMessage; if (0 >= (text ?? "").IndexOf("[0]")) { smsMessage = (((baseNotifyMessage ?? "").Length > 1) ? baseNotifyMessage : text).Replace("{dt}", DateTime.Now.ToShortDateString()).Replace("{tm}", DateTime.Now.ToShortTimeString()).Replace("{dpl}", businessEventID.ToString().Trim()); } else { smsMessage = ((text != null) ? string.Format(text, baseNotifyMessage.Split(new char[] { '|' })) : string.Join("", baseNotifyMessage.Split(new char[] { '|' })).Trim()); } result = SMSSender.Send(tokenInfo.ApplicationUser, tokenInfo.tokenInfoCore.InternalID.ToString(), tokenInfo.PhoneNumberUser, smsMessage); } } return(result); }
private void btnSendMessage_Click(object sender, System.EventArgs e) { SiteSettings siteSetting = this.GetSiteSetting(); string sMSSender = siteSetting.SMSSender; if (string.IsNullOrEmpty(sMSSender)) { this.ShowMsg("请先选择发送方式", false); return; } ConfigData configData = null; if (siteSetting.SMSEnabled) { configData = new ConfigData(HiCryptographer.Decrypt(siteSetting.SMSSettings)); } if (configData == null) { this.ShowMsg("请先选择发送方式并填写配置信息", false); return; } if (!configData.IsValid) { string text = ""; foreach (string current in configData.ErrorMsgs) { text += Formatter.FormatErrorMessage(current); } this.ShowMsg(text, false); return; } string text2 = this.txtmsgcontent.Value.Trim(); if (string.IsNullOrEmpty(text2)) { this.ShowMsg("请先填写发送的内容信息", false); return; } int num = System.Convert.ToInt32(this.litsmscount.Text); string text3 = null; foreach (System.Web.UI.WebControls.GridViewRow gridViewRow in this.grdMemberList.Rows) { System.Web.UI.WebControls.CheckBox checkBox = (System.Web.UI.WebControls.CheckBox)gridViewRow.FindControl("checkboxCol"); if (checkBox.Checked) { string text4 = ((System.Web.UI.DataBoundLiteralControl)gridViewRow.Controls[2].Controls[0]).Text.Trim().Replace("<div></div>", ""); if (!string.IsNullOrEmpty(text4) && System.Text.RegularExpressions.Regex.IsMatch(text4, "^(13|14|15|17|18)\\d{9}$")) { text3 = text3 + text4 + ","; } } } if (text3 == null) { this.ShowMsg("请先选择要发送的会员或检测所选手机号格式是否正确", false); return; } text3 = text3.Substring(0, text3.Length - 1); string[] array; if (text3.Contains(",")) { array = text3.Split(new char[] { ',' }); } else { array = new string[] { text3 }; } if (num < array.Length) { this.ShowMsg("发送失败,您的剩余短信条数不足", false); return; } SMSSender sMSSender2 = SMSSender.CreateInstance(sMSSender, configData.SettingsXml); string msg; bool success = sMSSender2.Send(array, text2, out msg); this.ShowMsg(msg, success); this.txtmsgcontent.Value = "输入发送内容……"; this.litsmscount.Text = (num - array.Length).ToString(); }
public OperationResult AfterCreate(string applicationUser, string applicationUseruserPhone, string applicationEmail, string tokenVendorID, string expirationDate, string supplierSerialNumber, string creationLotID, string pin, string baseNotifyMessage, int tokenInternalID, long businessEventID, TokenStatus tokenStatus) { TokenInfo _lastInsertedToken = new TokenInfo(); OperationResult _hResult = OperationResult.Error; TokenInfo[] _tkInfo = new TokenBusinessDAO().loadTokenUserByType(applicationUser, tokenVendorID); OperationResult result; if (_tkInfo == null) { result = OperationResult.PostValidationRulesFail; } else { for (int i = 0; i < _tkInfo.Length; i++) { if (tokenInternalID == _tkInfo[i].tokenInfoCore.InternalID) { _lastInsertedToken = _tkInfo[i]; _hResult = OperationResult.Success; } else { switch (_tkInfo[i].tokenInfoCore.TypeID) { case 1: if (_tkInfo[i].Status == TokenStatus.Enabled) { _hResult = SAFBaseFunctions.tokenDisable(_tkInfo[i].ApplicationUser, _tkInfo[i].tokenInfoCore.InternalID.ToString(), string.Empty); } break; case 2: if (_tkInfo[i].Status == TokenStatus.Enabled || _tkInfo[i].Status == TokenStatus.Disabled || _tkInfo[i].Status == TokenStatus.ReadyToDeploy || _tkInfo[i].Status == TokenStatus.DeployCompleted) { _hResult = SAFBaseFunctions.tokenCancel(_tkInfo[i].ApplicationUser, _tkInfo[i].tokenInfoCore.InternalID.ToString(), string.Empty); } break; case 3: if (_tkInfo[i].Status == TokenStatus.Enabled || _tkInfo[i].Status == TokenStatus.Disabled) { _hResult = SAFBaseFunctions.tokenCancel(_tkInfo[i].ApplicationUser, _tkInfo[i].tokenInfoCore.InternalID.ToString(), string.Empty); } break; } } } if (_hResult != OperationResult.Success) { result = _hResult; } else { string[] _arrayNotifMsg = (baseNotifyMessage ?? "").Split(new char[] { '|' }); string[] _params = new string[_arrayNotifMsg.Length - 1]; Array.Copy(_arrayNotifMsg, 1, _params, 0, _params.Length); string notifMsg = ((_arrayNotifMsg[0] ?? "").Length > 1) ? _arrayNotifMsg[0] : SAFConfiguration.readParameterExternal((tokenStatus == TokenStatus.ReadyToDeploy) ? "SMS.TEMPLATE.ON.CREATE.DEPLOY" : "SMS.TEMPLATE.ON.CREATE"); notifMsg = string.Format(notifMsg.Replace("{tm}", DateTime.Now.ToShortDateString()).Replace("{dt}", DateTime.Now.ToShortTimeString()), _params); result = SMSSender.Send(_lastInsertedToken.ApplicationUser, _lastInsertedToken.tokenInfoCore.InternalID.ToString(), _lastInsertedToken.PhoneNumberUser, notifMsg); } } return(result); }
public IHttpActionResult SendSMSCode(JObject request) { Logger.WriterLogger("Account.SendSMSCode, Params: " + request.ToString(), LoggerType.Info); ParamSendSMSCode param = new ParamSendSMSCode(); try { param = request.ToObject <ParamSendSMSCode>(); } catch { return(base.JsonFaultResult(new CommonException(40100).GetMessage(), request.ToString())); } string accessToken = param.accessToken; string sessionKey = ""; string sessionSecret = ""; // 验证令牌 int accessTookenCode = VerifyAccessToken(accessToken, out sessionKey, out sessionSecret); if (accessTookenCode > 0) { return(base.JsonFaultResult(new CommonException(accessTookenCode).GetMessage(), request.ToString())); } string mobile = param.Mobile; int cType = param.CType; if (string.IsNullOrEmpty(mobile)) { return(base.JsonFaultResult(new FaultInfo(40100, "手机号码为空"), request.ToString())); } if (!System.Text.RegularExpressions.Regex.IsMatch(mobile, "^(13|14|15|17|18)\\d{9}$")) { return(base.JsonFaultResult(new FaultInfo(40100, "请输入正确的手机号码"), request.ToString())); } if (cType == 1 && UserHelper.IsExistCellPhoneAndUserName(mobile) > 0) { return(base.JsonFaultResult(new FaultInfo(40100, "已经存在相同的手机号码"), request.ToString())); } int channel = param.channel; int platform = param.platform; string ver = param.ver; // 保存访问信息 base.SaveVisitInfo("", channel, platform, ver); SiteSettings settings = HiContext.Current.SiteSettings; if (!settings.SMSEnabled || string.IsNullOrEmpty(settings.SMSSettings)) { return(base.JsonFaultResult(new FaultInfo(40999, "手机服务未配置"), request.ToString())); } //生成随机短信验证码 string verifyCode = HiContext.Current.GenerateRandomNumber(4); ConfigData configData = new ConfigData(HiCryptographer.Decrypt(settings.SMSSettings)); SMSSender sMSSender = SMSSender.CreateInstance(settings.SMSSender, configData.SettingsXml); string smsContent = string.Format(SMS_FORART, verifyCode); string msg; bool flag = sMSSender.Send(mobile, smsContent, out msg); if (flag) { // 保存到数据库 Verify verfyinfo = new Verify(); verfyinfo.VerifyCode = verifyCode; verfyinfo.CellPhone = mobile; verfyinfo.CType = cType; TelVerifyHelper.CreateVerify(verfyinfo); Verify verifyto = new TelVerifyDao().GetVerify(mobile); if (verifyto != null && verifyto.CType == cType && verifyto.VerifyCode == verifyCode) { StandardResult <string> okResult = new StandardResult <string>(); okResult.code = 0; okResult.msg = "成功返回短信验证码"; okResult.data = base.Encrypt(verifyCode, sessionKey, sessionSecret); return(base.JsonActionResult(okResult)); } return(base.JsonFaultResult(new CommonException(40205).GetMessage(), request.ToString())); } return(base.JsonFaultResult(new CommonException(40999).GetMessage(), request.ToString())); }
private void SendSMS(HttpContext context) { string parameter = base.GetParameter(context, "content", true); string parameter2 = base.GetParameter(context, "ids", true); string TemplateCode = ""; if (string.IsNullOrWhiteSpace(parameter2)) { throw new HidistroAshxException("请先选择要删除的会员账号"); } if (string.IsNullOrEmpty(parameter)) { throw new HidistroAshxException("请先填写发送的内容信息"); } string sMSSender = base.CurrentSiteSetting.SMSSender; if (string.IsNullOrEmpty(sMSSender)) { throw new HidistroAshxException("请先选择发送方式"); } ConfigData configData = null; if (base.CurrentSiteSetting.SMSEnabled) { configData = new ConfigData(HiCryptographer.TryDecypt(base.CurrentSiteSetting.SMSSettings)); } if (configData == null) { throw new HidistroAshxException("请先选择发送方式并填写配置信息"); } if (!configData.IsValid) { string text = ""; foreach (string errorMsg in configData.ErrorMsgs) { text += Formatter.FormatErrorMessage(errorMsg); } throw new HidistroAshxException(text); } int amount = this.GetAmount(base.CurrentSiteSetting); int[] array = (from d in parameter2.Split(',') where !string.IsNullOrWhiteSpace(d) select int.Parse(d)).ToArray(); parameter2 = string.Join(",", array); int num = array.Count(); int num2 = 0; string text2 = null; IEnumerable <MemberInfo> membersById = MemberHelper.GetMembersById(parameter2); foreach (MemberInfo item in membersById) { string cellPhone = item.CellPhone; if (!string.IsNullOrEmpty(cellPhone) && Regex.IsMatch(cellPhone, "^(13|14|15|18|17)\\d{9}$")) { text2 = text2 + cellPhone + ","; } } if (string.IsNullOrWhiteSpace(text2)) { throw new HidistroAshxException("请先选择要发送的会员或检测所选手机号格式是否正确"); } text2 = text2.Substring(0, text2.Length - 1); string[] array2 = null; array2 = ((!text2.Contains(",")) ? new string[1] { text2 } : text2.Split(',')); if (amount < array2.Length) { throw new HidistroAshxException("发送失败,您的剩余短信条数不足"); } SMSSender sMSSender2 = SMSSender.CreateInstance(sMSSender, configData.SettingsXml); string message = default(string); if (sMSSender2.Send(array2, TemplateCode, parameter, out message)) { base.ReturnSuccessResult(context, (amount - array2.Length).ToString(), 0, true); return; } throw new HidistroAshxException(message); }