SendSMS() public static method

public static SendSMS ( string message, string to, string from ) : void
message string
to string
from string
return void
Ejemplo n.º 1
0
        private static void ReceiveUDP(IAsyncResult ar)
        {
            var u        = (UdpClient)((UdpState)(ar.AsyncState)).u;
            var e        = (IPEndPoint)((UdpState)(ar.AsyncState)).e;
            var rawBytes = new List <byte>();

            rawBytes.AddRange(u.EndReceive(ar, ref e));
            var FromAddress = rawBytes.GetRange(1, rawBytes[0]);

            var receiveBytes = rawBytes.GetRange(rawBytes[0] + 1, rawBytes.Count - 1 - rawBytes[0]).ToArray();

            switch ((PDUbase.MessageTypeIndicator)receiveBytes[0])
            {
            case PDUbase.MessageTypeIndicator.DeliverReport:
            case PDUbase.MessageTypeIndicator.Command:
                break;

            case PDUbase.MessageTypeIndicator.Submit:
                var packet = new SMS_Submit {
                    BinaryForm = receiveBytes
                };
                var hairpin = packet.DestinationAddress.ToString().StartsWith("21") ||
                              packet.DestinationAddress.ToString().StartsWith("11");
                if (hairpin)
                {
                    UDP.SendSMS(packet.UserData.ToString(), packet.DestinationAddress.ToString(), FromAddress.ToString());
                    break;
                }
                Http.SendSMS(packet.UserData.ToString(), packet.DestinationAddress.ToString(), "");
                break;

            default:
                break;
            }
        }
Ejemplo n.º 2
0
        private static void OnPost(IAsyncResult ar)
        {
            var listener = (HttpListener)ar.AsyncState;
            // Call EndGetContext to complete the asynchronous operation.
            var context = listener.EndGetContext(ar);
            var request = context.Request;
            // Obtain a response object.
            var response = context.Response;

            try
            {
                if (request.ContentLength64 > 160)
                {
                    response.StatusCode = 413;
                    var bufferb = System.Text.Encoding.UTF8.GetBytes("ENTITY TOO LARGE");
                    // Get a response stream and write the response to it.
                    response.ContentLength64 = bufferb.Length;
                    var outputr = response.OutputStream;
                    outputr.Write(bufferb, 0, bufferb.Length);
                    // You must close the output stream.
                    outputr.Close();
                }

                response.StatusCode = 202;

                var bytes = new byte[request.ContentLength64];
                request.InputStream.Read(bytes, 0, (int)request.ContentLength64);
                // Construct a response.
                UDP.SendSMS(bytes.ToString(), request.Url.AbsolutePath.TrimEnd('/').Split('/').Last(), "123456");
                var responseString = "ACCEPTED";
                var buffer         = System.Text.Encoding.UTF8.GetBytes(responseString);
                // Get a response stream and write the response to it.
                response.ContentLength64 = buffer.Length;
                var output = response.OutputStream;
                output.Write(buffer, 0, buffer.Length);
                // You must close the output stream.
                output.Close();
            }catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                response.StatusCode = 567;
                var buffer = System.Text.Encoding.UTF8.GetBytes("F****D UP REQUEST");
                // Get a response stream and write the response to it.
                response.ContentLength64 = buffer.Length;
                var outputr = response.OutputStream;
                outputr.Write(buffer, 0, buffer.Length);
                // You must close the output stream.
                outputr.Close();
            }

            listener.BeginGetContext(OnPost, null);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            //var fjf = new BinaryReader(new FileStream("hi", FileMode.OpenOrCreate));
            UDP.Start();
            Http.Start();
            var testSend = false;

            while (true)
            {
                Thread.Sleep(1000);

                if (testSend)
                {
                    UDP.SendSMS("Hello World", "1234", "123456");
                    testSend = false;
                }
            }
        }