Пример работы с SMS шлюзом на языке C#
Отправка смс
Получения статуса отправленной смс
Получение цены отправки
Получение баланса
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.IO; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { try { var XML = "XML=<?xml version=1.0 encoding=UTF-8?>\n" + "<SMS>\n" + "<operations>\n" + "<operation>SEND</operation>\n" + "</operations>\n" + "<authentification>\n" + "<username></username>\n" + "<password></password>\n" + "</authentification>\n" + "<message>\n" + "<sender>SMS</sender>\n" + "<text>Test message [UTF-8]</text>\n" + "</message>\n" + "<numbers>\n" + "<number messageID=msg11>380972920000</number>\n" + "</numbers>\n" + "</SMS>\n"; HttpWebRequest request = WebRequest.Create("http://api.myatompark.com/members/sms/xml.php") as HttpWebRequest; request.Method = "Post"; request.ContentType = "application/x-www-form-urlencoded"; UTF8Encoding encoding = new UTF8Encoding(); byte[] data = encoding.GetBytes(XML); request.ContentLength = data.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(data, 0, data.Length); using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { if (response.StatusCode != HttpStatusCode.OK) throw new Exception(String.Format( "Server error (HTTP {0}: {1}).", response.StatusCode, response.StatusDescription)); StreamReader reader = new StreamReader(response.GetResponseStream()); Console.WriteLine(reader.ReadToEnd()); Console.ReadKey(); } } catch (Exception e) { Console.WriteLine(e.Message); Console.ReadKey(); } } } }
Получения статуса отправленной смс*:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.IO; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { try { var XML = "XML=<?xml version=1.0 encoding=UTF-8?>\n" + "<SMS>\n" + "<operations>\n" + "<operation>GETPRICE</operation>\n" + "</operations>\n" + "<authentification>\n" + "<username></username>\n" + "<password></password>\n" + "</authentification>\n" + "<statistics>\n" + "<messageid>msg11</messageid>\n" + "</statistics>\n" + "</SMS>\n"; HttpWebRequest request = WebRequest.Create("http://api.myatompark.com/members/sms/xml.php") as HttpWebRequest; request.Method = "Post"; request.ContentType = "application/x-www-form-urlencoded"; UTF8Encoding encoding = new UTF8Encoding(); byte[] data = encoding.GetBytes(XML); request.ContentLength = data.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(data, 0, data.Length); using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { if (response.StatusCode != HttpStatusCode.OK) throw new Exception(String.Format( "Server error (HTTP {0}: {1}).", response.StatusCode, response.StatusDescription)); StreamReader reader = new StreamReader(response.GetResponseStream()); Console.WriteLine(reader.ReadToEnd()); Console.ReadKey(); } } catch (Exception e) { Console.WriteLine(e.Message); Console.ReadKey(); } } } }
* Информация о статусе смс будет доступна спустя несколько минут после отправки
Получение цены отправки:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.IO; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { try { var XML = "XML=<?xml version=1.0 encoding=UTF-8?>\n" + "<SMS>\n" + "<operations>\n" + "<operation>GETPRICE</operation>\n" + "</operations>\n" + "<authentification>\n" + "<username></username>\n" + "<password></password>\n" + "</authentification>\n" + "<message>\n" + "<sender>SMS</sender>\n" + "<text>Test message [UTF-8]</text>\n" + "</message>\n" + "<numbers>\n" + "<number messageID=msg11>380972920000</number>\n" + "</numbers>\n" + "</SMS>\n"; HttpWebRequest request = WebRequest.Create("http://api.myatompark.com/members/sms/xml.php") as HttpWebRequest; request.Method = "Post"; request.ContentType = "application/x-www-form-urlencoded"; UTF8Encoding encoding = new UTF8Encoding(); byte[] data = encoding.GetBytes(XML); request.ContentLength = data.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(data, 0, data.Length); using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { if (response.StatusCode != HttpStatusCode.OK) throw new Exception(String.Format( "Server error (HTTP {0}: {1}).", response.StatusCode, response.StatusDescription)); StreamReader reader = new StreamReader(response.GetResponseStream()); Console.WriteLine(reader.ReadToEnd()); Console.ReadKey(); } } catch (Exception e) { Console.WriteLine(e.Message); Console.ReadKey(); } } } }
Получение баланса
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.IO; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { try { var XML = "XML=<?xml version=1.0 encoding=UTF-8?>\n" + "<SMS>\n" + "<operations>\n" + "<operation>BALANCE</operation>\n" + "</operations>\n" + "<authentification>\n" + "<username></username>\n" + "<password></password>\n" + "</authentification>\n" + "</SMS>\n"; HttpWebRequest request = WebRequest.Create("http://api.myatompark.com/members/sms/xml.php") as HttpWebRequest; request.Method = "Post"; request.ContentType = "application/x-www-form-urlencoded"; UTF8Encoding encoding = new UTF8Encoding(); byte[] data = encoding.GetBytes(XML); request.ContentLength = data.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(data, 0, data.Length); using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { if (response.StatusCode != HttpStatusCode.OK) throw new Exception(String.Format( "Server error (HTTP {0}: {1}).", response.StatusCode, response.StatusDescription)); StreamReader reader = new StreamReader(response.GetResponseStream()); Console.WriteLine(reader.ReadToEnd()); Console.ReadKey(); } } catch (Exception e) { Console.WriteLine(e.Message); Console.ReadKey(); } } } }
По запросу предоставляется необходимое количество дополнительных смс для тестирования сервиса массовых смс-уведомлений ePochta SMS.
Есть вопрос?
- 8 (800) 555-09-63
- Бесплатно по России
Новости:
- 2020-11-27
- Внимание! С 1 декабря 2020 года меняется цена на отправку СМС в сети Билайн
- 2020-11-23
- ePochta объявляет старт Черной Пятницы: Спеццена на рассылку в WhatsApp
- 2020-11-18
- С 1 декабря 2020 года оператор МТС повышает стоимость СМС
- 2020-05-04
- Вебинар: СМС маркетинг. Что писать в тексте СМС рассылок?
- 2020-04-28
- Операторы повышают цены СМС рассылки по прямому каналу в РФ