|
@@ -0,0 +1,592 @@
|
|
|
+package info.aspirecn.rdc.iov.sjjh.servicenode.supplier.yh.service.impl;
|
|
|
+
|
|
|
+import brave.Tracer;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import info.aspirecn.iov.sjjh.channel.inter.platform.ChannelActionInterface;
|
|
|
+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.service.sms.action.SmsActionInterface;
|
|
|
+import info.aspirecn.rdc.aspirecloud.node.except.utils.ErrorUtils;
|
|
|
+import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.yh.constant.SjjhConstant;
|
|
|
+import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.yh.service.FaceCheckService;
|
|
|
+import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.yh.utils.*;
|
|
|
+import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.yh.vo.CommonRequestObject;
|
|
|
+import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.yh.vo.FaceCheckResObject;
|
|
|
+import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.yh.vo.NotifySms;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import okhttp3.*;
|
|
|
+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 java.net.SocketTimeoutException;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Timer;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author jianggang
|
|
|
+ * @Date 2019/6/10 14:33:24
|
|
|
+ * @Description
|
|
|
+ */
|
|
|
+
|
|
|
+@SuppressWarnings("ALL")
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class FaceCheckServiceImpl implements FaceCheckService {
|
|
|
+ @Autowired
|
|
|
+ private Tracer tracer;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private YHProperties yhProperties;
|
|
|
+
|
|
|
+ private OkHttpClient client = new OkHttpClient.Builder().build();
|
|
|
+
|
|
|
+ @Value("${wz.decryptKey}")
|
|
|
+ private String decryptKey;
|
|
|
+
|
|
|
+ @Value("${wz.aesDecryptKey}")
|
|
|
+ private String aesDecryptKey;
|
|
|
+
|
|
|
+ private String key="urlFaceCheck";
|
|
|
+ @Autowired
|
|
|
+ private CommonUtil commonUtil;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ StringRedisTemplate stringRedisTemplate;
|
|
|
+ @Autowired
|
|
|
+ SmsActionInterface smsActionInterface;
|
|
|
+ @Autowired
|
|
|
+ ChannelActionInterface channelActionInterface;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ObjectMapper objectMapper;
|
|
|
+ DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ChannelTypeHandleResponseObject callFaceCheck(HttpServletRequest request,
|
|
|
+ String channelId,
|
|
|
+ String ifJkCode,
|
|
|
+ Integer outTime,
|
|
|
+ String customBody) {
|
|
|
+
|
|
|
+ ChannelTypeHandleResponseObject res = new ChannelTypeHandleResponseObject();
|
|
|
+ res.setCode(Constant.SUCCESS);
|
|
|
+ /**默认使用卓望返回码*/
|
|
|
+ if (StringUtils.isBlank(ifJkCode)) {
|
|
|
+ ifJkCode = Constant.CUSTOMER_RETURN_ZW;
|
|
|
+ }
|
|
|
+ /**设置默认超时时间*/
|
|
|
+ if (outTime == null || outTime <= 0) {
|
|
|
+ outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
|
|
|
+ }
|
|
|
+ /**设置日志记录通道请求类型为同步*/
|
|
|
+ request.setAttribute(Constant.CHANNEL_TYPE_KEY, Constant.CHANNEL_TYPE_SYNC);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE);
|
|
|
+ /**设置上游返回码日志记录-默认*/
|
|
|
+ res.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ String hashKey = commonUtil.getKey();
|
|
|
+ boolean flag = checkVisitCount(hashKey,key,yhProperties.getUrlFaceUp(),channelId);
|
|
|
+ if(!flag){
|
|
|
+ countOver(res,ifJkCode);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
+ Gson gson = new Gson();
|
|
|
+ Map map = gson.fromJson(customBody, Map.class);
|
|
|
+ OkHttpClient okHttpClient = client.newBuilder()
|
|
|
+ .connectTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .writeTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .readTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .build();
|
|
|
+ if(StringUtils.isBlank((String)map.get("name"))
|
|
|
+ ||StringUtils.isBlank((String)map.get("idCode"))
|
|
|
+ ||StringUtils.isBlank((String)map.get("photo"))){
|
|
|
+
|
|
|
+ res.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ /**参数错误*/
|
|
|
+ if(Constant.CUSTOMER_RETURN_JK.equals(ifJkCode)){
|
|
|
+ res.setResultCode(Constant.JK_RETURN_CODE_9909);
|
|
|
+ res.setResultBody(Constant.RETURN_MESSAGE_77);
|
|
|
+ res.setResultDesc(Constant.RETURN_MESSAGE_77);
|
|
|
+ }else{
|
|
|
+ res.setResultCode(Constant.ZW_RETURN_CODE_77);
|
|
|
+ res.setResultBody(Constant.RETURN_MESSAGE_77);
|
|
|
+ res.setResultDesc(Constant.RETURN_MESSAGE_77);
|
|
|
+ }
|
|
|
+ reduceVisitCount(hashKey,key);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ /**参数校验*/
|
|
|
+ if(!PatternTools.checkResult(Constant.PATTERN_CN_NAME_REGEX,(String)map.get("name"))){
|
|
|
+ if(Constant.CUSTOMER_RETURN_ZW.equals(ifJkCode)) {
|
|
|
+ res.setResultCode(Constant.NAME_FORMAT_ERROR_CODE);
|
|
|
+ res.setResultDesc(Constant.NAME_FORMAT_ERROR);
|
|
|
+ res.setResultBody(Constant.NAME_FORMAT_ERROR);
|
|
|
+ } else {
|
|
|
+ res.setResultCode(Constant.JK_NAME_FORMAT_ERROR_CODE);
|
|
|
+ res.setResultDesc(Constant.JK_NAME_FORMAT_ERROR);
|
|
|
+ res.setResultBody(Constant.JK_NAME_FORMAT_ERROR);
|
|
|
+ }
|
|
|
+ res.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ reduceVisitCount(hashKey,key);
|
|
|
+ return res;
|
|
|
+ }else if(!PatternTools.checkResult(Constant.PATTERN_SPECIAL_ID_NUMBER_REGEX,(String)map.get("idCode"))){
|
|
|
+ if(Constant.CUSTOMER_RETURN_ZW.equals(ifJkCode)) {
|
|
|
+ res.setResultCode(Constant.IDCODE_FORMAT_ERROR_CODE);
|
|
|
+ res.setResultDesc(Constant.IDCODE_FORMAT_ERROR);
|
|
|
+ res.setResultBody(Constant.IDCODE_FORMAT_ERROR);
|
|
|
+ } else {
|
|
|
+ res.setResultCode(Constant.JK_IDCODE_FORMAT_ERROR_CODE);
|
|
|
+ res.setResultDesc(Constant.JK_IDCODE_FORMAT_ERROR);
|
|
|
+ res.setResultBody(Constant.JK_IDCODE_FORMAT_ERROR);
|
|
|
+ }
|
|
|
+ reduceVisitCount(hashKey,key);
|
|
|
+ res.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ CommonRequestObject commonRequestObject = new CommonRequestObject();
|
|
|
+ commonRequestObject.setUsername(yhProperties.getUsername());
|
|
|
+ commonRequestObject.setApiKey(yhProperties.getApiKeyY000r1());
|
|
|
+ commonRequestObject.setFormat("json");
|
|
|
+ String paramString = "name=" + map.get("name")
|
|
|
+ + "&identityCard=" + map.get("idCode")
|
|
|
+ + "&photo=" + map.get("photo");
|
|
|
+ String encryptParamString = Utils.encrypt(yhProperties.getKey(), paramString);
|
|
|
+ RequestBody requestBody = new FormBody.Builder().add("apiKey", yhProperties.getApiKeyY000r1())
|
|
|
+ .add("username", yhProperties.getUsername())
|
|
|
+ .add("format", "json")
|
|
|
+ .add("params", encryptParamString)
|
|
|
+ .build();
|
|
|
+ Request okRequest = new Request.Builder()
|
|
|
+ .url(yhProperties.getFaceCheckUri())
|
|
|
+ .post(requestBody)
|
|
|
+ .build();
|
|
|
+ Response response = okHttpClient.newCall(okRequest).execute();
|
|
|
+ String responseJson = response.body().string();
|
|
|
+ log.info("--------------->接口返回数据为:{}", responseJson);
|
|
|
+ FaceCheckResObject faceCheckResObject = mapper.readValue(responseJson, FaceCheckResObject.class);
|
|
|
+ /**判断计费状态*/
|
|
|
+ if(!check(faceCheckResObject,res,ifJkCode,channelId)){
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ boolean isCharge = Constant.FACE_RES_CODE_ZERO.equals(faceCheckResObject.getCode())
|
|
|
+ && (Constant.FACE_RES_RESULT_ONE.equals(faceCheckResObject.getData().getResult())
|
|
|
+ || Constant.FACE_RES_RESULT_TWO.equals(faceCheckResObject.getData().getResult())
|
|
|
+ || Constant.FACE_RES_RESULT_THREE.equals(faceCheckResObject.getData().getResult())
|
|
|
+ || Constant.FACE_RES_RESULT_FIVE.equals(faceCheckResObject.getData().getResult())
|
|
|
+ || Constant.FACE_RES_RESULT_TEN.equals(faceCheckResObject.getData().getResult())
|
|
|
+ || Constant.FACE_RES_RESULT_ELEVEN.equals(faceCheckResObject.getData().getResult()));
|
|
|
+ if (isCharge) {
|
|
|
+ res.setIsCharge(Constant.IS_CHARGE);
|
|
|
+ } else {
|
|
|
+ res.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ }
|
|
|
+ /**设置请求状态*/
|
|
|
+ res.setCode(Constant.SUCCESS);
|
|
|
+ switchResultCode(mapper, ifJkCode, faceCheckResObject, res);
|
|
|
+ /**设置上游返回码日志记录*/
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, faceCheckResObject.getCode());
|
|
|
+ } catch (SocketTimeoutException soe) {
|
|
|
+ ErrorUtils.captureException(soe);
|
|
|
+ res.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
+ res.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ return res;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ ErrorUtils.captureException(e);
|
|
|
+ res.setCode(Constant.FAIL);
|
|
|
+ res.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void switchResultCode(ObjectMapper mapper,String ifJkCode,
|
|
|
+ FaceCheckResObject faceCheckResObject, ChannelTypeHandleResponseObject res) throws JsonProcessingException{
|
|
|
+ if (Constant.TELECOM_RES_CODE_ZERO.equals(faceCheckResObject.getCode())) {
|
|
|
+ JSONObject resultBody = new JSONObject();
|
|
|
+ resultBody.put("verificationScore", faceCheckResObject.getData().getVerificationScore());
|
|
|
+ String resultCode = faceCheckResObject.getData().getResult();
|
|
|
+ if (resultCode.equals("1")) {
|
|
|
+ res.setResultCode(Constant.JK_RETURN_CODE_1143);
|
|
|
+ res.setResultDesc(Constant.RETURN_MESSAGE_68);
|
|
|
+ resultBody.put("message", Constant.RETURN_MESSAGE_68);
|
|
|
+ res.setResultBody(JSON.toJSONString(resultBody));
|
|
|
+
|
|
|
+ } else if (resultCode.equals("2")) {
|
|
|
+ res.setResultCode(Constant.JK_RETURN_CODE_1144);
|
|
|
+ res.setResultDesc(Constant.RETURN_MESSAGE_69);
|
|
|
+ resultBody.put("message", Constant.RETURN_MESSAGE_69);
|
|
|
+ res.setResultBody(JSON.toJSONString(resultBody));
|
|
|
+
|
|
|
+ } else if (resultCode.equals("3")) {
|
|
|
+ res.setResultCode(Constant.JK_RETURN_CODE_1145);
|
|
|
+ res.setResultDesc(Constant.RETURN_MESSAGE_70);
|
|
|
+ resultBody.put("message", Constant.RETURN_MESSAGE_70);
|
|
|
+ res.setResultBody(JSON.toJSONString(resultBody));
|
|
|
+
|
|
|
+ } else if (resultCode.equals("5")) {
|
|
|
+ res.setResultCode(Constant.JK_RETURN_CODE_1146);
|
|
|
+ res.setResultDesc(Constant.RETURN_MESSAGE_71);
|
|
|
+ resultBody.put("message", Constant.RETURN_MESSAGE_71);
|
|
|
+ res.setResultBody(JSON.toJSONString(resultBody));
|
|
|
+
|
|
|
+ } else if (resultCode.equals("10")) {
|
|
|
+ res.setResultCode(Constant.JK_RETURN_CODE_1147);
|
|
|
+ res.setResultDesc(Constant.RETURN_MESSAGE_72);
|
|
|
+ resultBody.put("message", Constant.RETURN_MESSAGE_72);
|
|
|
+ res.setResultBody(JSON.toJSONString(resultBody));
|
|
|
+
|
|
|
+ } else if (resultCode.equals("11")) {
|
|
|
+ res.setResultCode(Constant.JK_RETURN_CODE_1148);
|
|
|
+ res.setResultDesc(Constant.RETURN_MESSAGE_73);
|
|
|
+ resultBody.put("message", Constant.RETURN_MESSAGE_73);
|
|
|
+ res.setResultBody(JSON.toJSONString(resultBody));
|
|
|
+
|
|
|
+ } else if (resultCode.equals("7")) {
|
|
|
+ res.setResultCode(Constant.JK_RETURN_CODE_1149);
|
|
|
+ res.setResultDesc(Constant.RETURN_MESSAGE_74);
|
|
|
+ resultBody.put("message", Constant.RETURN_MESSAGE_74);
|
|
|
+ res.setResultBody(JSON.toJSONString(resultBody));
|
|
|
+
|
|
|
+ } else if (resultCode.equals("6")) {
|
|
|
+ res.setResultCode(Constant.JK_RETURN_CODE_NO_INFO);
|
|
|
+ res.setResultBody(Constant.UN_FIND_NUM);
|
|
|
+ res.setResultDesc(Constant.UN_FIND_NUM);
|
|
|
+
|
|
|
+ } else if (resultCode.equals("9")) {
|
|
|
+ res.setResultCode(Constant.JK_NAME_FORMAT_ERROR_CODE);
|
|
|
+ res.setResultDesc(Constant.JK_NAME_FORMAT_ERROR);
|
|
|
+ res.setResultBody(Constant.JK_NAME_FORMAT_ERROR);
|
|
|
+
|
|
|
+ } else if (resultCode.equals("8")) {
|
|
|
+ res.setResultCode(Constant.JK_IDCODE_FORMAT_ERROR_CODE);
|
|
|
+ res.setResultDesc(Constant.JK_IDCODE_FORMAT_ERROR);
|
|
|
+ res.setResultBody(Constant.JK_IDCODE_FORMAT_ERROR);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ res.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR);
|
|
|
+ res.setResultBody(Constant.OTHER_ERROR);
|
|
|
+ res.setResultDesc(Constant.OTHER_ERROR);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (faceCheckResObject.getCode().equals("200")) {
|
|
|
+ res.setResultCode(Constant.JK_RETURN_CODE_NO_INFO);
|
|
|
+ res.setResultBody(Constant.UN_FIND_NUM);
|
|
|
+ res.setResultDesc(Constant.UN_FIND_NUM);
|
|
|
+ } else {
|
|
|
+ res.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR);
|
|
|
+ res.setResultBody(Constant.OTHER_ERROR);
|
|
|
+ res.setResultDesc(Constant.OTHER_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ifJkCode.equals(Constant.CUSTOMER_RETURN_ZW)) {
|
|
|
+ switch (res.getResultCode()) {
|
|
|
+ case Constant.JK_RETURN_CODE_1143 :
|
|
|
+ res.setResultCode(Constant.ZW_RETURN_CODE_68);
|
|
|
+ break;
|
|
|
+ case Constant.JK_RETURN_CODE_1144 :
|
|
|
+ res.setResultCode(Constant.ZW_RETURN_CODE_69);
|
|
|
+ break;
|
|
|
+ case Constant.JK_RETURN_CODE_1145 :
|
|
|
+ res.setResultCode(Constant.ZW_RETURN_CODE_70);
|
|
|
+ break;
|
|
|
+ case Constant.JK_RETURN_CODE_1146 :
|
|
|
+ res.setResultCode(Constant.ZW_RETURN_CODE_71);
|
|
|
+ break;
|
|
|
+ case Constant.JK_RETURN_CODE_1147 :
|
|
|
+ res.setResultCode(Constant.ZW_RETURN_CODE_72);
|
|
|
+ break;
|
|
|
+ case Constant.JK_RETURN_CODE_1148 :
|
|
|
+ res.setResultCode(Constant.ZW_RETURN_CODE_73);
|
|
|
+ break;
|
|
|
+ case Constant.JK_RETURN_CODE_1149 :
|
|
|
+ res.setResultCode(Constant.ZW_RETURN_CODE_74);
|
|
|
+ break;
|
|
|
+ case Constant.JK_RETURN_CODE_NO_INFO :
|
|
|
+ res.setResultCode(Constant.UN_FIND_NUM_CODE);
|
|
|
+ break;
|
|
|
+ case Constant.JK_NAME_FORMAT_ERROR_CODE :
|
|
|
+ res.setResultCode(Constant.NAME_FORMAT_ERROR_CODE);
|
|
|
+ break;
|
|
|
+ case Constant.JK_IDCODE_FORMAT_ERROR_CODE :
|
|
|
+ res.setResultCode(Constant.IDCODE_FORMAT_ERROR_CODE);
|
|
|
+ break;
|
|
|
+ case Constant.JK_RETURN_CODE_OTHER_ERROR :
|
|
|
+ res.setResultCode(Constant.OTHER_ERROR_CODE);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ChannelTypeHandleResponseObject faceCheckWZDecode(HttpServletRequest request, String channelId, String ifJkCode,
|
|
|
+ Integer outTime, String customBody) {
|
|
|
+ ChannelTypeHandleResponseObject res = new ChannelTypeHandleResponseObject();
|
|
|
+ String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
|
|
|
+
|
|
|
+ /**默认使用卓望返回码*/
|
|
|
+ if (StringUtils.isBlank(ifJkCode)) {
|
|
|
+ ifJkCode = Constant.CUSTOMER_RETURN_ZW;
|
|
|
+ }
|
|
|
+ /**设置默认超时时间*/
|
|
|
+ if (outTime == null || outTime <= 0) {
|
|
|
+ outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
|
|
|
+ }
|
|
|
+ /**设置日志记录通道请求类型为同步*/
|
|
|
+ request.setAttribute(Constant.CHANNEL_TYPE_KEY, Constant.CHANNEL_TYPE_SYNC);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE);
|
|
|
+ /**设置上游返回码日志记录-默认*/
|
|
|
+ res.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ res.setCode(Constant.SUCCESS);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ try {
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ String ymd = dateTimeFormatter.format(now);
|
|
|
+ String hashKey = commonUtil.getKey();
|
|
|
+ boolean flag = checkVisitCount(hashKey,key,yhProperties.getUrlFaceUp(),channelId);
|
|
|
+ if(!flag){
|
|
|
+ countOver(res,ifJkCode);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ customBody = DecodeUtil.decodeParams(res, ifJkCode, customBody);
|
|
|
+ if (StringUtils.isBlank(customBody)) {
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ reduceVisitCount(hashKey,key);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ Gson gson = new Gson();
|
|
|
+ Map map = gson.fromJson(customBody, Map.class);
|
|
|
+ gson = null;
|
|
|
+ JSONObject paramObject = JSON.parseObject(customBody);
|
|
|
+ paramObject.put("photo", "base64");
|
|
|
+ log.info("supplier10000003.faceCheckWZDecode---customBody={},outTime={}", paramObject.toJSONString(), outTime);
|
|
|
+ request.setAttribute(Constant.CHANNEL_LOG_QUERY,
|
|
|
+ Base64.encodeBase64String(paramObject.toJSONString().getBytes("utf-8")));
|
|
|
+
|
|
|
+ OkHttpClient okHttpClient = client.newBuilder()
|
|
|
+ .connectTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .writeTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .readTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .build();
|
|
|
+ if(StringUtils.isBlank((String)map.get("name"))
|
|
|
+ ||StringUtils.isBlank((String)map.get("idCode"))
|
|
|
+ ||StringUtils.isBlank((String)map.get("photo"))){
|
|
|
+ res.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ /**参数错误*/
|
|
|
+ if(Constant.CUSTOMER_RETURN_JK.equals(ifJkCode)){
|
|
|
+ res.setResultCode(Constant.JK_RETURN_CODE_9909);
|
|
|
+ res.setResultBody(Constant.RETURN_MESSAGE_77);
|
|
|
+ res.setResultDesc(Constant.RETURN_MESSAGE_77);
|
|
|
+ }else{
|
|
|
+ res.setResultCode(Constant.ZW_RETURN_CODE_77);
|
|
|
+ res.setResultBody(Constant.RETURN_MESSAGE_77);
|
|
|
+ res.setResultDesc(Constant.RETURN_MESSAGE_77);
|
|
|
+ }
|
|
|
+ reduceVisitCount(hashKey,key);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ /**参数校验*/
|
|
|
+ if(!PatternTools.checkResult(4,(String)map.get("name"))){
|
|
|
+ if(Constant.CUSTOMER_RETURN_ZW.equals(ifJkCode)) {
|
|
|
+ res.setResultCode(Constant.NAME_FORMAT_ERROR_CODE);
|
|
|
+ res.setResultDesc(Constant.NAME_FORMAT_ERROR);
|
|
|
+ res.setResultBody(Constant.NAME_FORMAT_ERROR);
|
|
|
+ } else {
|
|
|
+ res.setResultCode(Constant.JK_NAME_FORMAT_ERROR_CODE);
|
|
|
+ res.setResultDesc(Constant.JK_NAME_FORMAT_ERROR);
|
|
|
+ res.setResultBody(Constant.JK_NAME_FORMAT_ERROR);
|
|
|
+ }
|
|
|
+ reduceVisitCount(hashKey,key);
|
|
|
+ res.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ return res;
|
|
|
+ }else if(!PatternTools.checkResult(Constant.PATTERN_SPECIAL_ID_NUMBER_REGEX,(String)map.get("idCode"))){
|
|
|
+ if(Constant.CUSTOMER_RETURN_ZW.equals(ifJkCode)) {
|
|
|
+ res.setResultCode(Constant.IDCODE_FORMAT_ERROR_CODE);
|
|
|
+ res.setResultDesc(Constant.IDCODE_FORMAT_ERROR);
|
|
|
+ res.setResultBody(Constant.IDCODE_FORMAT_ERROR);
|
|
|
+ } else {
|
|
|
+ res.setResultCode(Constant.JK_IDCODE_FORMAT_ERROR_CODE);
|
|
|
+ res.setResultDesc(Constant.JK_IDCODE_FORMAT_ERROR);
|
|
|
+ res.setResultBody(Constant.JK_IDCODE_FORMAT_ERROR);
|
|
|
+ }
|
|
|
+ reduceVisitCount(hashKey,key);
|
|
|
+ res.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ CommonRequestObject commonRequestObject = new CommonRequestObject();
|
|
|
+ commonRequestObject.setUsername(yhProperties.getUsername());
|
|
|
+ commonRequestObject.setApiKey(yhProperties.getApiKeyY000r1());
|
|
|
+ commonRequestObject.setFormat("json");
|
|
|
+ String paramString = "name=" + map.get("name")
|
|
|
+ + "&identityCard=" + map.get("idCode")
|
|
|
+ + "&photo=" + map.get("photo");
|
|
|
+ String encryptParamString = Utils.encrypt(yhProperties.getKey(), paramString);
|
|
|
+ RequestBody requestBody = new FormBody.Builder().add("apiKey", yhProperties.getApiKeyY000r1())
|
|
|
+ .add("username", yhProperties.getUsername())
|
|
|
+ .add("format", "json")
|
|
|
+ .add("params", encryptParamString)
|
|
|
+ .build();
|
|
|
+ Request okRequest = new Request.Builder()
|
|
|
+ .url(yhProperties.getFaceCheckUri())
|
|
|
+ .post(requestBody)
|
|
|
+ .build();
|
|
|
+ Response response = okHttpClient.newCall(okRequest).execute();
|
|
|
+ String responseJson = response.body().string();
|
|
|
+
|
|
|
+ map = null;
|
|
|
+ log.info("--------------->接口返回数据为:{}", responseJson);
|
|
|
+ FaceCheckResObject faceCheckResObject = JSONObject.toJavaObject(JSON.parseObject(responseJson), FaceCheckResObject.class);
|
|
|
+
|
|
|
+ if(!check(faceCheckResObject,res,ifJkCode,channelId)){
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ /**判断计费状态*/
|
|
|
+ boolean isCharge = Constant.FACE_RES_CODE_ZERO.equals(faceCheckResObject.getCode())
|
|
|
+ && (Constant.FACE_RES_RESULT_ONE.equals(faceCheckResObject.getData().getResult())
|
|
|
+ || Constant.FACE_RES_RESULT_TWO.equals(faceCheckResObject.getData().getResult())
|
|
|
+ || Constant.FACE_RES_RESULT_THREE.equals(faceCheckResObject.getData().getResult())
|
|
|
+ || Constant.FACE_RES_RESULT_FIVE.equals(faceCheckResObject.getData().getResult())
|
|
|
+ || Constant.FACE_RES_RESULT_TEN.equals(faceCheckResObject.getData().getResult())
|
|
|
+ || Constant.FACE_RES_RESULT_ELEVEN.equals(faceCheckResObject.getData().getResult()));
|
|
|
+ if (isCharge) {
|
|
|
+ res.setIsCharge(Constant.IS_CHARGE);
|
|
|
+ } else {
|
|
|
+ res.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ }
|
|
|
+ /**设置请求状态*/
|
|
|
+ res.setCode(Constant.SUCCESS);
|
|
|
+ switchResultCode(null, ifJkCode, faceCheckResObject, res);
|
|
|
+
|
|
|
+ /**设置上游返回码日志记录*/
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, faceCheckResObject.getCode());
|
|
|
+ } catch (SocketTimeoutException soe) {
|
|
|
+ ErrorUtils.captureException(soe);
|
|
|
+ res.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
+ res.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ return res;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ ErrorUtils.captureException(e);
|
|
|
+ res.setCode(Constant.FAIL);
|
|
|
+ res.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ public boolean checkVisitCount(String hashKey,String key,long upCount,String channelId){
|
|
|
+ //查看是否有超过权限的标志
|
|
|
+ /*Map map =SjjhConstant.hashMap.get(hashKey);
|
|
|
+ if(map!=null&&map.get(key+SjjhConstant.key_subStr)!=null && map.get(key+SjjhConstant.key_subStr).equals(Boolean.TRUE)){
|
|
|
+ return false;
|
|
|
+ }*/
|
|
|
+
|
|
|
+ String countStr = (String)stringRedisTemplate.boundHashOps(hashKey).get(key);
|
|
|
+ log.info("countStr:{}",countStr);
|
|
|
+ if(countStr!=null && Long.parseLong(countStr)>=upCount){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if(stringRedisTemplate.boundHashOps(hashKey).hasKey(key+SjjhConstant.key_subStr)){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ long visitCount = stringRedisTemplate.boundHashOps(hashKey).increment(key,1);
|
|
|
+ if(visitCount==1){
|
|
|
+ stringRedisTemplate.boundValueOps(hashKey).expire(1, TimeUnit.DAYS);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(upCount-visitCount==yhProperties.getNotityLimit()){
|
|
|
+ //起一个线程,处理此逻辑
|
|
|
+ testNotify(channelId,1);
|
|
|
+ }
|
|
|
+ if(upCount-visitCount==0){
|
|
|
+ //起一个线程,处理此逻辑,
|
|
|
+ testNotify(channelId,2);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(visitCount>upCount){
|
|
|
+ reduceVisitCount(hashKey,key);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ public void countOver(ChannelTypeHandleResponseObject ret,String ifJkCode){
|
|
|
+ if(Constant.CUSTOMER_RETURN_ZW.equals(ifJkCode)) {
|
|
|
+ ret.setResultCode(Constant.OTHER_ERROR_CODE);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR);
|
|
|
+
|
|
|
+ }
|
|
|
+ ret.setCode(Constant.REQUEST_LIMIT);
|
|
|
+ }
|
|
|
+ public void reduceVisitCount(String hashKey,String key){
|
|
|
+ long visitCount = stringRedisTemplate.boundHashOps(hashKey).increment(key,-1);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean check(FaceCheckResObject faceCheckResObject,ChannelTypeHandleResponseObject ret,String ifJkCode,String channelId){
|
|
|
+ if("210".equals(faceCheckResObject.getCode())){
|
|
|
+ int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
|
|
|
+ ret.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
+ if(hour>=yhProperties.getHour()){
|
|
|
+ String hashKey = commonUtil.getKey();
|
|
|
+ String keySign=key+SjjhConstant.key_subStr;
|
|
|
+ boolean flag = stringRedisTemplate.boundHashOps(hashKey).putIfAbsent(keySign,"1");
|
|
|
+ log.info("key:{},flag:{}",keySign,flag);
|
|
|
+ ret.setCode(Constant.REQUEST_LIMIT);
|
|
|
+ if(flag){
|
|
|
+ testNotify(channelId,3);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(Constant.CUSTOMER_RETURN_ZW.equals(ifJkCode)) {
|
|
|
+ ret.setResultCode(Constant.OTHER_ERROR_CODE);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR);
|
|
|
+
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testNotify(String channelId,int type){
|
|
|
+ String traceId= tracer.currentSpan().context().traceIdString();
|
|
|
+ NotifySms notifySms =new NotifySms();
|
|
|
+ notifySms.setSupplierProperties(yhProperties);
|
|
|
+ notifySms.setSmsActionInterface(smsActionInterface);
|
|
|
+ notifySms.setChannelActionInterface(channelActionInterface);
|
|
|
+ notifySms.setChannId(channelId);
|
|
|
+ notifySms.setTraceId(traceId);
|
|
|
+ notifySms.setType(type);
|
|
|
+ notifySms.setCount(0);
|
|
|
+ Timer timer =new Timer();
|
|
|
+ log.info("test..................,notify:{},traceId:{}",notifySms);
|
|
|
+ timer.schedule(new NotifyThread(notifySms),1*60*1000);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|