|
@@ -0,0 +1,598 @@
|
|
|
+package info.aspirecn.iov.sjjh.shupplier10000005.service;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
|
|
|
+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.shupplier10000005.SjjhConstant;
|
|
|
+import info.aspirecn.iov.sjjh.shupplier10000005.util.AesUtil;
|
|
|
+import info.aspirecn.iov.sjjh.shupplier10000005.util.MD5Util;
|
|
|
+import info.aspirecn.iov.sjjh.shupplier10000005.vo.*;
|
|
|
+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.stereotype.Service;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.xml.bind.JAXBContext;
|
|
|
+import javax.xml.bind.Unmarshaller;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.StringReader;
|
|
|
+import java.net.SocketTimeoutException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author xusonglin
|
|
|
+ * @version V1.0
|
|
|
+ **/
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class PhotoIdentityCheckServiceImpl implements PhotoIdentityCheckService {
|
|
|
+ @Value("${custom.photo-api}")
|
|
|
+ private String photoIdentityCheckApi;
|
|
|
+ @Value("${custom.aesDecryptKey}")
|
|
|
+ private String aesDecryptKey;
|
|
|
+ @Value("${custom.jkxyUrl}")
|
|
|
+ private String jkxyUrl;
|
|
|
+ @Value("${custom.app.key}")
|
|
|
+ private String appKey;
|
|
|
+ @Value("${custom.secret.key}")
|
|
|
+ private String secretKey;
|
|
|
+ @Value("${custom.photoCheck.url}")
|
|
|
+ private String photoCheckUrl;
|
|
|
+ @Value("${custom.photoCheck.hashcode}")
|
|
|
+ private String photoCheckHashCode;
|
|
|
+ @Value("${custom.photoCheck.key}")
|
|
|
+ private String photoCheckKey;
|
|
|
+ @Autowired
|
|
|
+ private ObjectMapper objectMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ChannelTypeHandleResponseObject photoIdentityCheck(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 <= 0) {
|
|
|
+ outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
|
|
|
+ }
|
|
|
+ log.info("supplier10000005.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);
|
|
|
+ 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(!checkParam(name,idCode,returnType,ret)){
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ PhotoIdentityCheckRequestObject.PhotoIdentityCheckRequestData dataObject = new PhotoIdentityCheckRequestObject.PhotoIdentityCheckRequestData();
|
|
|
+ dataObject.setName(name);
|
|
|
+ dataObject.setId_number(idCode);
|
|
|
+ dataObject.setImgstr(photo);
|
|
|
+ photo = null;
|
|
|
+
|
|
|
+ PhotoIdentityCheckRequestObject requestObject = new PhotoIdentityCheckRequestObject();
|
|
|
+ requestObject.setApi(photoIdentityCheckApi);
|
|
|
+ requestObject.setAppKey(appKey);
|
|
|
+ requestObject.setAppSecret(secretKey);
|
|
|
+ requestObject.setData(dataObject);
|
|
|
+ dataObject = null;
|
|
|
+
|
|
|
+ MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
|
|
|
+ RequestBody requestBody = RequestBody.create(mediaType, JSON.toJSONString(requestObject));
|
|
|
+ requestObject = null;
|
|
|
+ Request okRequest = new Request.Builder()
|
|
|
+ .post(requestBody)
|
|
|
+ .url(jkxyUrl)
|
|
|
+ .build();
|
|
|
+ OkHttpClient client = new OkHttpClient.Builder()
|
|
|
+ .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();
|
|
|
+ }
|
|
|
+ log.info("supplier10000005.scmDecodeIdCode接口responseContext={}", responseContext);
|
|
|
+ if (StringUtils.isNotBlank(responseContext)) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ upstreamCode = setPhotoIdentityCheckResponse(ret, returnType, responseContext);
|
|
|
+ response.close();
|
|
|
+ } else {
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ }
|
|
|
+ } catch (SocketTimeoutException ste) {
|
|
|
+ ErrorUtils.captureException(ste);
|
|
|
+ log.info("supplier10000005.photoIdentityCheck接口SocketTimeoutException={}", ste);
|
|
|
+ ret.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
+ } catch (Exception ioe) {
|
|
|
+ ErrorUtils.captureException(ioe);
|
|
|
+ log.info("supplier10000005.photoIdentityCheck接口Exception={}", ioe);
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ }
|
|
|
+
|
|
|
+ //上游返回码
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String setPhotoIdentityCheckResponse(ChannelTypeHandleResponseObject ret, String returnType, String result) {
|
|
|
+ JSONObject resultObject = new JSONObject();
|
|
|
+ JSONObject responseObject = JSON.parseObject(result);
|
|
|
+ String resultCode = responseObject.getString("data");
|
|
|
+ if (responseObject.getString("data").equals("2")) {
|
|
|
+ // 照片质量不合格
|
|
|
+ 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());
|
|
|
+ return resultCode;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (responseObject.getString("data").equals("3")) {
|
|
|
+ // 查询错误
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 有核验结果,解析msg
|
|
|
+ JSONObject responseMsg = JSON.parseObject(responseObject.getString("msg"));
|
|
|
+ String validateResult = responseMsg.getString("Validate_Result");
|
|
|
+ String similarity = responseMsg.getString("Similarity");
|
|
|
+ if (ArrayUtils.contains(SjjhConstant.PHOTO_CHECK_CHARGE_ARRAY, validateResult)) {
|
|
|
+ ret.setIsCharge(Constant.IS_CHARGE);
|
|
|
+ }
|
|
|
+ resultObject.put("verificationScore", similarity);
|
|
|
+ resultCode = resultCode + "-" + validateResult;
|
|
|
+ if (validateResult.equals("-1")) {
|
|
|
+ // 身份证号与姓名不匹配
|
|
|
+ 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());
|
|
|
+
|
|
|
+ } else if (validateResult.equals("-2")) {
|
|
|
+ // 库中无此号
|
|
|
+ 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);
|
|
|
+
|
|
|
+ } else if (validateResult.equals("-3")) {
|
|
|
+ // 身份证号与姓名匹配,库中无照片
|
|
|
+ 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 (validateResult.equals("1")) {
|
|
|
+ // 身份证号与姓名匹配,照片系统判断为同一人
|
|
|
+ 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 (validateResult.equals("2")) {
|
|
|
+ // 身份证号与姓名匹配,照片不能确定是否为同一人
|
|
|
+ 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 (validateResult.equals("3")) {
|
|
|
+ // 身份证号与姓名匹配,照片系统判断为不同人
|
|
|
+ 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 (validateResult.equals("7")) {
|
|
|
+ // 身份证号与姓名匹配,照片检测失败
|
|
|
+ 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());
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // 照片质量不合格,请重新上传
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+
|
|
|
+ return resultCode;
|
|
|
+
|
|
|
+ }
|
|
|
+ private String decodeParams(ChannelTypeHandleResponseObject ret, String returnType, String customBody, String decodeType) {
|
|
|
+ JSONObject requestParamObject = JSONObject.parseObject(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;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean checkParam(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 photoIdentityCheckV2(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 <= 0) {
|
|
|
+ outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
|
|
|
+ }
|
|
|
+ log.info("supplier10000005.photoIdentityCheckV2---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);
|
|
|
+ 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(!checkParam(name,idCode,returnType,ret)){
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
+ String sign = MD5Util.MD5(photoCheckHashCode + name + photo + idCode + photoCheckKey + sdf.format(new Date())).toLowerCase();
|
|
|
+ FormBody formBody = new FormBody.Builder()
|
|
|
+ .add("passName", name)
|
|
|
+ .add("hashcode", photoCheckHashCode)
|
|
|
+ .add("pid", idCode)
|
|
|
+ .add("photo", photo)
|
|
|
+ .add("sign", sign)
|
|
|
+ .build();
|
|
|
+ photo = null;
|
|
|
+ Request okRequest = new Request.Builder()
|
|
|
+ .post(formBody)
|
|
|
+ .url(photoCheckUrl)
|
|
|
+ .build();
|
|
|
+ OkHttpClient client = new OkHttpClient.Builder()
|
|
|
+ .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();
|
|
|
+ }
|
|
|
+ formBody = null;
|
|
|
+ log.info("supplier10000005.photoIdentityCheckV2接口responseContext={}", responseContext);
|
|
|
+ if (StringUtils.isNotBlank(responseContext)) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ upstreamCode = setPhotoIdentityCheckV2Response(ret, returnType, responseContext);
|
|
|
+ response.close();
|
|
|
+ } else {
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ }
|
|
|
+ } catch (SocketTimeoutException ste) {
|
|
|
+ ErrorUtils.captureException(ste);
|
|
|
+ log.info("supplier10000005.photoIdentityCheckV2接口SocketTimeoutException={}", ste);
|
|
|
+ ret.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
+ } catch (Exception ioe) {
|
|
|
+ ErrorUtils.captureException(ioe);
|
|
|
+ log.info("supplier10000005.photoIdentityCheckV2接口Exception={}", ioe);
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ }
|
|
|
+
|
|
|
+ //上游返回码
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String setPhotoIdentityCheckV2Response(ChannelTypeHandleResponseObject ret, String returnType, String result) {
|
|
|
+ PhotoIdentityCheckV2ResponseObject photoIdentityCheckV2ResponseObject = new PhotoIdentityCheckV2ResponseObject();
|
|
|
+ try {
|
|
|
+ JAXBContext context = JAXBContext.newInstance(PhotoIdentityCheckV2ResponseObject.class);
|
|
|
+ Unmarshaller unmarshaller = context.createUnmarshaller();
|
|
|
+ log.info(result);
|
|
|
+ photoIdentityCheckV2ResponseObject = (PhotoIdentityCheckV2ResponseObject) unmarshaller.unmarshal
|
|
|
+ (new StringReader(result.replace(SjjhConstant.PHOTO_CHECK_XML, "")));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ String errorCode = photoIdentityCheckV2ResponseObject.getErrorRes().getErrorCode();
|
|
|
+ String resultCode = errorCode;
|
|
|
+ JSONObject resultObject = new JSONObject();
|
|
|
+ if (errorCode.equals("502")) {
|
|
|
+ // 照片质量不合格
|
|
|
+ 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 (errorCode.equals("200")) {
|
|
|
+ String validateResult = photoIdentityCheckV2ResponseObject.getResult().getValidateResult();
|
|
|
+ String similarity = photoIdentityCheckV2ResponseObject.getResult().getSimilarity() == null ?
|
|
|
+ "" : photoIdentityCheckV2ResponseObject.getResult().getSimilarity();
|
|
|
+ if (ArrayUtils.contains(SjjhConstant.PHOTO_CHECK_CHARGE_ARRAY, validateResult)) {
|
|
|
+ ret.setIsCharge(Constant.IS_CHARGE);
|
|
|
+ }
|
|
|
+ resultObject.put("verificationScore", similarity);
|
|
|
+ resultCode = resultCode + "-" + validateResult;
|
|
|
+ if (validateResult.equals("-1")) {
|
|
|
+ // 身份证号与姓名不匹配
|
|
|
+ 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());
|
|
|
+
|
|
|
+ } else if (validateResult.equals("-2")) {
|
|
|
+ // 库中无此号
|
|
|
+ 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);
|
|
|
+
|
|
|
+ } else if (validateResult.equals("-3")) {
|
|
|
+ // 身份证号与姓名匹配,库中无照片
|
|
|
+ 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 (validateResult.equals("1")) {
|
|
|
+ // 身份证号与姓名匹配,照片系统判断为同一人
|
|
|
+ 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 (validateResult.equals("2")) {
|
|
|
+ // 身份证号与姓名匹配,照片不能确定是否为同一人
|
|
|
+ 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 (validateResult.equals("3")) {
|
|
|
+ // 身份证号与姓名匹配,照片系统判断为不同人
|
|
|
+ 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 (validateResult.equals("7")) {
|
|
|
+ // 身份证号与姓名匹配,照片检测失败
|
|
|
+ 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());
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // 照片质量不合格,请重新上传
|
|
|
+ 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 (errorCode.equals("501")) {
|
|
|
+ // 库中无此号
|
|
|
+ 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);
|
|
|
+ } 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);
|
|
|
+ return errorCode;
|
|
|
+ }
|
|
|
+
|
|
|
+ return resultCode;
|
|
|
+
|
|
|
+ }
|
|
|
+}
|