|
@@ -0,0 +1,437 @@
|
|
|
|
+package info.aspirecn.rdc.iov.sjjh.servicenode.supplier.bty.service.impl;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
+import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
|
|
|
|
+import com.google.common.base.Preconditions;
|
|
|
|
+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.rdc.aspirecloud.node.except.utils.ErrorUtils;
|
|
|
|
+import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.bty.service.BTYChannelService;
|
|
|
|
+import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.bty.utils.DESedeUtil;
|
|
|
|
+import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.bty.utils.SupplierProperties;
|
|
|
|
+import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.bty.vo.DecodeThreeElementRequestObject;
|
|
|
|
+import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.bty.vo.TwoParamIdCardRequestObject;
|
|
|
|
+import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.bty.vo.TwoParamIdCardResponseObject;
|
|
|
|
+import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.bty_interface.vo.CustomBodyObject;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import okhttp3.*;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.net.SocketTimeoutException;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author jianggang
|
|
|
|
+ * @Date 2018/10/25 09:37:28
|
|
|
|
+ * @Description
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+@Slf4j
|
|
|
|
+@Service
|
|
|
|
+public class BTYChannelServiceImpl implements BTYChannelService {
|
|
|
|
+ /**
|
|
|
|
+ * 一致
|
|
|
|
+ */
|
|
|
|
+ private static final String MATCH_OK = "1100";
|
|
|
|
+ /**
|
|
|
|
+ * 不一致
|
|
|
|
+ */
|
|
|
|
+ private static final String NO_MATCH = "1101";
|
|
|
|
+ /**
|
|
|
|
+ * 库中无此号
|
|
|
|
+ */
|
|
|
|
+ private static final String NO_FIND = "1102";
|
|
|
|
+ /**
|
|
|
|
+ * 无效身份证
|
|
|
|
+ */
|
|
|
|
+ private static final String INVALID_CARD = "1103";
|
|
|
|
+ /***/
|
|
|
|
+ private static final String PARA_ERROR_TITLE = "参数错误或姓名身份证号无效";
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private SupplierProperties supplierProperties;
|
|
|
|
+
|
|
|
|
+ private OkHttpClient client = new OkHttpClient.Builder().build();
|
|
|
|
+
|
|
|
|
+ //private static final ConnectionPool POOL = new ConnectionPool(4000,
|
|
|
|
+ // 5, TimeUnit.MINUTES);
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public ChannelTypeHandleResponseObject sendTwoParamIdCardRequest(HttpServletRequest request,
|
|
|
|
+ String channelId, Integer outTime, String customBody) {
|
|
|
|
+ TwoParamIdCardResponseObject twoParamIdCardResponseObject = new TwoParamIdCardResponseObject();
|
|
|
|
+ ChannelTypeHandleResponseObject res = new ChannelTypeHandleResponseObject();
|
|
|
|
+ String upstreamCode = Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
|
|
|
|
+ String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA);
|
|
|
|
+ if (StringUtils.isBlank(returnType)) {
|
|
|
|
+ returnType = Constant.CUSTOMER_RETURN_ZW;
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+
|
|
|
|
+ Preconditions.checkNotNull(channelId, "通道id为空");
|
|
|
|
+ Preconditions.checkNotNull(customBody, "请求json字符串为空");
|
|
|
|
+
|
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
|
+ CustomBodyObject customBodyObject = mapper.readValue(customBody, CustomBodyObject.class);
|
|
|
|
+ boolean code = checkCustomeBody(customBodyObject, returnType, res);
|
|
|
|
+ if (!code) {
|
|
|
|
+ res.setCode(Constant.SUCCESS);
|
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (outTime == null && outTime <= 0) {
|
|
|
|
+ outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
|
|
|
|
+ }
|
|
|
|
+ OkHttpClient okHttpClient = client.newBuilder()
|
|
|
|
+ .connectTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
|
+ .writeTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
|
+ .readTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
|
+ .build();
|
|
|
|
+
|
|
|
|
+ TwoParamIdCardRequestObject requestObject = new TwoParamIdCardRequestObject();
|
|
|
|
+ requestObject.setName(customBodyObject.getName());
|
|
|
|
+ requestObject.setIdCard(customBodyObject.getIdCode());
|
|
|
|
+ String body = JSON.toJSONString(requestObject);
|
|
|
|
+ RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), body);
|
|
|
|
+ Request okRequest = new Request.Builder()
|
|
|
|
+ .url(supplierProperties.getUrl())
|
|
|
|
+ .header("AppCode", supplierProperties.getAppCode())
|
|
|
|
+ .header("pcode", supplierProperties.getPCode())
|
|
|
|
+ .post(requestBody)
|
|
|
|
+ .build();
|
|
|
|
+ Response response = okHttpClient.newCall(okRequest).execute();
|
|
|
|
+ String responseJson = response.body().string();
|
|
|
|
+ log.info("接口返回数据为:---{}", responseJson);
|
|
|
|
+ twoParamIdCardResponseObject = mapper.readValue(responseJson, TwoParamIdCardResponseObject.class);
|
|
|
|
+
|
|
|
|
+ //判断是否计费:code为100且responseObject.getData().getState()为1100或1101时收费
|
|
|
|
+ boolean resultBool = "100".equals(twoParamIdCardResponseObject.getCode()) &&
|
|
|
|
+ twoParamIdCardResponseObject.getData() != null &&
|
|
|
|
+ (MATCH_OK.equals(twoParamIdCardResponseObject.getData().getState()) ||
|
|
|
|
+ NO_MATCH.equals(twoParamIdCardResponseObject.getData().getState()));
|
|
|
|
+ if (resultBool) {
|
|
|
|
+ res.setIsCharge(Constant.INTERFACE_QUERY_FEE);
|
|
|
|
+ } else {
|
|
|
|
+ res.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ res.setCode(Constant.SUCCESS);
|
|
|
|
+ upstreamCode = twoParamIdCardResponseObject.getCode();
|
|
|
|
+ getChannelTypeHandleResponseObject(
|
|
|
|
+ returnType, res, twoParamIdCardResponseObject);
|
|
|
|
+
|
|
|
|
+ } catch (SocketTimeoutException e) {
|
|
|
|
+ log.error("SocketTimeoutException message:{}", e);
|
|
|
|
+ ErrorUtils.captureException(e);
|
|
|
|
+ res.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
|
+ res.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
|
+ return res;
|
|
|
|
+ } catch(UnrecognizedPropertyException upe) {
|
|
|
|
+ log.info("BTY身份二要素-UnrecognizedPropertyException:{}", upe);
|
|
|
|
+ ErrorUtils.captureException(upe);
|
|
|
|
+ res.setCode(Constant.SUCCESS);
|
|
|
|
+ res.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
|
+ /**参数错误*/
|
|
|
|
+ if(Constant.CUSTOMER_RETURN_JK.equals(returnType)){
|
|
|
|
+ res.setResultCode(Constant.JK_RETURN_CODE_9909);
|
|
|
|
+ } else {
|
|
|
|
+ res.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
|
+ }
|
|
|
|
+ res.setResultBody(Constant.PARAMETER_NAME_ERROR);
|
|
|
|
+ res.setResultDesc(Constant.PARAMETER_NAME_ERROR);
|
|
|
|
+ return res;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("Exception message:{}", e);
|
|
|
|
+ ErrorUtils.captureException(e);
|
|
|
|
+ res.setCode(Constant.FAIL);
|
|
|
|
+ res.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据客户不同,返回对应码
|
|
|
|
+ *
|
|
|
|
+ * @param returnType
|
|
|
|
+ * @param res
|
|
|
|
+ * @param responseObject
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private ChannelTypeHandleResponseObject getChannelTypeHandleResponseObject(
|
|
|
|
+ String returnType,
|
|
|
|
+ ChannelTypeHandleResponseObject res,
|
|
|
|
+ TwoParamIdCardResponseObject responseObject) {
|
|
|
|
+ if ("1".equals(returnType)) {
|
|
|
|
+ if (MATCH_OK.equals(responseObject.getData().getState())) {
|
|
|
|
+ //匹配
|
|
|
|
+ res.setResultCode(Constant.JK_RETURN_CODE_MATCH);
|
|
|
|
+ res.setResultBody(Constant.MATCH);
|
|
|
|
+ res.setResultDesc(Constant.MATCH);
|
|
|
|
+ } else if (NO_MATCH.equals(responseObject.getData().getState())) {
|
|
|
|
+ //不匹配
|
|
|
|
+ res.setResultCode(Constant.JK_RETURN_CODE_NO_MATCH);
|
|
|
|
+ res.setResultBody(Constant.UN_MATCH);
|
|
|
|
+ res.setResultDesc(Constant.UN_MATCH);
|
|
|
|
+ } else if (NO_FIND.equals(responseObject.getData().getState())) {
|
|
|
|
+ //未找到
|
|
|
|
+ res.setResultCode(Constant.JK_RETURN_CODE_NO_INFO);
|
|
|
|
+ res.setResultBody(Constant.UN_FIND_NUM);
|
|
|
|
+ res.setResultDesc(Constant.UN_FIND_NUM);
|
|
|
|
+ } else if (INVALID_CARD.equals(responseObject.getData().getState())) {
|
|
|
|
+ //无效身份证
|
|
|
|
+ res.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
|
+ res.setResultBody(PARA_ERROR_TITLE);
|
|
|
|
+ res.setResultDesc(PARA_ERROR_TITLE);
|
|
|
|
+ } else {
|
|
|
|
+ //其他错误
|
|
|
|
+ res.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR);
|
|
|
|
+ res.setResultBody(Constant.OTHER_ERROR);
|
|
|
|
+ res.setResultDesc(Constant.OTHER_ERROR);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (MATCH_OK.equals(responseObject.getData().getState())) {
|
|
|
|
+ //匹配
|
|
|
|
+ res.setResultCode(Constant.MATCH_CODE);
|
|
|
|
+ res.setResultBody(Constant.MATCH);
|
|
|
|
+ res.setResultDesc(Constant.MATCH);
|
|
|
|
+ } else if (NO_MATCH.equals(responseObject.getData().getState())) {
|
|
|
|
+ //不匹配
|
|
|
|
+ res.setResultCode(Constant.UN_MATCH_CODE);
|
|
|
|
+ res.setResultBody(Constant.UN_MATCH);
|
|
|
|
+ res.setResultDesc(Constant.UN_MATCH);
|
|
|
|
+ } else if (NO_FIND.equals(responseObject.getData().getState())) {
|
|
|
|
+ //未找到
|
|
|
|
+ res.setResultCode(Constant.UN_FIND_NUM_CODE);
|
|
|
|
+ res.setResultBody(Constant.UN_FIND_NUM);
|
|
|
|
+ res.setResultDesc(Constant.UN_FIND_NUM);
|
|
|
|
+ } else if (INVALID_CARD.equals(responseObject.getData().getState())) {
|
|
|
|
+ //无效身份证
|
|
|
|
+ res.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
|
+ res.setResultBody(PARA_ERROR_TITLE);
|
|
|
|
+ res.setResultDesc(PARA_ERROR_TITLE);
|
|
|
|
+ } else {
|
|
|
|
+ //其他错误
|
|
|
|
+ res.setResultCode(Constant.OTHER_ERROR_CODE);
|
|
|
|
+ res.setResultBody(Constant.OTHER_ERROR);
|
|
|
|
+ res.setResultDesc(Constant.OTHER_ERROR);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public boolean checkCustomeBody(CustomBodyObject customBodyObject, String returnType, ChannelTypeHandleResponseObject ret) {
|
|
|
|
+ String name = customBodyObject.getName();
|
|
|
|
+ String idCode = customBodyObject.getIdCode();
|
|
|
|
+ if (StringUtils.isBlank(name) || !PatternTools.checkResult(Constant.PATTERN_CN_NAME_REGEX, name)) {
|
|
|
|
+ if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
|
|
|
|
+ ret.setResultCode(Constant.NAME_FORMAT_ERROR_CODE);
|
|
|
|
+ ret.setResultBody(Constant.NAME_FORMAT_ERROR);
|
|
|
|
+ ret.setResultDesc(Constant.NAME_FORMAT_ERROR);
|
|
|
|
+ } else {
|
|
|
|
+ ret.setResultCode(Constant.JK_NAME_FORMAT_ERROR_CODE);
|
|
|
|
+ ret.setResultBody(Constant.JK_NAME_FORMAT_ERROR);
|
|
|
|
+ ret.setResultDesc(Constant.JK_NAME_FORMAT_ERROR);
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isBlank(idCode) || !PatternTools.checkResult(Constant.PATTERN_ID_NUMBER_REGEX, idCode)) {
|
|
|
|
+ if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
|
|
|
|
+ ret.setResultCode(Constant.IDCODE_FORMAT_ERROR_CODE);
|
|
|
|
+ ret.setResultBody(Constant.IDCODE_FORMAT_ERROR);
|
|
|
|
+ ret.setResultDesc(Constant.IDCODE_FORMAT_ERROR);
|
|
|
|
+ } else {
|
|
|
|
+ ret.setResultCode(Constant.JK_IDCODE_FORMAT_ERROR_CODE);
|
|
|
|
+ ret.setResultBody(Constant.JK_IDCODE_FORMAT_ERROR);
|
|
|
|
+ ret.setResultDesc(Constant.JK_IDCODE_FORMAT_ERROR);
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public ChannelTypeHandleResponseObject checkIdCardWeiZhong(HttpServletRequest request, String channelId, Integer outTime, String customBody) {
|
|
|
|
+ String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA);
|
|
|
|
+ ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
|
|
|
|
+ String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
|
|
|
|
+
|
|
|
|
+ JSONObject requestParamObject = JSONObject.parseObject(customBody);
|
|
|
|
+ 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 ret;
|
|
|
|
+ }
|
|
|
|
+ customBody = DESedeUtil.decryptMode(requestParamObject.getString("params"), supplierProperties.getDecryptKey());
|
|
|
|
+ if (StringUtils.isBlank(customBody)) {
|
|
|
|
+ if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
|
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_133);
|
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_133);
|
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_133);
|
|
|
|
+ } else {
|
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_9931);
|
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_133);
|
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_133);
|
|
|
|
+ }
|
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+ return sendTwoParamIdCardRequest(request, channelId, outTime, customBody);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public ChannelTypeHandleResponseObject checkIdCardMD5AndSHA256(HttpServletRequest request, String channelId,
|
|
|
|
+ Integer outTime, String customBody, String decodeType) {
|
|
|
|
+ String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA);
|
|
|
|
+ ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
|
|
|
|
+ String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
|
|
|
|
+
|
|
|
|
+ JSONObject requestParamObject = JSONObject.parseObject(customBody);
|
|
|
|
+
|
|
|
|
+ if (requestParamObject.get("idCode") == null || requestParamObject.get("name") == null) {
|
|
|
|
+ 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 ret;
|
|
|
|
+ } else if (StringUtils.isBlank(requestParamObject.getString("idCode"))
|
|
|
|
+ || StringUtils.isBlank(requestParamObject.getString("name"))) {
|
|
|
|
+ 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 ret;
|
|
|
|
+ } else if (decodeType.equals("MD5")
|
|
|
|
+ && (requestParamObject.getString("idCode").length() != 32
|
|
|
|
+ || requestParamObject.getString("name").length() !=32)) {
|
|
|
|
+ ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
|
+ 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 ret;
|
|
|
|
+ } else if (decodeType.equals("SHA256")
|
|
|
|
+ && (requestParamObject.getString("idCode").length() != 64
|
|
|
|
+ || requestParamObject.getString("name").length() != 64)) {
|
|
|
|
+ ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
|
+ 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 ret;
|
|
|
|
+ } else {
|
|
|
|
+ CustomBodyObject customBodyObject = JSON.toJavaObject(requestParamObject, CustomBodyObject.class);
|
|
|
|
+
|
|
|
|
+ customBodyObject = getDecodeIdCard(customBodyObject, outTime, decodeType);
|
|
|
|
+ if (customBodyObject == null
|
|
|
|
+ || StringUtils.isBlank(customBodyObject.getIdCode())
|
|
|
|
+ || StringUtils.isBlank(customBodyObject.getName())) {
|
|
|
|
+ if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
|
|
|
|
+ ret.setResultCode(Constant.ZW_RETURN_CODE_134);
|
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_134);
|
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_134);
|
|
|
|
+ } else {
|
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_9932);
|
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_134);
|
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_134);
|
|
|
|
+ }
|
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+ return sendTwoParamIdCardRequest(request, channelId, outTime, JSON.toJSONString(customBodyObject));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private CustomBodyObject getDecodeIdCard(CustomBodyObject customBodyObject, Integer outTime, String decodeType) {
|
|
|
|
+ DecodeThreeElementRequestObject.DecodeThreeElementRequestData dataObject = new DecodeThreeElementRequestObject.DecodeThreeElementRequestData();
|
|
|
|
+ dataObject.setId_number(customBodyObject.getIdCode());
|
|
|
|
+ dataObject.setName(customBodyObject.getName());
|
|
|
|
+ dataObject.setEncrypt(decodeType);
|
|
|
|
+ DecodeThreeElementRequestObject requestObject = new DecodeThreeElementRequestObject();
|
|
|
|
+ requestObject.setApi(supplierProperties.getDecodeApi());
|
|
|
|
+ requestObject.setAppKey(supplierProperties.getDecodeAppKey());
|
|
|
|
+ requestObject.setAppSecret(supplierProperties.getDecodeAppSecret());
|
|
|
|
+ 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(supplierProperties.getDecodeUrl())
|
|
|
|
+ .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("supplier10000008.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")));
|
|
|
|
+ CustomBodyObject result = new CustomBodyObject();
|
|
|
|
+ result.setIdCode(msg.getString("idcard"));
|
|
|
|
+ result.setName(msg.getString("name"));
|
|
|
|
+ return result;
|
|
|
|
+ } else {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ } catch (SocketTimeoutException ste) {
|
|
|
|
+ ErrorUtils.captureException(ste);
|
|
|
|
+ log.info("supplier10000002.getDecodeIdCard接口SocketTimeoutException={}", ste);
|
|
|
|
+ return null;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ ErrorUtils.captureException(e);
|
|
|
|
+ log.info("supplier10000002.decodeIdCode接口Exception={}", e);
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|