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