Esempio n. 1
0
        public void RetrySMS(int sendMessageHistoryId)
        {
            var sendMessageHistory = this.unitOfWork.Repository <SendMessageHistory>().GetById(sendMessageHistoryId);

            using (var smsClient = new SMSClient(userName, password))
            {
                DateTime?sendTime = null;  // NULL 表示立刻發送
                string   subject  = sendMessageHistory.SendTitle;
                string   message  = sendMessageHistory.SendBody;

                var every8dMessageReceiver = new List <Every8d_MessageReceiver>
                {
                    new Every8d_MessageReceiver
                    {
                        NAME     = sendMessageHistory.DestinationName,
                        MOBILE   = sendMessageHistory.DestinationAddress,
                        EMAIL    = string.Empty, // p.Email, // 不要依賴 Every8d 寄送 Email
                        SENDTIME = null,
                        CONTENT  = message,
                    }
                };

                this.logService.Debug("Every8dSmsProvider(smsProviderType = {0}),重試簡訊(簡訊發送結果歷史紀錄編號:{1},發送內容:{2},發送名單:[{3}])",
                                      smsProviderType.ToString(),
                                      sendMessageHistory.Id,
                                      message,
                                      string.Join("、", every8dMessageReceiver.Select(p => p.MOBILE)));

                if (systemParameters.AllowSendMessage)
                {
                    SEND_SMS_RESULT sendMessageResult = smsClient.SendParamSMS(sendTime, subject, every8dMessageReceiver);

                    this.logService.Debug("Every8dSmsProvider(smsProviderType = {0}),重試簡訊(簡訊發送結果歷史紀錄編號:{1},回傳簡訊發送識別碼:{2},回傳結果:{3})",
                                          smsProviderType.ToString(),
                                          sendMessageHistory.Id,
                                          sendMessageResult.BATCH_ID,
                                          sendMessageResult.ToString());

                    UpdateDb(sendMessageHistory, sendMessageResult);
                }
            }
        }
Esempio n. 2
0
        public void SendSMS(int sendMessageQueueId)
        {
            var sendMessageQueue = this.unitOfWork.Repository <SendMessageQueue>().GetById(sendMessageQueueId);

            using (var smsClient = new SMSClient(userName, password))
            {
                DateTime?sendTime = null;  // NULL 表示立刻發送
                string   subject  = sendMessageQueue.SendTitle;
                string   message  = sendMessageQueue.SendBody;

                var messageReceiver = this.unitOfWork.Repository <MessageReceiver>().GetMany(p =>
                                                                                             p.SendMessageRuleId == sendMessageQueue.SendMessageRuleId &&
                                                                                             p.SendBody == message)
                                      .ToList();

                var every8dMessageReceiver = messageReceiver
                                             .Select(p => new Every8d_MessageReceiver
                {
                    NAME     = p.Name,
                    MOBILE   = p.E164Mobile,
                    EMAIL    = string.Empty, // p.Email, // 不要依賴 Every8d 寄送 Email
                    SENDTIME = null,
                    CONTENT  = message,
                }).ToList();

                this.logService.Debug("Every8dSmsProvider(smsProviderType = {0}),發送簡訊(簡訊編號:{1},簡訊序列編號:{2},發送內容:{3},發送名單(共{4}筆):[{5}])",
                                      smsProviderType.ToString(),
                                      sendMessageQueue.SendMessageRuleId,
                                      sendMessageQueue.Id,
                                      message,
                                      every8dMessageReceiver.Count,
                                      string.Join("、", every8dMessageReceiver.Select(p => p.MOBILE)));

                if (systemParameters.AllowSendMessage)
                {
                    SEND_SMS_RESULT sendMessageResult = smsClient.SendParamSMS(sendTime, subject, every8dMessageReceiver);

                    this.logService.Debug("Every8dSmsProvider(smsProviderType = {0}),發送簡訊(簡訊編號:{1},簡訊序列編號:{2},回傳簡訊發送識別碼:{3},回傳結果:{4})",
                                          smsProviderType.ToString(),
                                          sendMessageQueue.SendMessageRuleId,
                                          sendMessageQueue.Id,
                                          sendMessageResult.BATCH_ID,
                                          sendMessageResult.ToString());

                    // Send Email
                    string   body   = message;
                    string[] emails = messageReceiver.Where(p => !string.IsNullOrEmpty(p.Email)).Select(p => p.Email).ToArray();
                    if (emails.Any())
                    {
                        this.logService.Debug("Every8dSmsProvider(smsProviderType = {0}),發送Email(簡訊編號:{1},簡訊序列編號:{2},主旨:{3},內容:{4},發送名單:[{5}])",
                                              smsProviderType.ToString(),
                                              sendMessageQueue.SendMessageRuleId,
                                              sendMessageQueue.Id,
                                              subject,
                                              body,
                                              string.Join("、", emails));

                        BackgroundJob.Enqueue <CommonMailService>(x => x.Send(subject, body, emails));
                    }
                    else
                    {
                        this.logService.Debug("Every8dSmsProvider(smsProviderType = {0}),無須發送Email(簡訊編號:{1},簡訊序列編號:{2})",
                                              smsProviderType.ToString(),
                                              sendMessageQueue.SendMessageRuleId,
                                              sendMessageQueue.Id);
                    }

                    UpdateDb(sendMessageQueue, sendMessageResult);
                }
            }
        }