1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480 |
- 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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><RESPONSE errorcode=\"-20\" code=\"0\" countrows=\"1\"><ROWS><ROW><ErrorCode>-20</ErrorCode><ErrorMsg>计费失败,请与管理员联系(errorcode=-20)!</ErrorMsg></ROW></ROWS></RESPONSE>";
- 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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><RESPONSE errorcode=\"-20\" code=\"0\" countrows=\"1\"><ROWS><ROW><ErrorCode>-20</ErrorCode><ErrorMsg>计费失败,请与管理员联系(errorcode=-20)!</ErrorMsg></ROW></ROWS></RESPONSE>";
- 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<ConstraintViolation<Object>> set = validator.validate(jsonResolveObject);
- for (ConstraintViolation<Object> 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<TwoElementResponseObject.NciicCheckResponseItem> 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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ROWS><ROW no=\"1\"><INPUT><gmsfhm>610430199209130514</gmsfhm><xm>于博博</xm></INPUT><OUTPUT><ITEM><errormesage>服务结果:上传相片质量校验不合格,请重新拍摄上传</errormesage></ITEM><ITEM><errormesagecol></errormesagecol></ITEM></OUTPUT></ROW></ROWS>";
- 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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ROWS><ROW no=\"1\"><INPUT><gmsfhm>610430199209130514</gmsfhm><xm>于博博</xm></INPUT><OUTPUT><ITEM><errormesage>服务结果:上传相片质量校验不合格,请重新拍摄上传</errormesage></ITEM><ITEM><errormesagecol></errormesagecol></ITEM></OUTPUT></ROW></ROWS>";
- 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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ROWS><ROW no=\"1\"><INPUT><gmsfhm>610430199209130514</gmsfhm><xm>于博博</xm></INPUT><OUTPUT><ITEM><errormesage>服务结果:上传相片质量校验不合格,请重新拍摄上传</errormesage></ITEM><ITEM><errormesagecol></errormesagecol></ITEM></OUTPUT></ROW></ROWS>";
- 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<PhotoIdentityResponseObject.PhotoIdentityResponseItem> 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;
- }
- }
|