Răsfoiți Sursa

中煤加密修改

wks 3 ani în urmă
părinte
comite
13d2107821

+ 2 - 0
src/main/java/com/ydtech/config/properties/ZmApiConfigurationProperties.java

@@ -29,5 +29,7 @@ public class ZmApiConfigurationProperties {
     private String callbackUrl;
     // 审核回调地址
     private String passMsgUrl;
+    // 会话密钥
+    private String sessionKey;
 
 }

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

@@ -42,37 +42,8 @@ public class ZhongmeiRequestApiComponents {
     }
 
 
-//    /**
-//     * 加密请求
-//     * @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) {
-//        HttpHeaders httpHeaders = new HttpHeaders();
-//        httpHeaders.setContentType(MediaType.APPLICATION_JSON);
-//
-//        String jsonString = JSON.toJSONString(q, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullStringAsEmpty);
-//        log.info("---------> 请求参数:{}", jsonString);
-//        // 加密
-//        String s = AESUtilsWithDataBase.encryptECBPK5Hex(jsonString);
-//        log.info("---------> 加密后的参数:{}", s);
-//        HttpEntity<String> httpEntity = new HttpEntity<>(s, httpHeaders);
-//
-//        ResponseEntity<String> response = restTemplate.postForEntity(url, httpEntity, String.class);
-//        String body = response.getBody();
-//        S t  = AESUtilsWithDataBase.decryptMessage(body, tClass, "响应参数");
-//        if (ObjectUtils.isEmpty(t)) {
-//            throw new SystemException("请求失败");
-//        }
-//        return t;
-//    }
-
-
     /**
+     * 加密请求
      * @param q      请求参数
      * @param url    请求url
      * @param tClass 响应类型
@@ -81,25 +52,55 @@ public class ZhongmeiRequestApiComponents {
      * @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);
+        String jsonString = JSON.toJSONString(q, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullStringAsEmpty);
+        log.info("---------> 请求参数:{}", jsonString);
+        // 加密
+        String sessionKey = properties.getSessionKey();
+        String s = AESUtilsWithDataBase.encryptECBPK5Hex(jsonString, sessionKey);
+        log.info("---------> 加密后的参数:{}", s);
+        HttpEntity<String> httpEntity = new HttpEntity<>(s, httpHeaders);
 
-        S t = JSON.parseObject(body, tClass);
+        ResponseEntity<String> response = restTemplate.postForEntity(url, httpEntity, String.class);
+        String body = response.getBody();
+        S t  = AESUtilsWithDataBase.decryptMessage(body, tClass, "响应参数", sessionKey);
         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 响应体

+ 7 - 4
src/main/java/com/ydtech/modules/order/controller/ZhongMeiOrderApiController.java

@@ -1,8 +1,8 @@
 package com.ydtech.modules.order.controller;
 
 
-import com.alibaba.fastjson.JSON;
 import com.ydtech.aop.request.RequestSingleParam;
+import com.ydtech.config.properties.ZmApiConfigurationProperties;
 import com.ydtech.core.page.HttpResult;
 import com.ydtech.modules.ins.model.vo.QuoteRespVo;
 import com.ydtech.modules.ins.model.ya.CarModelDTO;
@@ -37,9 +37,12 @@ public class ZhongMeiOrderApiController {
 
     private final InsOrdersComponents insOrdersComponents;
 
-    public ZhongMeiOrderApiController(ZhongMeiOrderApiService zhongMeiOrderApiService, InsOrdersComponents insOrdersComponents) {
+    private final ZmApiConfigurationProperties properties;
+
+    public ZhongMeiOrderApiController(ZhongMeiOrderApiService zhongMeiOrderApiService, InsOrdersComponents insOrdersComponents, ZmApiConfigurationProperties properties) {
         this.zhongMeiOrderApiService = zhongMeiOrderApiService;
         this.insOrdersComponents = insOrdersComponents;
+        this.properties = properties;
     }
 
     @PostMapping(value = "/modelsQuery")
@@ -83,14 +86,14 @@ public class ZhongMeiOrderApiController {
     @PostMapping("/underwritingCallback")
     @ApiOperation(value = "承保回调")
     public HttpResult<Object> underwritingCallback(@RequestBody String s) {
-        CoverageRequest coverageRequest = AESUtilsWithDataBase.decryptMessage(s, CoverageRequest.class, "承保回调");
+        CoverageRequest coverageRequest = AESUtilsWithDataBase.decryptMessage(s, CoverageRequest.class, "承保回调", properties.getSessionKey());
         return this.zhongMeiOrderApiService.underwritingCallback(coverageRequest);
     }
 
     @PostMapping("/auditCallback")
     @ApiOperation(value = "审核回调")
     public HttpResult<Object> auditCallback(@RequestBody String s) {
-        ApprovedRequest approvedRequest = AESUtilsWithDataBase.decryptMessage(s, ApprovedRequest.class, "审核回调");
+        ApprovedRequest approvedRequest = AESUtilsWithDataBase.decryptMessage(s, ApprovedRequest.class, "审核回调", properties.getSessionKey());
         return this.zhongMeiOrderApiService.auditCallback(approvedRequest);
     }
 

+ 1 - 1
src/main/java/com/ydtech/modules/order/entity/api/zm/constants/enums/PaymentStatusEnum.java

@@ -6,7 +6,7 @@ import lombok.Getter;
 /**
  * @author wenks
  * @version 0.0.2
- * @description TODO
+ * @description 承保状态
  * @date 2023/4/25 18:30
  */
 @AllArgsConstructor

+ 1 - 1
src/main/java/com/ydtech/modules/order/entity/api/zm/request/InsurancePolicyPrintRequest.java

@@ -11,7 +11,7 @@ import lombok.NoArgsConstructor;
 /**
  * @author wenks
  * @version 0.0.2
- * @description TODO
+ * @description 电子保单下载
  * @date 2023/4/24 18:00
  */
 @EqualsAndHashCode(callSuper = true)

+ 5 - 6
src/main/java/com/ydtech/modules/order/utils/AESUtilsWithDataBase.java

@@ -19,7 +19,7 @@ public class AESUtilsWithDataBase {
     public static final String CODE_TYPE = "UTF-8";
 
     // 秘钥
-    private static final String sessionKey = "1237891234567589";
+//    private static final String sessionKey = "1237891234567589";
 
     /**
      * AES 加密操作  ECBPK5Hex
@@ -27,7 +27,7 @@ public class AESUtilsWithDataBase {
      * @param content 待加密内容
      * @return 返回Base64转码后的加密数据
      */
-    public static String encryptECBPK5Hex(String content) {
+    public static String encryptECBPK5Hex(String content, String sessionKey) {
         byte[] result = null;
         if (content == null || "".equals(content)) {
             return content;
@@ -60,7 +60,7 @@ public class AESUtilsWithDataBase {
      * @param content
      * @return
      */
-    public static String decryptECBPK5Hex(String content) {
+    public static String decryptECBPK5Hex(String content, String sessionKey) {
         String returnStr = content;
         byte[] result = null;
         if (content == null || "".equals(content)) {
@@ -105,13 +105,12 @@ public class AESUtilsWithDataBase {
         return ret;
     }
 
-    public static <T> T decryptMessage(String s, Class<T> c, String message) {
+    public static <T> T decryptMessage(String s, Class<T> c, String message, String sessionKey) {
         log.info("---------> 解密前的参数:{}", s);
         // 解密
-        String s1 = AESUtilsWithDataBase.decryptECBPK5Hex(s);
+        String s1 = AESUtilsWithDataBase.decryptECBPK5Hex(s,  sessionKey);
         log.info("---------> {}:{}", message, s1);
         return JSON.parseObject(s1, c);
     }
 
-
 }

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

@@ -223,6 +223,7 @@ zm:
     callbackDomain: http://sxzgkj.baoxianzhanggui.com/web-api
     callbackUrl: /order/zhongMeiApi/underwritingCallback
     passMsgUrl: /order/zhongMeiApi/auditCallback
+    sessionKey: 3788034787907281
 
 # 紫金财险
 zj:

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

@@ -330,10 +330,15 @@ zm:
     callbackDomain: http://test.baoxianzhanggui.com:8080
     callbackUrl: /order/zhongMeiApi/underwritingCallback
     passMsgUrl: /order/zhongMeiApi/auditCallback
+    sessionKey: 1237891234567589
 
 # 紫金财险
 zj:
   api:
+#    appKey: SXTQ-C-SX
+#    appSecret: vAI9sW4bM1m5Y074AUT72wvxKu55SbGY
+#    proposalCityCode: 320100
+#    proposalAreaCode: 320000
     # 为接入方提供获取token服务
     accessTokenUrl: https://test-open.zking.com/api/v1/public/token/getAccessToken
     # 车险业务