package org.sxkj.common.utils; import com.alibaba.fastjson.JSONObject; import java.io.*; import java.util.Random; import java.util.stream.Collectors; public class DockerExecSignExtractor { /** * 将db文件进行质检,获取sign * @param fileName * @param password * @return * @throws IOException * @throws InterruptedException */ public static String executeAndGetSign(String fileName, String password) throws IOException, InterruptedException { // 定义目标文件路径 String directoryPath = "/software/service/drone/server/sqlite/download/"; String command = String.format( "docker exec -it base_dev_dotnet dotnet /software/service/drone/server/sqlite/LandCloudCGDBPreCheckTool/LandCloud.CGDBPreCheckTool.dll checkdb --file=%s%s --pwd=%s", directoryPath, fileName, password ); // 执行命令 ProcessBuilder processBuilder = new ProcessBuilder("bash", "-c", command); processBuilder.redirectErrorStream(true); Process process = processBuilder.start(); int exitCode = process.waitFor(); if (exitCode != 0) { throw new RuntimeException("命令执行错误: " + exitCode); } // 定义生成的 .sign 文件路径 File signFile = new File(directoryPath + fileName + ".sign"); if (!signFile.exists()) { throw new RuntimeException("没用找到签章文件: " + signFile.getAbsolutePath()); } // 读取 .sign 文件并解析 JSON try (BufferedReader reader = new BufferedReader(new FileReader(signFile))) { StringBuilder content = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { content.append(line); } JSONObject jsonObject = JSONObject.parseObject(content.toString()); return jsonObject.getString("sign"); } } public static String test() throws FileNotFoundException { File signFile = new File("D:\\wayline\\task1838486031293353984.sign"); if (!signFile.exists()) { throw new RuntimeException("没用找到签章文件: " + signFile.getAbsolutePath()); } // 读取 .sign 文件并解析 JSON try (BufferedReader reader = new BufferedReader(new FileReader(signFile))) { StringBuilder content = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { content.append(line); } JSONObject jsonObject = JSONObject.parseObject(content.toString()); return jsonObject.getString("sign"); } catch (IOException e) { throw new RuntimeException(e); } } }