/// <summary> /// 异步发送短信 /// </summary> public static void SendSMSAsync() { //非休息时间 if (!IsNowDuringTheBreakTime()) { int maxSmsCount = Convert.ToInt32(ConfigurationManager.AppSettings["TopSelectNumber"] ?? "50"); var smsList = MessageDA.SelectSMSNotHandledDuringOneHour(maxSmsCount); if (smsList != null && smsList.Count > 0) { smsList.ForEach(sms => { var timeSpanSecond = Convert.ToInt32(ConfigurationManager.AppSettings["TimeSpanSecond"] ?? "30"); //检验手机号是否合法 if (CheckCellPhoneNumber(sms.MsgReceiver) && !MessageDA.CheckSendSMSTimespan(sms.MsgReceiver, timeSpanSecond)) { var paras = from p in sms.TemplateParmaters orderby p.Name ascending select p.Value; try { var result = SMSSenderService.SendSMS(sms.MsgReceiver, sms.ExternalTemplateID, paras.ToArray()); MessageDA.UpdateSmsStatusAfterHandled(sms.SysNo, result); } catch (Exception ex) { Logger.WriteLog(ex.ToString(), "SMS_Exception"); MessageDA.UpdateSmsStatusAfterHandled(sms.SysNo, false); } } }); } } }
public HttpResponseMessage SendFinalSMS(string telefone) { try { SMSSenderService senderService = new SMSSenderService(); senderService.SendSMS(String.Format("55{0}", telefone), "Seus resultados estão prontos! Acesso o site http://www.delboniauriemo.com.br"); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Parâmetros insuficientes")); } }
private void SendNotifications() { while (true) { using (HttpClient httpClient = new HttpClient()) { try { Task <string> response = httpClient.GetStringAsync($"https://api.thingspeak.com/channels/279981/feeds.json?api_key=EXO847SOXW7L55HJ"); JObject json = JObject.Parse(response.Result); IList <JToken> results = json["feeds"].Children().ToList(); IList <JsonHive> hives = new List <JsonHive>(); EmailService es = new EmailService(); SMSSenderService ss = new SMSSenderService(); foreach (var result in results) { JsonHive hiveRes = result.ToObject <JsonHive>(); hives.Add(hiveRes); } foreach (var hive in hives) { if (int.Parse(hive.Temperature) < 15 || int.Parse(hive.Temperature) > 30) { es.SendAsync("*****@*****.**", "Notification", $"The temperature in the hive is {hive.Temperature}. You might go check it!"); ss.SendAsync("+359 89 873 9493", $"The temperature in the hive is {hive.Temperature}. You might go check it!"); } if (int.Parse(hive.Humidity) < 40 || int.Parse(hive.Humidity) > 80) { es.SendAsync("*****@*****.**", "Notification", $"The temperature in the hive is {hive.Temperature}. You might go check it!"); ss.SendAsync("+359 89 873 9493", $"The humidity in the hive is {hive.Humidity}. You might go check it!"); } } } catch (Exception e) { Console.WriteLine(e.Message); } } Thread.Sleep(1 * 1000); // Only do this every 30 seconds } }
public ExtendedContactsController(IOptions <ApplicationSettings> appSettings, DataProtector dataProtector, EncryptionDecryption encryptDecrypt, IHttpContextAccessor httpContextAccessor, ExtendedContactService extendedContactService, DistrictService districtSerice, EmailSenderService emailSenderService, SMSSenderService smsSenderService) { _appSettings = appSettings; _dataProtector = dataProtector; _encryptDecrypt = encryptDecrypt; //_protector = protectionProvider.CreateProtector(GetType().FullName); _session = httpContextAccessor.HttpContext.Session; _request = httpContextAccessor.HttpContext.Request; _extendedContactService = extendedContactService; _districtSerice = districtSerice; _emailSenderService = emailSenderService; _smsSenderService = smsSenderService; }
public HttpResponseMessage ReceiverRating(NPSApiModel model) { try { NPSRepository repository = new NPSRepository(); NPSModel newNPS = new NPSModel(); newNPS.FAP = model.FAP.Replace(".", ""); newNPS.Celular = model.Celular; newNPS.AtendimentoNota = model.AtendimentoNota.Replace(".", ","); newNPS.InstalacaoNota = model.InstalacaoNota.Replace(".", ","); newNPS.RecomendacaoNota = model.RecomendacaoNota.Replace(".", ","); newNPS.Observacao = model.Observacao; newNPS.DataAvaliacao = Convert.ToDateTime(DateTime.Now); newNPS.IDLab = 1; repository.Add(newNPS); if ((Convert.ToDecimal(newNPS.AtendimentoNota) <= 2) || (Convert.ToDecimal(newNPS.InstalacaoNota) <= 2) || (Convert.ToDecimal(newNPS.RecomendacaoNota) <= 2)) { sendEmail(model); } var mensagem = "Obrigado! Você receberá um SMS quando seus exames ficarem prontos."; SMSSenderService senderService = new SMSSenderService(); senderService.SendSMS(String.Format(String.Format("55{0}", newNPS.Celular)), mensagem); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, e.Message)); } }
public HomeController(IOptions <ApplicationSettings> appSettings, SMSSenderService smsSenderService) { _smsSenderService = smsSenderService; _appSettings = appSettings; }