From 7a4f9541331bef779a506b38a27ed5c3373c0bec Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期四, 15 五月 2025 13:53:22 +0800
Subject: [PATCH] 开发二级等保功能及心跳消息队列修改

---
 ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/drainage/TCECUtil.java |  142 ++++++++++++++++++++++++++++++++--------------
 1 files changed, 98 insertions(+), 44 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 635d109..2478762 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
@@ -40,7 +40,7 @@
 	 * 获取token
 	 */
 	public static String queryToken(Operator operator){
-		HttpRequest post = HttpUtil.createPost(operator.getTestUrl() + InterfaceUrlEnum.QUERY_TOKEN.getUrl());
+		HttpRequest post = HttpUtil.createPost(operator.getUrl() + InterfaceUrlEnum.QUERY_TOKEN.getUrl());
 		JSONObject info = new JSONObject();
 		info.put("OperatorID", operator.getOurOperatorId());
 		info.put("OperatorSecret", operator.getOperatorSecret());
@@ -56,30 +56,30 @@
 		baseRequest.setOperator(operator);
 		baseRequest.setSig(buildSign(baseRequest));
 		String request_json = JacksonUtils.toJson(baseRequest);
-		log.info("获取授权token请求:" + request_json);
-		log.info("获取授权token请求Data:" + jsonString);
+		log.info("获取三方平台授权token请求地址:" + post.getUrl());
+		log.info("获取三方平台授权token请求参数:" + request_json);
+		log.info("获取三方平台授权token请求Data:" + jsonString);
 		post.body(request_json);
 		HttpResponse execute = post.execute();
 		if(200 != execute.getStatus()){
-			log.error("获取三方token失败:" + execute.body());
+			log.error("获取三方平台授权token失败:" + execute.body());
 			return null;
 		}
-		log.info("获取授权token响应:" + execute.body());
+		log.info("获取三方平台授权token响应参数:" + execute.body());
 		BaseResult baseResult = JSON.parseObject(execute.body(), BaseResult.class);
 		Integer Ret = baseResult.getRet();
 		if(0 != Ret){
-			log.error("获取三方token失败:" + baseResult.getMsg());
+			log.error("获取三方平台授权token失败:" + baseResult.getMsg());
 			return null;
 		}
 		//解密参数
 		String decrypt = AESUtil.decrypt(baseResult.getData(), operator.getDataSecret(), operator.getDataSecretIv());
-		log.info("获取授权token请求Data:" + decrypt);
+		log.info("获取三方平台授权token响应Data:" + decrypt);
 		QueryTokenResult queryTokenResult = JSON.parseObject(decrypt, QueryTokenResult.class);
 		String token = queryTokenResult.getAccessToken();
 		Long tokenAvailableTime = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC) + queryTokenResult.getTokenAvailableTime();
-		LocalDateTime localDateTime = Instant.ofEpochSecond(tokenAvailableTime).atOffset(ZoneOffset.UTC).toLocalDateTime();
 		operator.setAccessToken(token);
-		operator.setTokenAvailableTime(localDateTime);
+		operator.setTokenAvailableTime(tokenAvailableTime);
 		operatorClient.editOperator(operator);
 		return token;
 	}
@@ -90,7 +90,7 @@
 	 * @return
 	 */
 	public static String getToken(Operator operator){
-		if(null != operator.getTokenAvailableTime() && operator.getTokenAvailableTime().isBefore(LocalDateTime.now())){
+		if(null != operator.getTokenAvailableTime() && operator.getTokenAvailableTime() > LocalDateTime.now().toEpochSecond(ZoneOffset.UTC)){
 			return operator.getAccessToken();
 		}else{
 			return queryToken(operator);
@@ -104,14 +104,25 @@
 	 * @param info
 	 */
 	public static NotificationStationStatusResult notificationStationStatus(Operator operator, ConnectorStatusInfo info) {
-		HttpRequest post = HttpUtil.createPost(operator.getTestUrl() + InterfaceUrlEnum.NOTIFICATION_STATION_STATUS.getUrl());
+		HttpRequest post = HttpUtil.createPost(operator.getUrl() + InterfaceUrlEnum.NOTIFICATION_STATION_STATUS.getUrl());
 		buildBody(post, info, operator);
 		HttpResponse execute = post.execute();
 		if(200 != execute.getStatus()){
-			log.error("推送三方设备状态变化失败:" + execute.body());
+			log.error("推送三方平台设备状态失败:" + execute.body());
 			return null;
 		}
-		return JSON.parseObject(execute.body(), NotificationStationStatusResult.class);
+		log.info("推送三方平台设备状态响应:" + execute.body());
+		BaseResult baseResult = JSON.parseObject(execute.body(), BaseResult.class);
+		Integer Ret = baseResult.getRet();
+		if(0 != Ret){
+			log.error("推送三方平台设备状态失败:" + baseResult.getMsg());
+			return null;
+		}
+		//解密参数
+		String decrypt = AESUtil.decrypt(baseResult.getData(), operator.getDataSecret(), operator.getDataSecretIv());
+		log.info("推送三方平台设备状态Data:" + decrypt);
+		NotificationStationStatusResult notificationStationStatusResult = JSON.parseObject(decrypt, NotificationStationStatusResult.class);
+		return notificationStationStatusResult;
 	}
 	
 	
@@ -125,20 +136,25 @@
 	 * @return
 	 */
 	public static NotificationStartChargeResult notificationStartChargeResult(Operator operator, NotificationStartCharge info){
-		HttpRequest post = HttpUtil.createPost(operator.getTestUrl() + InterfaceUrlEnum.NOTIFICATION_START_CHARGE_RESULT.getUrl());
+		HttpRequest post = HttpUtil.createPost(operator.getUrl() + InterfaceUrlEnum.NOTIFICATION_START_CHARGE_RESULT.getUrl());
 		buildBody(post, info, operator);
 		HttpResponse execute = post.execute();
 		if(200 != execute.getStatus()){
-			log.error("推送三方启动充电结果失败:" + execute.body());
+			log.error("推送三方平台启动充电结果失败:" + execute.body());
 			return null;
 		}
-		JSONObject jsonObject = JSON.parseObject(execute.body());
-		Integer ret = jsonObject.getInteger("Ret");
-		if(0 != ret){
-			log.error("推送三方启动充电结果失败:" + execute.body());
+		log.info("推送三方平台启动充电结果响应:" + execute.body());
+		BaseResult baseResult = JSON.parseObject(execute.body(), BaseResult.class);
+		Integer Ret = baseResult.getRet();
+		if(0 != Ret){
+			log.error("推送三方平台启动充电结果失败:" + baseResult.getMsg());
 			return null;
 		}
-		return jsonObject.getObject("Data", NotificationStartChargeResult.class);
+		//解密参数
+		String decrypt = AESUtil.decrypt(baseResult.getData(), operator.getDataSecret(), operator.getDataSecretIv());
+		log.info("推送三方平台启动充电结果Data:" + decrypt);
+		NotificationStartChargeResult notificationStartChargeResult = JSON.parseObject(decrypt, NotificationStartChargeResult.class);
+		return notificationStartChargeResult;
 	}
 	
 	
@@ -153,20 +169,25 @@
 	 * @return
 	 */
 	public static NotificationEquipChargeStatusResult notificationEquipChargeStatus(Operator operator, QueryEquipChargeStatusResult info){
-		HttpRequest post = HttpUtil.createPost(operator.getTestUrl() + InterfaceUrlEnum.NOTIFICATION_EQUIP_CHARGE_STATUS.getUrl());
+		HttpRequest post = HttpUtil.createPost(operator.getUrl() + InterfaceUrlEnum.NOTIFICATION_EQUIP_CHARGE_STATUS.getUrl());
 		buildBody(post, info, operator);
 		HttpResponse execute = post.execute();
 		if(200 != execute.getStatus()){
-			log.error("推送三方充电状态失败:" + execute.body());
+			log.error("推送三方平台充电状态失败:" + execute.body());
 			return null;
 		}
-		JSONObject jsonObject = JSON.parseObject(execute.body());
-		Integer ret = jsonObject.getInteger("Ret");
-		if(0 != ret){
-			log.error("推送三方充电状态失败:" + execute.body());
+		log.info("推送三方平台充电状态响应:" + execute.body());
+		BaseResult baseResult = JSON.parseObject(execute.body(), BaseResult.class);
+		Integer Ret = baseResult.getRet();
+		if(0 != Ret){
+			log.error("推送三方平台充电状态失败:" + baseResult.getMsg());
 			return null;
 		}
-		return jsonObject.getObject("Data", NotificationEquipChargeStatusResult.class);
+		//解密参数
+		String decrypt = AESUtil.decrypt(baseResult.getData(), operator.getDataSecret(), operator.getDataSecretIv());
+		log.info("推送三方平台充电状态Data:" + decrypt);
+		NotificationEquipChargeStatusResult notificationEquipChargeStatusResult = JSON.parseObject(decrypt, NotificationEquipChargeStatusResult.class);
+		return notificationEquipChargeStatusResult;
 	}
 	
 	
@@ -176,20 +197,25 @@
 	 * @return
 	 */
 	public static NotificationStopCharge notificationStopChargeResult(Operator operator, NotificationStopChargeResult info){
-		HttpRequest post = HttpUtil.createPost(operator.getTestUrl() + InterfaceUrlEnum.NOTIFICATION_STOP_CHARGE_RESULT.getUrl());
+		HttpRequest post = HttpUtil.createPost(operator.getUrl() + InterfaceUrlEnum.NOTIFICATION_STOP_CHARGE_RESULT.getUrl());
 		buildBody(post, info, operator);
 		HttpResponse execute = post.execute();
 		if(200 != execute.getStatus()){
-			log.error("推送三方停止充电结果失败:" + execute.body());
+			log.error("推送三方平台停止充电结果失败:" + execute.body());
 			return null;
 		}
-		JSONObject jsonObject = JSON.parseObject(execute.body());
-		Integer ret = jsonObject.getInteger("Ret");
-		if(0 != ret){
-			log.error("推送三方停止充电结果失败:" + execute.body());
+		log.info("推送三方平台停止充电结果响应:" + execute.body());
+		BaseResult baseResult = JSON.parseObject(execute.body(), BaseResult.class);
+		Integer Ret = baseResult.getRet();
+		if(0 != Ret){
+			log.error("推送三方平台停止充电结果失败:" + baseResult.getMsg());
 			return null;
 		}
-		return jsonObject.getObject("Data", NotificationStopCharge.class);
+		//解密参数
+		String decrypt = AESUtil.decrypt(baseResult.getData(), operator.getDataSecret(), operator.getDataSecretIv());
+		log.info("推送三方平台停止充电结果Data:" + decrypt);
+		NotificationStopCharge notificationStopCharge = JSON.parseObject(decrypt, NotificationStopCharge.class);
+		return notificationStopCharge;
 	}
 	
 	
@@ -201,20 +227,25 @@
 	 * @return
 	 */
 	public static NotificationChargeOrderInfoResult notificationChargeOrderInfo(Operator operator, NotificationChargeOrderInfo info){
-		HttpRequest post = HttpUtil.createPost(operator.getTestUrl() + InterfaceUrlEnum.NOTIFICATION_CHARGE_ORDER_INFO.getUrl());
+		HttpRequest post = HttpUtil.createPost(operator.getUrl() + InterfaceUrlEnum.NOTIFICATION_CHARGE_ORDER_INFO.getUrl());
 		buildBody(post, info, operator);
 		HttpResponse execute = post.execute();
 		if(200 != execute.getStatus()){
-			log.error("推送三方充电订单信息失败:" + execute.body());
+			log.error("推送三方平台充电订单信息失败:" + execute.body());
 			return null;
 		}
-		JSONObject jsonObject = JSON.parseObject(execute.body());
-		Integer ret = jsonObject.getInteger("Ret");
-		if(0 != ret){
-			log.error("推送三方充电订单信息失败:" + execute.body());
+		log.info("推送三方平台充电订单信息响应:" + execute.body());
+		BaseResult baseResult = JSON.parseObject(execute.body(), BaseResult.class);
+		Integer Ret = baseResult.getRet();
+		if(0 != Ret){
+			log.error("推送三方平台充电订单信息失败:" + baseResult.getMsg());
 			return null;
 		}
-		return jsonObject.getObject("Data", NotificationChargeOrderInfoResult.class);
+		//解密参数
+		String decrypt = AESUtil.decrypt(baseResult.getData(), operator.getDataSecret(), operator.getDataSecretIv());
+		log.info("推送三方平台充电订单信息Data:" + decrypt);
+		NotificationChargeOrderInfoResult notificationChargeOrderInfoResult = JSON.parseObject(decrypt, NotificationChargeOrderInfoResult.class);
+		return notificationChargeOrderInfoResult;
 	}
 	
 	
@@ -236,7 +267,11 @@
 		baseRequest.setData(encrypt);
 		baseRequest.setOperator(operator);
 		baseRequest.setSig(buildSign(baseRequest));
-		post.body(JacksonUtils.toJson(baseRequest));
+		String request_json = JacksonUtils.toJson(baseRequest);
+		post.body(request_json);
+		log.info("推送三方平台请求地址:" + post.getUrl());
+		log.info("推送三方平台请求参数:" + request_json);
+		log.info("推送三方平台请求Data:" + jsonString);
 	}
 
 	
@@ -262,7 +297,10 @@
 				sign = SignUtil.bytesToHexString(hmacMd5);
 				break;
 			case "KuaiDian":
-				sign = SignUtil.hmacSign(model.getData(), key);
+				//进行字符串拼接、计算
+				String m1 = new StringBuilder(model.getOperatorID()).append(model.getData()).append(model.getTimeStamp()).append(model.getSeq()).toString();
+				// 打印计算得到的签名Sig
+				sign = SignUtil.hmacSign(m1, key);
 				break;
 		}
 		return sign;
@@ -292,11 +330,27 @@
 				sign = SignUtil.bytesToHexString(hmacMd5);
 				break;
 			case "KuaiDian":
-				sign = SignUtil.hmacSign(model.getData(), key);
+				//进行字符串拼接、计算
+				String m1 = new StringBuilder(model.getOperatorID()).append(model.getData()).append(model.getTimeStamp()).append(model.getSeq()).toString();
+				sign = SignUtil.hmacSign(m1, key);
 				break;
 		}
 		return sign;
 	}
+	public static String ourBuildSignJianGuan(BaseModel model){
+		Operator operator = model.getOperator();
+		if(null == operator){
+			return "";
+		}
+		//签名秘钥SigSecret
+		String key = operator.getOurSigSecret();
+		String sign = "";
+		//进行字符串拼接、计算
+		String m1 = new StringBuilder(model.getOperatorID()).append(model.getData()).append(model.getTimeStamp()).append(model.getSeq()).toString();
+		sign = SignUtil.hmacSign(m1, key);
+		return sign;
+	}
+
 
 	
 	

--
Gitblit v1.7.1