浏览代码

增加不良人像接口跳转通道

15810770710@163.com 3 年之前
父节点
当前提交
f4dd9106fd

+ 11 - 0
pom.xml

@@ -69,6 +69,17 @@
             <artifactId>quartz</artifactId>
             <version>2.3.0</version>
         </dependency>
+        <!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on -->
+        <dependency>
+            <groupId>org.bouncycastle</groupId>
+            <artifactId>bcprov-jdk15on</artifactId>
+            <version>1.52</version>
+        </dependency>
+        <dependency>
+            <groupId>com.javaSm3</groupId>
+            <artifactId>javaSm3</artifactId>
+            <version>1.0.0</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 1 - 1
src/main/java/com/jkcredit/illegal/info/controller/IllegalInfoController.java

@@ -28,7 +28,7 @@ public class IllegalInfoController {
     @PostMapping("/checkIllegalInfo.do")
     public CommonResponseObject checkIllegalInfo(@RequestBody IllegalInfoRequestParam requestParams) {
         log.info("checkIllegalInfo-接收参数:{}", requestParams);
-        IllegalInfoResult illegalInfoResult = illegalInfoService.checkIllegalInfo(requestParams);
+        IllegalInfoResult illegalInfoResult = illegalInfoService.checkIllegalInfoV2(requestParams);
         if (illegalInfoResult != null) {
             log.info("checkIllegalInfo-返回:{}", illegalInfoResult);
             return CommonResponseObject.success(illegalInfoResult);

+ 43 - 0
src/main/java/com/jkcredit/illegal/info/model/CriminalInfoChargeObject.java

@@ -0,0 +1,43 @@
+package com.jkcredit.illegal.info.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+import org.springframework.beans.BeanUtils;
+
+import java.io.Serializable;
+
+/**
+ * @author xusonglin
+ * @version V1.0
+ **/
+@Data
+@ToString
+@AllArgsConstructor
+@NoArgsConstructor
+public class CriminalInfoChargeObject implements Serializable {
+
+    private static final long serialVersionUID = 6076375676306229747L;
+
+    private String method;
+
+    private String traceId;
+
+    private String status;
+
+    private String idCard;
+
+    private String msg;
+
+    private String score;
+
+    private boolean isCharge;
+
+    public CriminalInfoChargeObject (CriminalInfoResult result, boolean isCharge, String traceId) {
+        BeanUtils.copyProperties(result, this);
+        this.method = "criminalInfo";
+        this.isCharge = isCharge;
+        this.traceId = traceId;
+    }
+}

+ 24 - 0
src/main/java/com/jkcredit/illegal/info/model/CriminalInfoRequestObject.java

@@ -0,0 +1,24 @@
+package com.jkcredit.illegal.info.model;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+import java.io.Serializable;
+
+/**
+ * @author xusonglin
+ * @version V1.0
+ **/
+@Data
+@ToString
+@AllArgsConstructor
+@NoArgsConstructor
+public class CriminalInfoRequestObject implements Serializable {
+    private static final long serialVersionUID = 1620343420073109176L;
+    private String idCode;
+    private String name;
+    private String traceId;
+}

+ 29 - 0
src/main/java/com/jkcredit/illegal/info/model/CriminalInfoResponseObject.java

@@ -0,0 +1,29 @@
+package com.jkcredit.illegal.info.model;
+
+import lombok.Data;
+import lombok.ToString;
+
+import java.io.Serializable;
+
+/**
+ * @author xusonglin
+ * @version V1.0
+ **/
+@Data
+@ToString
+public class CriminalInfoResponseObject implements Serializable {
+
+    private static final long serialVersionUID = -8532083136311801696L;
+    private CriminalInfoResponseHead head;
+    private String response;
+
+    @Data
+    public static class CriminalInfoResponseHead {
+        private String requestRefId;
+        private String responseCode;
+        private String result;
+        private String validState;
+        private String responseRefId;
+        private String responseMsg;
+    }
+}

+ 25 - 0
src/main/java/com/jkcredit/illegal/info/model/CriminalInfoResult.java

@@ -0,0 +1,25 @@
+package com.jkcredit.illegal.info.model;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/9/22 11:40
+ * @version: V1.0
+ **/
+@Data
+@NoArgsConstructor
+public class CriminalInfoResult implements Serializable {
+
+    private static final long serialVersionUID = -6237336433468586318L;
+    private String status;
+    private String idCard;
+    private String msg;
+    private String score;
+    //{"code":1,"idCard":"432421196501158096","score":50,"status":"EXIST"}
+}

+ 12 - 0
src/main/java/com/jkcredit/illegal/info/service/CriminalInfoService.java

@@ -0,0 +1,12 @@
+package com.jkcredit.illegal.info.service;
+
+import com.jkcredit.illegal.info.model.CriminalInfoRequestObject;
+import com.jkcredit.illegal.info.model.CriminalInfoResult;
+
+/**
+ * @author xusonglin
+ * @version V1.0
+ **/
+public interface CriminalInfoService {
+    CriminalInfoResult getCriminalInfo(CriminalInfoRequestObject requestObject);
+}

+ 1 - 0
src/main/java/com/jkcredit/illegal/info/service/IllegalInfoService.java

@@ -18,4 +18,5 @@ public interface IllegalInfoService {
 
     IllegalInfoResult checkPersonIllegalInfo(String params);
 
+    IllegalInfoResult checkIllegalInfoV2(IllegalInfoRequestParam requestParams);
 }

+ 104 - 0
src/main/java/com/jkcredit/illegal/info/service/impl/CriminalInfoServiceImpl.java

@@ -0,0 +1,104 @@
+package com.jkcredit.illegal.info.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.jkcredit.illegal.info.model.CriminalInfoChargeObject;
+import com.jkcredit.illegal.info.model.CriminalInfoRequestObject;
+import com.jkcredit.illegal.info.model.CriminalInfoResponseObject;
+import com.jkcredit.illegal.info.model.CriminalInfoResult;
+import com.jkcredit.illegal.info.service.CriminalInfoService;
+import com.jkcredit.illegal.info.util.DES3;
+import com.jkcredit.illegal.info.util.EncryptUtils;
+import com.jkcredit.illegal.info.util.HttpClientUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author xusonglin
+ * @version V1.0
+ **/
+@Service
+@Slf4j
+public class CriminalInfoServiceImpl implements CriminalInfoService {
+    @Value("${criminalInfo.url}")
+    private String url;
+    @Value("${criminalInfo.secretId}")
+    private String secretId;
+    @Value("${criminalInfo.secretKey}")
+    private String secretKey;
+    @Value("${criminalInfo.productCode}")
+    private String productCode;
+
+    private static final Log CHARGE_LOGGER = LogFactory.getLog("CHARGE_LOGGER");
+
+    private String getCriminalRequestString(CriminalInfoRequestObject requestObject) {
+        String requestString = "";
+        String traceId = requestObject.getTraceId();
+        try {
+            Map<String, Object> head = new HashMap<>();
+            head.put("requestRefId", traceId);
+            head.put("secretId", secretId);
+            head.put("productCode", productCode);
+            String signature = EncryptUtils.getSignatureUserMark002(traceId, secretId, secretKey);
+            head.put("signature", signature);
+
+            Map<String, Object> request = new HashMap<>();
+            request.put("certNo", requestObject.getIdCode());
+            request.put("name", requestObject.getName());
+
+            Map<String, Object> param = new HashMap<>();
+            param.put("param", request);
+            String cipher = DES3.getEncString(JSON.toJSONString(param), secretKey);
+            Map<String, Object> reqObj = new HashMap<>();
+            reqObj.put("head", head);
+            reqObj.put("request", cipher);
+            requestString = JSON.toJSONString(reqObj);
+        } catch (Exception e) {
+            log.error("CriminalInfo封装请求参数失败-流水号:{}, 入参:{}, 解析上游返回异常:{}", traceId, requestObject, e);
+        }
+
+        return requestString;
+    }
+
+    @Override
+    public CriminalInfoResult getCriminalInfo(CriminalInfoRequestObject requestObject) {
+        String traceId = requestObject.getTraceId();
+        String requestBody = getCriminalRequestString(requestObject);
+        CriminalInfoResult criminalInfoResult = new CriminalInfoResult();
+        Long startTime = System.currentTimeMillis();
+        String result = HttpClientUtil.sendPost(url, requestBody, 5000, "");
+        log.info("getCriminalInfo-流水号:{}, 入参:{}, 返回:{}, 时延:{}", traceId, requestBody, result, System.currentTimeMillis() - startTime);
+
+        if (StringUtils.isBlank(result)) {
+            log.info("getCriminalInfoError-流水号:{}, 入参:{}, 请求上游失败无返回", traceId, requestBody);
+            CHARGE_LOGGER.info(JSON.toJSONString(new CriminalInfoChargeObject(criminalInfoResult, false, traceId)));
+            return null;
+        }
+
+        CriminalInfoResponseObject criminalInfoResponseObject = JSON.toJavaObject(JSON.parseObject(result), CriminalInfoResponseObject.class);
+        if (criminalInfoResponseObject.getHead().getResponseCode().equals("0000") && criminalInfoResponseObject.getHead().getResult().equals("Y")) {
+            String encodeResponse = criminalInfoResponseObject.getResponse();
+            String decodeResponse = "";
+            try {
+                decodeResponse = DES3.getDecString(encodeResponse, secretKey);
+                log.info("getCriminalInfo-解密后:{}, 流水号:{}", decodeResponse, traceId);
+            } catch (Exception e) {
+                log.info("getCriminalInfoError-流水号:{}, 入参:{}, 解析上游返回失败无返回", traceId, requestBody);
+                CHARGE_LOGGER.info(JSON.toJSONString(new CriminalInfoChargeObject(criminalInfoResult, false, traceId)));
+                return null;
+            }
+            criminalInfoResult = JSON.toJavaObject(JSON.parseObject(decodeResponse), CriminalInfoResult.class);
+            CHARGE_LOGGER.info(JSON.toJSONString(new CriminalInfoChargeObject(criminalInfoResult, true, traceId)));
+            return criminalInfoResult;
+        } else {
+            CHARGE_LOGGER.info(JSON.toJSONString(new CriminalInfoChargeObject(criminalInfoResult, false, traceId)));
+            return null;
+        }
+    }
+}

+ 79 - 3
src/main/java/com/jkcredit/illegal/info/service/impl/IllegalInfoServiceImpl.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.jkcredit.illegal.info.constant.CommonConstant;
 import com.jkcredit.illegal.info.model.*;
+import com.jkcredit.illegal.info.service.CriminalInfoService;
 import com.jkcredit.illegal.info.service.IllegalInfoService;
 import com.jkcredit.illegal.info.util.AesUtil;
 import com.jkcredit.illegal.info.util.OkHttpUtil;
@@ -34,8 +35,11 @@ public class IllegalInfoServiceImpl implements IllegalInfoService {
     private String decodeKey;
     @Autowired
     StringRedisTemplate stringRedisTemplate;
+    @Autowired
+    CriminalInfoService criminalInfoService;
 
     private static final Log CHARGE_LOGGER = LogFactory.getLog("CHARGE_LOGGER");
+
     @Override
     public IllegalInfoResult checkIllegalInfo(IllegalInfoRequestParam requestParams) {
         String body = JSON.toJSONString(requestParams);
@@ -66,9 +70,9 @@ public class IllegalInfoServiceImpl implements IllegalInfoService {
 
         // 返回4个参数,code0表示结果正常,其他表示异常
         if (!illegalInfoResult.getCode().equals("0")
-            || illegalInfoResult.getIsDrugs().equals("2")
-            || illegalInfoResult.getIsEscape().equals("2")
-            || illegalInfoResult.getIsPedigree().equals("2")) {
+                || illegalInfoResult.getIsDrugs().equals("2")
+                || illegalInfoResult.getIsEscape().equals("2")
+                || illegalInfoResult.getIsPedigree().equals("2")) {
             // 查询错误,不计费
             CHARGE_LOGGER.info(JSON.toJSONString(new IllegalInfoChargeObject(illegalInfoResult, false, requestParams.getTraceId())));
             stringRedisTemplate.boundValueOps(CommonConstant.PERSON_ILLEGAL_INFO_QUERY_FAILED).increment();
@@ -184,4 +188,76 @@ public class IllegalInfoServiceImpl implements IllegalInfoService {
         requestParam.setIdCode(jsonObject.getString("idCode"));
         return requestParam;
     }
+
+    private IllegalInfoResult getCriminalInfoResult(IllegalInfoRequestParam requestParams) {
+        CriminalInfoRequestObject requestObject = new CriminalInfoRequestObject();
+        BeanUtils.copyProperties(requestParams, requestObject);
+        CriminalInfoResult criminalInfoResult = criminalInfoService.getCriminalInfo(requestObject);
+        IllegalInfoResult illegalInfoResult = new IllegalInfoResult().normalResult();
+        if (criminalInfoResult == null) {
+            return illegalInfoResult;
+        } else {
+            /**
+             * 前科 8
+             * 涉毒 14和26
+             * 在逃 50
+             * 未命中 2
+             */
+            if (criminalInfoResult.getScore().equals("14") || criminalInfoResult.getScore().equals("26")) {
+                // 涉毒
+                illegalInfoResult.setIsDrugs("1");
+            } else if (criminalInfoResult.getScore().equals("50")) {
+                // 在逃
+                illegalInfoResult.setIsEscape("1");
+            } else if (criminalInfoResult.getScore().equals("8")) {
+                // 前科
+                illegalInfoResult.setIsPedigree("1");
+            } else {
+                // 未命中重点人
+                return illegalInfoResult;
+            }
+            return illegalInfoResult;
+        }
+    }
+
+    @Override
+    public IllegalInfoResult checkIllegalInfoV2(IllegalInfoRequestParam requestParams) {
+        String body = JSON.toJSONString(requestParams);
+        Long startTime = System.currentTimeMillis();
+        String result = OkHttpUtil.doPost(illegalInfoUrl, body, CommonConstant.PERSON_TIME_OUT);
+        log.info("调用上游接口-流水号:{}, 入参:{}, 返回:{}, 时延:{}", requestParams.getTraceId(), body, result, System.currentTimeMillis() - startTime);
+        if (StringUtils.isBlank(result)) {
+            log.info("checkIllegalInfoRequestError-流水号:{}, 入参:{}, 请求上游失败无返回", requestParams.getTraceId(), body);
+            stringRedisTemplate.boundValueOps(CommonConstant.PERSON_ILLEGAL_INFO_TIME_OUT).increment();
+            IllegalInfoResult illegalInfoResult = getCriminalInfoResult(requestParams);
+            CHARGE_LOGGER.info(JSON.toJSONString(new IllegalInfoChargeObject(illegalInfoResult, false, requestParams.getTraceId())));
+            return illegalInfoResult;
+        }
+
+        IllegalInfoResult illegalInfoResult;
+        try {
+            illegalInfoResult = JSON.toJavaObject(JSON.parseObject(result), IllegalInfoResult.class);
+        } catch (Exception e) {
+            log.error("checkIllegalInfo解析异常-流水号:{}, 入参:{}, 解析上游返回异常:{}", requestParams.getTraceId(), body, e);
+            illegalInfoResult = getCriminalInfoResult(requestParams);
+            CHARGE_LOGGER.info(JSON.toJSONString(new IllegalInfoChargeObject(illegalInfoResult, false, requestParams.getTraceId())));
+            return illegalInfoResult;
+        }
+
+        // 返回4个参数,code0表示结果正常,其他表示异常
+        if (!illegalInfoResult.getCode().equals("0")
+                || illegalInfoResult.getIsDrugs().equals("2")
+                || illegalInfoResult.getIsEscape().equals("2")
+                || illegalInfoResult.getIsPedigree().equals("2")) {
+            // 查询错误,不计费
+            CHARGE_LOGGER.info(JSON.toJSONString(new IllegalInfoChargeObject(illegalInfoResult, false, requestParams.getTraceId())));
+            stringRedisTemplate.boundValueOps(CommonConstant.PERSON_ILLEGAL_INFO_QUERY_FAILED).increment();
+            log.info("checkIllegalInfoResultError-流水号:{}, 上游结果异常", requestParams.getTraceId());
+            illegalInfoResult = getCriminalInfoResult(requestParams);
+        } else {
+            // 查询成功,计费
+            CHARGE_LOGGER.info(JSON.toJSONString(new IllegalInfoChargeObject(illegalInfoResult, true, requestParams.getTraceId())));
+        }
+        return illegalInfoResult;
+    }
 }

+ 68 - 0
src/main/java/com/jkcredit/illegal/info/util/DES3.java

@@ -0,0 +1,68 @@
+package com.jkcredit.illegal.info.util;
+
+
+import org.apache.commons.codec.binary.Base64;
+import sun.misc.BASE64Decoder;
+import sun.misc.BASE64Encoder;
+
+import javax.crypto.Cipher;
+import javax.crypto.SecretKey;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.DESedeKeySpec;
+
+
+public class DES3 {
+
+    public static final String ALGORITHM = "DESede";
+    public static final String ALGORITHMCipher = "DESede/ECB/PKCS5Padding";
+    public static final String UTF8 = "UTF-8";
+
+
+    /**
+     * 加密
+     *
+     * @param
+     * @return secretKey  密钥
+     * @throws Exception
+     */
+    public static String getEncString(String strMing, String secretKey) throws Exception {
+        SecretKey sKsecretKey = getKey(secretKey);
+        Cipher cipher = Cipher.getInstance(ALGORITHMCipher);
+        cipher.init(Cipher.ENCRYPT_MODE, sKsecretKey);
+        byte[] byteMi = cipher.doFinal(strMing.getBytes(UTF8));
+        return new BASE64Encoder().encode(byteMi);
+    }
+
+
+    /**
+     * 解密
+     *
+     * @param
+     * @return secretKey  密钥
+     * @throws Exception
+     */
+    public static String getDecString(String paramAfterEncrypt, String secretKey) throws Exception {
+        SecretKey sKsecretKey = getKey(secretKey);
+        Cipher cipher = Cipher.getInstance(ALGORITHMCipher);
+        cipher.init(Cipher.DECRYPT_MODE, sKsecretKey);
+        byte[] byteMing = cipher.doFinal(new Base64().decode(paramAfterEncrypt));
+        return new String(byteMing, "UTF-8");
+    }
+
+
+    /**
+     * 使用DESede对secretKey进行加密
+     *
+     * @param secretKey 密钥
+     * @throws Exception
+     */
+    public static SecretKey getKey(String secretKey) throws Exception {
+        byte[] keyBytes = new BASE64Decoder().decodeBuffer(secretKey);
+        DESedeKeySpec dks = new DESedeKeySpec(keyBytes);
+        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM);
+        SecretKey sKsecretKey = keyFactory.generateSecret(dks);
+        return sKsecretKey;
+    }
+
+
+}

+ 20 - 0
src/main/java/com/jkcredit/illegal/info/util/EncryptUtils.java

@@ -0,0 +1,20 @@
+package com.jkcredit.illegal.info.util;
+
+import com.qtong.utils.SM3Digest;
+
+public class EncryptUtils {
+
+    /**
+     * (redis方式)获取签名 sm3
+     *
+     * @param requestRefId
+     * @param secretId
+     * @return
+     * @throws Exception
+     */
+    public static String getSignatureUserMark002(String requestRefId, String secretId, String secretKey) throws Exception {
+        String message = "requestRefId=" + requestRefId + "&" + "secretId=" + secretId + "&" + "secretKey=" + secretKey;
+        return new SM3Digest().doSM3Encryption(message);
+    }
+
+}

+ 50 - 0
src/main/java/com/jkcredit/illegal/info/util/HttpClientUtil.java

@@ -0,0 +1,50 @@
+package com.jkcredit.illegal.info.util;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+
+import java.io.IOException;
+
+/**
+ * @author xusonglin
+ * @version V1.0
+ **/
+@Slf4j
+public class HttpClientUtil {
+    public static String sendPost(String url, String jsonStr, int outTime, String token) {
+        CloseableHttpClient httpClient = HttpClients.createDefault();
+        RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(1000)
+                .setSocketTimeout(outTime).setConnectTimeout(3000).build();
+        HttpPost httpPost = new HttpPost(url);
+        String result = null;
+        try {
+            httpPost = new HttpPost(url);
+            httpPost.setConfig(requestConfig);
+            httpPost.addHeader("Content-Type", "application/json");
+            httpPost.addHeader("Accept", "application/json");
+            if (StringUtils.isNotBlank(token)) {
+                httpPost.addHeader("token", token);
+            }
+            StringEntity entity = new StringEntity(jsonStr, "utf-8");
+            httpPost.setEntity(entity);
+            HttpResponse response = httpClient.execute(httpPost);
+            if (response != null) {
+                HttpEntity resEntity = response.getEntity();
+                if (resEntity != null) {
+                    result = EntityUtils.toString(resEntity, "utf-8");
+                }
+            }
+        } catch (IOException ioe) {
+            log.info("sendPost, 参数:{}-SocketTimeoutException:", jsonStr, ioe);
+        }
+        return result;
+    }
+}

+ 9 - 0
src/main/java/com/jkcredit/illegal/info/util/test/SM3.java

@@ -0,0 +1,9 @@
+package com.jkcredit.illegal.info.util.test;
+
+/**
+ * @author xusonglin
+ * @version V1.0
+ **/
+public class SM3 {
+
+}

+ 0 - 0
src/main/resources/lib/JavaSm3.jar