From 708c121dafd545fd4f7caded0c7e29506be378c1 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期四, 06 二月 2025 13:56:59 +0800
Subject: [PATCH] 添加测试环境的itod配置

---
 ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/drainage/TCECUtil.java |   98 +++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 86 insertions(+), 12 deletions(-)

diff --git a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/drainage/TCECUtil.java b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/drainage/TCECUtil.java
index 697d9d9..ac01a0d 100644
--- a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/drainage/TCECUtil.java
+++ b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/drainage/TCECUtil.java
@@ -4,6 +4,8 @@
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.ruoyi.common.core.utils.SpringUtils;
+import com.ruoyi.integration.drainage.kuaidian.model.NotificationStationChangeResult;
+import com.ruoyi.integration.drainage.kuaidian.model.StationChange;
 import com.ruoyi.integration.drainage.model.*;
 import com.ruoyi.integration.drainage.model.enu.InterfaceUrlEnum;
 import com.ruoyi.other.api.domain.Operator;
@@ -15,7 +17,9 @@
 import java.time.ZoneOffset;
 import java.time.format.DateTimeFormatter;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * 中电联TCEC标准
@@ -24,24 +28,20 @@
  */
 @Slf4j
 public class TCECUtil {
-	/**
-	 * 运营商标识
-	 */
-	private static final String OperatorID = "";
 	
-	private static OperatorClient operatorClient = SpringUtils.getBean(OperatorClient.class);
+//	private static OperatorClient operatorClient = SpringUtils.getBean(OperatorClient.class);
 	
-	private static Map<Long, Integer> map = new HashMap<>();
+	public static Map<Long, Integer> map = new HashMap<>();
 	
 	
 	/**
 	 * 获取token
 	 */
 	public static String queryToken(Operator operator){
-		HttpRequest post = HttpUtil.createPost("");
+		HttpRequest post = HttpUtil.createPost(operator.getTestUrl() + InterfaceUrlEnum.QUERY_TOKEN.getUrl());
 		post.contentType("application/json;charset=utf-8");
 		JSONObject body = new JSONObject();
-		body.put("OperatorID", OperatorID);
+		body.put("OperatorID", operator.getOurOperatorId());
 		body.put("OperatorSecret", operator.getOurOperatorSecret());
 		post.body(body.toJSONString());
 		HttpResponse execute = post.execute();
@@ -60,7 +60,7 @@
 		LocalDateTime localDateTime = Instant.ofEpochSecond(tokenAvailableTime).atOffset(ZoneOffset.UTC).toLocalDateTime();
 		operator.setAccessToken(token);
 		operator.setTokenAvailableTime(localDateTime);
-		operatorClient.editOperator(operator);
+//		operatorClient.editOperator(operator);
 		return token;
 	}
 	
@@ -93,6 +93,10 @@
 		}
 		return JSON.parseObject(execute.body(), NotificationStationStatusResult.class);
 	}
+	
+	
+	
+	
 	
 	
 	/**
@@ -211,14 +215,14 @@
 		post.contentType("application/json;charset=utf-8");
 		post.header("Authorization", "Bearer " + getToken(operator));
 		BaseRequest baseRequest = new BaseRequest();
-		baseRequest.setOperatorID(OperatorID);
+		baseRequest.setOperatorID(operator.getOurOperatorId());
 		baseRequest.setTimeStamp(timeStamp);
 		baseRequest.setSeq(String.format("%04d", integer));
 		String jsonString = JSON.toJSONString(o);
-		String encrypt = AESUtil.encrypt(jsonString, operator.getDataSecret(), operator.getDataSecretIv());
+		String encrypt = AESUtil.encrypt(jsonString, operator.getOurDataSecret(), operator.getOurDataSecretIv());
 		baseRequest.setData(encrypt);
 		baseRequest.setOperator(operator);
-		baseRequest.setSig(buildSign(baseRequest));
+		baseRequest.setSig(ourBuildSign(baseRequest));
 		post.body(JSON.toJSONString(baseRequest));
 		//清空小于当前时间的map中的无效数据
 		for (Long k : map.keySet()) {
@@ -236,6 +240,9 @@
 	 */
 	public static String buildSign(BaseModel model){
 		Operator operator = model.getOperator();
+		if(null == operator){
+			return "";
+		}
 		//签名秘钥SigSecret
 		String key = operator.getSigSecret();
 		String sign = "";
@@ -254,4 +261,71 @@
 		return sign;
 	}
 	
+	
+	
+	/**
+	 * 构建签名字符串
+	 * @param model
+	 * @return
+	 */
+	public static String ourBuildSign(BaseModel model){
+		Operator operator = model.getOperator();
+		if(null == operator){
+			return "";
+		}
+		//签名秘钥SigSecret
+		String key = operator.getOurSigSecret();
+		String sign = "";
+		switch (operator.getName()){
+			case "XinDianTu":
+				//进行字符串拼接、计算
+				String m = new StringBuilder(operator.getOurOperatorId()).append(model.getData()).append(model.getTimeStamp()).append(model.getSeq()).toString();
+				byte[] hmacMd5 = SignUtil.getHMacMD5Bytes(key.getBytes(), m.getBytes());
+				// 打印计算得到的签名Sig
+				sign = SignUtil.bytesToHexString(hmacMd5);
+				break;
+			case "KuaiDian":
+				sign = SignUtil.hmacSign(model.getData(), key);
+				break;
+		}
+		return sign;
+	}
+	
+	
+	public static void main(String[] args) {
+		BaseModel model = new BaseModel();
+		model.setOperatorID("MA25CNM38");
+		model.setData("AoArdDDcmHcmOMkCLHodTpY1xLtt9yhLqxvKPyfdlmEOBj1LJnQM+Z4JOZllt3Pj9rubfgxJ51zMAfzquQegJzHGAT9Y7JrKFzFe6jGtXo0=");
+		model.setTimeStamp(20250205120800L);
+		model.setSeq("0001");
+		Operator operator = new Operator();
+		operator.setName("XinDianTu");
+		operator.setSigSecret("S94xUpTpOIlLJBk8");
+		model.setOperator(operator);
+		String key = operator.getSigSecret();
+
+		String m = new StringBuilder(model.getOperatorID()).append(model.getData()).append(model.getTimeStamp()).append(model.getSeq()).toString();
+		byte[] hmacMd5 = SignUtil.getHMacMD5Bytes(key.getBytes(), m.getBytes());
+		// 打印计算得到的签名Sig
+		String s = SignUtil.bytesToHexString(hmacMd5);
+		System.err.println(s);
+		
+		
+//		BaseModel model = new BaseModel();
+//		model.setOperatorID("MA25CNM38");
+//		model.setData("xQYYEPiwoc4JENnQsF50qP6Tmnj7uU/AshWn3QbIgrMIk8zvFpy6fWLIiLzQHcLPFCihqH1uzoNhGVNcS8Wvf5gIx9+cWJvYtjwtsjAGMEwNQ6y+rF1jjKnqCNcQbHbhqJ2l76sD54QCFKyenKxymrXri19bDV8hizn3nBw+jcHBtqKHWzjdSHwPDWPIw4rXnrbWLya2PXVgYtVg93WPtliw+0xsqW0BxJamE70/Ilbg4wB5fOAOvXmbLFI+v9jRjpcA7ImhprqPMYkXYAfa2QlICrJEBK7DfpJvRMzKzeT90kOAITqIqFvbfV0ti+greRqToLP6ni4o6w3ID42UmKasIpLTnx+qtR4bVTBTRuDzXvNXDA92RqHaJO21xbSen1eHN/yGfrchBIM0gmav7EpaYAerfU4ubnmJ6xujR6okYepJwBD5DiSIrObfS+GWVPRekvnjvm7BC02NXTrGKA==");
+//		model.setTimeStamp(20250205161426L);
+//		model.setSeq("0001");
+//		Operator operator = new Operator();
+//		operator.setOurOperatorId("2921700136");
+//		operator.setOurSigSecret("KBm5J2fbGzyhX023");
+//		model.setOperator(operator);
+//		String key = operator.getOurSigSecret();
+//
+//		String m = new StringBuilder(operator.getOurOperatorId()).append(model.getData()).append(model.getTimeStamp()).append(model.getSeq()).toString();
+//		byte[] hmacMd5 = SignUtil.getHMacMD5Bytes(key.getBytes(), m.getBytes());
+//		// 打印计算得到的签名Sig
+//		String s = SignUtil.bytesToHexString(hmacMd5);
+//		System.err.println(s);
+	}
 }

--
Gitblit v1.7.1