zengsj преди 10 месеца
родител
ревизия
2778d7a195

+ 26 - 25
src/main/java/com/yizhu/supervise/common/util/PostUtil.java

@@ -2,6 +2,8 @@ package com.yizhu.supervise.common.util;
 
 import cn.hutool.http.HttpRequest;
 import cn.hutool.http.HttpResponse;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
 import lombok.extern.slf4j.Slf4j;
 import openapi.Client;
 import openapi.Response;
@@ -22,45 +24,44 @@ public class PostUtil {
 
     public PostUtil() {
     }
-
-    public static HisResponseTO post(String method,String jsonStr) {
+    public static HisResponseTO post(String method, String jsonStr) {
         HisResponseTO<?> hisResponse = new HisResponseTO();
-       // Client client = new Client(apiUrl, appKey, appSecret, encodingAesKey);
-//        List bodyList = new ArrayList();
-//        bodyList.add(param);
-        // Request request = new Request(serviceId, method, bodyList);
-     //   Response response = null;
         HttpRequest request = HttpRequest.post(apiUrl);
-        // 设置请求头
-        request.header("Content-Type", "application/json"); // 设置Content-Type为JSON格式
-        request.header("Authorization", "Bearer your_access_token_here"); // 示例:设置Authorization头
-        request.header("apiUrl",apiUrl);
-        request.header("appKey", appKey);
-        request.header("appSecret", appSecret);
-        request.header("X-Ca-Key", appKey);
-        request.header("X-Ca-Nonce", UUID.randomUUID().toString());
-        request.header("X-Ca-Timestamp", String.valueOf(System.currentTimeMillis()));
-        log.info("请求方法:"+method+"request参数" + request);
-        log.info("请求方法:"+method+"实际请求参数" +jsonStr );
+        String uuid = UUID.randomUUID().toString();
+        String ts = String.valueOf(System.currentTimeMillis());
         String encryptStr = SM4Utils.encryptNationalSerAlgorithmCBC(jsonStr, appSecret);
         String contentMd5 = SM3Util.encode(encryptStr);
-        request.header("X-Content-MD5", contentMd5);
-        Map<String,String> headers = new HashMap();
+        //签名
+        Map<String, String> headers = new HashMap();
         headers.put("X-Ca-Key", appKey);
+        headers.put("X-Ca-Nonce", uuid);
+        headers.put("X-Ca-Timestamp", ts);
         headers.put("X-Service-Id", serviceId);
         headers.put("X-Service-Method", method);
-        String signature = SignUtil.signWithSm3(headers);
+        headers.put("X-Content-MD5", contentMd5);
+        List<String> siginlist = Arrays.asList("X-Service-Id", "X-Service-Method", "X-Ca-Key", "X-Ca-Nonce", "X-Ca-Timestamp", "X-Content-MD5");
+        String sbStr = SignUtil.buildHeaders(headers, siginlist);
+        String signature = SM3Util.encode(sbStr);
+        // 设置请求头
+        request.header("Content-Type", "application/json;charset=UTF-8");
+        request.header("X-Ca-Key", appKey);
         request.header("X-Ca-Signature", signature);
-        request.header("stringBody",encryptStr);
+        request.header("X-Content-MD5", contentMd5);
+        request.header("X-Service-Method", method);
+        request.header("X-Service-Id", serviceId);
+        request.header("X-Ca-Nonce", uuid);
+        request.header("X-Ca-Timestamp", ts);
+        request.header("X-Ca-Signature-Headers", "X-Service-Id,X-Service-Method,X-Ca-Key,X-Ca-Nonce,X-Ca-Timestamp,X-Content-MD5");
+        request.header("signature", signature);
         // 设置请求体(JSON格式)
-        request.body(jsonStr);
+        request.body(encryptStr);
         // 发送请求并获取响应
         try {
             HttpResponse response = request.execute();
             log.debug("监管平台返回结果:" + JSONUtils.toString(response));
             String body = response.body();
             if (body != null) {
-                hisResponse = (HisResponseTO)JSONUtils.parse(body, HisResponseTO.class);
+                hisResponse = (HisResponseTO) JSONUtils.parse(body, HisResponseTO.class);
                 hisResponse.setMsg(hisResponse.getBody().getMsg());
             } else {
                 hisResponse.setMsgCode("-1");
@@ -89,7 +90,7 @@ public class PostUtil {
             String body = response.getBody();
             log.debug("body:" + body);
             if (body != null) {
-                fileResponse = (FileResponseTO)JSONUtils.parse(body, fileResponse.getClass());
+                fileResponse = (FileResponseTO) JSONUtils.parse(body, fileResponse.getClass());
                 fileResponse.setMsg("上传成功");
             } else {
                 fileResponse.setMsgCode("-1");

+ 2 - 2
src/main/java/com/yizhu/supervise/controllers/SuperviseController.java

@@ -62,7 +62,7 @@ public class SuperviseController {
     @Operation(summary = "测试医院药品目录推送单对象接口", description = "互联网医院药品目录推送接口")
     @PostMapping("/sendDrugCategoryOne")
     @ResponseBody
-    public HisResponseTO sendDrugCategoryOne(HttpServletRequest request,@Valid  @RequestBody DrugCategoryReq list) {
+    public HisResponseTO sendDrugCategoryOne(HttpServletRequest request,@Valid  @RequestBody DrugCategoryReq param) {
         String urlType = request.getHeader("urlType");
         String apiUrl = url;
         if(StringUtils.isNotBlank(urlType)&&"1".equals(urlType)){
@@ -72,7 +72,7 @@ public class SuperviseController {
         PostUtil.setAppKey(appKey);
         PostUtil.setAppSecret(appSecret);
         try{
-            return PostUtil.post(ServiceMethodEnum.DRUG_PUSH.getServiceMethod(), JSONObject.toJSONString(list));
+            return openapi.updateInterface.PostUtil.post(ServiceMethodEnum.DRUG_PUSH.getServiceMethod(), param);
         }catch (Exception e){
             log.error("方法名称:-/supervise/sendDrugCategory  错误信息:"+e.getMessage());
             HisResponseTO<?> hisResponse = new HisResponseTO();

+ 1 - 0
src/main/resources/application-dev.yml

@@ -23,6 +23,7 @@ spring:
         max-idle: 8 # 连接池中的最大空闲连接
         min-idle: 0 # 连接池中的最小空闲连接
 param:
+  unitID: 20250228091949564
   #专网地址
   local-url: http://10.152.101.6:8080/net-diag-service/test-openapi/api
   #外网地址

+ 1 - 0
src/main/resources/application-pro.yml

@@ -27,6 +27,7 @@ spring:
         max-idle: 8 # 连接池中的最大空闲连接
         min-idle: 0 # 连接池中的最小空闲连接
 param:
+  unitID: 20250228091949564
   #专网地址
   local-url: http://10.152.101.6:8080/net-diag-service/openapi/api
   #外网地址

+ 1 - 0
src/main/resources/application-test.yml

@@ -22,6 +22,7 @@ spring:
         max-idle: 8 # 连接池中的最大空闲连接
         min-idle: 0 # 连接池中的最小空闲连接
 param:
+  unitID: 20250228091949564
   #专网地址
   local-url: http://10.152.101.6:8080/net-diag-service/test-openapi/api
   #外网地址