|
@@ -0,0 +1,892 @@
|
|
|
+package info.aspirecn.iov.sjjh.supplier10000040.service;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.jcraft.jsch.JSchException;
|
|
|
+import com.jcraft.jsch.SftpException;
|
|
|
+import info.aspirecn.iov.sjjh.commons.lang.ChannelTypeHandleResponseObject;
|
|
|
+import info.aspirecn.iov.sjjh.commons.lang.Constant;
|
|
|
+import info.aspirecn.iov.sjjh.commons.lang.PatternTools;
|
|
|
+import info.aspirecn.iov.sjjh.supplier10000040.constant.ChannelConstant;
|
|
|
+import info.aspirecn.iov.sjjh.supplier10000040.model.*;
|
|
|
+import info.aspirecn.iov.sjjh.supplier10000040.util.*;
|
|
|
+import info.aspirecn.rdc.aspirecloud.node.except.utils.ErrorUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import okhttp3.*;
|
|
|
+import org.apache.commons.codec.binary.Base64;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import sun.rmi.runtime.Log;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.validation.ConstraintViolation;
|
|
|
+import javax.validation.Validation;
|
|
|
+import javax.validation.Validator;
|
|
|
+import javax.validation.ValidatorFactory;
|
|
|
+import java.io.*;
|
|
|
+import java.net.SocketTimeoutException;
|
|
|
+import java.security.MessageDigest;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.ThreadPoolExecutor;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description:
|
|
|
+ * @author: xusonglin
|
|
|
+ * @create: 2020/4/22 15:00
|
|
|
+ * @version: V1.0
|
|
|
+ **/
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class ChannelServiceImpl implements ChannelService {
|
|
|
+ @Autowired
|
|
|
+ private ObjectMapper objectMapper;
|
|
|
+ @Autowired
|
|
|
+ private StringRedisTemplate redisTemplate;
|
|
|
+ @Autowired
|
|
|
+ private EsOpeateUtils esOpeateUtils;
|
|
|
+ @Autowired
|
|
|
+ private SendService sendService;
|
|
|
+
|
|
|
+ @Value("${localDir.upload}")
|
|
|
+ private String localUploadDir;
|
|
|
+
|
|
|
+ @Value("${localDir.keyFilePath}")
|
|
|
+ private String keyFilePath;
|
|
|
+
|
|
|
+ @Value("${ftpServer.host}")
|
|
|
+ private String ftpServerHost;
|
|
|
+
|
|
|
+ @Value("${ftpServer.port}")
|
|
|
+ private String ftpServerPort;
|
|
|
+
|
|
|
+ @Value("${ftpServer.username}")
|
|
|
+ private String ftpServerUsername;
|
|
|
+
|
|
|
+ @Value("${ftpServer.passphrase}")
|
|
|
+ private String ftpServerPassphrase;
|
|
|
+
|
|
|
+ @Value("${ftpServer.dir.upload}")
|
|
|
+ private String ftpServerUploadDir;
|
|
|
+
|
|
|
+ @Value("${supplier.illegalInfoV2.url}")
|
|
|
+ private String illegalInfoV2Url;
|
|
|
+
|
|
|
+ @Value("${supplier.decodeApi}")
|
|
|
+ private String decodeApi;
|
|
|
+
|
|
|
+ @Value("${supplier.decodeUrl}")
|
|
|
+ private String decodeUrl;
|
|
|
+
|
|
|
+ @Value("${supplier.decodeAppKey}")
|
|
|
+ private String decodeAppKey;
|
|
|
+
|
|
|
+ @Value("${supplier.decodeAppSecret}")
|
|
|
+ private String decodeAppSecret;
|
|
|
+
|
|
|
+ DateTimeFormatter yMdHms = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
|
|
+
|
|
|
+ private static final String MEDIA_TYPE = "application/json;charset=UTF-8";
|
|
|
+
|
|
|
+ private OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ChannelTypeHandleResponseObject validateIllegalInfo(HttpServletRequest request, String customBody,
|
|
|
+ int outTime, String type, String interfaceType) {
|
|
|
+ ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ String upstreamCode = Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
|
|
|
+ String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA);
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(returnType)) {
|
|
|
+ returnType = Constant.CUSTOMER_RETURN_ZW;
|
|
|
+ }
|
|
|
+ if (outTime <= 0) {
|
|
|
+ outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
|
|
|
+ }
|
|
|
+ log.info("validateIllegalInfo---customBody={},outTime={}", customBody, outTime);
|
|
|
+ try {
|
|
|
+ IllegalInfoRequestObject illegalInfoRequestObject = objectMapper.readValue(customBody, IllegalInfoRequestObject.class);
|
|
|
+ // 参数校验
|
|
|
+ if (!validateParams(ret, returnType, illegalInfoRequestObject)) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 封装放入缓存参数对象
|
|
|
+ RedisParamObject redisParamObject = new RedisParamObject();
|
|
|
+ BeanUtils.copyProperties(illegalInfoRequestObject, redisParamObject);
|
|
|
+ redisParamObject.setReturnType(type);
|
|
|
+ redisParamObject.setTraceId((String) request.getAttribute("x-b3-traceid"));
|
|
|
+ redisParamObject.setInterfaceType(interfaceType);
|
|
|
+ // 身份证姓名放入缓存
|
|
|
+
|
|
|
+ redisParamObject.setStatus(ChannelConstant.REQUEST_STATUS_1);
|
|
|
+ redisParamObject.setVersion(1);
|
|
|
+ redisParamObject.setTimestamp(System.currentTimeMillis());
|
|
|
+ redisTemplate.boundHashOps("asynchronous-illegal-info-request").put(request.getAttribute("x-b3-traceid"),
|
|
|
+ JSON.toJSONString(redisParamObject));
|
|
|
+ ret.setIfSuccessAsyn(1);
|
|
|
+ ret.setIsCharge(Constant.IS_CHARGE);
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.IFCJ_KEY, Constant.IFCJ_NO_CJ);
|
|
|
+ if (returnType.equals(Constant.CUSTOMER_RETURN_JK)) {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_MATCH);
|
|
|
+ } else {
|
|
|
+ ret.setResultCode(Constant.MATCH_CODE);
|
|
|
+ }
|
|
|
+ ret.setResultBody(Constant.QUERY_SUCCESS);
|
|
|
+ ret.setResultDesc(Constant.QUERY_SUCCESS);
|
|
|
+ upstreamCode = "1000";
|
|
|
+ } catch (Exception ioe) {
|
|
|
+ ErrorUtils.captureException(ioe);
|
|
|
+ log.info("supplier10000040.validateIllegalInfo接口Exception={}", ioe);
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ if (returnType.equals(Constant.CUSTOMER_RETURN_JK)) {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR);
|
|
|
+ } else {
|
|
|
+ ret.setResultCode(Constant.OTHER_ERROR_CODE);
|
|
|
+ }
|
|
|
+ ret.setResultBody(Constant.OTHER_ERROR);
|
|
|
+ ret.setResultDesc(Constant.OTHER_ERROR);
|
|
|
+ }
|
|
|
+ //上游返回码
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean validateParams(ChannelTypeHandleResponseObject ret, String returnType, IllegalInfoRequestObject requestObject) {
|
|
|
+ if (!validateParamNullValue(requestObject)) {
|
|
|
+ if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
|
|
|
+ ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
+ ret.setResultBody(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ } else {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
+ ret.setResultBody(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ } else if (StringUtils.isBlank(requestObject.getName()) ||
|
|
|
+ !PatternTools.checkResult(Constant.PATTERN_CN_NAME_REGEX, requestObject.getName())) {
|
|
|
+ if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
|
|
|
+ ret.setResultCode(Constant.NAME_FORMAT_ERROR_CODE);
|
|
|
+ ret.setResultDesc(Constant.NAME_FORMAT_ERROR);
|
|
|
+ ret.setResultBody(Constant.NAME_FORMAT_ERROR);
|
|
|
+ } else {
|
|
|
+ ret.setResultCode(Constant.JK_NAME_FORMAT_ERROR_CODE);
|
|
|
+ ret.setResultDesc(Constant.JK_NAME_FORMAT_ERROR);
|
|
|
+ ret.setResultBody(Constant.JK_NAME_FORMAT_ERROR);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ } else if (StringUtils.isBlank(requestObject.getIdCode())
|
|
|
+ || !PatternTools.checkResult(Constant.PATTERN_SPECIAL_ID_NUMBER_REGEX, requestObject.getIdCode())) {
|
|
|
+ if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
|
|
|
+ ret.setResultCode(Constant.IDCODE_FORMAT_ERROR_CODE);
|
|
|
+ ret.setResultDesc(Constant.IDCODE_FORMAT_ERROR);
|
|
|
+ ret.setResultBody(Constant.IDCODE_FORMAT_ERROR);
|
|
|
+ } else {
|
|
|
+ ret.setResultCode(Constant.JK_IDCODE_FORMAT_ERROR_CODE);
|
|
|
+ ret.setResultDesc(Constant.JK_IDCODE_FORMAT_ERROR);
|
|
|
+ ret.setResultBody(Constant.JK_IDCODE_FORMAT_ERROR);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ private boolean validateType(ChannelTypeHandleResponseObject ret, String returnType, IllegalInfoV2CustomBodyObject customBodyObject) {
|
|
|
+ if (StringUtils.isBlank(customBodyObject.getType()) || !customBodyObject.getType().equals("1")) {
|
|
|
+ if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
|
|
|
+ ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ } else {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean validateParamNullValue(Object jsonResolveObject) {
|
|
|
+ ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
|
|
|
+ Validator validator = vf.getValidator();
|
|
|
+ Set<ConstraintViolation<Object>> set = validator.validate(jsonResolveObject);
|
|
|
+ for (ConstraintViolation<Object> con : set) {
|
|
|
+ if (StringUtils.isNotBlank(con.getMessage())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getRedisNowTimeKey() {
|
|
|
+ String redisNowTimeKey;
|
|
|
+
|
|
|
+ String nowTime = yMdHms.format(LocalDateTime.now());
|
|
|
+ String seconds = nowTime.substring(12, 14);
|
|
|
+ if (Long.parseLong(seconds) < 20) {
|
|
|
+ redisNowTimeKey = nowTime.substring(0, 12) + "00";
|
|
|
+ } else if (Long.parseLong(seconds) < 40) {
|
|
|
+ redisNowTimeKey = nowTime.substring(0, 12) + "20";
|
|
|
+ } else {
|
|
|
+ redisNowTimeKey = nowTime.substring(0, 12) + "40";
|
|
|
+ }
|
|
|
+ return redisNowTimeKey;
|
|
|
+ }
|
|
|
+
|
|
|
+// @Override
|
|
|
+// public boolean sendRequest(Set<String> set, String key) {
|
|
|
+// List<IllegalInfoParamExcelObject> paramExcelObjectList = new ArrayList<>();
|
|
|
+// for (String content : set) {
|
|
|
+// RedisParamObject redisParamObject = JSON.toJavaObject(JSON.parseObject(content), RedisParamObject.class);
|
|
|
+// IllegalInfoParamExcelObject paramExcelObject = new IllegalInfoParamExcelObject();
|
|
|
+// BeanUtils.copyProperties(redisParamObject, paramExcelObject);
|
|
|
+// paramExcelObject.setTraceId(redisParamObject.getInterfaceType() + "-" + redisParamObject.getTraceId());
|
|
|
+// paramExcelObjectList.add(paramExcelObject);
|
|
|
+// }
|
|
|
+//
|
|
|
+// String fileName = System.currentTimeMillis() + ".xlsx";
|
|
|
+// String path = localUploadDir + File.separator + fileName;
|
|
|
+// Map<String, String> headMap = new LinkedHashMap<>();
|
|
|
+// headMap.put("traceId", "序列号");
|
|
|
+// headMap.put("name", "姓名");
|
|
|
+// headMap.put("idCode", "身份证号");
|
|
|
+// try {
|
|
|
+// OutputStream outXlsx = new FileOutputStream(path);
|
|
|
+// ExcelUtil.createExcel(outXlsx, paramExcelObjectList);
|
|
|
+// } catch (IOException ioe) {
|
|
|
+// log.info("supplier10000040.sendRequest,导出参数excel发生异常,Exception={}", ioe);
|
|
|
+// return false;
|
|
|
+// }
|
|
|
+// try {
|
|
|
+// SFTPUtil.upload(ftpServerHost, Integer.parseInt(ftpServerPort), ftpServerUsername, ftpServerPassphrase,
|
|
|
+// "/" + ftpServerUploadDir + "/" + fileName, path, keyFilePath);
|
|
|
+// File localFile = new File(path);
|
|
|
+// boolean deleteResult = false;
|
|
|
+// if (localFile.exists()) {
|
|
|
+// deleteResult = localFile.delete();
|
|
|
+// }
|
|
|
+// if (!deleteResult) {
|
|
|
+// log.info("supplier10000040.sendRequest删除参数excel失败,文件{}", path);
|
|
|
+// }
|
|
|
+// for (String content : set) {
|
|
|
+// long removeResult = redisTemplate.boundSetOps(key).remove(content);
|
|
|
+// log.info("key:{},removeValue:{},result:{}", key, content, removeResult);
|
|
|
+// }
|
|
|
+// return true;
|
|
|
+// } catch (JSchException jschException) {
|
|
|
+// log.info("supplier10000040.sendRequest,上传文件时连接sftp服务器失败, 文件{}, 失败原因{}", path, jschException.getMessage());
|
|
|
+// return false;
|
|
|
+// } catch (FileNotFoundException fileNotFoundException) {
|
|
|
+// log.info("supplier10000040.sendRequest,上传文件到sftp服务器生成文件失败, 文件{}, 失败原因{}", path, fileNotFoundException.getMessage());
|
|
|
+// return false;
|
|
|
+// } catch (SftpException sftpException) {
|
|
|
+// log.info("supplier10000040.sendRequest,上传文件到sftp服务器失败, 文件{}, 失败原因{}", path, sftpException.getMessage());
|
|
|
+// return false;
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean sendRequest(List<IllegalInfoParamExcelObject> excelObjectList) {
|
|
|
+ String fileName = System.currentTimeMillis() + ".xlsx";
|
|
|
+ String path = localUploadDir + File.separator + fileName;
|
|
|
+ Map<String, String> headMap = new LinkedHashMap<>();
|
|
|
+ headMap.put("traceId", "序列号");
|
|
|
+ headMap.put("name", "姓名");
|
|
|
+ headMap.put("idCode", "身份证号");
|
|
|
+ try {
|
|
|
+ OutputStream outXlsx = new FileOutputStream(path);
|
|
|
+ ExcelUtil.createExcel(outXlsx, excelObjectList);
|
|
|
+ } catch (IOException ioe) {
|
|
|
+ log.info("supplier10000040.sendRequest,导出参数excel发生异常,Exception={}", ioe);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ SFTPUtil.upload(ftpServerHost, Integer.parseInt(ftpServerPort), ftpServerUsername, ftpServerPassphrase,
|
|
|
+ "/" + ftpServerUploadDir + "/" + fileName, path, keyFilePath);
|
|
|
+ return true;
|
|
|
+ } catch (JSchException jschException) {
|
|
|
+ log.info("supplier10000040.sendRequest,上传文件时连接sftp服务器失败, 文件{}, 失败原因{}", path, jschException.getMessage());
|
|
|
+ return false;
|
|
|
+ } catch (FileNotFoundException fileNotFoundException) {
|
|
|
+ log.info("supplier10000040.sendRequest,上传文件到sftp服务器生成文件失败, 文件{}, 失败原因{}", path, fileNotFoundException.getMessage());
|
|
|
+ return false;
|
|
|
+ } catch (SftpException sftpException) {
|
|
|
+ log.info("supplier10000040.sendRequest,上传文件到sftp服务器失败, 文件{}, 失败原因{}", path, sftpException.getMessage());
|
|
|
+ return false;
|
|
|
+ } finally {
|
|
|
+ File localFile = new File(path);
|
|
|
+ boolean deleteResult = false;
|
|
|
+ if (localFile.exists()) {
|
|
|
+ deleteResult = localFile.delete();
|
|
|
+ }
|
|
|
+ if (!deleteResult) {
|
|
|
+ log.info("supplier10000040.sendRequest删除参数excel失败,文件{}", path);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void sendFailedMessage(String traceId) {
|
|
|
+ AsyncReqMqMessage asyncReqMqMessage = new AsyncReqMqMessage();
|
|
|
+ asyncReqMqMessage.setTraceid(traceId);
|
|
|
+ asyncReqMqMessage.setQueryCache(false);
|
|
|
+ asyncReqMqMessage.setSyncReturn(false);
|
|
|
+ asyncReqMqMessage.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ String asyncReqInfoStr = (String) redisTemplate.boundHashOps("sjjh_async_request_info").get(traceId);
|
|
|
+ log.info("sendFailedMessage, asyncReqInfoStr:{}", asyncReqInfoStr);
|
|
|
+ if (StringUtils.isNotEmpty(asyncReqInfoStr)) {
|
|
|
+ CacheStreamObject.AsyncMsg asyncReqInfo = JSON.parseObject(asyncReqInfoStr, CacheStreamObject.AsyncMsg.class);
|
|
|
+ CallbackDownstreamRequest request = new CallbackDownstreamRequest();
|
|
|
+ request.setAccessId(asyncReqInfo.getAccessId());
|
|
|
+ request.setTransationId(traceId);
|
|
|
+ if (asyncReqInfo.getIfJkCode() == 1) {
|
|
|
+ request.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR);
|
|
|
+ } else {
|
|
|
+ request.setResultCode(Constant.OTHER_ERROR_CODE);
|
|
|
+ }
|
|
|
+
|
|
|
+ request.setResultBody(Constant.OTHER_ERROR);
|
|
|
+ try {
|
|
|
+ asyncReqMqMessage.setCallbackResult(Base64.encodeBase64String(JSON.toJSONString(request, SerializerFeature.WriteMapNullValue).getBytes("UTF-8")));
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ ErrorUtils.captureException(e);
|
|
|
+ log.info("supplier10000040.sendFailedMessage 发送到kafka的message转base64失败Exception={}", e);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String message = JSON.toJSONString(asyncReqMqMessage, SerializerFeature.WriteMapNullValue);
|
|
|
+ log.info("发送到kafka的message:{}", message);
|
|
|
+ Boolean sendResult;
|
|
|
+ sendResult = sendService.sendMsg(JSON.toJSONString(asyncReqMqMessage, SerializerFeature.WriteMapNullValue));
|
|
|
+ if (!sendResult) {//成功发起请求记录日志
|
|
|
+ KafkaAccessLog kafkaAccessLog = new KafkaAccessLog();
|
|
|
+ kafkaAccessLog.setType(1);
|
|
|
+ kafkaAccessLog.setContent(message);
|
|
|
+ String kafkaContent = JSON.toJSONString(kafkaAccessLog);
|
|
|
+ long addKafkaAccessLogResult = redisTemplate.boundSetOps("Kafka_AccessLog").add(kafkaContent);
|
|
|
+ log.info("kafka信息:{}发送redis是否成功:{}", message, addKafkaAccessLogResult);
|
|
|
+ }
|
|
|
+ boolean logFlag = false;
|
|
|
+ //修改es日志记录
|
|
|
+ try {
|
|
|
+ logFlag = esOpeateUtils.updateByQuery(traceId, "use", Constant.IS_NOT_CHARGE, "1000");
|
|
|
+ } catch (Exception ex) {
|
|
|
+ log.error("update es 异常:{}", ex);
|
|
|
+ }
|
|
|
+ if (!logFlag) {
|
|
|
+ KafkaAccessLog kafkaAccessLog = new KafkaAccessLog();
|
|
|
+ kafkaAccessLog.setType(2);
|
|
|
+ Map<String, String> contentMap = new HashMap<String, String>();
|
|
|
+ contentMap.put("traceId", traceId);
|
|
|
+ contentMap.put("ifCj", "use");
|
|
|
+ contentMap.put("isCharge", String.valueOf(Constant.IS_NOT_CHARGE));
|
|
|
+ String contentStr = JSON.toJSONString(contentMap);
|
|
|
+ kafkaAccessLog.setContent(contentStr);
|
|
|
+ String kafkaContent = JSON.toJSONString(kafkaAccessLog);
|
|
|
+ long addKafkaAccessLogResult = redisTemplate.boundSetOps("Kafka_AccessLog").add(kafkaContent);
|
|
|
+ log.info("log update 信息:{}是否成功:{}", contentStr, addKafkaAccessLogResult);
|
|
|
+ } else {
|
|
|
+ // 修改es成功
|
|
|
+ redisTemplate.boundHashOps("asynchronous-illegal-info-request").delete(traceId);
|
|
|
+ log.info("dealParamInfo -- 移除处理完成的参数:{}", traceId);
|
|
|
+ }
|
|
|
+ Long removeResult = redisTemplate.boundZSetOps("sjjh_async_request_traceids").remove(traceId);
|
|
|
+ log.info("删除sjjh_async_request_traceids:{},结果:{}", traceId, removeResult);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ChannelTypeHandleResponseObject validateIllegalInfoV2(HttpServletRequest request, String customBody, int outTime, String interfaceType) {
|
|
|
+ ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ String upstreamCode = Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
|
|
|
+ String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA);
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(returnType)) {
|
|
|
+ returnType = Constant.CUSTOMER_RETURN_ZW;
|
|
|
+ }
|
|
|
+ if (outTime <= 0) {
|
|
|
+ outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
|
|
|
+ }
|
|
|
+ log.info("validateIllegalInfoV2---customBody={},outTime={}", customBody, outTime);
|
|
|
+ IllegalInfoV2CustomBodyObject customBodyObject = new IllegalInfoV2CustomBodyObject();
|
|
|
+ try {
|
|
|
+ customBodyObject = objectMapper.readValue(customBody, IllegalInfoV2CustomBodyObject.class);
|
|
|
+ } catch (IOException ioe) {
|
|
|
+ log.info("supplier10000040.validateIllegalInfoV2接口-IOException:{}", ioe);
|
|
|
+ ErrorUtils.captureException(ioe);
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 参数校验
|
|
|
+ if (!validateParams(ret, returnType, customBodyObject) || !validateType(ret, returnType, customBodyObject)) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ IllegalInfoV2RequestObject illegalInfoRequestObject = new IllegalInfoV2RequestObject();
|
|
|
+ BeanUtils.copyProperties(customBodyObject, illegalInfoRequestObject);
|
|
|
+ String traceId = request.getHeader("x-b3-traceid");
|
|
|
+ illegalInfoRequestObject.setTraceId(traceId);
|
|
|
+ illegalInfoRequestObject.setIdCode(illegalInfoRequestObject.getIdCode().toUpperCase());
|
|
|
+ MediaType mediaType = MediaType.parse(MEDIA_TYPE);
|
|
|
+ RequestBody requestBody = RequestBody.create(mediaType, JSON.toJSONString(illegalInfoRequestObject));
|
|
|
+
|
|
|
+ Request okRequest = new Request.Builder()
|
|
|
+ .post(requestBody)
|
|
|
+ .url(illegalInfoV2Url)
|
|
|
+ .build();
|
|
|
+ OkHttpClient client = okHttpClient.newBuilder()
|
|
|
+ .connectTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .readTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .writeTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ String responseContext = "";
|
|
|
+ try {
|
|
|
+ Long startTime = System.currentTimeMillis();
|
|
|
+ Response response = client.newCall(okRequest).execute();
|
|
|
+ log.info("supplier10000040.validateIllegalInfoV2接口-上游返回时间={}", System.currentTimeMillis() - startTime);
|
|
|
+ if (response.body() != null) {
|
|
|
+ responseContext = response.body().string();
|
|
|
+ log.info("supplier10000040.validateIllegalInfoV2接口responseContext={}",responseContext);
|
|
|
+ }
|
|
|
+ response.close();
|
|
|
+ } catch (SocketTimeoutException ste) {
|
|
|
+ log.info("supplier10000040.validateIllegalInfoV2接口-SocketTimeoutException:{}", ste);
|
|
|
+ ErrorUtils.captureException(ste);
|
|
|
+ ret.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
+ return ret;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("supplier10000040.validateIllegalInfoV2接口Exception={}", e);
|
|
|
+ ErrorUtils.captureException(e);
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ JSONObject resultJsonObject = JSON.parseObject(responseContext);
|
|
|
+ if (resultJsonObject.get("code") != null && resultJsonObject.getString("code").equals("1")) {
|
|
|
+ IllegalInfoV2ResponseObject responseObject = JSON.toJavaObject(resultJsonObject, IllegalInfoV2ResponseObject.class);
|
|
|
+ if (responseObject != null) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ setIllegalInfoV2Response(responseObject, interfaceType, ret);
|
|
|
+ } else {
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ret.setResultCode(Constant.OTHER_ERROR_CODE);
|
|
|
+ ret.setResultBody(Constant.OTHER_ERROR);
|
|
|
+ ret.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ }
|
|
|
+ if (resultJsonObject.get("code") != null) {
|
|
|
+ upstreamCode = resultJsonObject.getString("code");
|
|
|
+ }
|
|
|
+
|
|
|
+ //上游返回码
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ private ChannelTypeHandleResponseObject setIllegalInfoV2Response(IllegalInfoV2ResponseObject responseObject,
|
|
|
+ String interfaceType, ChannelTypeHandleResponseObject ret) {
|
|
|
+ if (!responseObject.getCode().equals("1")) {
|
|
|
+ ret.setResultCode(Constant.OTHER_ERROR_CODE);
|
|
|
+ ret.setResultBody(Constant.OTHER_ERROR);
|
|
|
+ ret.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ String code = responseObject.getMessage().getCode();
|
|
|
+ String isDrugs = responseObject.getMessage().getIsDrugs();
|
|
|
+ String isEscape = responseObject.getMessage().getIsEscape();
|
|
|
+ String isPedigree = responseObject.getMessage().getIsPedigree();
|
|
|
+
|
|
|
+ if (!checkIllegalInfoV2ErrorResult(code, isDrugs, isEscape, isPedigree, interfaceType)) {
|
|
|
+ ret.setResultCode(Constant.OTHER_ERROR_CODE);
|
|
|
+ ret.setResultBody(Constant.OTHER_ERROR);
|
|
|
+ ret.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ if (interfaceType.equals(ChannelConstant.ILLEGAL_INFO_SCORE)) {
|
|
|
+ // 评分版
|
|
|
+ String resultCode = isDrugs + isEscape + isPedigree;
|
|
|
+ ret = IllegalInfoScoreUtil.getIllegalInfoScoreResult(resultCode, ret);
|
|
|
+
|
|
|
+ } else if (interfaceType.equals(ChannelConstant.ILLEGAL_INFO_SIMPLE)) {
|
|
|
+ // 简版
|
|
|
+ if (isDrugs.equals("1") || isEscape.equals("1") || isPedigree.equals("1")) {
|
|
|
+ ret.setResultBody("1");
|
|
|
+ } else {
|
|
|
+ ret.setResultBody("0");
|
|
|
+ }
|
|
|
+ ret.setResultCode(Constant.SUCCESS);
|
|
|
+ ret.setIsCharge(Constant.IS_CHARGE);
|
|
|
+
|
|
|
+ } else if (interfaceType.equals(ChannelConstant.ILLEGAL_INFO_DRUG_ESCAPE)) {
|
|
|
+ // xd zt 定制版
|
|
|
+ if (isDrugs.equals("1") || isEscape.equals("1")) {
|
|
|
+ ret.setResultBody("1");
|
|
|
+ } else {
|
|
|
+ ret.setResultBody("0");
|
|
|
+ }
|
|
|
+ ret.setResultCode(Constant.SUCCESS);
|
|
|
+ ret.setIsCharge(Constant.IS_CHARGE);
|
|
|
+ } else {
|
|
|
+ // 详版
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ result.put("isDrugs", isDrugs);
|
|
|
+ result.put("isEscape", isEscape);
|
|
|
+ result.put("isPedigree", isPedigree);
|
|
|
+ ret.setResultCode(Constant.MATCH_CODE);
|
|
|
+ ret.setResultBody(JSON.toJSONString(result));
|
|
|
+ ret.setIsCharge(Constant.IS_CHARGE);
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean checkIllegalInfoV2ErrorResult (String code, String isDrugs, String isEscape, String isPedigree, String interfaceType) {
|
|
|
+ if (StringUtils.isBlank(code) || StringUtils.isBlank(isDrugs) || StringUtils.isBlank(isEscape) || StringUtils.isBlank(isPedigree)) {
|
|
|
+ return false;
|
|
|
+ } else if (!code.equals("0")) {
|
|
|
+ return false;
|
|
|
+ } else if (interfaceType.equals(ChannelConstant.ILLEGAL_INFO_DRUG_ESCAPE) && (isDrugs.equals("2") || isEscape.equals("2"))) {
|
|
|
+ return false;
|
|
|
+ } else if (!interfaceType.equals(ChannelConstant.ILLEGAL_INFO_DRUG_ESCAPE) && (isDrugs.equals("2") || isEscape.equals("2") || isPedigree.equals("2"))) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getDecodeIdCard(HttpServletRequest request, String customBody, int outTime, String decodeType, ChannelTypeHandleResponseObject ret) {
|
|
|
+ JSONObject customBodyObject = JSON.parseObject(customBody);
|
|
|
+ if (StringUtils.isBlank(customBodyObject.getString("idCode")) || StringUtils.isBlank(customBodyObject.getString("name"))
|
|
|
+ || (decodeType.equals(ChannelConstant.DECODE_TYPE_SHA256) && (customBodyObject.getString("idCode").length() != 64 || customBodyObject.getString("name").length() != 64))
|
|
|
+ || (decodeType.equals(ChannelConstant.DECODE_TYPE_MD5) && (customBodyObject.getString("idCode").length() != 32 || customBodyObject.getString("name").length() != 32))
|
|
|
+ ) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ String result = "";
|
|
|
+ String decodeResponseContext = Md5Sha256DecodeUtil.getDecodeIdCard(customBodyObject.getString("idCode"),
|
|
|
+ customBodyObject.getString("name"), decodeType, outTime);
|
|
|
+
|
|
|
+ JSONObject decodeResponseObject = JSON.parseObject(decodeResponseContext);
|
|
|
+ if (decodeResponseObject != null && decodeResponseObject.getString("code").equals("200") && decodeResponseObject.getString("data").equals("1")) {
|
|
|
+ JSONObject msg = JSON.parseObject(JSON.toJSONString(decodeResponseObject.get("msg")));
|
|
|
+ if (StringUtils.isNotBlank(msg.getString("idcard")) && StringUtils.isNotBlank(msg.getString("name"))) {
|
|
|
+ customBodyObject.put("idCode", msg.getString("idcard"));
|
|
|
+ customBodyObject.put("name", msg.getString("name"));
|
|
|
+ result = JSON.toJSONString(customBodyObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(result)) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_134);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_134);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_134);
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getAesDecodeIdCard(HttpServletRequest request, String customBody, ChannelTypeHandleResponseObject ret) {
|
|
|
+ JSONObject customBodyObject = JSON.parseObject(customBody);
|
|
|
+ if (customBodyObject.get("idCode") == null || customBodyObject.get("name") == null) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
+ ret.setResultBody(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(customBodyObject.getString("idCode")) || StringUtils.isBlank(customBodyObject.getString("name"))) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ String userId = request.getHeader(ChannelConstant.USER_ID_HEADER_KEY);
|
|
|
+ String aesDecryptKey = encrypt32(ChannelConstant.AES_KEY + userId).substring(8, 24);
|
|
|
+ log.info("getAesDecodeIdCard.user:{},aesDecryptKey:{}", userId, aesDecryptKey);
|
|
|
+ String decodeIdCode = AesUtil.decryAES(aesDecryptKey, customBodyObject.getString("idCode"));
|
|
|
+ String decodeName = AesUtil.decryAES(aesDecryptKey, customBodyObject.getString("name"));
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(decodeIdCode) || StringUtils.isBlank(decodeName)) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_133);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_133);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_133);
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ customBodyObject.put("idCode", decodeIdCode);
|
|
|
+ customBodyObject.put("name", decodeName);
|
|
|
+ return customBodyObject.toJSONString();
|
|
|
+ } catch (Exception e) {
|
|
|
+ ErrorUtils.captureException(e);
|
|
|
+ log.info("supplier10000040.getAesDecodeIdCard解密失败,Exception={}", e);
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_133);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_133);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_133);
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String encrypt32(String encryptStr) {
|
|
|
+ MessageDigest md5;
|
|
|
+ try {
|
|
|
+ md5 = MessageDigest.getInstance("MD5");
|
|
|
+ byte[] md5Bytes = md5.digest(encryptStr.getBytes());
|
|
|
+ StringBuffer hexValue = new StringBuffer();
|
|
|
+ for (int i = 0; i < md5Bytes.length; i++) {
|
|
|
+ int val = ((int) md5Bytes[i]) & 0xff;
|
|
|
+ if (val < 16)
|
|
|
+ hexValue.append("0");
|
|
|
+ hexValue.append(Integer.toHexString(val));
|
|
|
+ }
|
|
|
+ encryptStr = hexValue.toString();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ return encryptStr;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean isIllegalInfoV2ScoreSHA256TestData(HttpServletRequest request, String customBody, ChannelTypeHandleResponseObject ret) {
|
|
|
+ JSONObject customBodyObject = JSON.parseObject(customBody);
|
|
|
+ String idCode = customBodyObject.getString("idCode");
|
|
|
+ String name = customBodyObject.getString("name");
|
|
|
+ String type = customBodyObject.getString("type");
|
|
|
+ if (idCode == null || name == null || type == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (idCode.equals("010fea543ecc27a2a47a1d83c24941960e04fc0040be7a4de9117ab1d0d74bb1")
|
|
|
+ && name.equals("6b4fbd39a02eae625eb38d97a20750e84ac3cd01b06f1a279b709de6ac303b66")
|
|
|
+ && type.equals("1")) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ ret.setResultCode(Constant.MATCH_CODE);
|
|
|
+ ret.setResultBody("30");
|
|
|
+ ret.setResultDesc("30");
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, "test-1");
|
|
|
+ return true;
|
|
|
+ } else if (idCode.equals("eac5b0fec35ac8df2dc9a38a43773c37b5082fc5892c1ed29e254819433e8f25")
|
|
|
+ && name.equals("1d841bc0ee98309cb7916670b7f0fdef5f4c35150711a41405ef3633b56322cf")
|
|
|
+ && type.equals("1")) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ ret.setResultCode(Constant.MATCH_CODE);
|
|
|
+ ret.setResultBody("30-55");
|
|
|
+ ret.setResultDesc("30-55");
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, "test-1");
|
|
|
+ return true;
|
|
|
+ } else if (idCode.equals("cbd41cfeb36bede8b618ea7173d80919a343d210e048a6d69d5641d1fa34ff5f")
|
|
|
+ && name.equals("bb1695365ab4734f7e1bc84e0651731391ad699f75577b11bcc3e43108c9c2f8")
|
|
|
+ && type.equals("1")) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ ret.setResultCode(Constant.MATCH_CODE);
|
|
|
+ ret.setResultBody("55-60");
|
|
|
+ ret.setResultDesc("55-60");
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, "test-1");
|
|
|
+ return true;
|
|
|
+ } else if (idCode.equals("01d50825a2592b3d9a21cd6a144134ba0da21840825e80298113f89ed50392b5")
|
|
|
+ && name.equals("eaa7e959207fb76c8e7e38b022709defb9a1f0255538fd40ed47b7f2b70f4824")
|
|
|
+ && type.equals("1")) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ ret.setResultCode(Constant.MATCH_CODE);
|
|
|
+ ret.setResultBody("60-65");
|
|
|
+ ret.setResultDesc("60-65");
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, "test-1");
|
|
|
+ return true;
|
|
|
+ } else if (idCode.equals("e3d20f804609da6875fda87fc87fe61f9a8ce9fa3a3bada5743288c730a0e32c")
|
|
|
+ && name.equals("6004493a9414ea3b0a058c543e73920418da5228c7ca603f8ea8cc59d759dab9")
|
|
|
+ && type.equals("1")) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ ret.setResultCode(Constant.MATCH_CODE);
|
|
|
+ ret.setResultBody("65-70");
|
|
|
+ ret.setResultDesc("65-70");
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, "test-1");
|
|
|
+ return true;
|
|
|
+ } else if (idCode.equals("ffefcf3e3937ab7bbdddf287e80815dc39842d8eca6ba35a956f3d6b79850dee")
|
|
|
+ && name.equals("a31915d77b7e052780cbbb4e8e7a88ea03001b3170f98a260403641991126a99")
|
|
|
+ && type.equals("1")) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ ret.setResultCode(Constant.MATCH_CODE);
|
|
|
+ ret.setResultBody("70-85");
|
|
|
+ ret.setResultDesc("70-85");
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, "test-1");
|
|
|
+ return true;
|
|
|
+ } else if (idCode.equals("8bcbbb7e94673ca5c62207dc40c342bda85cd5c79b343c3d5321c2d6aedeaa85")
|
|
|
+ && name.equals("1c244860bfa8267a7af76a412cd5c5f2e9e9851e7e9f3857041a41c6a4a3fc3e")
|
|
|
+ && type.equals("1")) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ ret.setResultCode(Constant.MATCH_CODE);
|
|
|
+ ret.setResultBody("85-90");
|
|
|
+ ret.setResultDesc("85-90");
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, "test-1");
|
|
|
+ return true;
|
|
|
+ } else if (idCode.equals("282f8dcbdaacbb8ce12e064c67ef06228811fbc05144b83b3e727b28b2eb03d5")
|
|
|
+ && name.equals("a653f33d1b06678ec0dc06e2ea6f4a3e1f58a84d7b7689a22e1d9cd78b415953")
|
|
|
+ && type.equals("1")) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ ret.setResultCode(Constant.MATCH_CODE);
|
|
|
+ ret.setResultBody("90-100");
|
|
|
+ ret.setResultDesc("90-100");
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, "test-1");
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getAesMd5DecodeIdCode(HttpServletRequest request, String customBody,
|
|
|
+ ChannelTypeHandleResponseObject ret, int outTime) {
|
|
|
+ JSONObject customBodyObject = JSON.parseObject(customBody);
|
|
|
+ if (customBodyObject.get("idCode") == null || customBodyObject.get("name") == null) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
+ ret.setResultBody(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(customBodyObject.getString("idCode")) || StringUtils.isBlank(customBodyObject.getString("name"))) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ String userId = request.getHeader(ChannelConstant.USER_ID_HEADER_KEY);
|
|
|
+ // 对姓名AES解密
|
|
|
+ String aesDecryptKey = encrypt32(ChannelConstant.AES_KEY + userId).substring(8, 24);
|
|
|
+ log.info("getAesDecodeIdCard.user:{},aesDecryptKey:{}", userId, aesDecryptKey);
|
|
|
+ String decodeName = AesUtil.decryAES(aesDecryptKey, customBodyObject.getString("name"));
|
|
|
+
|
|
|
+ // 对身份证MD5解密
|
|
|
+ String decodeIdCode = "";
|
|
|
+ String decodeIdCodeResponseContext = Md5Sha256DecodeUtil.getDecodeIdCard(customBodyObject.getString("idCode"),
|
|
|
+ "", ChannelConstant.DECODE_TYPE_MD5, outTime);
|
|
|
+ JSONObject decodeResponseObject = JSON.parseObject(decodeIdCodeResponseContext);
|
|
|
+ if (decodeResponseObject != null && decodeResponseObject.getString("code").equals("200") && decodeResponseObject.getString("data").equals("1")) {
|
|
|
+ JSONObject msg = JSON.parseObject(JSON.toJSONString(decodeResponseObject.get("msg")));
|
|
|
+ if (StringUtils.isNotBlank(msg.getString("idcard"))) {
|
|
|
+ decodeIdCode = msg.getString("idcard");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(decodeIdCode) || StringUtils.isBlank(decodeName)) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_133);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_133);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_133);
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ customBodyObject.put("idCode", decodeIdCode);
|
|
|
+ customBodyObject.put("name", decodeName);
|
|
|
+ return customBodyObject.toJSONString();
|
|
|
+ } catch (Exception e) {
|
|
|
+ ErrorUtils.captureException(e);
|
|
|
+ log.info("supplier10000040.getAesDecodeIdCard解密失败,Exception={}", e);
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_133);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_133);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_133);
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getDecodeIdCode(HttpServletRequest request, String customBody, int outTime, String decodeType, ChannelTypeHandleResponseObject ret) {
|
|
|
+ JSONObject customBodyObject = JSON.parseObject(customBody);
|
|
|
+ if (StringUtils.isBlank(customBodyObject.getString("idCode")) || StringUtils.isBlank(customBodyObject.getString("name"))
|
|
|
+ || (decodeType.equals(ChannelConstant.DECODE_TYPE_SHA256) && customBodyObject.getString("idCode").length() != 64)
|
|
|
+ || (decodeType.equals(ChannelConstant.DECODE_TYPE_MD5) && customBodyObject.getString("idCode").length() != 32)
|
|
|
+ ) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ String result = "";
|
|
|
+ String decodeResponseContext = Md5Sha256DecodeUtil.getDecodeIdCard(customBodyObject.getString("idCode"),
|
|
|
+ "", decodeType, outTime);
|
|
|
+
|
|
|
+ JSONObject decodeResponseObject = JSON.parseObject(decodeResponseContext);
|
|
|
+ if (decodeResponseObject != null && decodeResponseObject.getString("code").equals("200") && decodeResponseObject.getString("data").equals("1")) {
|
|
|
+ JSONObject msg = JSON.parseObject(JSON.toJSONString(decodeResponseObject.get("msg")));
|
|
|
+ if (StringUtils.isNotBlank(msg.getString("idcard"))) {
|
|
|
+ customBodyObject.put("idCode", msg.getString("idcard"));
|
|
|
+ result = JSON.toJSONString(customBodyObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(result)) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_134);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_134);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_134);
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+}
|