Пример #1
0
        static void Main(string[] args)
        {
            SMPPClient client = new SMPPClient();
            SMSC       sms    = new SMSC()
            {
                Host       = "smpp.smsc.ru",
                Port       = 3700,
                SystemId   = "SystemId",
                Password   = "******",
                SourceTon  = 5,
                SourceNpi  = 1,
                AddrTon    = 1,
                AddrNpi    = 1,
                SystemType = ""
            };

            client.AddSMSC(sms);

            if (client.Connect())
            {
                int res = client.SendSms("from", "to", "message");
                Console.WriteLine(res);

                client.Disconnect();
                client.ClearSMSC();
            }

            Console.ReadLine();
        }
Пример #2
0
        public bool SendSms(string from, string to, string text)
        {
            bool result = false;

            Log("Отправляется: from={0} to={1} {2}", from, to, text);

            if (smppClient.CanSend)
            {
                AutoResetEvent sentEvent;
                int            sequence;
                lock (events)
                {
                    sequence         = smppClient.SendSms(from, to, text);
                    sentEvent        = new AutoResetEvent(false);
                    events[sequence] = sentEvent;
                }
                if (sentEvent.WaitOne(waitForResponse, true))
                {
                    lock (events)
                    {
                        events.Remove(sequence);
                    }
                    int  statusCode;
                    bool exist;
                    lock (statusCodes)
                    {
                        exist = statusCodes.TryGetValue(sequence, out statusCode);
                    }
                    if (exist)
                    {
                        lock (statusCodes)
                        {
                            statusCodes.Remove(sequence);
                        }
                        if (statusCode == StatusCodes.ESME_ROK)
                        {
                            result = true;
                        }
                        else
                        {
                            onLog(new LogEventArgs(string.Format("Error: {0} at sequence {1}", statusCode, sequence)));
                        }
                    }
                }
            }
            else
            {
                onLog(new LogEventArgs("Error: canSend = false"));
            }

            return(result);
        }
Пример #3
0
        public bool SendSms(string from, string to, string text)
        {
            bool result = false;

            if (smppClient.CanSend)
            {
                AutoResetEvent sentEvent;
                int            sequence;
                lock (events)
                {
                    sequence         = smppClient.SendSms(from, to, text);
                    sentEvent        = new AutoResetEvent(false);
                    events[sequence] = sentEvent;
                }
                if (sentEvent.WaitOne(waitForResponse, true))
                {
                    lock (events)
                    {
                        events.Remove(sequence);
                    }
                    int  statusCode;
                    bool exist;
                    lock (statusCodes)
                    {
                        exist = statusCodes.TryGetValue(sequence, out statusCode);
                    }
                    if (exist)
                    {
                        lock (statusCodes)
                        {
                            statusCodes.Remove(sequence);
                        }
                        if (statusCode == StatusCodes.ESME_ROK)
                        {
                            result = true;
                        }
                    }
                }
            }
            return(result);
        }