修改PBCAgent2G

This commit is contained in:
xydkj 2026-05-26 16:51:17 +08:00
parent 7a9cdac10a
commit 861ecd6108

View File

@ -1,8 +1,6 @@
package cn.com.infosec.netsign.agent;
import cn.com.infosec.netsign.agent.config.OkHttpClientHolder;
import cn.com.infosec.netsign.agent.config.SignServerProperties;
import cn.com.infosec.netsign.agent.config.SignServerPropertiesLoader;
import cn.com.infosec.netsign.agent.dto.*;
import cn.com.infosec.netsign.agent.exception.BusinessException;
import com.fasterxml.jackson.core.JsonProcessingException;
@ -22,22 +20,31 @@ public class PBCAgent2G{
MediaType.parse("application/json; charset=utf-8");
private static final String baseUrl = "http://127.0.0.1:8080/api/v1/openapi";
private static final String apiKey = "key";
private static final String rawSignPath = "/rawSign";
private static final String rawVerifyPath = "/rawVerify";
private static final String dettachedSignPath = "/dettachedSign";
private static final String dettachedVerifyPath = "/dettachedVerify";
private static final String dettachedVerifySimplePath = "/dettachedVerifySimple";
private static final String uploadCertPath = "/uploadCert";
private final OkHttpClient okHttpClient;
private final ObjectMapper objectMapper;
private final SignServerProperties properties;
private final ThreadLocal<Integer> lastReturnCode = new ThreadLocal<>();
public PBCAgent2G() {
this.okHttpClient = OkHttpClientHolder.getClient();
this.objectMapper = new ObjectMapper();
this.properties = SignServerPropertiesLoader.getProperties();
}
public PBCAgent2G(boolean usingSingleServiceList) {
this.okHttpClient = OkHttpClientHolder.getClient();
this.objectMapper = new ObjectMapper();
this.properties = SignServerPropertiesLoader.getProperties();
}
@ -82,10 +89,10 @@ public class PBCAgent2G{
);
Request request = new Request.Builder()
.url(buildUrl(properties.getRawSignPath()))
.url(buildUrl(rawSignPath))
.post(requestBody)
.addHeader("Content-Type", "application/json")
.addHeader("X-API-Key", properties.getApiKey())
.addHeader("X-API-Key", apiKey)
.build();
@ -164,10 +171,10 @@ public class PBCAgent2G{
);
Request request = new Request.Builder()
.url(buildUrl(properties.getRawVerifyPath()))
.url(buildUrl(rawVerifyPath))
.post(requestBody)
.addHeader("Content-Type", "application/json")
.addHeader("X-API-Key", properties.getApiKey())
.addHeader("X-API-Key", apiKey)
.build();
System.out.println("准备连接签名服务器");
@ -234,10 +241,10 @@ public class PBCAgent2G{
);
Request request = new Request.Builder()
.url(buildUrl(properties.getDettachedSignPath()))
.url(buildUrl(dettachedSignPath))
.post(requestBody)
.addHeader("Content-Type", "application/json")
.addHeader("X-API-Key", properties.getApiKey())
.addHeader("X-API-Key", apiKey)
.build();
@ -306,10 +313,10 @@ public class PBCAgent2G{
);
Request request = new Request.Builder()
.url(buildUrl(properties.getDettachedVerifyPath()))
.url(buildUrl(dettachedVerifyPath))
.post(requestBody)
.addHeader("Content-Type", "application/json")
.addHeader("X-API-Key", properties.getApiKey())
.addHeader("X-API-Key", apiKey)
.build();
System.out.println("准备连接签名服务器");
@ -380,10 +387,10 @@ public class PBCAgent2G{
);
Request request = new Request.Builder()
.url(buildUrl(properties.getDettachedVerifySimplePath()))
.url(buildUrl(dettachedVerifySimplePath))
.post(requestBody)
.addHeader("Content-Type", "application/json")
.addHeader("X-API-Key", properties.getApiKey())
.addHeader("X-API-Key", apiKey)
.build();
System.out.println("准备连接签名服务器");
@ -446,10 +453,10 @@ public class PBCAgent2G{
);
Request request = new Request.Builder()
.url(buildUrl(properties.getUploadCertPath()))
.url(buildUrl(uploadCertPath))
.post(requestBody)
.addHeader("Content-Type", "application/json")
.addHeader("X-API-Key", properties.getApiKey())
.addHeader("X-API-Key", apiKey)
.build();
System.out.println("准备连接签名服务器");
@ -486,7 +493,7 @@ public class PBCAgent2G{
private String buildUrl(String path) {
String baseUrl = properties.getBaseUrl();
String baseUrl = "http://127.0.0.1:8080/api/v1/openapi";
if (baseUrl.endsWith("/") && path.startsWith("/")) {
return baseUrl.substring(0, baseUrl.length() - 1) + path;
@ -495,7 +502,7 @@ public class PBCAgent2G{
if (!baseUrl.endsWith("/") && !path.startsWith("/")) {
return baseUrl + "/" + path;
}
System.out.println(baseUrl + path);
return baseUrl + path;
}
}