|
@@ -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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|