From f1665083644aaccbaccf8a5352c2c4f161f28645 Mon Sep 17 00:00:00 2001
From: tjx <t2856754968@163.com>
Date: 星期五, 24 十月 2025 11:54:03 +0800
Subject: [PATCH] 111
---
src/test/java/com/gs/xiaomi/XiaomiApplicationTests.java | 273 ++----------------------------------------------------
1 files changed, 13 insertions(+), 260 deletions(-)
diff --git a/src/test/java/com/gs/xiaomi/XiaomiApplicationTests.java b/src/test/java/com/gs/xiaomi/XiaomiApplicationTests.java
index 297f9b1..bfbb38d 100644
--- a/src/test/java/com/gs/xiaomi/XiaomiApplicationTests.java
+++ b/src/test/java/com/gs/xiaomi/XiaomiApplicationTests.java
@@ -1,28 +1,19 @@
package com.gs.xiaomi;
-import cn.hutool.core.date.DateUtil;
-import cn.hutool.crypto.SmUtil;
import cn.hutool.crypto.digest.DigestUtil;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.gs.xiaomi.config.DataAcquisitionConfiguration;
import com.gs.xiaomi.dto.BCS101Request;
+import com.gs.xiaomi.dto.NumbericalDto;
import com.gs.xiaomi.service.BCS101ApiService;
-import com.gs.xiaomi.service.XM104Service;
+import com.gs.xiaomi.service.Xm104Service;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.Base64;
-import java.util.Date;
@SpringBootTest
class XiaomiApplicationTests {
@Autowired
- private XM104Service xm104Service;
+ private Xm104Service xm104Service;
@Autowired
private BCS101ApiService bcs101ApiService;
@@ -30,6 +21,14 @@
@Test
void contextLoads() throws Exception {
xm104Service.getDb();
+ }
+
+ //manualSynchronization
+ @Test
+ void contextLoads1() throws Exception {
+ NumbericalDto barcode = new NumbericalDto();
+ barcode.setAsn("9316692923");
+ xm104Service.manualSynchronization(barcode);
}
@Test
@@ -52,254 +51,8 @@
request.setPageNo(1);
request.setPageSize(1000);
- //Error: ERROR_IN_MODULECHAIN;ERROR_IN_MODULECHAIN, Sender Channel 'CC_MI_OEM_HTTP_OUT' (ID: a58369adbaa03aafb76d2c02c2ae7cd7): Catching exception calling messaging system
- System.out.println("=== 娴嬭瘯BCS101 API鏈嶅姟锛圔asic Auth鐗堟湰锛� ===");
- try {
- // 璋冪敤鏍囧噯BCS101 API鏈嶅姟锛堝彧浣跨敤Basic Auth锛�
- String response = bcs101ApiService.getBCS101Data(request);
- System.out.println("BCS101 API Response: " + response);
- } catch (Exception e) {
- System.out.println("BCS101 API璋冪敤寮傚父: " + e.getMessage());
- e.printStackTrace();
- }
+ String bcs101Data = bcs101ApiService.getBCS101Data(request);
+ System.out.println(bcs101Data);
- //Error: ERROR_IN_MODULECHAIN;ERROR_IN_MODULECHAIN, Sender Channel 'CC_MI_OEM_HTTP_OUT' (ID: a58369adbaa03aafb76d2c02c2ae7cd7): Catching exception calling messaging system
- System.out.println("\n=== 娴嬭瘯BCS101 API鏈嶅姟锛堝甫X5鍗忚鐗堟湰锛� ===");
- try {
- // 璋冪敤甯5鍗忚鐨凚CS101 API鏈嶅姟
- String responseWithX5 = bcs101ApiService.getBCS101DataWithX5(request, true);
- System.out.println("BCS101 API Response (X5): " + responseWithX5);
- } catch (Exception e) {
- System.out.println("BCS101 API X5璋冪敤寮傚父: " + e.getMessage());
- e.printStackTrace();
- }
-
- System.out.println("\n=== 娴嬭瘯BCS101 API鏈嶅姟锛堣皟璇曠増鏈級 ===");
- try {
- // 璋冪敤璋冭瘯鐗堟湰API鏈嶅姟
- String debugResponse = bcs101ApiService.getBCS101DataDebug(request);
- System.out.println("BCS101 API Debug Response: " + debugResponse);
- } catch (Exception e) {
- System.out.println("BCS101 API 璋冭瘯鐗堟湰璋冪敤寮傚父: " + e.getMessage());
- e.printStackTrace();
- }
-
- System.out.println("\n=== 娴嬭瘯BCS101 API鏈嶅姟锛堢畝鍖栫増鏈級 ===");
- try {
- // 璋冪敤绠�鍖栫増鏈珹PI鏈嶅姟
- String simpleResponse = bcs101ApiService.getBCS101DataSimple(request);
- System.out.println("BCS101 API Simple Response: " + simpleResponse);
- } catch (Exception e) {
- System.out.println("BCS101 API 绠�鍖栫増鏈皟鐢ㄥ紓甯�: " + e.getMessage());
- e.printStackTrace();
- }
-
- System.out.println("\n=== 娴嬭瘯BCS101 API鏈嶅姟锛圶5鍗忚鏍囧噯鐗堟湰锛� ===");
- try {
- // 璋冪敤X5鍗忚鏍囧噯鐗堟湰
- String x5StandardResponse = bcs101ApiService.getBCS101DataX5Standard(request);
- System.out.println("BCS101 API X5Standard Response: " + x5StandardResponse);
- } catch (Exception e) {
- System.out.println("BCS101 API X5鏍囧噯鐗堟湰璋冪敤寮傚父: " + e.getMessage());
- e.printStackTrace();
- }
-
- System.out.println("\n=== 娴嬭瘯BCS101 API鏈嶅姟锛圶5鍗忚鍙樹綋鐗堟湰锛� ===");
- try {
- // 璋冪敤X5鍗忚鍙樹綋鐗堟湰
- String x5VariantResponse = bcs101ApiService.getBCS101DataX5Variant(request);
- System.out.println("BCS101 API X5Variant Response: " + x5VariantResponse);
- } catch (Exception e) {
- System.out.println("BCS101 API X5鍙樹綋鐗堟湰璋冪敤寮傚父: " + e.getMessage());
- e.printStackTrace();
- }
- }
-
- @Test
- void test1() throws UnsupportedEncodingException, JsonProcessingException {
- // 鍒涘缓娴嬭瘯璇锋眰瀵硅薄
- BCS101Request request = new BCS101Request();
- request.setSupplierId("177301");
- request.setDocNo("9311036039");
- request.setDocType("ASNGR");
- request.setPageNo(1);
- request.setPageSize(1000);
-
-
- ObjectMapper objectMapper = new ObjectMapper();
-
- System.out.println("=== BCS101 API 瀹為檯璇锋眰鍙傛暟璇︽儏 ===\n");
-
- //鏃堕棿
- String yyyyMMddHHmmss = DateUtil.format(new Date(), "yyyyMMddHHmmss");
- System.out.println(yyyyMMddHHmmss);
-
- // 1. 鍘熷JSON鏁版嵁
- String jsonData = objectMapper.writeValueAsString(request);
- System.out.println("1. 鍘熷JSON鏁版嵁:");
- System.out.println(jsonData);
- System.out.println();
-
- // 2. Base64缂栫爜
- String base64Data = Base64.getEncoder().encodeToString(jsonData.getBytes("UTF-8"));
- System.out.println("2. Base64缂栫爜鍚�:");
- System.out.println(base64Data);
- System.out.println();
-
- // 3. URL缂栫爜
- String urlEncodedData = URLEncoder.encode(base64Data, "UTF-8");
- System.out.println("3. URL缂栫爜鍚�:");
- System.out.println(urlEncodedData);
- System.out.println();
-
- // 4. Form鏁版嵁
- String formData = "data=" + urlEncodedData;
- System.out.println("4. Form鏁版嵁 (璇锋眰Body):");
- System.out.println(formData);
- System.out.println();
-
- // 5. 璇锋眰URL
- System.out.println("5. 璇锋眰URL:");
- System.out.println(DataAcquisitionConfiguration.BCS_101_URL);
- System.out.println();
-
- // 6. Basic Auth
- String credentials = DataAcquisitionConfiguration.BCS_USER_NAME + ":" + DataAcquisitionConfiguration.BCS_PWD;
- String auth = Base64.getEncoder().encodeToString(credentials.getBytes("UTF-8"));
- System.out.println("6. Basic Auth淇℃伅:");
- System.out.println("鐢ㄦ埛鍚�: " + DataAcquisitionConfiguration.BCS_USER_NAME);
- System.out.println("瀵嗙爜: " + DataAcquisitionConfiguration.BCS_PWD);
- System.out.println("Base64缂栫爜: " + auth);
- System.out.println();
-
- // 7. X5鍗忚鍙傛暟
- String appId = DataAcquisitionConfiguration.BCS_APP_ID;
- String appKey = DataAcquisitionConfiguration.BCS_APP_Key;
- long timestamp = System.currentTimeMillis() / 1000;
-
- System.out.println("7. X5鍗忚鍙傛暟:");
- System.out.println("App ID: " + appId);
- System.out.println("App Key: " + appKey);
- System.out.println("Timestamp: " + timestamp);
- System.out.println();
-
- // 8. X5绛惧悕璁$畻
- String signString = appId + appKey + timestamp + formData;
- String signature;
- try {
- signature = SmUtil.sm3(signString).toUpperCase();
- System.out.println("8. X5绛惧悕 (浣跨敤SM3):");
- } catch (Exception e) {
- signature = DigestUtil.md5Hex(signString).toUpperCase();
- System.out.println("8. X5绛惧悕 (浣跨敤MD5):");
- }
- System.out.println("绛惧悕瀛楃涓�: " + signString);
- System.out.println("绛惧悕鍊�: " + signature);
- System.out.println();
-
- // 9. 瀹屾暣鐨凥TTP璇锋眰澶�
- System.out.println("9. 瀹屾暣鐨凥TTP璇锋眰澶�:");
- System.out.println("Content-Type: application/x-www-form-urlencoded");
- System.out.println("Authorization: Basic " + auth);
- System.out.println("X-App-Id: " + appId);
- System.out.println("X-Timestamp: " + timestamp);
- System.out.println("X-Signature: " + signature);
- System.out.println();
-
- // 10. 瀹屾暣鐨刢URL鍛戒护绀轰緥
- System.out.println("10. 瀹屾暣鐨刢URL鍛戒护绀轰緥:");
- System.out.println("curl -X POST \\");
- System.out.println(" '" + DataAcquisitionConfiguration.BCS_101_URL + "' \\");
- System.out.println(" -H 'Content-Type: application/x-www-form-urlencoded' \\");
- System.out.println(" -H 'Authorization: Basic " + auth + "' \\");
- System.out.println(" -H 'X-App-Id: " + appId + "' \\");
- System.out.println(" -H 'X-Timestamp: " + timestamp + "' \\");
- System.out.println(" -H 'X-Signature: " + signature + "' \\");
- System.out.println(" -d '" + formData + "'");
- System.out.println();
-
- // 11. Postman鏍煎紡
- System.out.println("11. Postman娴嬭瘯鏍煎紡:");
- System.out.println("Method: POST");
- System.out.println("URL: " + DataAcquisitionConfiguration.BCS_101_URL);
- System.out.println("Headers:");
- System.out.println(" Content-Type: application/x-www-form-urlencoded");
- System.out.println(" Authorization: Basic " + auth);
- System.out.println(" X-App-Id: " + appId);
- System.out.println(" X-Timestamp: " + timestamp);
- System.out.println(" X-Signature: " + signature);
- System.out.println("Body (x-www-form-urlencoded):");
- System.out.println(" data: " + urlEncodedData);
- System.out.println();
-
- // 12. 瀹為檯璋冪敤API骞惰幏鍙栧搷搴�
- System.out.println("12. === 瀹為檯API璋冪敤鍜屽搷搴� ===");
- StringBuilder responseResult = new StringBuilder();
-
- System.out.println("\n=== 娴嬭瘯BCS101 API鏈嶅姟锛圔asic Auth鐗堟湰锛� ===");
- try {
- String response = bcs101ApiService.getBCS101Data(request);
- System.out.println("BCS101 API Response: " + response);
- responseResult.append("Basic Auth鍝嶅簲: ").append(response.length()).append("瀛楃; ");
- } catch (Exception e) {
- System.out.println("BCS101 API璋冪敤寮傚父: " + e.getMessage());
- responseResult.append("Basic Auth寮傚父: ").append(e.getMessage()).append("; ");
- }
-
- System.out.println("\n=== 娴嬭瘯BCS101 API鏈嶅姟锛堝甫X5鍗忚鐗堟湰锛� ===");
- try {
- String responseWithX5 = bcs101ApiService.getBCS101DataWithX5(request, true);
- System.out.println("BCS101 API Response (X5): " + responseWithX5);
- responseResult.append("X5鍗忚鍝嶅簲: ").append(responseWithX5.length()).append("瀛楃; ");
- } catch (Exception e) {
- System.out.println("BCS101 API X5璋冪敤寮傚父: " + e.getMessage());
- responseResult.append("X5鍗忚寮傚父: ").append(e.getMessage()).append("; ");
- }
-
- System.out.println("\n=== 娴嬭瘯BCS101 API鏈嶅姟锛堣皟璇曠増鏈級 ===");
- try {
- String debugResponse = bcs101ApiService.getBCS101DataDebug(request);
- System.out.println("BCS101 API Debug Response: " + debugResponse);
- responseResult.append("璋冭瘯鐗堟湰鍝嶅簲: ").append(debugResponse.length()).append("瀛楃; ");
- } catch (Exception e) {
- System.out.println("BCS101 API 璋冭瘯鐗堟湰璋冪敤寮傚父: " + e.getMessage());
- responseResult.append("璋冭瘯鐗堟湰寮傚父: ").append(e.getMessage()).append("; ");
- }
-
- System.out.println("\n=== 娴嬭瘯BCS101 API鏈嶅姟锛堢畝鍖栫増鏈級 ===");
- try {
- String simpleResponse = bcs101ApiService.getBCS101DataSimple(request);
- System.out.println("BCS101 API Simple Response: " + simpleResponse);
- responseResult.append("绠�鍖栫増鏈搷搴�: ").append(simpleResponse.length()).append("瀛楃; ");
- } catch (Exception e) {
- System.out.println("BCS101 API 绠�鍖栫増鏈皟鐢ㄥ紓甯�: " + e.getMessage());
- responseResult.append("绠�鍖栫増鏈紓甯�: ").append(e.getMessage()).append("; ");
- }
-
- System.out.println("\n=== 娴嬭瘯BCS101 API鏈嶅姟锛圶5鍗忚鏍囧噯鐗堟湰锛� ===");
- try {
- String x5StandardResponse = bcs101ApiService.getBCS101DataX5Standard(request);
- System.out.println("BCS101 API X5Standard Response: " + x5StandardResponse);
- responseResult.append("X5鏍囧噯鐗堟湰鍝嶅簲: ").append(x5StandardResponse.length()).append("瀛楃; ");
- } catch (Exception e) {
- System.out.println("BCS101 API X5鏍囧噯鐗堟湰璋冪敤寮傚父: " + e.getMessage());
- responseResult.append("X5鏍囧噯鐗堟湰寮傚父: ").append(e.getMessage()).append("; ");
- }
-
- System.out.println("\n=== 娴嬭瘯BCS101 API鏈嶅姟锛圶5鍗忚鍙樹綋鐗堟湰锛� ===");
- try {
- String x5VariantResponse = bcs101ApiService.getBCS101DataX5Variant(request);
- System.out.println("BCS101 API X5Variant Response: " + x5VariantResponse);
- responseResult.append("X5鍙樹綋鐗堟湰鍝嶅簲: ").append(x5VariantResponse.length()).append("瀛楃; ");
- } catch (Exception e) {
- System.out.println("BCS101 API X5鍙樹綋鐗堟湰璋冪敤寮傚父: " + e.getMessage());
- responseResult.append("X5鍙樹綋鐗堟湰寮傚父: ").append(e.getMessage()).append("; ");
- }
-
- // 杩斿洖姹囨�讳俊鎭�
- String summary = String.format("璇锋眰鍙傛暟[渚涘簲鍟咺D: %s, 鍗曟嵁鍙�: %s, 绛惧悕: %s, 鏃堕棿鎴�: %d] | 鍝嶅簲姹囨�籟%s]",
- request.getSupplierId(), request.getDocNo(), signature, timestamp, responseResult.toString());
- System.out.println("\n=== 娴嬭瘯姹囨�� ===");
- System.out.println(summary);
}
}
--
Gitblit v1.9.3