|
|
@@ -5,6 +5,10 @@ import cn.hutool.json.JSONUtil;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.zsElectric.boot.charging.entity.ThirdPartyApiLog;
|
|
|
import com.zsElectric.boot.charging.service.ThirdPartyApiLogService;
|
|
|
+import com.zsElectric.boot.common.constant.ConnectivityConstants;
|
|
|
+import com.zsElectric.boot.common.util.AESCryptoUtils;
|
|
|
+import com.zsElectric.boot.common.util.electric.RequestParmsEntity;
|
|
|
+import com.zsElectric.boot.common.util.electric.ResponseParmsEntity;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -91,6 +95,7 @@ public class ThirdPartyApiLogAspect {
|
|
|
apiLog.setRequestMethod(request.getMethod());
|
|
|
apiLog.setRequestUrl(request.getRequestURL().toString());
|
|
|
apiLog.setInterfaceName(request.getRequestURI());
|
|
|
+ apiLog.setInterfaceDescription(getInterfaceDescription(request.getRequestURI()));
|
|
|
apiLog.setClientIp(getClientIp(request));
|
|
|
apiLog.setUserAgent(request.getHeader("User-Agent"));
|
|
|
|
|
|
@@ -112,6 +117,9 @@ public class ThirdPartyApiLogAspect {
|
|
|
|
|
|
// 尝试提取业务字段
|
|
|
extractBusinessFields(arg, apiLog);
|
|
|
+
|
|
|
+ // 尝试解密请求数据(针对 RequestParmsEntity 类型)
|
|
|
+ decryptRequestData(arg, apiLog);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -129,6 +137,9 @@ public class ThirdPartyApiLogAspect {
|
|
|
|
|
|
if (result != null) {
|
|
|
apiLog.setResponseBody(objectMapper.writeValueAsString(result));
|
|
|
+
|
|
|
+ // 尝试解密响应数据(针对 ResponseParmsEntity 类型)
|
|
|
+ decryptResponseData(result, apiLog);
|
|
|
}
|
|
|
|
|
|
// 异步保存日志
|
|
|
@@ -151,6 +162,62 @@ public class ThirdPartyApiLogAspect {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 解密请求数据
|
|
|
+ * 针对 LinkDataController 接收的 RequestParmsEntity 类型参数进行解密
|
|
|
+ */
|
|
|
+ private void decryptRequestData(Object requestBody, ThirdPartyApiLog apiLog) {
|
|
|
+ try {
|
|
|
+ // 判断是否为 RequestParmsEntity 类型
|
|
|
+ if (requestBody instanceof RequestParmsEntity) {
|
|
|
+ RequestParmsEntity requestParms = (RequestParmsEntity) requestBody;
|
|
|
+ String encryptedData = requestParms.getData();
|
|
|
+
|
|
|
+ if (StrUtil.isNotBlank(encryptedData)) {
|
|
|
+ // 使用系统密钥解密
|
|
|
+ String decryptedData = AESCryptoUtils.decrypt(
|
|
|
+ encryptedData,
|
|
|
+ ConnectivityConstants.DATA_SECRET,
|
|
|
+ ConnectivityConstants.DATA_SECRET_IV
|
|
|
+ );
|
|
|
+
|
|
|
+ apiLog.setDecryptedRequestData(decryptedData);
|
|
|
+ log.debug("请求数据解密成功: {}", decryptedData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("解密请求数据失败: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解密响应数据
|
|
|
+ * 针对返回的 ResponseParmsEntity 类型响应进行解密
|
|
|
+ */
|
|
|
+ private void decryptResponseData(Object responseBody, ThirdPartyApiLog apiLog) {
|
|
|
+ try {
|
|
|
+ // 判断是否为 ResponseParmsEntity 类型
|
|
|
+ if (responseBody instanceof ResponseParmsEntity) {
|
|
|
+ ResponseParmsEntity responseParms = (ResponseParmsEntity) responseBody;
|
|
|
+ String encryptedData = responseParms.getData();
|
|
|
+
|
|
|
+ if (StrUtil.isNotBlank(encryptedData)) {
|
|
|
+ // 使用系统密钥解密
|
|
|
+ String decryptedData = AESCryptoUtils.decrypt(
|
|
|
+ encryptedData,
|
|
|
+ ConnectivityConstants.DATA_SECRET,
|
|
|
+ ConnectivityConstants.DATA_SECRET_IV
|
|
|
+ );
|
|
|
+
|
|
|
+ apiLog.setDecryptedResponseData(decryptedData);
|
|
|
+ log.debug("响应数据解密成功: {}", decryptedData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("解密响应数据失败: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 提取业务字段
|
|
|
*/
|
|
|
@@ -218,6 +285,49 @@ public class ThirdPartyApiLogAspect {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取接口中文说明
|
|
|
+ * 根据接口路径返回对应的中文说明
|
|
|
+ */
|
|
|
+ private String getInterfaceDescription(String uri) {
|
|
|
+ if (StrUtil.isBlank(uri)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // LinkDataController 接口说明
|
|
|
+ if (uri.contains("/query_token")) {
|
|
|
+ return "获取token";
|
|
|
+ } else if (uri.contains("/notification_start_charge_result")) {
|
|
|
+ return "推送启动充电结果";
|
|
|
+ } else if (uri.contains("/notification_equip_charge_status")) {
|
|
|
+ return "推送充电状态";
|
|
|
+ } else if (uri.contains("/notification_stop_charge_result")) {
|
|
|
+ return "推送停止充电结果";
|
|
|
+ } else if (uri.contains("/notification_charge_order_info")) {
|
|
|
+ return "推送充电订单信息";
|
|
|
+ } else if (uri.contains("/notification_stationStatus")) {
|
|
|
+ return "设备状态变化推送";
|
|
|
+ }
|
|
|
+ // ChargingBusinessController 接口说明
|
|
|
+ else if (uri.contains("/queryEquipBusinessPolicy")) {
|
|
|
+ return "查询业务策略信息";
|
|
|
+ } else if (uri.contains("/queryEquipAuth")) {
|
|
|
+ return "请求设备认证";
|
|
|
+ } else if (uri.contains("/queryStationsInfo")) {
|
|
|
+ return "查询充电站信息";
|
|
|
+ } else if (uri.contains("/queryStationStatus")) {
|
|
|
+ return "设备接口状态查询";
|
|
|
+ } else if (uri.contains("/startCharging")) {
|
|
|
+ return "请求启动充电";
|
|
|
+ } else if (uri.contains("/queryChargingStatus")) {
|
|
|
+ return "查询充电状态";
|
|
|
+ } else if (uri.contains("/stopCharging")) {
|
|
|
+ return "请求停止充电";
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取客户端真实IP
|
|
|
*/
|