Преглед изворни кода

中煤财险API 参数加密

wks пре 3 година
родитељ
комит
9239821623

+ 40 - 39
src/main/java/com/ydtech/modules/order/components/ZhongmeiRequestApiComponents.java

@@ -7,6 +7,7 @@ import com.ydtech.modules.order.entity.api.zm.BaseRequest;
 import com.ydtech.modules.order.entity.api.zm.BaseResponse;
 import com.ydtech.modules.order.entity.api.zm.request.*;
 import com.ydtech.modules.order.entity.api.zm.response.*;
+import com.ydtech.modules.order.utils.AESUtilsWithDataBase;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
@@ -39,40 +40,6 @@ public class ZhongmeiRequestApiComponents {
         this.restTemplate = restTemplate;
     }
 
-//    private <Q extends BaseRequest, S extends BaseResponse> S post(Q q, String url, Class<S> tClass) {
-//        String jsonString = JSON.toJSONString(q);
-//        log.info("---------> 请求参数:{}", jsonString);
-//
-//        HttpHeaders httpHeaders = new HttpHeaders();
-//        httpHeaders.setContentType(MediaType.APPLICATION_JSON);
-//
-//        // 加密
-//        String s = AESUtilsWithDataBase.encryptECBPK5Hex(jsonString);
-//        HttpEntity<String> httpEntity = new HttpEntity<>(s, httpHeaders);
-//
-//        ResponseEntity<String> response = restTemplate.postForEntity(url, httpEntity, String.class);
-//        String body = response.getBody();
-//
-//        // 解密
-//        String s1 = AESUtilsWithDataBase.decryptECBPK5Hex(body);
-//        log.info("---------> 响应参数:{}", s1);
-//
-//        S t = JSON.parseObject(s1, tClass);
-//        if (ObjectUtils.isEmpty(t)) {
-//            throw new SystemException("请求失败");
-//        }
-//        return t;
-//    }
-
-
-    /**
-     * @param q      请求参数
-     * @param url    请求url
-     * @param tClass 响应类型
-     * @param <Q>    Request 请求体
-     * @param <S>    Response 响应体
-     * @return <S>
-     */
     private <Q extends BaseRequest, S extends BaseResponse> S post(Q q, String url, Class<S> tClass) {
         String jsonString = JSON.toJSONString(q);
         log.info("---------> 请求参数:{}", jsonString);
@@ -80,19 +47,53 @@ public class ZhongmeiRequestApiComponents {
         HttpHeaders httpHeaders = new HttpHeaders();
         httpHeaders.setContentType(MediaType.APPLICATION_JSON);
 
-        HttpEntity<Q> yaQuoteInfoVoHttpEntity = new HttpEntity<>(q, httpHeaders);
-        ResponseEntity<String> response = restTemplate.postForEntity(url, yaQuoteInfoVoHttpEntity, String.class);
+        // 加密
+        String s = AESUtilsWithDataBase.encryptECBPK5Hex(jsonString);
+        HttpEntity<String> httpEntity = new HttpEntity<>(s, httpHeaders);
+
+        ResponseEntity<String> response = restTemplate.postForEntity(url, httpEntity, String.class);
         String body = response.getBody();
-        log.info("---------> 响应参数:{}", body);
 
-        S t = JSON.parseObject(body, tClass);
+        // 解密
+        String s1 = AESUtilsWithDataBase.decryptECBPK5Hex(body);
+        log.info("---------> 响应参数:{}", s1);
+
+        S t = JSON.parseObject(s1, tClass);
         if (ObjectUtils.isEmpty(t)) {
             throw new SystemException("请求失败");
         }
-
         return t;
     }
 
+
+//    /**
+//     * @param q      请求参数
+//     * @param url    请求url
+//     * @param tClass 响应类型
+//     * @param <Q>    Request 请求体
+//     * @param <S>    Response 响应体
+//     * @return <S>
+//     */
+//    private <Q extends BaseRequest, S extends BaseResponse> S post(Q q, String url, Class<S> tClass) {
+//        String jsonString = JSON.toJSONString(q);
+//        log.info("---------> 请求参数:{}", jsonString);
+//
+//        HttpHeaders httpHeaders = new HttpHeaders();
+//        httpHeaders.setContentType(MediaType.APPLICATION_JSON);
+//
+//        HttpEntity<Q> yaQuoteInfoVoHttpEntity = new HttpEntity<>(q, httpHeaders);
+//        ResponseEntity<String> response = restTemplate.postForEntity(url, yaQuoteInfoVoHttpEntity, String.class);
+//        String body = response.getBody();
+//        log.info("---------> 响应参数:{}", body);
+//
+//        S t = JSON.parseObject(body, tClass);
+//        if (ObjectUtils.isEmpty(t)) {
+//            throw new SystemException("请求失败");
+//        }
+//
+//        return t;
+//    }
+
     /**
      * @param <Q>     Request 请求体
      * @param <S>     Response 响应体