feat:自动火试金接口签名测试
This commit is contained in:
@@ -27,15 +27,10 @@ import java.util.*;
|
|||||||
|
|
||||||
public class DatabusApiInvocationExample {
|
public class DatabusApiInvocationExample {
|
||||||
public static final String TIMESTAMP = Long.toString(System.currentTimeMillis());
|
public static final String TIMESTAMP = Long.toString(System.currentTimeMillis());
|
||||||
private static final String APP_ID = "iwork";
|
private static final String APP_ID = "qms-auto-ingredients";
|
||||||
private static final String APP_SECRET = "lpGXiNe/GMLk0vsbYGLa8eYxXq8tGhTbuu3/D4MJzIk=";
|
private static final String APP_SECRET = "tjDKCUGNEDR9yNgbxIsvtXsRMuQK+tj1HNEMpgjJOPU=";
|
||||||
// private static final String APP_ID = "test";
|
|
||||||
// private static final String APP_SECRET = "RSYtKXrXPLMy3oeh0cOro6QCioRUgqfnKCkDkNq78sI=";
|
|
||||||
// private static final String APP_ID = "testAnnoy";
|
|
||||||
// private static final String APP_SECRET = "jyGCymUjCFL2i3a4Tm3qBIkUrUl4ZgKPYvOU/47ZWcM=";
|
|
||||||
private static final String ENCRYPTION_TYPE = CryptoSignatureUtils.ENCRYPT_TYPE_AES;
|
private static final String ENCRYPTION_TYPE = CryptoSignatureUtils.ENCRYPT_TYPE_AES;
|
||||||
// private static final String TARGET_API = "http://172.16.46.63:30081/admin-api/databus/api/portal/";
|
private static final String TARGET_API = "http://172.16.46.62:30081/admin-api/databus/api/portal";
|
||||||
private static final String TARGET_API = "http://127.0.0.1:48080/admin-api/databus/api/portal/";
|
|
||||||
private static final HttpClient HTTP_CLIENT = HttpClient.newBuilder()
|
private static final HttpClient HTTP_CLIENT = HttpClient.newBuilder()
|
||||||
.connectTimeout(Duration.ofSeconds(5))
|
.connectTimeout(Duration.ofSeconds(5))
|
||||||
.build();
|
.build();
|
||||||
@@ -45,7 +40,6 @@ public class DatabusApiInvocationExample {
|
|||||||
public static final String ZT_TIMESTAMP = "ZT-Timestamp";
|
public static final String ZT_TIMESTAMP = "ZT-Timestamp";
|
||||||
public static final String ZT_NONCE = "ZT-Nonce";
|
public static final String ZT_NONCE = "ZT-Nonce";
|
||||||
public static final String ZT_SIGNATURE = "ZT-Signature";
|
public static final String ZT_SIGNATURE = "ZT-Signature";
|
||||||
public static final String ZT_AUTH_TOKEN = "ZT-Auth-Token";
|
|
||||||
public static final String CONTENT_TYPE = "Content-Type";
|
public static final String CONTENT_TYPE = "Content-Type";
|
||||||
|
|
||||||
private DatabusApiInvocationExample() {
|
private DatabusApiInvocationExample() {
|
||||||
@@ -53,21 +47,22 @@ public class DatabusApiInvocationExample {
|
|||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
OUT.println("=== GET 请求示例 ===");
|
OUT.println("=== GET 请求示例 ===");
|
||||||
// executeGetExample();
|
executeGetExample();
|
||||||
// OUT.println();
|
// OUT.println();
|
||||||
// OUT.println("=== POST 请求示例 ===");
|
// OUT.println("=== POST 请求示例 ===");
|
||||||
executePostExample();
|
// executePostExample();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void executeGetExample() throws Exception {
|
private static void executeGetExample() throws Exception {
|
||||||
Map<String, Object> queryParams = new LinkedHashMap<>();
|
Map<String, Object> queryParams = new LinkedHashMap<>();
|
||||||
queryParams.put("businessCode", "11");
|
queryParams.put("taskTimeStart", "2025-11-27 09:00:00");
|
||||||
queryParams.put("fileId", "11");
|
queryParams.put("taskTimeEnd", "2025-11-28 23:00:00");
|
||||||
queryParams.put("null", null);
|
// queryParams.put("id", "1994323064365080578");
|
||||||
String signature = generateSignature(queryParams, Map.of());
|
String signature = generateSignature(queryParams, Map.of());
|
||||||
URI requestUri = buildUri(TARGET_API, queryParams);
|
String url = TARGET_API + "/qms.ytjc.auto-ingredients.task-list/v1"; //获取检验批列表
|
||||||
String nonce = "171615676c7d4d96b9f55f3d90ad27e0";
|
// String url = TARGET_API + "/qms.ytjc.auto-ingredients.task-detail-list/v1"; //获取检验批中的检测任务
|
||||||
|
URI requestUri = buildUri(url, queryParams);
|
||||||
|
String nonce = randomNonce();
|
||||||
HttpRequest request = HttpRequest.newBuilder(requestUri)
|
HttpRequest request = HttpRequest.newBuilder(requestUri)
|
||||||
.timeout(Duration.ofSeconds(10))
|
.timeout(Duration.ofSeconds(10))
|
||||||
.header(ZT_APP_ID, APP_ID)
|
.header(ZT_APP_ID, APP_ID)
|
||||||
@@ -85,18 +80,53 @@ public class DatabusApiInvocationExample {
|
|||||||
private static void executePostExample() throws Exception {
|
private static void executePostExample() throws Exception {
|
||||||
Map<String, Object> queryParams = new LinkedHashMap<>();
|
Map<String, Object> queryParams = new LinkedHashMap<>();
|
||||||
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
|
||||||
|
|
||||||
jsonObject.put("id", "1983446576685985794");
|
|
||||||
jsonObject.put("remark", "");
|
|
||||||
|
|
||||||
// long extraTimestamp = 1761556157185L;
|
String jsonStr = "{\n" +
|
||||||
// String bodyJson = String.format(jsonObject.toJSONString(), extraTimestamp);
|
" \"taskId\": \"1994323064365080578\",\n" +
|
||||||
|
" \"sampleList\": [\n" +
|
||||||
|
" {\n" +
|
||||||
|
" \"id\": \"1994322711672328211\",\n" +
|
||||||
|
" \"sampleCode\": \"TJK2511-0004\",\n" +
|
||||||
|
" \"sampleName\": \"铜精矿\",\n" +
|
||||||
|
" \"cupNumber\": \"2\",\n" +
|
||||||
|
" \"ingredient_AgNO3\": \"0\",\n" +
|
||||||
|
" \"ingredient_C\": \"7.4\",\n" +
|
||||||
|
" \"ingredient_KNO3\": \"0\",\n" +
|
||||||
|
" \"ingredient_Na2B4O7_10H2O\": \"12.3\",\n" +
|
||||||
|
" \"ingredient_Na2CO3\": \"19.3\",\n" +
|
||||||
|
" \"ingredient_PbO\": \"170.1\",\n" +
|
||||||
|
" \"ingredient_SiO2\": \"18.4\",\n" +
|
||||||
|
" \"remark\": [\n" +
|
||||||
|
" \"备注1==\",\n" +
|
||||||
|
" \"备注2==\"\n" +
|
||||||
|
" ]\n" +
|
||||||
|
" },\n" +
|
||||||
|
" {\n" +
|
||||||
|
" \"id\": \"1994322711672328196\",\n" +
|
||||||
|
" \"sampleCode\": \"TJK2511-0004\",\n" +
|
||||||
|
" \"sampleName\": \"铜精矿\",\n" +
|
||||||
|
" \"cupNumber\": \"1\",\n" +
|
||||||
|
" \"ingredient_AgNO3\": \"0\",\n" +
|
||||||
|
" \"ingredient_C\": \"7.5\",\n" +
|
||||||
|
" \"ingredient_KNO3\": \"0\",\n" +
|
||||||
|
" \"ingredient_Na2B4O7_10H2O\": \"12\",\n" +
|
||||||
|
" \"ingredient_Na2CO3\": \"19.2\",\n" +
|
||||||
|
" \"ingredient_PbO\": \"170.4\",\n" +
|
||||||
|
" \"ingredient_SiO2\": \"17.9\",\n" +
|
||||||
|
" \"remark\": [\n" +
|
||||||
|
" \"备注1\",\n" +
|
||||||
|
" \"备注2\"\n" +
|
||||||
|
" ]\n" +
|
||||||
|
" }\n" +
|
||||||
|
" ]\n" +
|
||||||
|
"}";
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(jsonStr);
|
||||||
String bodyJson = jsonObject.toJSONString();
|
String bodyJson = jsonObject.toJSONString();
|
||||||
|
|
||||||
Map<String, Object> bodyParams = parseBodyJson(bodyJson);
|
Map<String, Object> bodyParams = parseBodyJson(bodyJson);
|
||||||
String signature = generateSignature(queryParams, bodyParams);
|
String signature = generateSignature(queryParams, bodyParams);
|
||||||
String url = TARGET_API + "qms.ytjc.iwork/v1";
|
String url = TARGET_API + "/qms.ytjc.auto-ingredients.submit-assay-result/v1";
|
||||||
URI requestUri = buildUri(url, queryParams);
|
URI requestUri = buildUri(url, queryParams);
|
||||||
String nonce = randomNonce();
|
String nonce = randomNonce();
|
||||||
String cipherBody = encryptPayload(bodyJson);
|
String cipherBody = encryptPayload(bodyJson);
|
||||||
@@ -109,7 +139,6 @@ public class DatabusApiInvocationExample {
|
|||||||
.header(ZT_TIMESTAMP, TIMESTAMP)
|
.header(ZT_TIMESTAMP, TIMESTAMP)
|
||||||
.header(ZT_NONCE, nonce)
|
.header(ZT_NONCE, nonce)
|
||||||
.header(ZT_SIGNATURE, signature)
|
.header(ZT_SIGNATURE, signature)
|
||||||
.header(ZT_AUTH_TOKEN, "82e5c281ddfa4386988fa4074e8794d7")
|
|
||||||
.header(CONTENT_TYPE, "application/json")
|
.header(CONTENT_TYPE, "application/json")
|
||||||
.POST(HttpRequest.BodyPublishers.ofString(cipherBody, StandardCharsets.UTF_8))
|
.POST(HttpRequest.BodyPublishers.ofString(cipherBody, StandardCharsets.UTF_8))
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
Reference in New Issue
Block a user