Ejemplo n.º 1
0
        public static string Send(string queue_url, string msg)
        {
            AmazonSQS          sqs    = AWSClientFactory.CreateAmazonSQSClient();
            SendMessageRequest msgreq = new SendMessageRequest();

            msgreq.QueueUrl    = queue_url;
            msgreq.MessageBody = msg;
            SendMessageResponse msgres = sqs.SendMessage(msgreq);
            SendMessageResult   msgrst = msgres.SendMessageResult;

            return(msgrst.ToString());
        }
Ejemplo n.º 2
0
        public void RetrySMS(int sendMessageHistoryId)
        {
            var sendMessageHistory = this.unitOfWork.Repository <SendMessageHistory>().GetById(sendMessageHistoryId);

            string message = sendMessageHistory.SendBody;

            var senderAddress = sendMessageHistory.SenderAddress;

            string[] recipientAddress = { sendMessageHistory.DestinationAddress };

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

            if (systemParameters.AllowSendMessage)
            {
                var smsRequest = new SMSRequest(senderAddress, message, recipientAddress);
                // 還是不知道怎麼使用
                // http://dev.infobip.com/v1/docs/logs-vs-delivery-reports
                // http://dev.infobip.com/docs/notify-url
                // 還是不知道怎麼使用 smsRequest.NotifyURL = "";
                //smsRequest.NotifyURL = @"http://zutech-sms.azurewebsites.net/api/InfobipNotification";

                SendMessageResult sendMessageResult = this.smsClient.SmsMessagingClient.SendSMS(smsRequest);

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

                string requestId = sendMessageResult.ClientCorrelator; // you can use this to get deliveryReportList later.

                UpdateDb_RetrySMS(sendMessageHistory, sendMessageResult);
            }
        }
Ejemplo n.º 3
0
        public void SendSMS(int sendMessageQueueId)
        {
            var sendMessageQueue = this.unitOfWork.Repository <SendMessageQueue>().GetById(sendMessageQueueId);

            string message = sendMessageQueue.SendBody;

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

            var senderAddress   = string.Empty;
            var sendMessageRule = this.unitOfWork.Repository <SendMessageRule>().GetById(sendMessageQueue.SendMessageRuleId);

            if (sendMessageRule != null)
            {
                senderAddress = sendMessageRule.SenderAddress;
            }

            string[] recipientAddress = messageReceivers.Select(p => p.E164Mobile).ToArray();

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

            if (systemParameters.AllowSendMessage)
            {
                var smsRequest = new SMSRequest(senderAddress, message, recipientAddress);
                //smsRequest.NotifyURL = "http://zutech-sms.azurewebsites.net/api/InfobipDeliveryReport";
                // 還是不知道怎麼使用
                // http://dev.infobip.com/v1/docs/logs-vs-delivery-reports
                // http://dev.infobip.com/docs/notify-url


                SendMessageResult sendMessageResult = this.smsClient.SmsMessagingClient.SendSMS(smsRequest);

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

                // Send Email
                string   subject = sendMessageQueue.SendTitle;
                string   body    = message;
                string[] emails  = messageReceivers.Where(p => !string.IsNullOrEmpty(p.Email)).Select(p => p.Email).ToArray();
                if (emails.Any())
                {
                    this.logService.Debug("InfobipSmsProvider(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("InfobipSmsProvider(smsProviderType = {0}),無須發送Email(簡訊編號:{1},簡訊序列編號:{2})",
                                          smsProviderType.ToString(),
                                          sendMessageQueue.SendMessageRuleId,
                                          sendMessageQueue.Id);
                }

                string requestId = sendMessageResult.ClientCorrelator; // you can use this to get deliveryReportList later.

                UpdateDb_SendSMS(sendMessageQueue, messageReceivers, sendMessageResult);
            }
        }