【修改】带数据库参数运行judgement

This commit is contained in:
huababa1
2025-10-20 02:42:06 +08:00
parent 54254d4375
commit b740609f4a
2 changed files with 83 additions and 0 deletions

View File

@@ -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<String> data { get; set; }
public string msg { get; set; }
}
}

View File

@@ -187,10 +187,25 @@ class Program
} }
else 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 var startInfo = new ProcessStartInfo
{ {
FileName = exePath, FileName = exePath,
WorkingDirectory = workingDirectory, // 必须! 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根据需要 UseShellExecute = true, // 或 false根据需要
Verb = "runas" // 指定管理员运行 Verb = "runas" // 指定管理员运行
}; };
@@ -510,6 +525,34 @@ class Program
} }
// 将 result 转换为 JSON 并返回 // 将 result 转换为 JSON 并返回
responseMessage = JsonSerializer.Serialize(result); 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<String> softwareList = await FetchSoftwareWhiteListFromApi(apiUrl);
List<string> result = new List<string>();
// 将 result 转换为 JSON 并返回
responseMessage = JsonSerializer.Serialize(softwareList);
} }
else if (action == "/closeapps") else if (action == "/closeapps")
{ {
@@ -652,6 +695,31 @@ class Program
return new List<AppCheck>(); return new List<AppCheck>();
} }
} }
static async Task<List<String>> FetchSoftwareWhiteListFromApi(string url)
{
try
{
using HttpClient client = new();
var response = await client.GetStringAsync(url);
var apiResponse = JsonSerializer.Deserialize<ApiWhiteResponse>(response);
if (apiResponse != null && apiResponse.code == 0)
{
// 如果 code 为 0说明数据有效返回 softwareList
return apiResponse.data ?? new List<String>();
}
else
{
// Console.WriteLine($"API error: {apiResponse?.msg}");
return new List<String>();
}
}
catch (Exception ex)
{
// Console.WriteLine("获取接口数据失败: " + ex.Message);
return new List<String>();
}
}
static string CreateJsonResponse<T>(int code, T data, string msg) static string CreateJsonResponse<T>(int code, T data, string msg)
{ {
var response = new StandardResponse<T> var response = new StandardResponse<T>