private static void SendMessage(NotificationTaskQueue notificationTaskQueue) { var credentials = new NotificationsCredentials { EmailFrom = Properties.Settings.Default.EmailFrom, EmailPassword = Properties.Settings.Default.EmailPassword, SmtpPort = Properties.Settings.Default.SmtpPort, SmtpServer = Properties.Settings.Default.SmtpServer, SmscLogin = Properties.Settings.Default.SmscLogin, SmscPassword = Properties.Settings.Default.SmscPassword }; new NotificationSender().SendNotificationByNotificationTaskQueueId(notificationTaskQueue.Id, credentials); }
public SmsResponceModel SendSms(string phones, string message, NotificationsCredentials credentials, int translit = 1, string time = "", int id = 0, int format = 0, string sender = "", string query = "") { string[] formats = { "flash=1", "push=1", "hlr=1", "bin=1", "bin=2", "ping=1", "mms=1", "mail=1", "call=1" }; // (id, cnt, cost, balance) или (id, -error) return(SmscSendCmd("send", "phones=" + UrlEncode(phones) + "&mes=" + UrlEncode(message) + "&id=" + id + "&translit=" + translit + (format > 0 ? "&" + formats[format - 1] : "") + (sender != "" ? "&sender=" + UrlEncode(sender) : "") + (time != "" ? "&time=" + UrlEncode(time) : "") + (query != "" ? "&" + query : ""), credentials)); }
private SmsResponceModel SmscSendCmd(string cmd, string arg, NotificationsCredentials credentials) { string url, _url; arg = "login="******"&psw=" + UrlEncode(credentials.SmscPassword) + "&fmt=3&charset=" + SmscCharset + "&" + arg; url = _url = $"http://smsc.kz/sys/{cmd}.php{(_smscPost ? "" : "?" + arg)}"; string ret; int index = 0; HttpWebRequest request; StreamReader sr; HttpWebResponse response; do { if (index++ > 0) { url = _url.Replace("smsc.kz/", "www" + index + ".smsc.kz/"); } request = (HttpWebRequest)WebRequest.Create(url); try { response = (HttpWebResponse)request.GetResponse(); sr = new StreamReader(response.GetResponseStream()); ret = sr.ReadToEnd(); } catch (WebException) { ret = ""; } } while (ret == "" && index < 5); return(JsonConvert.DeserializeObject <SmsResponceModel>(ret)); }
public void SendNotificationByNotificationTaskQueueId(int notificationTaskQueueId, NotificationsCredentials credentials) { var notificationTaskQueue = _executor.GetQuery <GetNotificationTaskQueueByIdQuery>().Process(q => q.Execute(notificationTaskQueueId)); if (notificationTaskQueue != null) { if (notificationTaskQueue.ConditionStageId == null || notificationTaskQueue.Document.CurrentWorkflows.Any(d => d.CurrentStage.Code.Equals(notificationTaskQueue.ConditionStage.Code))) //if (notificationTaskQueue.ConditionStageId == null || notificationTaskQueue.ConditionStage.Code.Equals(notificationTaskQueue.Document.CurrentWorkflow.CurrentStage.Code)) { var sendModel = new SendModel { IsSms = notificationTaskQueue.IsSms, EmailAddresses = notificationTaskQueue.DicCustomer.ContactInfos .Where(ci => ci.Type.Code == DicContactInfoType.Codes.Email) .Select(ci => ci.Info) .ToList(), MobilePhones = notificationTaskQueue.DicCustomer.ContactInfos .Where(ci => ci.Type.Code == DicContactInfoType.Codes.MobilePhone) .Select(ci => ci.Info) .ToList(), Message = notificationTaskQueue.Message, Subject = notificationTaskQueue.Subject, Attachment = notificationTaskQueue.Attachment, Credentials = credentials }; var statusCode = new SendHelper().Send(sendModel); // TODO: Если успешно отправлено, ставить Executed, если нет, то обновить дату отправки сообщения. _executor.GetHandler <UpdateNotificationStatusHandler>().Process <int>(h => h.Handle(notificationTaskQueue, statusCode)); } } }