From 9e43c32ad97ad39a1b9aa2852d788ca1c566e982 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期四, 20 二月 2025 17:41:10 +0800
Subject: [PATCH] 对账
---
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/drainage/TCECUtil.java | 156 +++++++++++++++++++++++++++++++++++----------------
1 files changed, 107 insertions(+), 49 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 2bc2f07..edc211e 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,28 +40,46 @@
* 获取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());
+ Long timeStamp = Long.valueOf(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")));
post.contentType("application/json;charset=utf-8");
- JSONObject body = new JSONObject();
- body.put("OperatorID", operator.getOurOperatorId());
- body.put("OperatorSecret", operator.getOurOperatorSecret());
- post.body(body.toJSONString());
+ BaseRequest baseRequest = new BaseRequest();
+ baseRequest.setOperatorID(operator.getOurOperatorId());
+ baseRequest.setTimeStamp(timeStamp);
+ baseRequest.setSeq("0001");
+ String jsonString = JacksonUtils.toJson(info);
+ String encrypt = AESUtil.encrypt(jsonString, operator.getDataSecret(), operator.getDataSecretIv());
+ baseRequest.setData(encrypt);
+ baseRequest.setOperator(operator);
+ baseRequest.setSig(buildSign(baseRequest));
+ String request_json = JacksonUtils.toJson(baseRequest);
+ 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;
}
- JSONObject jsonObject = JSON.parseObject(execute.body());
- Integer succStat = jsonObject.getInteger("SuccStat");
- if(0 != succStat){
- log.error("获取三方token失败:" + jsonObject.getString("FailReason"));
+ 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());
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();
+ //解密参数
+ String decrypt = AESUtil.decrypt(baseResult.getData(), operator.getDataSecret(), operator.getDataSecretIv());
+ 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();
operator.setAccessToken(token);
- operator.setTokenAvailableTime(localDateTime);
+ operator.setTokenAvailableTime(tokenAvailableTime);
operatorClient.editOperator(operator);
return token;
}
@@ -72,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);
@@ -86,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;
}
@@ -107,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;
}
@@ -135,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;
}
@@ -158,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;
}
@@ -183,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;
}
@@ -218,7 +267,11 @@
baseRequest.setData(encrypt);
baseRequest.setOperator(operator);
baseRequest.setSig(buildSign(baseRequest));
- post.body(JSON.toJSONString(baseRequest));
+ String request_json = JacksonUtils.toJson(baseRequest);
+ post.body(request_json);
+ log.info("推送三方平台请求地址:" + post.getUrl());
+ log.info("推送三方平台请求参数:" + request_json);
+ log.info("推送三方平台请求Data:" + jsonString);
}
@@ -244,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;
@@ -274,7 +330,9 @@
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;
--
Gitblit v1.7.1