using RabbitMQ.Client; using System.Diagnostics; using System.Threading.Channels; using RabbitMQ.Client.Events; using Newtonsoft.Json; using System.Text; namespace smsdemo { public partial class Form1 : Form { private int clickX = 0; // 点击的X坐标 private int clickY = 0; // 点击的Y坐标 private int sendCount = 0; // 发送的短信数量 private bool isServiceRun = false; // 是否服务化运行 private bool isADBTap = false; // 是否adb点击 private static IConnection connection; private static IChannel channel; private static AsyncEventingBasicConsumer consumer; private static string queueName = "queue_sms_local_send"; private static string hostName = "100.64.0.25:5672"; public Form1() { InitializeComponent(); using (MemoryStream ms = new MemoryStream(Properties.Resources.net_0)) { Image image = Image.FromStream(ms); // 假设 PictureBox 控件名为 pictureBox1 pictureBox1.Image = image; } using (MemoryStream ms = new MemoryStream(Properties.Resources.adb_0)) { Image image = Image.FromStream(ms); // 假设 PictureBox 控件名为 pictureBox1 pictureBox2.Image = image; } using (MemoryStream ms = new MemoryStream(Properties.Resources.error_1)) { Image image = Image.FromStream(ms); // 假设 PictureBox 控件名为 pictureBox1 pictureBox3.Image = image; } using (MemoryStream ms = new MemoryStream(Properties.Resources.send_1)) { Image image = Image.FromStream(ms); // 假设 PictureBox 控件名为 pictureBox1 pictureBox4.Image = image; } Connect(); } static void Connect() { try { var factory = new ConnectionFactory { HostName = hostName , VirtualHost="/",UserName= "admin", Password= "admin" }; factory.Uri = new Uri("amqp://admin:admin@100.64.0.25:5672/"); connection = factory.CreateConnectionAsync().Result; channel = connection.CreateChannelAsync().Result; channel.QueueDeclareAsync(queue: queueName, durable: false, exclusive: false, autoDelete: false, arguments: null); consumer = new AsyncEventingBasicConsumer(channel); channel.QueueBindAsync(queue: "queue_sms_local_send", exchange: "exchange_sms_local_send", routingKey: "sms", arguments: null).Wait(); consumer.ReceivedAsync += async (model, ea) => { var body = ea.Body.ToArray(); var message = Encoding.UTF8.GetString(body); try { dynamic json = JsonConvert.DeserializeObject(message)!; Console.WriteLine($"Received JSON: {json}"); string? mobile = json.mobile; string? code = json.code; if (mobile != null && code != null) { Console.WriteLine($"Received mobile: {mobile}, code: {code}"); } else { Console.WriteLine("JSON does not contain 'mobile' or 'code' fields."); } } catch (JsonException ex) { Console.WriteLine($"Error deserializing JSON: {ex.Message}"); } await Task.CompletedTask; // Ensure all code paths return a Task }; channel.BasicConsumeAsync(queue: queueName, autoAck: true, consumer: consumer); connection.ConnectionShutdownAsync += async (sender, args) => { Console.WriteLine("Connection shut down. Reconnecting..."); await Task.Run(() => Reconnect()); }; } catch (Exception ex) { Console.WriteLine($"Connection error: {ex.Message}. Reconnecting in 5 seconds..."); System.Threading.Thread.Sleep(5000); Reconnect(); } } static void Reconnect() { while (true) { try { Disconnect(); Connect(); Console.WriteLine("Reconnected successfully."); break; } catch (Exception ex) { Console.WriteLine($"Reconnection failed: {ex.Message}. Retrying in 5 seconds..."); System.Threading.Thread.Sleep(5000); } } } static void Disconnect() { if (channel != null && channel.IsOpen) { channel.AbortAsync(); } if (connection != null && connection.IsOpen) { connection.Dispose(); } } private void button1_Click(object sender, EventArgs e) { textBox1.Text = ""; textBox2.Text = ""; } private void button2_Click(object sender, EventArgs e) { var phone = textBox1.Text; var text = textBox2.Text; if (string.IsNullOrEmpty(phone) || string.IsNullOrEmpty(text)) { MessageBox.Show("Please enter a phone number and message text."); return; } try { // 创建一个 ProcessStartInfo 对象,用于配置要启动的进程 ProcessStartInfo psi = new ProcessStartInfo { //adb shell am start -a android.intent.action.SENDTO -d sms:目标手机号码 --es sms_body "短信内容" --ez exit_on_sent true FileName = "adb.exe", // 要启动的程序,这里是命令行解释器 Arguments = " shell am start -a android.intent.action.SENDTO -d sms:" + phone + " --es sms_body \"" + text + "\" --ez exit_on_sent true", // 传递给 cmd.exe 的参数,/c 表示执行完命令后关闭命令行窗口,dir 是要执行的命令,这里以列出目录内容为例 UseShellExecute = false, // 不使用系统外壳程序启动进程 RedirectStandardOutput = true, // 重定向标准输出流,以便获取命令执行结果 CreateNoWindow = true // 不创建新的命令行窗口 }; // 创建一个 Process 对象并启动进程 using (Process process = new Process { StartInfo = psi }) { process.Start(); // 读取命令执行的结果 string output = process.StandardOutput.ReadToEnd(); // 等待进程执行完毕 process.WaitForExit(); // 在文本框中显示命令执行结果 textBox3.Text += output; } Thread.Sleep(2000); ProcessStartInfo psisend = new ProcessStartInfo { //adb shell am start -a android.intent.action.SENDTO -d sms:目标手机号码 --es sms_body "短信内容" --ez exit_on_sent true FileName = "adb.exe", // 要启动的程序,这里是命令行解释器 Arguments = "shell input tap 1010 1414", // 传递给 cmd.exe 的参数,/c 表示执行完命令后关闭命令行窗口,dir 是要执行的命令,这里以列出目录内容为例 UseShellExecute = false, // 不使用系统外壳程序启动进程 RedirectStandardOutput = true, // 重定向标准输出流,以便获取命令执行结果 CreateNoWindow = true // 不创建新的命令行窗口 }; // 创建一个 Process 对象并启动进程 using (Process process = new Process { StartInfo = psisend }) { process.Start(); // 读取命令执行的结果 string output = process.StandardOutput.ReadToEnd(); // 等待进程执行完毕 process.WaitForExit(); // 在文本框中显示命令执行结果 textBox3.Text += output; } sendCount++; } catch (Exception ex) { MessageBox.Show($"执行命令时发生错误: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void timer1_Tick(object sender, EventArgs e) { //检查adb连接 //30s 检查一次 ProcessStartInfo psi = new ProcessStartInfo { FileName = "adb.exe", Arguments = "devices", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true }; } private void button3_Click(object sender, EventArgs e) { //初始化adb } private void button4_Click(object sender, EventArgs e) { using (MemoryStream ms = new MemoryStream(Properties.Resources.net_0)) { Image image = Image.FromStream(ms); // 假设 PictureBox 控件名为 pictureBox1 pictureBox1.Image = image; } using (MemoryStream ms = new MemoryStream(Properties.Resources.adb_0)) { Image image = Image.FromStream(ms); // 假设 PictureBox 控件名为 pictureBox1 pictureBox2.Image = image; } using (MemoryStream ms = new MemoryStream(Properties.Resources.error_1)) { Image image = Image.FromStream(ms); // 假设 PictureBox 控件名为 pictureBox1 pictureBox3.Image = image; } using (MemoryStream ms = new MemoryStream(Properties.Resources.send_1)) { Image image = Image.FromStream(ms); // 假设 PictureBox 控件名为 pictureBox1 pictureBox4.Image = image; } //自检 Reconnect(); Thread.Sleep(2000); //网络 using (MemoryStream ms = new MemoryStream(Properties.Resources.net_1)) { Image image = Image.FromStream(ms); // 假设 PictureBox 控件名为 pictureBox1 pictureBox1.Image = image; } using (MemoryStream ms = new MemoryStream(Properties.Resources.adb_1)) { Image image = Image.FromStream(ms); // 假设 PictureBox 控件名为 pictureBox1 pictureBox2.Image = image; } using (MemoryStream ms = new MemoryStream(Properties.Resources.error_0)) { Image image = Image.FromStream(ms); // 假设 PictureBox 控件名为 pictureBox1 pictureBox3.Image = image; } using (MemoryStream ms = new MemoryStream(Properties.Resources.send_0)) { Image image = Image.FromStream(ms); // 假设 PictureBox 控件名为 pictureBox1 pictureBox4.Image = image; } //adb } private void button5_Click(object sender, EventArgs e) { //校准屏幕点击 } private void textBox4_TextChanged(object sender, EventArgs e) { } private void button6_Click(object sender, EventArgs e) { //统计 MessageBox.Show("共发送短信:"+ sendCount); } } }