package info.aspirecn.iov.sjjh.supplier10000043.service; import brave.Tracer; import com.alibaba.fastjson.JSONArray; import info.aspirecn.iov.sjjh.channel.inter.platform.ChannelActionInterface; import info.aspirecn.iov.sjjh.service.sms.action.SmsActionInterface; import info.aspirecn.iov.sjjh.supplier10000043.constant.SupplierProperties; import info.aspirecn.iov.sjjh.supplier10000043.util.AesUtil; import info.aspirecn.iov.sjjh.supplier10000043.util.CommonUtil; import info.aspirecn.iov.sjjh.supplier10000043.util.NotifyThread; import okhttp3.*; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.databind.ObjectMapper; 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.supplier10000043.constant.SjjhConstant; import info.aspirecn.iov.sjjh.supplier10000043.model.*; import info.aspirecn.iov.sjjh.supplier10000043.util.DESedeUtil; import info.aspirecn.rdc.aspirecloud.node.except.utils.ErrorUtils; import lombok.extern.slf4j.Slf4j; import org.apache.axis.AxisFault; import org.apache.axis.AxisProperties; import org.apache.cxf.frontend.ClientProxy; import org.apache.commons.lang3.StringUtils; import org.apache.cxf.endpoint.Client; import org.apache.cxf.transport.http.HTTPConduit; import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; import org.apache.tomcat.util.codec.binary.Base64; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletRequest; import javax.validation.ConstraintViolation; import javax.validation.Validation; import javax.validation.Validator; import javax.validation.ValidatorFactory; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.namespace.QName; import javax.xml.rpc.encoding.XMLType; import javax.xml.ws.WebServiceException; import java.io.IOException; import java.io.StringReader; import java.net.SocketTimeoutException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; /** * @description: * @author: xusonglin * @create: 2020/6/15 16:02 * @version: V1.0 **/ @Service @Slf4j public class ChannelServiceImpl implements ChannelService { @Autowired private Tracer tracer; @Value("${supplier.url}") private String url; @Autowired private CommonUtil commonUtil; @Value("${supplier.twoElementsMethod}") private String twoElementsMethod; @Value("${supplier.photoIdentityMethod}") private String photoIdentityMethod; @Value("${supplier.decryptKey}") private String decryptKey; @Value("${supplier.urlV2}") private String urlV2; @Value("${spring.application.name}") private String applicationName; @Value("${supplier.decodeApi}") private String decodeApi; @Value("${supplier.decodeUrl}") private String decodeUrl; @Value("${supplier.decodeAppKey}") private String decodeAppKey; @Value("${supplier.decodeAppSecret}") private String decodeAppSecret; @Value("${supplier.aesDecryptKey}") private String aesDecryptKey; @Value("${supplier.urlV3}") private String urlV3; @Value("${supplier.urlV4}") private String urlV4; @Autowired SupplierProperties supplierProperties; @Autowired StringRedisTemplate stringRedisTemplate; @Autowired SmsActionInterface smsActionInterface; @Autowired ChannelActionInterface channelActionInterface; DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd"); @Autowired private ObjectMapper objectMapper; @Override public ChannelTypeHandleResponseObject twoElementsCheck(HttpServletRequest request, String customBody, int outTime, String decodeType) { ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject(); ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE); ret.setCode(Constant.SUCCESS); String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE; request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA); if (StringUtils.isBlank(returnType)) { returnType = Constant.CUSTOMER_RETURN_ZW; } if (outTime <= SjjhConstant.PARA_ZERO) { outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT; } log.info("supplier10000043.twoElementsCheck---customBody={},outTime={}", customBody, outTime); /* String key="url"+twoElementsMethod; LocalDateTime now = LocalDateTime.now(); String ymd = dateTimeFormatter.format(now); String hashKey = "043-"+ymd; boolean flag = checkVisitCount(hashKey,key,supplierProperties.getUrlSecondUp()); if(!flag){ countOver(ret); return ret; }*/ if (!decodeType.equals(SjjhConstant.DECODE_TYPE_COMMON)) { customBody = decodeParams(ret, returnType, customBody, decodeType); if (StringUtils.isBlank(customBody)) { // ret.setCode(Constant.SUCCESS); request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); //reduceVisitCount(hashKey,key); return ret; } } try { TwoElementsRequestObject requestObject = objectMapper.readValue(customBody, TwoElementsRequestObject.class); log.info("supplier10000043.twoElementsCheck---requestObject={}", requestObject); // 参数校验 if (!validateRequestParams(ret, returnType, requestObject)) { ret.setCode(Constant.SUCCESS); // reduceVisitCount(hashKey,key); request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); return ret; } // 直接引用远程的wsdl文件 // 以下都是套路 AxisProperties.setProperty("axis.socketSecureFactory", "org.apache.axis.components.net.SunFakeTrustSocketFactory"); org.apache.axis.client.Service service = new org.apache.axis.client.Service(); org.apache.axis.client.Call call = (org.apache.axis.client.Call) service.createCall(); call.setTargetEndpointAddress(url); call.setOperationName(twoElementsMethod);// WSDL里面描述的接口名称 call.setTimeout(outTime); call.addParameter(SjjhConstant.PARAMETER_INLICENSE, XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);// 接口的参数 call.addParameter(SjjhConstant.PARAMETER_INCONDITIONS, XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN); call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// 设置返回类型 String paramXml = SjjhConstant.TWO_ELEMENTS_XML_TEMPLATE .replace("{fsd}", requestObject.getIdCode().substring(0, 6)) .replace("{ywlx}", SjjhConstant.PARAMETER_YWLX) .replace("{idCode}", requestObject.getIdCode()) .replace("{name}", requestObject.getName()); String result = (String) call.invoke(new Object[]{SjjhConstant.TWO_ELEMENTS_SECRET_KEY, paramXml}); // String result = "-20计费失败,请与管理员联系(errorcode=-20)!"; log.info("twoElementsCheck上游返回xml:{}", result); upstreamCode = setTwoElementsCheckResponse(ret, returnType, result); } catch (SocketTimeoutException ste) { log.info("supplier10000043.twoElementsCheck接口-SocketTimeoutException:{}", ste); ErrorUtils.captureException(ste); ret.setCode(Constant.REQUEST_TIMEOUT); } catch (AxisFault axisFault) { log.info("supplier10000043.twoElementsCheck接口-AxisFaultException:{}", axisFault); ErrorUtils.captureException(axisFault); ret.setCode(Constant.REQUEST_TIMEOUT); } catch (Exception ioe) { log.info("supplier10000043.twoElementsCheck接口-Exception:{}", ioe); ErrorUtils.captureException(ioe); ret.setCode(Constant.FAIL); } request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); return ret; } @Override public ChannelTypeHandleResponseObject twoElementsCheckNew(HttpServletRequest request, String customBody, int outTime, String decodeType) { ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject(); ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE); ret.setCode(Constant.SUCCESS); String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE; request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA); if (StringUtils.isBlank(returnType)) { returnType = Constant.CUSTOMER_RETURN_ZW; } if (outTime <= SjjhConstant.PARA_ZERO) { outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT; } log.info("supplier10000043.twoElementsCheckNew---customBody={},outTime={}", customBody, outTime); /* String key="url"+twoElementsMethod; LocalDateTime now = LocalDateTime.now(); String ymd = dateTimeFormatter.format(now); String hashKey = "043-"+ymd; boolean flag = checkVisitCount(hashKey,key,supplierProperties.getUrlSecondUp()); if(!flag){ countOver(ret); return ret; }*/ if (!decodeType.equals(SjjhConstant.DECODE_TYPE_COMMON)) { customBody = decodeParams(ret, returnType, customBody, decodeType); if (StringUtils.isBlank(customBody)) { ret.setCode(Constant.SUCCESS); //reduceVisitCount(hashKey,key); request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); return ret; } } try { TwoElementsRequestObject requestObject = objectMapper.readValue(customBody, TwoElementsRequestObject.class); log.info("supplier10000043.twoElementsCheckNew---requestObject={}", requestObject); // 参数校验 if (!validateRequestParams(ret, returnType, requestObject)) { ret.setCode(Constant.SUCCESS); //reduceVisitCount(hashKey,key); request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); return ret; } JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setServiceClass(NciicServicesPortType.class);// 设置请求接口 factory.setAddress(url); NciicServicesPortType nciicServices = (NciicServicesPortType) factory.create(); // 创建客户端对象 // 设置客户端的配置信息,超时等. Client proxy = ClientProxy.getClient(nciicServices); HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setConnectionTimeout(outTime); // 连接超时时间 policy.setReceiveTimeout(outTime);// 请求超时时间. conduit.setClient(policy); String paramXml = SjjhConstant.TWO_ELEMENTS_XML_TEMPLATE .replace("{fsd}", requestObject.getIdCode().substring(0, 6)) .replace("{ywlx}", SjjhConstant.PARAMETER_YWLX) .replace("{idCode}", requestObject.getIdCode()) .replace("{name}", requestObject.getName()); String result = nciicServices.nciicCheck(SjjhConstant.TWO_ELEMENTS_SECRET_KEY,paramXml); // String result = "-20计费失败,请与管理员联系(errorcode=-20)!"; log.info("twoElementsCheck上游返回xml:{}", result); upstreamCode = setTwoElementsCheckResponse(ret, returnType, result); } catch (SocketTimeoutException ste) { log.info("supplier10000043.twoElementsCheck接口-SocketTimeoutException:{}", ste); ErrorUtils.captureException(ste); ret.setCode(Constant.REQUEST_TIMEOUT); } catch (AxisFault axisFault) { log.info("supplier10000043.twoElementsCheck接口-AxisFaultException:{}", axisFault); ErrorUtils.captureException(axisFault); ret.setCode(Constant.REQUEST_TIMEOUT); } catch (Exception ioe) { log.info("supplier10000043.twoElementsCheck接口-Exception:{}", ioe); ErrorUtils.captureException(ioe); ret.setCode(Constant.FAIL); } request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); return ret; } private String decodeParams(ChannelTypeHandleResponseObject ret, String returnType, String customBody, String decodeType) { JSONObject requestParamObject = JSONObject.parseObject(customBody); if (decodeType.equals(SjjhConstant.DECODE_TYPE_WEIZHONG)) { if (requestParamObject.get("params") == null) { 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 ""; } customBody = DESedeUtil.decryptMode(requestParamObject.getString("params"), decryptKey); if (StringUtils.isBlank(customBody)) { if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) { ret.setResultCode(Constant.ZW_RETURN_CODE_133); } else { ret.setResultCode(Constant.JK_RETURN_CODE_9931); } ret.setResultBody(Constant.RETURN_MESSAGE_133); ret.setResultDesc(Constant.RETURN_MESSAGE_133); return ""; } requestParamObject = null; return customBody; } if (decodeType.equals(SjjhConstant.DECODE_TYPE_MD5) || decodeType.equals(SjjhConstant.DECODE_TYPE_SHA256)) { if (requestParamObject.get("idCode") == null || requestParamObject.get("name") == null) { if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) { ret.setResultCode(Constant.INVALID_PARAMETER_CODE); } else { ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER); } ret.setResultBody(Constant.PARAMETER_NAME_ERROR); ret.setResultDesc(Constant.PARAMETER_NAME_ERROR); return ""; } if (StringUtils.isBlank(requestParamObject.getString("idCode")) || StringUtils.isBlank(requestParamObject.getString("name")) || (decodeType.equals(SjjhConstant.DECODE_TYPE_MD5) && (requestParamObject.getString("idCode").length() != 32 || requestParamObject.getString("name").length() != 32)) || (decodeType.equals(SjjhConstant.DECODE_TYPE_SHA256) && (requestParamObject.getString("idCode").length() != 64 || requestParamObject.getString("name").length() != 64))) { if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) { ret.setResultCode(Constant.INVALID_PARAMETER_CODE); } else { ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER); } ret.setResultBody(Constant.INVALID_PARAMETER); ret.setResultDesc(Constant.INVALID_PARAMETER); return ""; } requestParamObject = getDecodeIdCard(requestParamObject, 10000, decodeType); if (StringUtils.isBlank(requestParamObject.getString("idCode")) || StringUtils.isBlank(requestParamObject.getString("name"))) { if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) { ret.setResultCode(Constant.ZW_RETURN_CODE_134); } else { ret.setResultCode(Constant.JK_RETURN_CODE_9932); } ret.setResultBody(Constant.RETURN_MESSAGE_134); ret.setResultDesc(Constant.RETURN_MESSAGE_134); return ""; } else { customBody = JSON.toJSONString(requestParamObject); requestParamObject = null; return customBody; } } if (decodeType.equals(SjjhConstant.DECODE_TYPE_AES)) { if (requestParamObject.get("params") == null) { 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 ""; } try { customBody = AesUtil.decryAES(aesDecryptKey, requestParamObject.getString("params")); if (StringUtils.isBlank(customBody)) { if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) { ret.setResultCode(Constant.ZW_RETURN_CODE_133); } else { ret.setResultCode(Constant.JK_RETURN_CODE_9931); } ret.setResultBody(Constant.RETURN_MESSAGE_133); ret.setResultDesc(Constant.RETURN_MESSAGE_133); return ""; } requestParamObject = null; return customBody; } catch (Exception e) { ErrorUtils.captureException(e); if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) { ret.setResultCode(Constant.ZW_RETURN_CODE_133); } else { ret.setResultCode(Constant.JK_RETURN_CODE_9931); } ret.setResultBody(Constant.RETURN_MESSAGE_133); ret.setResultDesc(Constant.RETURN_MESSAGE_133); return ""; } } return customBody; } private boolean validateRequestParams(ChannelTypeHandleResponseObject ret, String returnType, TwoElementsRequestObject 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_SPECIAL_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; } else { return true; } } private boolean validateParamNullValue(Object jsonResolveObject) { ValidatorFactory vf = Validation.buildDefaultValidatorFactory(); Validator validator = vf.getValidator(); Set> set = validator.validate(jsonResolveObject); for (ConstraintViolation con : set) { if (StringUtils.isNotBlank(con.getMessage())) { return false; } } return true; } private String setTwoElementsCheckResponse(ChannelTypeHandleResponseObject ret, String returnType, String responseXml) { String resultCode; try { if (responseXml.contains(SjjhConstant.RESULT_NOT_FIND)) { resultCode = SjjhConstant.REQUEST_NOT_FIND; setNotFindResponse(ret, returnType); } /*else if (responseXml.contains(SjjhConstant.ERROR_CODE)) { resultCode = setErrorResponse(ret, returnType, responseXml); if("-53".equals(resultCode)){ String hashKey = commonUtil.getKey(); boolean flag = stringRedisTemplate.boundHashOps(hashKey).putIfAbsent(SjjhConstant.secondKey,true); if(flag){ Map map = SjjhConstant.hashMap.get(hashKey); if(map==null){ SjjhConstant.hashMap.put(hashKey,map); } map.put(SjjhConstant.secondKey,true); } ret.setCode(Constant.REQUEST_TIMEOUT); return resultCode; } }*/ else { resultCode = SjjhConstant.REQUEST_SUCCESS; setTwoElementsCheckSuccessResponse(ret, returnType, responseXml); } ret.setCode(Constant.SUCCESS); } catch (JAXBException jaxb) { resultCode = SjjhConstant.PARSE_FAILURE; log.info("supplier10000043.twoElementsCheck接口-解析上游返回xml失败:{}", jaxb.getMessage()); ErrorUtils.captureException(jaxb); ret.setCode(Constant.FAIL); if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) { 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); } return resultCode; } private void setNotFindResponse(ChannelTypeHandleResponseObject ret, String returnType) { if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_NO_INFO); } else { ret.setResultCode(Constant.UN_FIND_NUM_CODE); } ret.setResultBody(Constant.UN_FIND_NUM); ret.setResultDesc(Constant.UN_FIND_NUM); } private void setTwoElementsCheckSuccessResponse(ChannelTypeHandleResponseObject ret, String returnType, String responseXml) throws JAXBException { JAXBContext context = JAXBContext.newInstance(TwoElementResponseObject.class); Unmarshaller unmarshaller = context.createUnmarshaller(); TwoElementResponseObject responseObject = (TwoElementResponseObject) unmarshaller.unmarshal(new StringReader(responseXml)); String result = SjjhConstant.RESULT_MATCH; List items = responseObject.getRow().get(0).getOutput().getItems(); for (TwoElementResponseObject.NciicCheckResponseItem item : items) { if (item.getIdCodeResult() != null && item.getIdCodeResult().equals(SjjhConstant.RESULT_UN_MATCH)) { result = SjjhConstant.RESULT_UN_MATCH; } if (item.getNameResult() != null && item.getNameResult().equals(SjjhConstant.RESULT_UN_MATCH)) { result = SjjhConstant.RESULT_UN_MATCH; } } if (result.equals(SjjhConstant.RESULT_MATCH)) { // 一致 if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_MATCH); } else { ret.setResultCode(Constant.MATCH_CODE); } ret.setResultBody(Constant.MATCH); ret.setResultDesc(Constant.MATCH); } else { // 不一致 if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_NO_MATCH); } else { ret.setResultCode(Constant.UN_MATCH_CODE); } ret.setResultBody(Constant.UN_MATCH); ret.setResultDesc(Constant.UN_MATCH); } ret.setIsCharge(Constant.IS_CHARGE); } public String setErrorResponse(ChannelTypeHandleResponseObject ret, String returnType, String responseXml) throws JAXBException { JAXBContext context = JAXBContext.newInstance(ErrorResponseObject.class); Unmarshaller unmarshaller = context.createUnmarshaller(); ErrorResponseObject errorResponseObject = (ErrorResponseObject) unmarshaller.unmarshal(new StringReader(responseXml)); // 查询错误 if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) { 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); return errorResponseObject.getRow().getRowObject().getErrorCode(); } @Override public ChannelTypeHandleResponseObject photoIdentityCheck(HttpServletRequest request, String customBody, int outTime, String decodeType) { ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject(); ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE); ret.setCode(Constant.SUCCESS); String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE; request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA); String channelId = request.getHeader("channelId"); if (StringUtils.isBlank(returnType)) { returnType = Constant.CUSTOMER_RETURN_ZW; } if (outTime <= SjjhConstant.PARA_ZERO) { outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT; } String key="url"+photoIdentityMethod; LocalDateTime now = LocalDateTime.now(); String ymd = dateTimeFormatter.format(now); String hashKey = "043-"+ymd; boolean flag = checkVisitCount(hashKey,key,supplierProperties.getUrlPhotoUp(),channelId); if(!flag){ countOver(ret,returnType); return ret; } log.info("supplier10000043.photoIdentityCheck---customBody={},outTime={}", customBody, outTime); if (!decodeType.equals(SjjhConstant.DECODE_TYPE_COMMON)) { customBody = decodeParams(ret, returnType, customBody, decodeType); if (StringUtils.isBlank(customBody)) { ret.setCode(Constant.SUCCESS); reduceVisitCount(hashKey,key); request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); return ret; } } try { JSONObject jsonObject = JSON.parseObject(customBody); String name = jsonObject.getString("name");//requestObject.getName(); String idCode = jsonObject.getString("idCode"); String photo = jsonObject.getString("photo"); customBody = null; jsonObject.put("photo", "图片base64"); request.setAttribute(Constant.CHANNEL_LOG_QUERY, Base64.encodeBase64String(jsonObject.toJSONString().getBytes(SjjhConstant.PARA_ENCODE))); jsonObject = null; if(!checkParm(name,idCode,returnType,ret)){ reduceVisitCount(hashKey,key); return ret; } /* JSONObject jsonObject = JSON.parseObject(customBody); jsonObject.put("photo","图片base64"); request.setAttribute(Constant.CHANNEL_LOG_QUERY, Base64.encodeBase64String(jsonObject.toJSONString().getBytes(SjjhConstant.PARA_ENCODE))); PhotoIdentityRequestObject requestObject = objectMapper.readValue(customBody, PhotoIdentityRequestObject.class); // 参数校验 if (!validateRequestParams(ret, returnType, requestObject)) { ret.setCode(Constant.SUCCESS); request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); return ret; }*/ JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setServiceClass(NciicServicesPortType.class);// 设置请求接口 factory.setAddress(url);//"http://127.0.0.1/nciic_ws/services/NciicServices" NciicServicesPortType nciicServices = (NciicServicesPortType) factory.create(); // 创建客户端对象 // 设置客户端的配置信息,超时等. Client proxy = ClientProxy.getClient(nciicServices); HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setConnectionTimeout(outTime); // 连接超时时间 policy.setReceiveTimeout(outTime);// 请求超时时间. conduit.setClient(policy); String paramXml = SjjhConstant.PHOTO_IDENTITY_XML_TEMPLATE .replace("{fsd}", idCode.substring(0, 6)) .replace("{ywlx}", SjjhConstant.PARAMETER_YWLX) .replace("{idCode}", idCode) .replace("{name}", name) .replace("{photo}", photo); photo = null; //String result = "610430199209130514于博博服务结果:上传相片质量校验不合格,请重新拍摄上传"; String result = nciicServices.nciicCompare(SjjhConstant.PHOTO_IDENTITY_SECRET_KEY, paramXml); log.info("photoIdentityCheck上游返回xml:{}", result); upstreamCode = setPhotoIdentityCheckResponse(ret, returnType, result,key+SjjhConstant.key_subStr,channelId); // 直接引用远程的wsdl文件 // 以下都是套路 /* AxisProperties.setProperty("axis.socketSecureFactory", "org.apache.axis.components.net.SunFakeTrustSocketFactory"); org.apache.axis.client.Service service = new org.apache.axis.client.Service(); org.apache.axis.client.Call call = (org.apache.axis.client.Call) service.createCall(); call.setTargetEndpointAddress(url); call.setOperationName(photoIdentityMethod);// WSDL里面描述的接口名称 call.setTimeout(outTime); call.addParameter(SjjhConstant.PARAMETER_INLICENSE, XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);// 接口的参数 call.addParameter(SjjhConstant.PARAMETER_INCONDITIONS, XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN); call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// 设置返回类型 String paramXml = SjjhConstant.PHOTO_IDENTITY_XML_TEMPLATE .replace("{fsd}", idCode.substring(0, 6)) .replace("{ywlx}", SjjhConstant.PARAMETER_YWLX) .replace("{idCode}", idCode) .replace("{name}", name) .replace("{photo}", photo); String result = (String) call.invoke(new Object[]{SjjhConstant.PHOTO_IDENTITY_SECRET_KEY, paramXml}); // String result = "610430199209130514于博博服务结果:上传相片质量校验不合格,请重新拍摄上传"; log.info("photoIdentityCheck上游返回xml:{}", result); upstreamCode = setPhotoIdentityCheckResponse(ret, returnType, result);*/ } catch (WebServiceException ste) { log.info("supplier10000043.photoIdentityCheck接口-SocketTimeoutException:{}", ste); ErrorUtils.captureException(ste); ret.setCode(Constant.REQUEST_TIMEOUT); } catch (Exception ioe) { log.info("supplier10000043.photoIdentityCheck接口-Exception:{}", ioe); ErrorUtils.captureException(ioe); ret.setCode(Constant.FAIL); } request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); return ret; } public boolean checkParm(String name,String idCode,String returnType,ChannelTypeHandleResponseObject ret){ if (StringUtils.isBlank(name) || StringUtils.isBlank(idCode)) { 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(name) || !PatternTools.checkResult(Constant.PATTERN_SPECIAL_CN_NAME_REGEX, name)) { 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(idCode) || !PatternTools.checkResult(Constant.PATTERN_SPECIAL_ID_NUMBER_REGEX, idCode)) { 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; } @Override public ChannelTypeHandleResponseObject photoIdentityCheckNew(HttpServletRequest request, String customBody, int outTime, String decodeType) { ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject(); ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE); ret.setCode(Constant.SUCCESS); String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE; request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA); if (StringUtils.isBlank(returnType)) { returnType = Constant.CUSTOMER_RETURN_ZW; } if (outTime <= SjjhConstant.PARA_ZERO) { outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT; } String channelId = request.getHeader("channelId"); String key="url"+photoIdentityMethod; LocalDateTime now = LocalDateTime.now(); String ymd = dateTimeFormatter.format(now); String hashKey = "043-"+ymd; boolean flag = checkVisitCount(hashKey,key,supplierProperties.getUrlPhotoUp(),channelId); if(!flag){ countOver(ret,returnType); return ret; } log.info("supplier10000043.photoIdentityCheck---customBody={},outTime={}", customBody, outTime); if (!decodeType.equals(SjjhConstant.DECODE_TYPE_COMMON)) { customBody = decodeParams(ret, returnType, customBody, decodeType); if (StringUtils.isBlank(customBody)) { ret.setCode(Constant.SUCCESS); reduceVisitCount(hashKey,key); request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); return ret; } } try { JSONObject jsonObject = JSON.parseObject(customBody); String name = jsonObject.getString("name");//requestObject.getName(); String idCode = jsonObject.getString("idCode"); String photo = jsonObject.getString("photo"); customBody = null; jsonObject.put("photo", "图片base64"); request.setAttribute(Constant.CHANNEL_LOG_QUERY, Base64.encodeBase64String(jsonObject.toJSONString().getBytes(SjjhConstant.PARA_ENCODE))); jsonObject = null; if(!checkParm(name,idCode,returnType,ret)){ reduceVisitCount(hashKey,key); return ret; } // 直接引用远程的wsdl文件 JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setServiceClass(NciicServicesPortType.class);// 设置请求接口 factory.setAddress(url);//"http://127.0.0.1/nciic_ws/services/NciicServices" NciicServicesPortType nciicServices = (NciicServicesPortType) factory.create(); // 创建客户端对象 // 设置客户端的配置信息,超时等. Client proxy = ClientProxy.getClient(nciicServices); HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setConnectionTimeout(outTime); // 连接超时时间 policy.setReceiveTimeout(outTime);// 请求超时时间. conduit.setClient(policy); String paramXml = SjjhConstant.PHOTO_IDENTITY_XML_TEMPLATE .replace("{fsd}", idCode.substring(0, 6)) .replace("{ywlx}", SjjhConstant.PARAMETER_YWLX) .replace("{idCode}", idCode) .replace("{name}", name) .replace("{photo}", photo); photo = null; //String result = "610430199209130514于博博服务结果:上传相片质量校验不合格,请重新拍摄上传"; String result = nciicServices.nciicCompare(SjjhConstant.PHOTO_IDENTITY_SECRET_KEY, paramXml); log.info("photoIdentityCheck上游返回xml:{}", result); upstreamCode = setPhotoIdentityCheckResponse(ret, returnType, result,key+SjjhConstant.key_subStr,channelId); }catch (WebServiceException exception){ log.info("supplier10000043.photoIdentityCheck接口-WebServiceException:{}", exception); ErrorUtils.captureException(exception); ret.setCode(Constant.REQUEST_TIMEOUT); } catch (Exception ioe) { log.info("supplier10000043.photoIdentityCheck接口-Exception:{}", ioe); ErrorUtils.captureException(ioe); ret.setCode(Constant.FAIL); } request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); return ret; } private String setPhotoIdentityCheckResponse(ChannelTypeHandleResponseObject ret, String returnType, String responseXml,String key,String channelId) { String resultCode; try { if (responseXml.contains(SjjhConstant.RESULT_NOT_FIND)) { resultCode = SjjhConstant.REQUEST_NOT_FIND; setNotFindResponse(ret, returnType); }else if (responseXml.contains(SjjhConstant.ERROR_CODE)) { resultCode = setErrorResponse(ret, returnType, responseXml); if("-53".equals(resultCode)){ //不是规定时间出现的,只是超时,进行切换 ret.setCode(Constant.REQUEST_TIMEOUT); //时间范围判断 int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); if(hour>=supplierProperties.getHour()){ String hashKey = commonUtil.getKey(); boolean flag = stringRedisTemplate.boundHashOps(hashKey).putIfAbsent(key,"1"); if(flag){ testNotify(channelId,3); } //规定的时间之后出现的,才是达量,覆盖超时码 ret.setCode(Constant.REQUEST_LIMIT); } return resultCode; } } else if (responseXml.contains(SjjhConstant.ERROR_MESSAGE)) { resultCode = SjjhConstant.REQUEST_ERROR; setPhotoIdentityErrorResponse(ret, returnType, responseXml); } else { resultCode = SjjhConstant.REQUEST_SUCCESS; setPhotoIdentityCheckSuccessResponse(ret, returnType, responseXml); } ret.setCode(Constant.SUCCESS); } catch (JAXBException jaxb) { resultCode = SjjhConstant.PARSE_FAILURE; log.info("supplier10000043.setPhotoIdentityCheckResponse接口-解析上游返回xml失败:{}", jaxb.getMessage()); ErrorUtils.captureException(jaxb); ret.setCode(Constant.FAIL); if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) { 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); } return resultCode; } private void setPhotoIdentityCheckSuccessResponse(ChannelTypeHandleResponseObject ret, String returnType, String responseXml) throws JAXBException { JAXBContext context = JAXBContext.newInstance(PhotoIdentityResponseObject.class); Unmarshaller unmarshaller = context.createUnmarshaller(); PhotoIdentityResponseObject responseObject = (PhotoIdentityResponseObject) unmarshaller.unmarshal(new StringReader(responseXml)); String idCodeNameResult = SjjhConstant.RESULT_MATCH; String photoResult = ""; String photoResultScore = ""; List items = responseObject.getRow().get(0).getOutput().getItems(); for (PhotoIdentityResponseObject.PhotoIdentityResponseItem item : items) { if (item.getIdCodeResult() != null && item.getIdCodeResult().equals(SjjhConstant.RESULT_UN_MATCH)) { idCodeNameResult = SjjhConstant.RESULT_UN_MATCH; } if (item.getNameResult() != null && item.getNameResult().equals(SjjhConstant.RESULT_UN_MATCH)) { idCodeNameResult = SjjhConstant.RESULT_UN_MATCH; } if (StringUtils.isNotBlank(item.getPhotoResult())) { photoResult = item.getPhotoResult(); } if (StringUtils.isNotBlank(item.getPhotoResultScore())) { photoResultScore = item.getPhotoResultScore(); } } JSONObject resultObject = new JSONObject(); resultObject.put("verificationScore", photoResultScore); if (idCodeNameResult.equals(SjjhConstant.RESULT_MATCH)) { if (photoResult.equals(SjjhConstant.RESPONSE_PHOTO_MATCH)) { // 身份证号与姓名匹配,系统判断为同一人 if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_1143); } else { ret.setResultCode(Constant.ZW_RETURN_CODE_68); } resultObject.put("message", Constant.RETURN_MESSAGE_68); ret.setResultBody(resultObject.toJSONString()); ret.setResultDesc(resultObject.toJSONString()); } else if (photoResult.equals(SjjhConstant.RESPONSE_PHOTO_UN_MATCH)) { // 身份证号与姓名匹配,系统判断为不同人 if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_1145); } else { ret.setResultCode(Constant.ZW_RETURN_CODE_70); } resultObject.put("message", Constant.RETURN_MESSAGE_70); ret.setResultBody(resultObject.toJSONString()); ret.setResultDesc(resultObject.toJSONString()); } else if (photoResult.equals(SjjhConstant.RESPONSE_PHOTO_UNCERTAINTY)) { // 身份证号与姓名匹配,不能确定是否为同一人 if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_1144); } else { ret.setResultCode(Constant.ZW_RETURN_CODE_69); } resultObject.put("message", Constant.RETURN_MESSAGE_69); ret.setResultBody(resultObject.toJSONString()); ret.setResultDesc(resultObject.toJSONString()); } else if (photoResult.equals(SjjhConstant.RESPONSE_NO_PHOTO)) { // 身份证号与姓名匹配,库中无照片 // 修改日期:2020-11-11 // 修改原因:开发时上游文档没有“库中无照片”的说明,客户需要将库中无照片与照片检测失败两个message区分开,返回码为1147 if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_1147); } else { ret.setResultCode(Constant.ZW_RETURN_CODE_72); } resultObject.put("message", Constant.RETURN_MESSAGE_72); ret.setResultBody(resultObject.toJSONString()); ret.setResultDesc(resultObject.toJSONString()); } else { // 身份证号与姓名匹配,照片检测失败 if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_1148); } else { ret.setResultCode(Constant.ZW_RETURN_CODE_73); } resultObject.put("message", Constant.RETURN_MESSAGE_73); ret.setResultBody(resultObject.toJSONString()); ret.setResultDesc(resultObject.toJSONString()); } ret.setIsCharge(Constant.IS_CHARGE); } else { // 身份证号与姓名不匹配 if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_1146); } else { ret.setResultCode(Constant.ZW_RETURN_CODE_71); } resultObject.put("message", Constant.RETURN_MESSAGE_71); ret.setResultBody(resultObject.toJSONString()); ret.setResultDesc(resultObject.toJSONString()); ret.setIsCharge(Constant.IS_CHARGE); } } private void setPhotoIdentityErrorResponse(ChannelTypeHandleResponseObject ret, String returnType, String responseXml) throws JAXBException { JAXBContext context = JAXBContext.newInstance(PhotoIdentityErrorResponseObject.class); Unmarshaller unmarshaller = context.createUnmarshaller(); PhotoIdentityErrorResponseObject errorResponseObject = (PhotoIdentityErrorResponseObject) unmarshaller.unmarshal(new StringReader(responseXml)); JSONObject resultObject = new JSONObject(); String errorMessage = ""; for (PhotoIdentityErrorResponseObject.PhotoIdentityErrorResponseItem item : errorResponseObject.getRow().get(0).getOutput().getItem()) { if (StringUtils.isNotBlank(item.getErrorMesage())) { errorMessage = item.getErrorMesage(); } } if (errorMessage.equals(SjjhConstant.RESPONSE_ERROR_PHOTO_QUALITY) || errorMessage.equals(SjjhConstant.RESPONSE_ERROR_PHOTO_SIZE)) { if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_1149); } else { ret.setResultCode(Constant.ZW_RETURN_CODE_74); } resultObject.put("message", Constant.RETURN_MESSAGE_74); resultObject.put("verificationScore", ""); ret.setResultBody(resultObject.toJSONString()); ret.setResultDesc(resultObject.toJSONString()); } else { // 查询错误 if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) { 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); } } @Override public ChannelTypeHandleResponseObject photoIdentityCheckV2(HttpServletRequest request, String customBody, int outTime, String decodeType) { ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject(); ret.setCode(Constant.SUCCESS); ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE); String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE; request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA); if (StringUtils.isBlank(returnType)) { returnType = Constant.CUSTOMER_RETURN_ZW; } if (outTime <= SjjhConstant.PARA_ZERO) { outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT; } String channelId = request.getHeader("channelId"); String key="url2"+photoIdentityMethod; LocalDateTime now = LocalDateTime.now(); String ymd = dateTimeFormatter.format(now); String hashKey = "043-"+ymd; boolean flag = checkVisitCount(hashKey,key,supplierProperties.getUrl2PhotoUp(),channelId); if(!flag){ countOver(ret,returnType); return ret; } log.info("supplier10000043.photoIdentityCheckV2---customBody={},outTime={}", customBody, outTime); if (!decodeType.equals(SjjhConstant.DECODE_TYPE_COMMON)) { customBody = decodeParams(ret, returnType, customBody, decodeType); if (StringUtils.isBlank(customBody)) { reduceVisitCount(hashKey,key); ret.setCode(Constant.SUCCESS); request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); return ret; } } try { JSONObject jsonObject = JSON.parseObject(customBody); String name = jsonObject.getString("name");//requestObject.getName(); String idCode = jsonObject.getString("idCode"); String photo = jsonObject.getString("photo"); customBody = null; jsonObject.put("photo", "图片base64"); request.setAttribute(Constant.CHANNEL_LOG_QUERY, Base64.encodeBase64String(jsonObject.toJSONString().getBytes(SjjhConstant.PARA_ENCODE))); jsonObject = null; if(!checkParm(name,idCode,returnType,ret)){ reduceVisitCount(hashKey,key); return ret; } JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setServiceClass(NciicServicesPortType.class);// 设置请求接口 factory.setAddress(urlV2); NciicServicesPortType nciicServices = (NciicServicesPortType) factory.create(); // 创建客户端对象 // 设置客户端的配置信息,超时等. Client proxy = ClientProxy.getClient(nciicServices); HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setConnectionTimeout(outTime); // 连接超时时间 policy.setReceiveTimeout(outTime);// 请求超时时间. conduit.setClient(policy); String paramXml = SjjhConstant.PHOTO_IDENTITY_XML_TEMPLATE_V2 .replace("{fsd}", idCode.substring(0, 6)) .replace("{ywlx}", SjjhConstant.PARAMETER_JZSC) .replace("{idCode}", idCode) .replace("{name}", name) .replace("{photo}", photo); String result = nciicServices.nciicCompare(SjjhConstant.PHOTO_IDENTITY_SECRET_KEY_V2,paramXml); log.info("photoIdentityCheck上游返回xml:{}", result); upstreamCode = setPhotoIdentityCheckResponse(ret, returnType, result,key+SjjhConstant.key_subStr,channelId); } catch (WebServiceException ste) { log.info("supplier10000043.photoIdentityCheckV2接口-WebServiceException:{}", ste); ErrorUtils.captureException(ste); ret.setCode(Constant.REQUEST_TIMEOUT); } catch (Exception ioe) { log.info("supplier10000043.photoIdentityCheckV2接口-Exception:{}", ioe); ErrorUtils.captureException(ioe); ret.setCode(Constant.FAIL); } request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); return ret; } public ChannelTypeHandleResponseObject photoIdentityCheckV2New(HttpServletRequest request, String customBody, int outTime, String decodeType) { ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject(); ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE); ret.setCode(Constant.SUCCESS); String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE; request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA); if (StringUtils.isBlank(returnType)) { returnType = Constant.CUSTOMER_RETURN_ZW; } if (outTime <= SjjhConstant.PARA_ZERO) { outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT; } String channelId = request.getHeader("channelId"); String key="url2"+photoIdentityMethod; LocalDateTime now = LocalDateTime.now(); String ymd = dateTimeFormatter.format(now); String hashKey = "043-"+ymd; boolean flag = checkVisitCount(hashKey,key,supplierProperties.getUrl2PhotoUp(),channelId); if(!flag){ countOver(ret,returnType); return ret; } log.info("supplier10000043.photoIdentityCheckV2New---customBody={},outTime={}", customBody, outTime); if (!decodeType.equals(SjjhConstant.DECODE_TYPE_COMMON)) { customBody = decodeParams(ret, returnType, customBody, decodeType); if (StringUtils.isBlank(customBody)) { reduceVisitCount(hashKey,key); ret.setCode(Constant.SUCCESS); request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); return ret; } } try { JSONObject jsonObject = JSON.parseObject(customBody); String name = jsonObject.getString("name");//requestObject.getName(); String idCode = jsonObject.getString("idCode"); String photo = jsonObject.getString("photo"); customBody = null; jsonObject.put("photo", "图片base64"); request.setAttribute(Constant.CHANNEL_LOG_QUERY, Base64.encodeBase64String(jsonObject.toJSONString().getBytes(SjjhConstant.PARA_ENCODE))); jsonObject = null; if(!checkParm(name,idCode,returnType,ret)){ reduceVisitCount(hashKey,key); return ret; } JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setServiceClass(NciicServicesPortType.class);// 设置请求接口 factory.setAddress(urlV2); NciicServicesPortType nciicServices = (NciicServicesPortType) factory.create(); // 创建客户端对象 // 设置客户端的配置信息,超时等. Client proxy = ClientProxy.getClient(nciicServices); HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setConnectionTimeout(outTime); // 连接超时时间 policy.setReceiveTimeout(outTime);// 请求超时时间. conduit.setClient(policy); String paramXml = SjjhConstant.PHOTO_IDENTITY_XML_TEMPLATE_V2 .replace("{fsd}", idCode.substring(0, 6)) .replace("{ywlx}", SjjhConstant.PARAMETER_JZSC) .replace("{idCode}", idCode) .replace("{name}", name) .replace("{photo}", photo); String result = nciicServices.nciicCompare(SjjhConstant.PHOTO_IDENTITY_SECRET_KEY_V2,paramXml); log.info("photoIdentityCheck上游返回xml:{}", result); upstreamCode = setPhotoIdentityCheckResponse(ret, returnType, result,key+SjjhConstant.key_subStr,channelId); }catch (WebServiceException exception){ log.info("supplier10000043.photoIdentityCheck接口-WebServiceException:{}", exception); ErrorUtils.captureException(exception); ret.setCode(Constant.REQUEST_TIMEOUT); } catch (Exception ioe) { log.info("supplier10000043.photoIdentityCheckV2New接口-Exception:{}", ioe); ErrorUtils.captureException(ioe); ret.setCode(Constant.FAIL); } request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); return ret; } public boolean checkVisitCount(String hashKey,String key,long upCount,String channelId){ //查看是否有超过权限的标志 /*Map map =SjjhConstant.hashMap.get(hashKey); if(map!=null&&map.get(key+SjjhConstant.key_subStr)!=null && map.get(key+SjjhConstant.key_subStr).equals(Boolean.TRUE)){ return false; }*/ String countStr = (String)stringRedisTemplate.boundHashOps(hashKey).get(key); log.info("countStr:{}",countStr); if(countStr!=null && Long.parseLong(countStr)>=upCount){ return false; } if(stringRedisTemplate.boundHashOps(hashKey).hasKey(key+SjjhConstant.key_subStr)){ return false; } long visitCount = stringRedisTemplate.boundHashOps(hashKey).increment(key,1); if(visitCount==1){ stringRedisTemplate.boundValueOps(hashKey).expire(1, TimeUnit.DAYS); } if(upCount-visitCount==supplierProperties.getNotityLimit()){ //起一个线程,处理此逻辑 testNotify(channelId,1); } if(upCount-visitCount==0){ //起一个线程,处理此逻辑, testNotify(channelId,2); } if(visitCount>upCount){ reduceVisitCount(hashKey,key); return false; } return true; } private JSONObject getDecodeIdCard(JSONObject requestParamObject, Integer outTime, String decodeType) { DecodeThreeElementRequestObject.DecodeThreeElementRequestData dataObject = new DecodeThreeElementRequestObject.DecodeThreeElementRequestData(); dataObject.setId_number(requestParamObject.getString("idCode")); dataObject.setName(requestParamObject.getString("name")); dataObject.setEncrypt(decodeType); DecodeThreeElementRequestObject requestObject = new DecodeThreeElementRequestObject(); requestObject.setApi(decodeApi); requestObject.setAppKey(decodeAppKey); requestObject.setAppSecret(decodeAppSecret); requestObject.setData(dataObject); MediaType mediaType = MediaType.parse("application/json; charset=utf-8"); RequestBody requestBody = RequestBody.create(mediaType, JSON.toJSONString(requestObject)); Request okHttpRequest = new Request.Builder() .post(requestBody) .url(decodeUrl) .build(); OkHttpClient decodeClient = new OkHttpClient.Builder() .connectTimeout(outTime, TimeUnit.MILLISECONDS) .readTimeout(outTime, TimeUnit.MILLISECONDS) .writeTimeout(outTime, TimeUnit.MILLISECONDS) .build(); try { Response decodeResponse = decodeClient.newCall(okHttpRequest).execute(); String decodeResponseContext = ""; if (decodeResponse.body() != null) { decodeResponseContext = decodeResponse.body().string(); } log.info("supplier100000043.scmDecodeIdCode接口decodeResponseContext={}", decodeResponseContext); 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"))); requestParamObject.put("idCode", msg.getString("idcard")); requestParamObject.put("name", msg.getString("name")); return requestParamObject; } else { return null; } } catch (SocketTimeoutException ste) { ErrorUtils.captureException(ste); log.info("supplier100000043.getDecodeIdCard接口SocketTimeoutException={}", ste); return null; } catch (Exception e) { ErrorUtils.captureException(e); log.info("supplier100000043.decodeIdCode接口Exception={}", e); return null; } } public void reduceVisitCount(String hashKey,String key){ long visitCount = stringRedisTemplate.boundHashOps(hashKey).increment(key,-1); } public void countOver(ChannelTypeHandleResponseObject ret,String returnType){ if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) { ret.setResultCode(Constant.OTHER_ERROR_CODE); } else { ret.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR); } ret.setCode(Constant.REQUEST_LIMIT); } public static void main(String[] args) { int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); System.out.println(hour); } public void testNotify(String channelId,int type){ String traceId= tracer.currentSpan().context().traceIdString(); NotifySms notifySms =new NotifySms(); notifySms.setSupplierProperties(supplierProperties); notifySms.setSmsActionInterface(smsActionInterface); notifySms.setChannelActionInterface(channelActionInterface); notifySms.setChannId(channelId); notifySms.setTraceId(traceId); notifySms.setType(type); notifySms.setCount(0); Timer timer =new Timer(); log.info("test..................,notify:{}",notifySms); timer.schedule(new NotifyThread(notifySms),1*60*1000); } /* public void norify(String channelId,int type){ boolean flag = stringRedisTemplate.boundHashOps(Constant.rx_warn_key).putIfAbsent("sign","1"); if(flag == ){ } }*/ public ChannelTypeHandleResponseObject photoIdentityCheckV3New(HttpServletRequest request, String customBody, int outTime, String decodeType) { ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject(); ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE); ret.setCode(Constant.SUCCESS); String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE; request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA); if (StringUtils.isBlank(returnType)) { returnType = Constant.CUSTOMER_RETURN_ZW; } if (outTime <= SjjhConstant.PARA_ZERO) { outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT; } String channelId = request.getHeader("channelId"); String key="url3"+photoIdentityMethod; LocalDateTime now = LocalDateTime.now(); String ymd = dateTimeFormatter.format(now); String hashKey = "043-"+ymd; boolean flag = checkVisitCount(hashKey,key,supplierProperties.getUrl3PhotoUp(),channelId); if(!flag){ countOver(ret,returnType); return ret; } log.info("supplier10000043.photoIdentityCheckV3New---customBody={},outTime={}", customBody, outTime); if (!decodeType.equals(SjjhConstant.DECODE_TYPE_COMMON)) { customBody = decodeParams(ret, returnType, customBody, decodeType); if (StringUtils.isBlank(customBody)) { reduceVisitCount(hashKey,key); ret.setCode(Constant.SUCCESS); request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); return ret; } } try { JSONObject jsonObject = JSON.parseObject(customBody); String name = jsonObject.getString("name");//requestObject.getName(); String idCode = jsonObject.getString("idCode"); String photo = jsonObject.getString("photo"); customBody = null; jsonObject.put("photo", "图片base64"); request.setAttribute(Constant.CHANNEL_LOG_QUERY, Base64.encodeBase64String(jsonObject.toJSONString().getBytes(SjjhConstant.PARA_ENCODE))); jsonObject = null; if(!checkParm(name,idCode,returnType,ret)){ reduceVisitCount(hashKey,key); return ret; } JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setServiceClass(NciicServicesPortType.class);// 设置请求接口 factory.setAddress(urlV3); NciicServicesPortType nciicServices = (NciicServicesPortType) factory.create(); // 创建客户端对象 // 设置客户端的配置信息,超时等. Client proxy = ClientProxy.getClient(nciicServices); HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setConnectionTimeout(outTime); // 连接超时时间 policy.setReceiveTimeout(outTime);// 请求超时时间. conduit.setClient(policy); String paramXml = SjjhConstant.PHOTO_IDENTITY_XML_TEMPLATE_V3 .replace("{fsd}", idCode.substring(0, 6)) .replace("{ywlx}", SjjhConstant.PARAMETER_YWLX_BQ) .replace("{idCode}", idCode) .replace("{name}", name) .replace("{photo}", photo); String result = nciicServices.nciicCompare(SjjhConstant.PHOTO_IDENTITY_SECRET_KEY_V3,paramXml); log.info("photoIdentityCheck上游返回xml:{}", result); upstreamCode = setPhotoIdentityCheckResponse(ret, returnType, result,key+SjjhConstant.key_subStr,channelId); }catch (WebServiceException exception){ log.info("supplier10000043.photoIdentityCheckV3接口-WebServiceException:{}", exception); ErrorUtils.captureException(exception); ret.setCode(Constant.REQUEST_TIMEOUT); } catch (Exception ioe) { log.info("supplier10000043.photoIdentityCheckV3New接口-Exception:{}", ioe); ErrorUtils.captureException(ioe); ret.setCode(Constant.FAIL); } request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); return ret; } @Override public ChannelTypeHandleResponseObject photoIdentityCheckV4New(HttpServletRequest request, String customBody, int outTime, String decodeType) { ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject(); ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE); ret.setCode(Constant.SUCCESS); String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE; request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA); if (StringUtils.isBlank(returnType)) { returnType = Constant.CUSTOMER_RETURN_ZW; } if (outTime <= SjjhConstant.PARA_ZERO) { outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT; } String channelId = request.getHeader("channelId"); String key="url4"+photoIdentityMethod; LocalDateTime now = LocalDateTime.now(); String ymd = dateTimeFormatter.format(now); String hashKey = "043-"+ymd; boolean flag = checkVisitCount(hashKey,key,supplierProperties.getUrl4PhotoUp(),channelId); if(!flag){ countOver(ret,returnType); return ret; } log.info("supplier10000043.photoIdentityCheckV4New---customBody={},outTime={}", customBody, outTime); if (!decodeType.equals(SjjhConstant.DECODE_TYPE_COMMON)) { customBody = decodeParams(ret, returnType, customBody, decodeType); if (StringUtils.isBlank(customBody)) { reduceVisitCount(hashKey,key); ret.setCode(Constant.SUCCESS); request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); return ret; } } try { JSONObject jsonObject = JSON.parseObject(customBody); String name = jsonObject.getString("name");//requestObject.getName(); String idCode = jsonObject.getString("idCode"); String photo = jsonObject.getString("photo"); customBody = null; jsonObject.put("photo", "图片base64"); request.setAttribute(Constant.CHANNEL_LOG_QUERY, Base64.encodeBase64String(jsonObject.toJSONString().getBytes(SjjhConstant.PARA_ENCODE))); jsonObject = null; if(!checkParm(name,idCode,returnType,ret)){ reduceVisitCount(hashKey,key); return ret; } JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setServiceClass(NciicServicesPortType.class);// 设置请求接口 factory.setAddress(urlV4); NciicServicesPortType nciicServices = (NciicServicesPortType) factory.create(); // 创建客户端对象 // 设置客户端的配置信息,超时等. Client proxy = ClientProxy.getClient(nciicServices); HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setConnectionTimeout(outTime); // 连接超时时间 policy.setReceiveTimeout(outTime);// 请求超时时间. conduit.setClient(policy); String paramXml = SjjhConstant.PHOTO_IDENTITY_XML_TEMPLATE_V4 .replace("{fsd}", idCode.substring(0, 6)) .replace("{ywlx}", SjjhConstant.PARAMETER_YWLX_YTST) .replace("{idCode}", idCode) .replace("{name}", name) .replace("{photo}", photo); String result = nciicServices.nciicCompare(SjjhConstant.PHOTO_IDENTITY_SECRET_KEY_V4,paramXml); log.info("photoIdentityCheck上游返回xml:{}", result); upstreamCode = setPhotoIdentityCheckResponse(ret, returnType, result,key+SjjhConstant.key_subStr,channelId); }catch (WebServiceException exception){ log.info("supplier10000043.photoIdentityCheckV4New接口-WebServiceException:{}", exception); ErrorUtils.captureException(exception); ret.setCode(Constant.REQUEST_TIMEOUT); } catch (Exception ioe) { log.info("supplier10000043.photoIdentityCheckV4New接口-Exception:{}", ioe); ErrorUtils.captureException(ioe); ret.setCode(Constant.FAIL); } request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); return ret; } }