From b740609f4ae508dc92e7d609c25d1cd94df01caa Mon Sep 17 00:00:00 2001 From: huababa1 <2037205722@qq.com> Date: Mon, 20 Oct 2025 02:42:06 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E3=80=91=E5=B8=A6?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E5=8F=82=E6=95=B0=E8=BF=90=E8=A1=8C?= =?UTF-8?q?judgement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Applications/ApiWhiteResponse.cs | 15 +++++++ Applications/Program.cs | 68 ++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 Applications/ApiWhiteResponse.cs diff --git a/Applications/ApiWhiteResponse.cs b/Applications/ApiWhiteResponse.cs new file mode 100644 index 0000000..4e9621d --- /dev/null +++ b/Applications/ApiWhiteResponse.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Applications +{ + public class ApiWhiteResponse + { + public int code { get; set; } + public List data { get; set; } + public string msg { get; set; } + } +} diff --git a/Applications/Program.cs b/Applications/Program.cs index 517faf2..f38cf1b 100644 --- a/Applications/Program.cs +++ b/Applications/Program.cs @@ -187,10 +187,25 @@ class Program } else { + //ip = "www.hblk.top:48080"; + // 如果带有端口号(即含冒号)就去掉冒号及后面内容 + if (ip.Contains(":")) + { + ip = ip.Split(':')[0]; + } + Console.WriteLine(ip); + string dbUser = "root"; // ✅ 你的数据库账号 + string dbPass = "root"; // ✅ 你的数据库密码 var startInfo = new ProcessStartInfo { FileName = exePath, WorkingDirectory = workingDirectory, // 必须! + + Arguments = $"-jar \"{exePath}\" " + + $"--spring.datasource.url=\"jdbc:mysql://{ip}:3306/pc-exam?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true\" " + + $"--spring.datasource.username={dbUser} " + + $"--spring.datasource.password={dbPass}", + UseShellExecute = true, // 或 false,根据需要 Verb = "runas" // 指定管理员运行 }; @@ -510,6 +525,34 @@ class Program } // 将 result 转换为 JSON 并返回 responseMessage = JsonSerializer.Serialize(result); + + + } + // 检测学生端环境 + else if (action == "/white") + { + Console.WriteLine("check111"); + string apiUrl; + + if (ip.Contains(":")) + { + // 已包含端口号或域名带端口 + apiUrl = $"http://{ip}/admin-api/exam/param/getAppWhiteList/{taskId}"; + } + else + { + // 未包含端口号 + apiUrl = $"http://{ip}:48080/admin-api/exam/param/getAppWhiteList/{taskId}"; + } + Console.WriteLine(apiUrl); + + List softwareList = await FetchSoftwareWhiteListFromApi(apiUrl); + List result = new List(); + + // 将 result 转换为 JSON 并返回 + responseMessage = JsonSerializer.Serialize(softwareList); + + } else if (action == "/closeapps") { @@ -652,6 +695,31 @@ class Program return new List(); } } + static async Task> FetchSoftwareWhiteListFromApi(string url) + { + try + { + using HttpClient client = new(); + var response = await client.GetStringAsync(url); + var apiResponse = JsonSerializer.Deserialize(response); + + if (apiResponse != null && apiResponse.code == 0) + { + // 如果 code 为 0,说明数据有效,返回 softwareList + return apiResponse.data ?? new List(); + } + else + { + // Console.WriteLine($"API error: {apiResponse?.msg}"); + return new List(); + } + } + catch (Exception ex) + { + // Console.WriteLine("获取接口数据失败: " + ex.Message); + return new List(); + } + } static string CreateJsonResponse(int code, T data, string msg) { var response = new StandardResponse