|
@@ -0,0 +1,963 @@
|
|
|
+package info.aspirecn.iov.sjjh.supplier10000044.service;
|
|
|
+
|
|
|
+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.supplier10000044.constant.SjjhConstant;
|
|
|
+import info.aspirecn.iov.sjjh.supplier10000044.model.*;
|
|
|
+import info.aspirecn.iov.sjjh.supplier10000044.util.DESedeUtil;
|
|
|
+import info.aspirecn.rdc.aspirecloud.node.except.utils.ErrorUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import okhttp3.*;
|
|
|
+import org.apache.commons.lang3.ArrayUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+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 java.io.IOException;
|
|
|
+import java.net.SocketTimeoutException;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
+
|
|
|
+ * @description:
|
|
|
+ * @author: xusonglin
|
|
|
+ * @create: 2020/7/7 15:50
|
|
|
+ * @version: V1.0
|
|
|
+ **/
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class ChannelServiceImpl implements ChannelService {
|
|
|
+ @Value("${supplier.getTokenUrl}")
|
|
|
+ private String getTokenUrl;
|
|
|
+ @Value("${supplier.url}")
|
|
|
+ private String url;
|
|
|
+ @Value("${supplier.clientId}")
|
|
|
+ private String clientId;
|
|
|
+ @Value("${supplier.clientSecret}")
|
|
|
+ private String clientSecret;
|
|
|
+ @Value("${supplier.authMode-0x40}")
|
|
|
+ private Integer authMode40;
|
|
|
+ @Value("${supplier.authMode-0x42}")
|
|
|
+ private Integer authMode42;
|
|
|
+ @Value("${supplier.decryptKey}")
|
|
|
+ private String decryptKey;
|
|
|
+ @Value("${supplier.decodeApi}")
|
|
|
+ private String decodeApi;
|
|
|
+ @Value("${supplier.decodeUrl}")
|
|
|
+ private String decodeUrl;
|
|
|
+ @Value("${supplier.decodeAppKey}")
|
|
|
+ private String decodeAppKey;
|
|
|
+ @Value("${supplier.decodeAppSecret}")
|
|
|
+ private String decodeAppSecret;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ StringRedisTemplate stringRedisTemplate;
|
|
|
+ @Autowired
|
|
|
+ private ObjectMapper objectMapper;
|
|
|
+
|
|
|
+ private OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ChannelTypeHandleResponseObject twoElementsCheck(HttpServletRequest request, String customBody, int outTime) {
|
|
|
+ ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ log.info("supplier10000044.twoElementsCheck---customBody={},outTime={}", customBody, outTime);
|
|
|
+ try {
|
|
|
+ TwoElementsRequestObject requestObject = objectMapper.readValue(customBody,
|
|
|
+ TwoElementsRequestObject.class);
|
|
|
+ log.info("supplier10000044.twoElementsCheck---requestObject={}", requestObject);
|
|
|
+
|
|
|
+ if (!validateRequestParams(ret, returnType, requestObject)) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ requestObject.setIdCode(requestObject.getIdCode().toUpperCase());
|
|
|
+ String accessToken = getAccessToken(outTime);
|
|
|
+ IdentityInfoResponseObject responseObject = getIdentityInfoResponseObject(requestObject, outTime, accessToken, ret);
|
|
|
+ if (responseObject != null && responseObject.getRetCode().equals(SjjhConstant.RESPONSE_CODE_4022)) {
|
|
|
+ accessToken = queryAccessToken(outTime);
|
|
|
+ responseObject = getIdentityInfoResponseObject(requestObject, outTime, accessToken, ret);
|
|
|
+ }
|
|
|
+ if (responseObject != null) {
|
|
|
+ upstreamCode = responseObject.getRetCode() + "-" + responseObject.getResStr();
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ setTwoElementsCheck(ret, returnType, responseObject);
|
|
|
+ }
|
|
|
+ } catch (SocketTimeoutException ste) {
|
|
|
+ log.info("supplier10000044.twoElementsCheck接口-SocketTimeoutException:{}", ste);
|
|
|
+ ErrorUtils.captureException(ste);
|
|
|
+ ret.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
+ } catch (Exception ioe) {
|
|
|
+ log.info("supplier10000044.twoElementsCheck接口-Exception:{}", ioe);
|
|
|
+ ErrorUtils.captureException(ioe);
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ }
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setTwoElementsCheck(ChannelTypeHandleResponseObject ret, String returnType, IdentityInfoResponseObject responseObject) {
|
|
|
+ String responseCode = responseObject.getResStr();
|
|
|
+ boolean isCharge = responseCode != null
|
|
|
+ && ArrayUtils.contains(SjjhConstant.IDENTITY_CHARGE_CODE, responseCode);
|
|
|
+ if (isCharge) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_FEE);
|
|
|
+ }
|
|
|
+ if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
|
|
|
+ if (responseObject.getRetCode() != null && responseObject.getRetCode().equals(SjjhConstant.RESPONSE_CODE_4002)) {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_0XXX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1174);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_114);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_114);
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_5XXX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1175);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_115);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_115);
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_6XXX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1176);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_116);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_116);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR);
|
|
|
+ ret.setResultBody(Constant.OTHER_ERROR);
|
|
|
+ ret.setResultDesc(Constant.OTHER_ERROR);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (responseObject.getRetCode() != null && responseObject.getRetCode().equals(SjjhConstant.RESPONSE_CODE_4002)) {
|
|
|
+ ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_0XXX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_114);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_114);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_114);
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_5XXX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_115);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_115);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_115);
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_6XXX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_116);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_116);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_116);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.OTHER_ERROR_CODE);
|
|
|
+ ret.setResultBody(Constant.OTHER_ERROR);
|
|
|
+ ret.setResultDesc(Constant.OTHER_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private IdentityInfoResponseObject getIdentityInfoResponseObject(TwoElementsRequestObject requestObject, int outTime, String accessToken, ChannelTypeHandleResponseObject ret) {
|
|
|
+ TwoElementsParamObject paramObject = TwoElementsParamObject.getParamObject(accessToken, requestObject.getIdCode(), requestObject.getName(), authMode40);
|
|
|
+ log.info("supplier10000044.twoElementsCheck接口请求上游参数:{}", JSON.toJSONString(paramObject));
|
|
|
+ String responseContext = callService(paramObject, outTime, SjjhConstant.TWO_ELEMENTS_CHECK, ret);
|
|
|
+ log.info("supplier10000044.{}接口上游返回:{}", SjjhConstant.TWO_ELEMENTS_CHECK, responseContext);
|
|
|
+ if (StringUtils.isBlank(responseContext)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ IdentityInfoResponseObject responseObject = objectMapper.readValue(responseContext,
|
|
|
+ IdentityInfoResponseObject.class);
|
|
|
+ return responseObject;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("supplier10000044.{}-getIdentityInfoResponseObject接口-Exception:{}", SjjhConstant.TWO_ELEMENTS_CHECK, e);
|
|
|
+ ErrorUtils.captureException(e);
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private IdentityInfoResponseObject getIdentityInfoResponseObject(PhotoIdentityRequestObject requestObject, int outTime, String accessToken, ChannelTypeHandleResponseObject ret) {
|
|
|
+ PhotoIdentityParamObject paramObject = PhotoIdentityParamObject.getParamObject(accessToken, requestObject.getIdCode(),
|
|
|
+ requestObject.getName(), requestObject.getPhoto(), authMode42);
|
|
|
+ PhotoIdentityParamObject logParamObject = PhotoIdentityParamObject.getLogParamObject(accessToken, requestObject.getIdCode(),
|
|
|
+ requestObject.getName(), authMode42);
|
|
|
+ log.info("supplier10000044.photoIdentityCheck接口请求上游参数:{}", JSON.toJSONString(logParamObject));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ String responseContext = "{\"retCode\":0,\"retMessage\":\"成功\",\"apiVersion\":\"3.3.0\",\"certToken\":\"98cec673-a969-462a-b154-47b56b887fcb\",\"resStr\":\"02XX\"}";
|
|
|
+ log.info("supplier10000044.{}接口上游返回:{}", SjjhConstant.PHOTO_IDENTITY_CHECK, responseContext);
|
|
|
+ if (StringUtils.isBlank(responseContext)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ IdentityInfoResponseObject responseObject = objectMapper.readValue(responseContext,
|
|
|
+ IdentityInfoResponseObject.class);
|
|
|
+ return responseObject;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("supplier10000044.{}-getIdentityInfoResponseObject接口-Exception:{}", SjjhConstant.PHOTO_IDENTITY_CHECK, e);
|
|
|
+ ErrorUtils.captureException(e);
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String callService(Object paramObject, int outTime, String method, ChannelTypeHandleResponseObject ret) {
|
|
|
+ try {
|
|
|
+ String jsonStr = objectMapper.writeValueAsString(paramObject);
|
|
|
+
|
|
|
+ MediaType mediaType = MediaType.parse(org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE);
|
|
|
+ RequestBody requestBody = RequestBody.create(mediaType, jsonStr);
|
|
|
+
|
|
|
+ Request okRequest = new Request.Builder().post(requestBody).url(url).build();
|
|
|
+ OkHttpClient client = okHttpClient.newBuilder()
|
|
|
+ .connectTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .readTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .writeTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .build();
|
|
|
+ Response response = client.newCall(okRequest).execute();
|
|
|
+ String responseContext = "";
|
|
|
+ if (response.body() != null) {
|
|
|
+ responseContext = response.body().string();
|
|
|
+ }
|
|
|
+ response.close();
|
|
|
+ return responseContext;
|
|
|
+ } catch (SocketTimeoutException ste) {
|
|
|
+ log.info("supplier10000044.{}接口-SocketTimeoutException:{}", method, ste);
|
|
|
+ ErrorUtils.captureException(ste);
|
|
|
+ ret.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
+ return "";
|
|
|
+ } catch (Exception ioe) {
|
|
|
+ log.info("supplier10000044.{}接口-Exception:{}", method, ioe);
|
|
|
+ ErrorUtils.captureException(ioe);
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ChannelTypeHandleResponseObject photoIdentityCheck(HttpServletRequest request, String customBody, int outTime) {
|
|
|
+ ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ log.info("supplier10000044.photoIdentityCheck---customBody={},outTime={}", customBody, outTime);
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ requestObject.setIdCode(requestObject.getIdCode().toUpperCase());
|
|
|
+ String accessToken = getAccessToken(outTime);
|
|
|
+ IdentityInfoResponseObject responseObject = getIdentityInfoResponseObject(requestObject, outTime, accessToken, ret);
|
|
|
+ if (responseObject != null && responseObject.getRetCode().equals(SjjhConstant.RESPONSE_CODE_4022)) {
|
|
|
+ accessToken = queryAccessToken(outTime);
|
|
|
+ responseObject = getIdentityInfoResponseObject(requestObject, outTime, accessToken, ret);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (responseObject != null) {
|
|
|
+ upstreamCode = responseObject.getRetCode() + "-" + responseObject.getResStr();
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ setPhotoIdentityCheck(ret, returnType, responseObject);
|
|
|
+ }
|
|
|
+ } catch (SocketTimeoutException ste) {
|
|
|
+ log.info("supplier10000044.photoIdentityCheck接口-SocketTimeoutException:{}", ste);
|
|
|
+ ErrorUtils.captureException(ste);
|
|
|
+ ret.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
+ } catch (Exception ioe) {
|
|
|
+ log.info("supplier10000044.photoIdentityCheck接口-Exception:{}", ioe);
|
|
|
+ ErrorUtils.captureException(ioe);
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ }
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setPhotoIdentityCheck(ChannelTypeHandleResponseObject ret, String returnType, IdentityInfoResponseObject responseObject) {
|
|
|
+ String responseCode = responseObject.getResStr();
|
|
|
+ boolean isCharge = responseCode != null
|
|
|
+ && ArrayUtils.contains(SjjhConstant.PHOTO_IDENTITY_CHARGE_CODE, responseCode);
|
|
|
+ if (isCharge) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_FEE);
|
|
|
+ }
|
|
|
+ if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
|
|
|
+ if (responseObject.getRetCode() != null && responseObject.getRetCode().equals(SjjhConstant.RESPONSE_CODE_4002)) {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_00XX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1143);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_68);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_68);
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_01XX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1145);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_70);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_70);
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_02XX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1144);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_69);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_69);
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_5XXX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1175);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_115);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_115);
|
|
|
+ } else if (responseCode != null && (responseCode.equals(SjjhConstant.RESPONSE_CODE_6XXX) || responseCode.equals(SjjhConstant.RESPONSE_CODE_0CXX))) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1176);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_116);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_116);
|
|
|
+ } else if (responseCode != null && ArrayUtils.contains(SjjhConstant.PHOTO_BELOW_STANDARD, responseCode)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1177);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_117);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_117);
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_0DXX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1147);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_72);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_72);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR);
|
|
|
+ ret.setResultBody(Constant.OTHER_ERROR);
|
|
|
+ ret.setResultDesc(Constant.OTHER_ERROR);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (responseObject.getRetCode() != null && responseObject.getRetCode().equals(SjjhConstant.RESPONSE_CODE_4002)) {
|
|
|
+ ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_00XX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_68);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_68);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_68);
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_01XX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_70);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_70);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_70);
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_02XX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_69);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_69);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_69);
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_5XXX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_115);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_115);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_115);
|
|
|
+ } else if (responseCode != null && (responseCode.equals(SjjhConstant.RESPONSE_CODE_6XXX) || responseCode.equals(SjjhConstant.RESPONSE_CODE_0CXX))) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_116);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_116);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_116);
|
|
|
+ } else if (responseCode != null && ArrayUtils.contains(SjjhConstant.PHOTO_BELOW_STANDARD, responseCode)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_117);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_117);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_117);
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_0DXX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_72);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_72);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_72);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.OTHER_ERROR_CODE);
|
|
|
+ ret.setResultBody(Constant.OTHER_ERROR);
|
|
|
+ ret.setResultDesc(Constant.OTHER_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getAccessToken(int outTime) {
|
|
|
+ String redisToken = stringRedisTemplate.opsForValue().get(SjjhConstant.REDIS_TOKEN_KEY);
|
|
|
+ String token;
|
|
|
+ if (StringUtils.isNotBlank(redisToken)) {
|
|
|
+ String[] redisTokenArray = redisToken.split("&&");
|
|
|
+ String accessTokenTimestamp = redisTokenArray[1];
|
|
|
+ if (System.currentTimeMillis() - Long.parseLong(accessTokenTimestamp) >= 7200000 ) {
|
|
|
+
|
|
|
+ token = queryAccessToken(outTime);
|
|
|
+ log.info("超过2小时,重新获取token");
|
|
|
+ } else {
|
|
|
+
|
|
|
+ token = redisTokenArray[0];
|
|
|
+ log.info("从redis中获取token");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ token = queryAccessToken(outTime);
|
|
|
+ log.info("token不存在,获取token");
|
|
|
+ }
|
|
|
+
|
|
|
+ return token;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String queryAccessToken(int outTime) {
|
|
|
+ StringBuilder tokenUrl = new StringBuilder(getTokenUrl);
|
|
|
+ tokenUrl.append("?clientId=").append(clientId);
|
|
|
+ tokenUrl.append("&clientSecret=").append(clientSecret);
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(tokenUrl.toString())
|
|
|
+ .build();
|
|
|
+ OkHttpClient client = okHttpClient.newBuilder()
|
|
|
+ .connectTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .readTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .writeTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ String responseContext = "";
|
|
|
+ try {
|
|
|
+ Response response = client.newCall(request).execute();
|
|
|
+ if (response.body() != null) {
|
|
|
+ responseContext = response.body().string();
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.info("supplier10000044.getAccessToken调用接口异常-Exception:{}", e);
|
|
|
+ ErrorUtils.captureException(e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ log.info("supplier10000044.getAccessToken返回结果:{}", responseContext);
|
|
|
+ GetTokenResponseObject responseObject = JSONObject.toJavaObject(
|
|
|
+ JSON.parseObject(responseContext), GetTokenResponseObject.class);
|
|
|
+ if (responseObject != null && responseObject.getRetCode().equals(SjjhConstant.RET_CODE_0)) {
|
|
|
+ String token = responseObject.getAccessToken() + "&&" + System.currentTimeMillis();
|
|
|
+ stringRedisTemplate.opsForValue().set(SjjhConstant.REDIS_TOKEN_KEY, token, 2, TimeUnit.HOURS);
|
|
|
+ return responseObject.getAccessToken();
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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_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;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ChannelTypeHandleResponseObject twoElementsCheckNew(HttpServletRequest request, String customBody, int outTime, String decodeType) {
|
|
|
+ ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ log.info("supplier10000044.twoElementsCheckNew---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);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ TwoElementsRequestObject requestObject = objectMapper.readValue(customBody,
|
|
|
+ TwoElementsRequestObject.class);
|
|
|
+ log.info("supplier10000044.twoElementsCheckNew---requestObject={}", requestObject);
|
|
|
+
|
|
|
+ if (!validateRequestParams(ret, returnType, requestObject)) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ requestObject.setIdCode(requestObject.getIdCode().toUpperCase());
|
|
|
+ String accessToken = getAccessToken(outTime);
|
|
|
+ IdentityInfoResponseObject responseObject = getIdentityInfoResponseObject(requestObject, outTime, accessToken, ret);
|
|
|
+ if (responseObject != null && responseObject.getRetCode().equals(SjjhConstant.RESPONSE_CODE_4022)) {
|
|
|
+ accessToken = queryAccessToken(outTime);
|
|
|
+ responseObject = getIdentityInfoResponseObject(requestObject, outTime, accessToken, ret);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (responseObject != null) {
|
|
|
+ upstreamCode = responseObject.getRetCode() + "-" + responseObject.getResStr();
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ setTwoElementsCheckNew(ret, returnType, responseObject);
|
|
|
+ }
|
|
|
+ } catch (SocketTimeoutException ste) {
|
|
|
+ log.info("supplier10000044.twoElementsCheckNew接口-SocketTimeoutException:{}", ste);
|
|
|
+ ErrorUtils.captureException(ste);
|
|
|
+ ret.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
+ } catch (Exception ioe) {
|
|
|
+ log.info("supplier10000044.twoElementsCheckNew接口-Exception:{}", ioe);
|
|
|
+ ErrorUtils.captureException(ioe);
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ }
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setTwoElementsCheckNew(ChannelTypeHandleResponseObject ret, String returnType, IdentityInfoResponseObject responseObject) {
|
|
|
+ String responseCode = responseObject.getResStr();
|
|
|
+ boolean isCharge = responseCode != null
|
|
|
+ && ArrayUtils.contains(SjjhConstant.IDENTITY_CHARGE_CODE, responseCode);
|
|
|
+ if (isCharge) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_FEE);
|
|
|
+ }
|
|
|
+ if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
|
|
|
+ if ((responseObject.getRetCode() != null && responseObject.getRetCode().equals(SjjhConstant.RESPONSE_CODE_4002))
|
|
|
+ || (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_6XXX))) {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_0XXX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_MATCH);
|
|
|
+ ret.setResultBody(Constant.MATCH);
|
|
|
+ ret.setResultDesc(Constant.MATCH);
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_5XXX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_NO_MATCH);
|
|
|
+ ret.setResultBody(Constant.UN_MATCH);
|
|
|
+ ret.setResultDesc(Constant.UN_MATCH);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR);
|
|
|
+ ret.setResultBody(Constant.OTHER_ERROR);
|
|
|
+ ret.setResultDesc(Constant.OTHER_ERROR);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if ((responseObject.getRetCode() != null && responseObject.getRetCode().equals(SjjhConstant.RESPONSE_CODE_4002))
|
|
|
+ || (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_6XXX))) {
|
|
|
+ ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_0XXX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.MATCH_CODE);
|
|
|
+ ret.setResultBody(Constant.MATCH);
|
|
|
+ ret.setResultDesc(Constant.MATCH);
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_5XXX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.UN_MATCH_CODE);
|
|
|
+ ret.setResultBody(Constant.UN_MATCH);
|
|
|
+ ret.setResultDesc(Constant.UN_MATCH);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.OTHER_ERROR_CODE);
|
|
|
+ ret.setResultBody(Constant.OTHER_ERROR);
|
|
|
+ ret.setResultDesc(Constant.OTHER_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ChannelTypeHandleResponseObject photoIdentityCheckNew(HttpServletRequest request, String customBody, int outTime, String decodeType) {
|
|
|
+ ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ log.info("supplier10000044.photoIdentityCheckNew---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);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(customBody);
|
|
|
+ jsonObject.put("photo","图片base64");
|
|
|
+ request.setAttribute(Constant.CHANNEL_LOG_QUERY,
|
|
|
+ Base64.encodeBase64String(jsonObject.toJSONString().getBytes(SjjhConstant.PARA_ENCODE)));
|
|
|
+ jsonObject = null;
|
|
|
+ PhotoIdentityRequestObject requestObject = objectMapper.readValue(customBody,
|
|
|
+ PhotoIdentityRequestObject.class);
|
|
|
+ customBody = null;
|
|
|
+
|
|
|
+ if (!validateRequestParams(ret, returnType, requestObject)) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ requestObject.setIdCode(requestObject.getIdCode().toUpperCase());
|
|
|
+ String accessToken = getAccessToken(outTime);
|
|
|
+ IdentityInfoResponseObject responseObject = getIdentityInfoResponseObject(requestObject, outTime, accessToken, ret);
|
|
|
+ if (responseObject != null && responseObject.getRetCode().equals(SjjhConstant.RESPONSE_CODE_4022)) {
|
|
|
+ accessToken = queryAccessToken(outTime);
|
|
|
+ responseObject = getIdentityInfoResponseObject(requestObject, outTime, accessToken, ret);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (responseObject != null) {
|
|
|
+ upstreamCode = responseObject.getRetCode() + "-" + responseObject.getResStr();
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ setPhotoIdentityCheckNew(ret, returnType, responseObject);
|
|
|
+ }
|
|
|
+ } catch (SocketTimeoutException ste) {
|
|
|
+ log.info("supplier10000044.photoIdentityCheckNew接口-SocketTimeoutException:{}", ste);
|
|
|
+ ErrorUtils.captureException(ste);
|
|
|
+ ret.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
+ } catch (Exception ioe) {
|
|
|
+ log.info("supplier10000044.photoIdentityCheckNew接口-Exception:{}", ioe);
|
|
|
+ ErrorUtils.captureException(ioe);
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ }
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setPhotoIdentityCheckNew(ChannelTypeHandleResponseObject ret, String returnType, IdentityInfoResponseObject responseObject) {
|
|
|
+ String responseCode = responseObject.getResStr();
|
|
|
+
|
|
|
+ boolean isCharge = responseCode != null
|
|
|
+ && ArrayUtils.contains(SjjhConstant.PHOTO_IDENTITY_CHARGE_CODE_NEW, responseCode);
|
|
|
+ if (isCharge) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_FEE);
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject resultObject = new JSONObject();
|
|
|
+ resultObject.put("verificationScore", "");
|
|
|
+
|
|
|
+ if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
|
|
|
+ if (responseObject.getRetCode() != null && responseObject.getRetCode().equals(SjjhConstant.RESPONSE_CODE_4002)) {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_00XX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1143);
|
|
|
+ resultObject.put("message", Constant.RETURN_MESSAGE_68);
|
|
|
+ ret.setResultBody(resultObject.toJSONString());
|
|
|
+ ret.setResultDesc(resultObject.toJSONString());
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_01XX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1145);
|
|
|
+ resultObject.put("message", Constant.RETURN_MESSAGE_70);
|
|
|
+ ret.setResultBody(resultObject.toJSONString());
|
|
|
+ ret.setResultDesc(resultObject.toJSONString());
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_02XX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1144);
|
|
|
+ resultObject.put("message", Constant.RETURN_MESSAGE_69);
|
|
|
+ ret.setResultBody(resultObject.toJSONString());
|
|
|
+ ret.setResultDesc(resultObject.toJSONString());
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_5XXX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1146);
|
|
|
+ resultObject.put("message", Constant.RETURN_MESSAGE_71);
|
|
|
+ ret.setResultBody(resultObject.toJSONString());
|
|
|
+ ret.setResultDesc(resultObject.toJSONString());
|
|
|
+ } else if (responseCode != null && (responseCode.equals(SjjhConstant.RESPONSE_CODE_6XXX) || responseCode.equals(SjjhConstant.RESPONSE_CODE_0CXX))) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ } else if (responseCode != null && ArrayUtils.contains(SjjhConstant.PHOTO_BELOW_STANDARD, responseCode)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1149);
|
|
|
+ resultObject.put("message", Constant.RETURN_MESSAGE_74);
|
|
|
+ ret.setResultBody(resultObject.toJSONString());
|
|
|
+ ret.setResultDesc(resultObject.toJSONString());
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_0DXX)) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1147);
|
|
|
+ resultObject.put("message", Constant.RETURN_MESSAGE_72);
|
|
|
+ ret.setResultBody(resultObject.toJSONString());
|
|
|
+ ret.setResultDesc(resultObject.toJSONString());
|
|
|
+ } else {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR);
|
|
|
+ ret.setResultBody(Constant.OTHER_ERROR);
|
|
|
+ ret.setResultDesc(Constant.OTHER_ERROR);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (responseObject.getRetCode() != null && responseObject.getRetCode().equals(SjjhConstant.RESPONSE_CODE_4002)) {
|
|
|
+ ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_00XX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_68);
|
|
|
+ resultObject.put("message", Constant.RETURN_MESSAGE_68);
|
|
|
+ ret.setResultBody(resultObject.toJSONString());
|
|
|
+ ret.setResultDesc(resultObject.toJSONString());
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_01XX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_70);
|
|
|
+ resultObject.put("message", Constant.RETURN_MESSAGE_70);
|
|
|
+ ret.setResultBody(resultObject.toJSONString());
|
|
|
+ ret.setResultDesc(resultObject.toJSONString());
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_02XX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_69);
|
|
|
+ resultObject.put("message", Constant.RETURN_MESSAGE_69);
|
|
|
+ ret.setResultBody(resultObject.toJSONString());
|
|
|
+ ret.setResultDesc(resultObject.toJSONString());
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_5XXX)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_71);
|
|
|
+ resultObject.put("message", Constant.RETURN_MESSAGE_71);
|
|
|
+ ret.setResultBody(resultObject.toJSONString());
|
|
|
+ ret.setResultDesc(resultObject.toJSONString());
|
|
|
+ } else if (responseCode != null && (responseCode.equals(SjjhConstant.RESPONSE_CODE_6XXX) || responseCode.equals(SjjhConstant.RESPONSE_CODE_0CXX))) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ } else if (responseCode != null && ArrayUtils.contains(SjjhConstant.PHOTO_BELOW_STANDARD, responseCode)) {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_74);
|
|
|
+ resultObject.put("message", Constant.RETURN_MESSAGE_74);
|
|
|
+ ret.setResultBody(resultObject.toJSONString());
|
|
|
+ ret.setResultDesc(resultObject.toJSONString());
|
|
|
+ } else if (responseCode != null && responseCode.equals(SjjhConstant.RESPONSE_CODE_0DXX)) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_72);
|
|
|
+ resultObject.put("message", Constant.RETURN_MESSAGE_72);
|
|
|
+ ret.setResultBody(resultObject.toJSONString());
|
|
|
+ ret.setResultDesc(resultObject.toJSONString());
|
|
|
+ } else {
|
|
|
+
|
|
|
+ ret.setResultCode(Constant.OTHER_ERROR_CODE);
|
|
|
+ ret.setResultBody(Constant.OTHER_ERROR);
|
|
|
+ ret.setResultDesc(Constant.OTHER_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 "";
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ return customBody;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return customBody;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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("supplier100000044.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("supplier100000044.getDecodeIdCard接口SocketTimeoutException={}", ste);
|
|
|
+ return null;
|
|
|
+ } catch (Exception e) {
|
|
|
+ ErrorUtils.captureException(e);
|
|
|
+ log.info("supplier100000044.decodeIdCode接口Exception={}", e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|