コード例 #1
0
        public override SentSmsModel Send(SmsModel message, IEnumerable <string> mobileNumbers)
        {
            var messageText = HttpUtility.UrlEncode(message.Message);

            using (var client = new WebClient())
            {
                var numbers = new StringBuilder();
                foreach (var number in mobileNumbers)
                {
                    numbers.AppendFormat("{0},", number);
                }
                if (numbers.Length > 0)
                {
                    numbers.Remove(numbers.Length - 1, 1);
                }

                var response = client.UploadValues("https://api.textlocal.in/send/",
                                                   new NameValueCollection
                {
                    { "apikey", GetSetting("API Key") },
                    { "numbers", numbers.ToString() },
                    { "message", messageText },
                    { "sender", GetSetting("Sender") },
                    { "format", "xml" }
                });
                var result = new XmlDocument();
                result.LoadXml(Encoding.UTF8.GetString(response));

                var sentSms = new SentSmsModel(message, mobileNumbers);
                sentSms.IsSent         = result.DocumentElement.SelectSingleNode("/response/status").InnerText.Trim().Equals("success");
                sentSms.GatewayMessage = sentSms.IsSent ? null : result.DocumentElement.SelectSingleNode("/response/errors/error/message").InnerText.Trim();
                return(sentSms);
            }
        }
コード例 #2
0
 public abstract SentSmsModel Send(SmsModel message, IEnumerable <string> mobileNumbers);
コード例 #3
0
ファイル: SentSmsModel.cs プロジェクト: waliarubal/SmsBuddy
 public SentSmsModel(SmsModel sms, IEnumerable <string> mobileNumbers) : this()
 {
     Message       = sms.Message;
     Time          = DateTime.Now;
     MobileNumbers = new ExtendedObservableCollection <string>(mobileNumbers);
 }