예제 #1
0
        public void TestServerSmgpSendSmsSimple()
        {
            var client = new SmgpSmsClient(_configurations);

            var server = new SmgpSmsServer(new SmsServerConfigurations()
            {
                HostName  = _configurations.HostName,
                HostPort  = _configurations.HostPort,
                UserName  = _configurations.UserName,
                Password  = _configurations.UserName,
                ServiceID = _configurations.ServiceId,
            });


            var ts1 = server.StartAsync();

            ts1.Wait();


            var receivers = new string[] { "18613350979" };
            var content   = "【测试短信】测试短信";

            var cancel = new CancellationTokenSource();

            client.SmsResponseReceived += (sender, e) =>
            {
                var response = e.Envolope.Response as SmgpMessageSubmitResponse;
                Debug.WriteLine("<!>RESPONSE: {0}", response.Status);
            };

            client.SmsReportReceived += (sender, e) =>
            {
                var report = e.Report as SmgpMessageReport;
                Debug.WriteLine("<!>REPORT: {0}", report.Status);
                cancel.Cancel();
            };

            Task.Run(async() =>
            {
                //await client.StartAsync();
                await client.SendSmsAsync(receivers, content);

                await Task.Delay(150000, cancel.Token);

                await client.StopAsync();
            }).Wait();

            var ts2 = server.StopAsync();

            ts2.Wait();
        }
예제 #2
0
        private static void RunSmgpServer()
        {
            var smgpConfigurations = Program.SmgpServerConfigurations;
            var server1            = new SmgpSmsServer(smgpConfigurations);
            var t1 = server1.StartAsync();

            t1.Wait();

            Console.Title = "SMGP Gateway";
            Console.WriteLine("Ready.");
            while (true)
            {
                if (Console.KeyAvailable)
                {
                    var key = Console.ReadKey(true);
                    if (key.Key == ConsoleKey.Escape && (key.Modifiers & ConsoleModifiers.Shift) != 0)
                    {
                        break;
                    }
                    else if (key.Key == ConsoleKey.F3)
                    {
                        var text = server1.GetStats();
                        Console.WriteLine(text);
                        server1.ClearStats();
                    }
                    else if (key.Key == ConsoleKey.F4)
                    {
                        var task = server1.BroadcastTestUplinkMessageAsync();
                        task.Wait();
                        if (task.Result)
                        {
                            Console.WriteLine("completed...");
                        }
                        Console.WriteLine();
                    }
                    else if (key.Key == ConsoleKey.F5)
                    {
                        Console.Write("Please enter the number of test strips: ");
                        string input = Console.ReadLine();
                        int    count = 1;
                        if (int.TryParse(input, out count))
                        {
                            var task = server1.BroadcastTestUplinkMessageLoopAsync(count);
                            task.Wait();
                            if (task.Result)
                            {
                                Console.WriteLine("completed...");
                            }
                            Console.WriteLine();
                        }
                    }
                }
                Task.Delay(100).Wait();
            }
            Console.WriteLine("Terminating...");
            var t2 = server1.StopAsync();

            t2.Wait();

            var stats = server1.GetStats();

            Console.WriteLine(stats);
        }