How to create an SMS gateway?

后端 未结 4 1247
孤街浪徒
孤街浪徒 2021-02-01 10:19

I know there are lots of 3rd party sites to send bulk SMS via the internet, but if I wanted to create one myself, how would I go about it? I know how to create an SMS gateway us

4条回答
  •  南笙
    南笙 (楼主)
    2021-02-01 10:59

    it can be done in Two Ways 1)GSM modem 2)http (service provider)(Faster than Modem)

    I have used http://www.ozekisms.com/ gateway Service

    C# Code to send Http Request and how to add User name and Password IP address and Port.

    Refer this Code hope will help you out.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using SMSClient;
    
    namespace SMSDemoConsole
    {
        class Program
        {
            private static void WriteEvent(String myEvent)
            {
                Console.WriteLine(myEvent);
            }
    
            #region Events
            static void mySMSClient_OnMessageReceived(object sender, DeliveryEventArgs e)
            {
                WriteEvent(DateTime.Now.ToString() + " " + "Message received. Sender address: " + e.Senderaddress + " Message text: " + e.Messagedata + "\r\n");
            }
    
            static void mySMSClient_OnMessageDeliveryError(object sender, DeliveryErrorEventArgs e)
            {
                WriteEvent(DateTime.Now.ToString() + " " + "Message could not be delivered. ID: " + e.Messageid + " Error message: " + e.ErrorMessage + "\r\n");
            }
    
            static void mySMSClient_OnMessageDeliveredToHandset(object sender, DeliveryEventArgs e)
            {
                WriteEvent(DateTime.Now.ToString() + " " + "Message delivered to handset. ID: " + e.Messageid + "\r\n");
            }
    
            static void mySMSClient_OnMessageDeliveredToNetwork(object sender, DeliveryEventArgs e)
            {
                WriteEvent(DateTime.Now.ToString() + " " + "Message delivered to network. ID: " + e.Messageid + "\r\n");
            }
    
            static void mySMSClient_OnMessageAcceptedForDelivery(object sender, DeliveryEventArgs e)
            {
                WriteEvent(DateTime.Now.ToString() + " " + "Message accepted for delivery. ID: " + e.Messageid + "\r\n");
            }
    
            static void mySMSClient_OnClientConnectionError(object sender, ErrorEventArgs e)
            {
                WriteEvent(DateTime.Now.ToString() + " " + e.ErrorMessage + "\r\n");
            }
    
            static void mySMSClient_OnClientDisconnected(object sender, EventArgs e)
            {
                WriteEvent(DateTime.Now.ToString() + " Disconnected from the SMS gateway " + "\r\n");
            }
    
            static void mySMSClient_OnClientConnected(object sender, EventArgs e)
            {
                WriteEvent(DateTime.Now.ToString() + " Successfully connected to the SMS gateway " + "\r\n");
            }
            #endregion
    
            static void Main(string[] args)
            {
                ozSMSClient mySMSClient = new ozSMSClient();
                mySMSClient.OnClientConnected += new SimpleEventHandler(mySMSClient_OnClientConnected);
                mySMSClient.OnClientDisconnected += new SimpleEventHandler(mySMSClient_OnClientDisconnected);
                mySMSClient.OnClientConnectionError += new ErrorEventHandler(mySMSClient_OnClientConnectionError);
                mySMSClient.OnMessageAcceptedForDelivery += new DeliveryEventHandler(mySMSClient_OnMessageAcceptedForDelivery);
                mySMSClient.OnMessageDeliveredToNetwork += new DeliveryEventHandler(mySMSClient_OnMessageDeliveredToNetwork);
                mySMSClient.OnMessageDeliveredToHandset += new DeliveryEventHandler(mySMSClient_OnMessageDeliveredToHandset);
                mySMSClient.OnMessageDeliveryError += new DeliveryErrorEventHandler(mySMSClient_OnMessageDeliveryError);
                mySMSClient.OnMessageReceived += new DeliveryEventHandler(mySMSClient_OnMessageReceived);
    
                mySMSClient.Username = "admin";
                mySMSClient.Password = "abc123";
                mySMSClient.Host = "127.0.0.1";
                mySMSClient.Port = 9500;
    
                mySMSClient.Connected = true;
    
                mySMSClient.sendMessage("+44987654", "TEST", "vp=" + DateTime.Now + "&ttt=werwerwe rewwe34232 1");
    
    
                Console.ReadKey();
                mySMSClient.Connected = false;
            }
        }
    }
    

    Thanks.

提交回复
热议问题