示例#1
0
        public void TestCmppConfigurationSerialize()
        {
            var config1 = new CmppConfiguration()
            {
                HostName       = "127.0.0.1",
                HostPort       = 7891,
                UserName       = "******",
                Password       = "******",
                ServiceId      = "001001",
                SpCode         = "01850",
                KeepConnection = false
            };

            Debug.WriteLine(JsonConvert.SerializeObject(config1));

            var config2 = new CmppConfiguration()
            {
                HostName        = "211.136.112.109",
                HostPort        = 7891,
                UserName        = "******",
                Password        = "******",
                ServiceId       = "10690810",
                SpCode          = "106908100066",
                KeepConnection  = false,
                RemoveSignature = true
            };

            Debug.WriteLine(JsonConvert.SerializeObject(config2));


            var config3 = new CmppConfiguration()
            {
                HostName        = "101.227.68.68",
                HostPort        = 7891,
                UserName        = "******",
                Password        = "******",
                ServiceId       = "HELP",
                SpCode          = "020106",
                KeepConnection  = true,
                RemoveSignature = false
            };

            Debug.WriteLine(JsonConvert.SerializeObject(config3));

            var config4 = new CmppConfiguration()
            {
                HostName        = "58.253.87.82",
                HostPort        = 7890,
                UserName        = "******",
                Password        = "******",
                ServiceId       = "HELP",
                SpCode          = "1069050871325900",
                KeepConnection  = true,
                RemoveSignature = false
            };

            Debug.WriteLine(JsonConvert.SerializeObject(config4));
        }
示例#2
0
        private static void TestSmgpChannel()
        {
            var configs = new CmppConfiguration()
            {
                HostName  = "211.136.112.109",
                HostPort  = 7891,
                UserName  = "******",
                Password  = "******",
                ServiceId = "10690810",
                SpCode    = "106908100066",
            };

            configs = new CmppConfiguration()
            {
                HostName        = "101.227.68.68",
                HostPort        = 7891,
                UserName        = "******",
                Password        = "******",
                ServiceId       = "HELP",
                SpCode          = "020106",
                KeepConnection  = false,
                RemoveSignature = false
            };


            var receiver = Program.GetArgumentValue("no");
            var content  = Program.GetArgumentValue("text");

            if (string.IsNullOrEmpty(receiver))
            {
                receiver = "18613350979";
            }
            if (string.IsNullOrEmpty(content))
            {
                content = "【天天快递】明天下雨,请记得带伞。";
            }

            Console.WriteLine("sending \"{0}\" to {1}...", content, receiver);

            var t = Task.Run(async() =>
            {
                CmppSmsClient client = new CmppSmsClient(configs);
                await client.StartAsync();

                client.SmsResponseReceived += (sender, e) =>
                {
                    var response = e.Envolope.Response as CmppMessageSubmitResponse;
                    Console.WriteLine("<!> RESPONSE: " + response.Result.ToString());
                };

                client.SmsReportReceived += (sender, e) =>
                {
                    var report = e.Report as CmppMessageReport;
                    Console.WriteLine("<!> REPORT: " + report.Stat.ToString());
                };

                await client.SendSmsAsync(receiver, content);
            });

            try
            {
                t.Wait();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            int count = 60;

            while (count > 0)
            {
                count--;
                Console.Title = string.Format("waiting {0}...", count);
                Task.Delay(1000).Wait();
            }
        }