Form1.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. using RabbitMQ.Client;
  2. using System.Diagnostics;
  3. using System.Threading.Channels;
  4. using RabbitMQ.Client.Events;
  5. using Newtonsoft.Json;
  6. using System.Text;
  7. namespace smsdemo
  8. {
  9. public partial class Form1 : Form
  10. {
  11. private int clickX = 0; // 点击的X坐标
  12. private int clickY = 0; // 点击的Y坐标
  13. private int sendCount = 0; // 发送的短信数量
  14. private bool isServiceRun = false; // 是否服务化运行
  15. private bool isADBTap = false; // 是否adb点击
  16. private static IConnection connection;
  17. private static IChannel channel;
  18. private static AsyncEventingBasicConsumer consumer;
  19. private static string queueName = "queue_sms_local_send";
  20. private static string hostName = "100.64.0.25:5672";
  21. public Form1()
  22. {
  23. InitializeComponent();
  24. using (MemoryStream ms = new MemoryStream(Properties.Resources.net_0))
  25. {
  26. Image image = Image.FromStream(ms);
  27. // 假设 PictureBox 控件名为 pictureBox1
  28. pictureBox1.Image = image;
  29. }
  30. using (MemoryStream ms = new MemoryStream(Properties.Resources.adb_0))
  31. {
  32. Image image = Image.FromStream(ms);
  33. // 假设 PictureBox 控件名为 pictureBox1
  34. pictureBox2.Image = image;
  35. }
  36. using (MemoryStream ms = new MemoryStream(Properties.Resources.error_1))
  37. {
  38. Image image = Image.FromStream(ms);
  39. // 假设 PictureBox 控件名为 pictureBox1
  40. pictureBox3.Image = image;
  41. }
  42. using (MemoryStream ms = new MemoryStream(Properties.Resources.send_1))
  43. {
  44. Image image = Image.FromStream(ms);
  45. // 假设 PictureBox 控件名为 pictureBox1
  46. pictureBox4.Image = image;
  47. }
  48. Connect();
  49. }
  50. static void Connect()
  51. {
  52. try
  53. {
  54. var factory = new ConnectionFactory { HostName = hostName , VirtualHost="/",UserName= "admin", Password= "admin" };
  55. factory.Uri = new Uri("amqp://admin:admin@100.64.0.25:5672/");
  56. connection = factory.CreateConnectionAsync().Result;
  57. channel = connection.CreateChannelAsync().Result;
  58. channel.QueueDeclareAsync(queue: queueName, durable: false, exclusive: false, autoDelete: false, arguments: null);
  59. consumer = new AsyncEventingBasicConsumer(channel);
  60. channel.QueueBindAsync(queue: "queue_sms_local_send", exchange: "exchange_sms_local_send", routingKey: "sms", arguments: null).Wait();
  61. consumer.ReceivedAsync += async (model, ea) =>
  62. {
  63. var body = ea.Body.ToArray();
  64. var message = Encoding.UTF8.GetString(body);
  65. try
  66. {
  67. dynamic json = JsonConvert.DeserializeObject(message)!;
  68. Console.WriteLine($"Received JSON: {json}");
  69. string? mobile = json.mobile;
  70. string? code = json.code;
  71. if (mobile != null && code != null)
  72. {
  73. Console.WriteLine($"Received mobile: {mobile}, code: {code}");
  74. }
  75. else
  76. {
  77. Console.WriteLine("JSON does not contain 'mobile' or 'code' fields.");
  78. }
  79. }
  80. catch (JsonException ex)
  81. {
  82. Console.WriteLine($"Error deserializing JSON: {ex.Message}");
  83. }
  84. await Task.CompletedTask; // Ensure all code paths return a Task
  85. };
  86. channel.BasicConsumeAsync(queue: queueName, autoAck: true, consumer: consumer);
  87. connection.ConnectionShutdownAsync += async (sender, args) =>
  88. {
  89. Console.WriteLine("Connection shut down. Reconnecting...");
  90. await Task.Run(() => Reconnect());
  91. };
  92. }
  93. catch (Exception ex)
  94. {
  95. Console.WriteLine($"Connection error: {ex.Message}. Reconnecting in 5 seconds...");
  96. System.Threading.Thread.Sleep(5000);
  97. Reconnect();
  98. }
  99. }
  100. static void Reconnect()
  101. {
  102. while (true)
  103. {
  104. try
  105. {
  106. Disconnect();
  107. Connect();
  108. Console.WriteLine("Reconnected successfully.");
  109. break;
  110. }
  111. catch (Exception ex)
  112. {
  113. Console.WriteLine($"Reconnection failed: {ex.Message}. Retrying in 5 seconds...");
  114. System.Threading.Thread.Sleep(5000);
  115. }
  116. }
  117. }
  118. static void Disconnect()
  119. {
  120. if (channel != null && channel.IsOpen)
  121. {
  122. channel.AbortAsync();
  123. }
  124. if (connection != null && connection.IsOpen)
  125. {
  126. connection.Dispose();
  127. }
  128. }
  129. private void button1_Click(object sender, EventArgs e)
  130. {
  131. textBox1.Text = "";
  132. textBox2.Text = "";
  133. }
  134. private void button2_Click(object sender, EventArgs e)
  135. {
  136. var phone = textBox1.Text;
  137. var text = textBox2.Text;
  138. if (string.IsNullOrEmpty(phone) || string.IsNullOrEmpty(text))
  139. {
  140. MessageBox.Show("Please enter a phone number and message text.");
  141. return;
  142. }
  143. try
  144. {
  145. // 创建一个 ProcessStartInfo 对象,用于配置要启动的进程
  146. ProcessStartInfo psi = new ProcessStartInfo
  147. {
  148. //adb shell am start -a android.intent.action.SENDTO -d sms:目标手机号码 --es sms_body "短信内容" --ez exit_on_sent true
  149. FileName = "adb.exe", // 要启动的程序,这里是命令行解释器
  150. 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 是要执行的命令,这里以列出目录内容为例
  151. UseShellExecute = false, // 不使用系统外壳程序启动进程
  152. RedirectStandardOutput = true, // 重定向标准输出流,以便获取命令执行结果
  153. CreateNoWindow = true // 不创建新的命令行窗口
  154. };
  155. // 创建一个 Process 对象并启动进程
  156. using (Process process = new Process { StartInfo = psi })
  157. {
  158. process.Start();
  159. // 读取命令执行的结果
  160. string output = process.StandardOutput.ReadToEnd();
  161. // 等待进程执行完毕
  162. process.WaitForExit();
  163. // 在文本框中显示命令执行结果
  164. textBox3.Text += output;
  165. }
  166. Thread.Sleep(2000);
  167. ProcessStartInfo psisend = new ProcessStartInfo
  168. {
  169. //adb shell am start -a android.intent.action.SENDTO -d sms:目标手机号码 --es sms_body "短信内容" --ez exit_on_sent true
  170. FileName = "adb.exe", // 要启动的程序,这里是命令行解释器
  171. Arguments = "shell input tap 1010 1414", // 传递给 cmd.exe 的参数,/c 表示执行完命令后关闭命令行窗口,dir 是要执行的命令,这里以列出目录内容为例
  172. UseShellExecute = false, // 不使用系统外壳程序启动进程
  173. RedirectStandardOutput = true, // 重定向标准输出流,以便获取命令执行结果
  174. CreateNoWindow = true // 不创建新的命令行窗口
  175. };
  176. // 创建一个 Process 对象并启动进程
  177. using (Process process = new Process { StartInfo = psisend })
  178. {
  179. process.Start();
  180. // 读取命令执行的结果
  181. string output = process.StandardOutput.ReadToEnd();
  182. // 等待进程执行完毕
  183. process.WaitForExit();
  184. // 在文本框中显示命令执行结果
  185. textBox3.Text += output;
  186. }
  187. sendCount++;
  188. }
  189. catch (Exception ex)
  190. {
  191. MessageBox.Show($"执行命令时发生错误: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  192. }
  193. }
  194. private void timer1_Tick(object sender, EventArgs e)
  195. {
  196. //检查adb连接
  197. //30s 检查一次
  198. ProcessStartInfo psi = new ProcessStartInfo
  199. {
  200. FileName = "adb.exe",
  201. Arguments = "devices",
  202. UseShellExecute = false,
  203. RedirectStandardOutput = true,
  204. CreateNoWindow = true
  205. };
  206. }
  207. private void button3_Click(object sender, EventArgs e)
  208. {
  209. //初始化adb
  210. }
  211. private void button4_Click(object sender, EventArgs e)
  212. {
  213. using (MemoryStream ms = new MemoryStream(Properties.Resources.net_0))
  214. {
  215. Image image = Image.FromStream(ms);
  216. // 假设 PictureBox 控件名为 pictureBox1
  217. pictureBox1.Image = image;
  218. }
  219. using (MemoryStream ms = new MemoryStream(Properties.Resources.adb_0))
  220. {
  221. Image image = Image.FromStream(ms);
  222. // 假设 PictureBox 控件名为 pictureBox1
  223. pictureBox2.Image = image;
  224. }
  225. using (MemoryStream ms = new MemoryStream(Properties.Resources.error_1))
  226. {
  227. Image image = Image.FromStream(ms);
  228. // 假设 PictureBox 控件名为 pictureBox1
  229. pictureBox3.Image = image;
  230. }
  231. using (MemoryStream ms = new MemoryStream(Properties.Resources.send_1))
  232. {
  233. Image image = Image.FromStream(ms);
  234. // 假设 PictureBox 控件名为 pictureBox1
  235. pictureBox4.Image = image;
  236. }
  237. //自检
  238. Reconnect();
  239. Thread.Sleep(2000);
  240. //网络
  241. using (MemoryStream ms = new MemoryStream(Properties.Resources.net_1))
  242. {
  243. Image image = Image.FromStream(ms);
  244. // 假设 PictureBox 控件名为 pictureBox1
  245. pictureBox1.Image = image;
  246. }
  247. using (MemoryStream ms = new MemoryStream(Properties.Resources.adb_1))
  248. {
  249. Image image = Image.FromStream(ms);
  250. // 假设 PictureBox 控件名为 pictureBox1
  251. pictureBox2.Image = image;
  252. }
  253. using (MemoryStream ms = new MemoryStream(Properties.Resources.error_0))
  254. {
  255. Image image = Image.FromStream(ms);
  256. // 假设 PictureBox 控件名为 pictureBox1
  257. pictureBox3.Image = image;
  258. }
  259. using (MemoryStream ms = new MemoryStream(Properties.Resources.send_0))
  260. {
  261. Image image = Image.FromStream(ms);
  262. // 假设 PictureBox 控件名为 pictureBox1
  263. pictureBox4.Image = image;
  264. }
  265. //adb
  266. }
  267. private void button5_Click(object sender, EventArgs e)
  268. {
  269. //校准屏幕点击
  270. }
  271. private void textBox4_TextChanged(object sender, EventArgs e)
  272. {
  273. }
  274. private void button6_Click(object sender, EventArgs e)
  275. {
  276. //统计
  277. MessageBox.Show("共发送短信:"+ sendCount);
  278. }
  279. }
  280. }