From 52952b8b5d92efc12eabf007ff57bf9fed3c7e8a Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期一, 21 七月 2025 14:40:13 +0800
Subject: [PATCH] 大屏vo
---
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/drainage/kuaidian/TCECKDUtil.java | 116 ++++++++-------------------------------------------------
1 files changed, 17 insertions(+), 99 deletions(-)
diff --git a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/drainage/kuaidian/TCECKDUtil.java b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/drainage/kuaidian/TCECKDUtil.java
index 71d41df..ebb5256 100644
--- a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/drainage/kuaidian/TCECKDUtil.java
+++ b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/drainage/kuaidian/TCECKDUtil.java
@@ -8,6 +8,7 @@
import com.ruoyi.common.core.utils.SpringUtils;
import com.ruoyi.integration.drainage.AESUtil;
import com.ruoyi.integration.drainage.SignUtil;
+import com.ruoyi.integration.drainage.TCECUtil;
import com.ruoyi.integration.drainage.kuaidian.model.NotificationStationChangeResult;
import com.ruoyi.integration.drainage.kuaidian.model.StationChange;
import com.ruoyi.integration.drainage.model.*;
@@ -31,59 +32,7 @@
* @Date 2025/1/21 11:48
*/
@Slf4j
-public class TCECKDUtil {
- /**
- * 运营商标识
- */
- private static final String OperatorID = "";
-
- private static OperatorClient operatorClient = SpringUtils.getBean(OperatorClient.class);
-
- private static Map<Long, Integer> map = new HashMap<>();
-
-
- /**
- * 获取token
- */
- public static String queryToken(Operator operator){
- HttpRequest post = HttpUtil.createPost("");
- post.contentType("application/json;charset=utf-8");
- JSONObject body = new JSONObject();
- body.put("OperatorID", OperatorID);
- body.put("OperatorSecret", operator.getOurOperatorSecret());
- post.body(body.toJSONString());
- HttpResponse execute = post.execute();
- if(200 != execute.getStatus()){
- log.error("获取三方token失败:" + execute.body());
- return null;
- }
- JSONObject jsonObject = JSON.parseObject(execute.body());
- Integer succStat = jsonObject.getInteger("SuccStat");
- if(0 != succStat){
- log.error("获取三方token失败:" + jsonObject.getString("FailReason"));
- return null;
- }
- String token = jsonObject.getString("AccessToken");
- Long tokenAvailableTime = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC) + jsonObject.getLong("TokenAvailableTime");
- LocalDateTime localDateTime = Instant.ofEpochSecond(tokenAvailableTime).atOffset(ZoneOffset.UTC).toLocalDateTime();
- operator.setAccessToken(token);
- operator.setTokenAvailableTime(localDateTime);
- operatorClient.editOperator(operator);
- return token;
- }
-
-
- /**
- * 获取token
- * @return
- */
- public static String getToken(Operator operator){
- if(null != operator.getTokenAvailableTime() && operator.getTokenAvailableTime().isBefore(LocalDateTime.now())){
- return operator.getAccessToken();
- }else{
- return queryToken(operator);
- }
- }
+public class TCECKDUtil extends TCECUtil {
@@ -97,63 +46,32 @@
*/
public static NotificationStationChangeResult notificationStationChange(Operator operator, Integer type, List<Integer> siteIds) {
StationChange stationChange = new StationChange();
- stationChange.setOperatorId(OperatorID);
+ stationChange.setOperatorId(operator.getOurOperatorId());
stationChange.setType(type);
List<String> collect = siteIds.stream().map(String::valueOf).collect(Collectors.toList());
stationChange.setStationIds(collect);
- HttpRequest post = HttpUtil.createPost(operator.getTestUrl() + InterfaceUrlEnum.NOTIFICATION_STATION_CHANGE.getUrl());
+ HttpRequest post = HttpUtil.createPost(operator.getUrl() + InterfaceUrlEnum.NOTIFICATION_STATION_CHANGE.getUrl());
buildBody(post, stationChange, operator);
HttpResponse execute = post.execute();
if(200 != execute.getStatus()){
- log.error("推送站点变更通知失败:" + execute.body());
+ log.error("推送三方平台站点变更通知失败:" + execute.body());
return null;
}
- return JSON.parseObject(execute.body(), NotificationStationChangeResult.class);
- }
-
-
-
- /**
- * 构建请求参数和消息头
- * @param post
- * @param o
- */
- public static void buildBody(HttpRequest post, Object o, Operator operator){
- Long timeStamp = Long.valueOf(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")));
- Integer integer = map.get(timeStamp);
- if(null == integer){
- integer = 1;
- }else{
- integer++;
+ 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;
}
- map.put(timeStamp, integer);
- post.contentType("application/json;charset=utf-8");
- post.header("Authorization", "Bearer " + getToken(operator));
- BaseRequest baseRequest = new BaseRequest();
- baseRequest.setOperatorID(OperatorID);
- baseRequest.setTimeStamp(timeStamp);
- baseRequest.setSeq(String.format("%04d", integer));
- String jsonString = JSON.toJSONString(o);
- String encrypt = AESUtil.encrypt(jsonString, operator.getDataSecret(), operator.getDataSecretIv());
- baseRequest.setData(encrypt);
- baseRequest.setOperator(operator);
- baseRequest.setSig(buildSign(baseRequest));
- post.body(JSON.toJSONString(baseRequest));
- //清空小于当前时间的map中的无效数据
- for (Long k : map.keySet()) {
- if(k <= (timeStamp - 10)){
- map.remove(k);
- }
- }
+ //解密参数
+ String decrypt = AESUtil.decrypt(baseResult.getData(), operator.getDataSecret(), operator.getDataSecretIv());
+ log.info("推送三方平台站点变更通知Data:" + decrypt);
+ NotificationStationChangeResult notificationStationChangeResult = JSON.parseObject(decrypt, NotificationStationChangeResult.class);
+ return notificationStationChangeResult;
}
+
- public static String buildSign(BaseModel model){
- Operator operator = model.getOperator();
- //签名秘钥SigSecret
- String key = operator.getSigSecret();
- String sign = SignUtil.hmacSign(model.getData(), key);
- return sign;
- }
}
--
Gitblit v1.7.1