Browse Source

4.25接口调试

czt 1 week ago
parent
commit
b49e6cebc0

+ 1 - 1
ruoyi-admin/src/main/resources/application.yml

@@ -148,7 +148,7 @@ xss:
   urlPatterns: /system/*,/monitor/*,/tool/*
   # 接口
 api:
-  rootUrl: http://charge-external.yuncloudtech.cn
+  rootUrl: https://cdsc-fest.cdjqsw.cn:44350
   # 接口安全配置
   security:
     aes-key: "ajdklhfiqjkalqfu" # 前置系统提供的16位AES密钥

+ 1 - 1
ruoyi-api/src/main/java/com/ruoyi/api/job/SftpDataImportTask.java

@@ -71,7 +71,7 @@ public class SftpDataImportTask {
         String remotePath = sftpConfig.getBaseUrl() + "/check/"+projectId+"/" + year + "/" + month + "/" + day;
         String remoteFileName = "check.csv";
 
-        // 2. 本地临时文件路径
+        // 2. 本地临时文件路径0
         Path localTempDir = Paths.get(downloadTempPath);
         try {
             if (!Files.exists(localTempDir)) {

+ 4 - 4
ruoyi-api/src/main/java/com/ruoyi/api/service/impl/UnifiedApiServiceImpl.java

@@ -127,7 +127,7 @@ public class UnifiedApiServiceImpl implements IUnifiedApiService {
                     return handleTableChangeList(requestVO);
                 case "customerPhoneNoChange":  // 新增联系电话变更
                     return handleCustomerPhoneNoChange(requestVO);
-                case "deductionList":  // 新增联系电话变更
+                case "deductionList":  // 新增减免明细查询
                     return handleDeductionList(requestVO);
                 default:
                     return UnifiedApiRespDTO.error("不支持的operationType: " + requestVO.getOperationType());
@@ -2505,8 +2505,8 @@ public class UnifiedApiServiceImpl implements IUnifiedApiService {
             // 构建请求参数(严格按甲方字段)
             Map<String, Object> params = new HashMap<>();
             params.put("accountNumber", queryVO.getAccountNumber());
-            params.put("meterReadTimeStart", queryVO.getMeterReadTimeStart());
-            params.put("meterReadTimeEnd", queryVO.getMeterReadTimeEnd());
+//            params.put("meterReadTimeStart", queryVO.getMeterReadTimeStart());
+//            params.put("meterReadTimeEnd", queryVO.getMeterReadTimeEnd());
             params.put("startTime", queryVO.getStartTime());
             params.put("endTime", queryVO.getEndTime());
 
@@ -2517,7 +2517,7 @@ public class UnifiedApiServiceImpl implements IUnifiedApiService {
             params.put("limit", limit);
 
             // 调用营收系统接口
-            DeductionListResp revenueResp = httpClientUtil.doPost(
+            DeductionListResp revenueResp = httpClientUtil.doPostNotCaseSensitive(
                     rootUrl + "/api/customer/deductionList",
                     params,
                     DeductionListResp.class

File diff suppressed because it is too large
+ 11 - 4
ruoyi-api/src/main/java/com/ruoyi/api/utils/ApiSecurityUtil.java


+ 121 - 3
ruoyi-api/src/main/java/com/ruoyi/api/utils/HttpClientUtil.java

@@ -81,14 +81,132 @@ public class HttpClientUtil {
             connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
 //            connection.setRequestProperty("appKey", "xxxxxxxxx");
 //            connection.setRequestProperty("appSecret", "xxxxxxxxxxxxxxxx");
-            connection.setRequestProperty("__tenant", "39fdfe6a-b1a9-ea14-7c44-e42efad2aca3");
+//            connection.setRequestProperty("__tenant", "39fdfe6a-b1a9-ea14-7c44-e42efad2aca3");
+            connection.setConnectTimeout(10000);  // 10秒连接超时
+            connection.setReadTimeout(30000);     // 30秒读取超时
+            connection.setDoOutput(true);
+
+            // 3. 发送请求
+            try (OutputStream os = connection.getOutputStream()) {
+                byte[] input = encryptedRequest.getBytes(StandardCharsets.UTF_8);
+                os.write(input, 0, input.length);
+            }
+
+            // 4. 获取响应
+            int responseCode = connection.getResponseCode();
+            if (responseCode == HttpURLConnection.HTTP_OK) {
+                StringBuilder response = new StringBuilder();
+                try (BufferedReader br = new BufferedReader(
+                        new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
+                    String line;
+                    while ((line = br.readLine()) != null) {
+                        response.append(line);
+                    }
+                }
+
+                responseStr = response.toString();
+                logger.info("第三方原始响应: {}", responseStr);
+
+                // 解析外层响应(包含code, message, status, data)
+                Map<String, Object> outerResponse = JSON.parseObject(responseStr, Map.class);
+
+                // 检查业务状态码
+                String code = (String) outerResponse.get("code");
+                if (!"200".equals(code)) {
+                    String message = (String) outerResponse.get("message");
+                    throw new RuntimeException("第三方接口业务异常,code: " + code + ", message: " + message);
+                }
+                success = true;
+
+                // 获取data字段中的加密数据
+                Map<String, String> data = (Map<String, String>) outerResponse.get("data");
+                if (data == null) {
+                    throw new RuntimeException("响应中缺少data字段");
+                }
+
+                String encryptedResponseText = data.get("text");
+                String responseSign = data.get("sign");
+
+                if (encryptedResponseText == null || responseSign == null) {
+                    throw new RuntimeException("响应数据格式不正确,缺少text或sign字段");
+                }
+
+                // 5. 验签和解密
+                boolean verifyResult = apiSecurityUtil.rsaVerify(
+                        encryptedResponseText,
+                        responseSign,
+                        thirdPartyPublicKeyBase64
+                );
+
+                if (!verifyResult) {
+                    throw new RuntimeException("响应验签失败,数据可能被篡改");
+                }
+
+                decryptedText = apiSecurityUtil.aesDecrypt(encryptedResponseText, aesKey);
+                logger.debug("解密后的响应: {}", decryptedText);
+
+                return JSON.parseObject(decryptedText, responseType);
+
+            } else {
+                throw new RuntimeException("HTTP请求失败,状态码: " + responseCode);
+            }
+
+        } catch (Exception e) {
+            exception = e;
+            logger.error("HTTP请求失败: {}", e.getMessage(), e);
+            throw new RuntimeException("HTTP请求失败: " + e.getMessage());
+        } finally {
+            if (connection != null) {
+                connection.disconnect();
+            }
+            // 异步记录日志
+            recordApiLog(url, requestJson, encryptedRequest, responseStr, decryptedText, success, exception);
+        }
+    }
+
+
+    public <T> T doPostNotCaseSensitive(String url, Object request, Class<T> responseType) {
+        HttpURLConnection connection = null;
+        String encryptedRequest = null;
+        String requestJson = null;
+        String responseStr = null;
+        String decryptedText = null;
+        boolean success = false;
+        Exception exception = null;
+        try {
+
+            String requestBody = JSON.toJSONString(request);
+            requestJson = requestBody;
+
+            // 1. 加密和签名(保持您原有的逻辑)
+            String originalRequest = JSON.toJSONString(request);
+            logger.info("调用第三方接口 URL: {}, 原始请求参数: {}", url, requestJson);
+
+            String encryptedData = apiSecurityUtil.aesEncrypt(requestJson, aesKey);
+            String sign = apiSecurityUtil.rsaSign(encryptedData, rsaPrivateKeyBase64);
+
+            Map<String, String> finalRequest = new HashMap<>();
+            finalRequest.put("text", encryptedData);
+            finalRequest.put("sign", sign);
+
+            // 保存加密后的请求参数用于日志
+            encryptedRequest = JSON.toJSONString(finalRequest);
+
+            // 2. 创建HTTP连接
+            URL urlObj = new URL(url);
+            connection = (HttpURLConnection) urlObj.openConnection();
+            connection.setRequestMethod("POST");
+            connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
+//            connection.setRequestProperty("appKey", "xxxxxxxxx");
+//            connection.setRequestProperty("appSecret", "xxxxxxxxxxxxxxxx");
+//            connection.setRequestProperty("__tenant", "39fdfe6a-b1a9-ea14-7c44-e42efad2aca3");
             connection.setConnectTimeout(10000);  // 10秒连接超时
             connection.setReadTimeout(30000);     // 30秒读取超时
             connection.setDoOutput(true);
 
             // 3. 发送请求
             try (OutputStream os = connection.getOutputStream()) {
-                byte[] input = requestBody.getBytes(StandardCharsets.UTF_8);
+                byte[] input = encryptedRequest.getBytes(StandardCharsets.UTF_8);
                 os.write(input, 0, input.length);
             }
 
@@ -327,7 +445,7 @@ public class HttpClientUtil {
 
             // 3. 发送请求
             try (OutputStream os = connection.getOutputStream()) {
-                byte[] input = requestBody.getBytes(StandardCharsets.UTF_8);
+                byte[] input = encryptedRequest.getBytes(StandardCharsets.UTF_8);
                 os.write(input, 0, input.length);
             }
 

File diff suppressed because it is too large
+ 1 - 1
ruoyi-api/src/main/java/com/ruoyi/api/utils/Sm4Utils.java