Authored by qinchao

认证

@@ -7,6 +7,7 @@ import com.yoho.service.model.reviewed.request.ImageBO; @@ -7,6 +7,7 @@ import com.yoho.service.model.reviewed.request.ImageBO;
7 import com.yoho.service.model.reviewed.request.ImageReviewedReq; 7 import com.yoho.service.model.reviewed.request.ImageReviewedReq;
8 import com.yoho.service.model.reviewed.response.ImageReviewResp; 8 import com.yoho.service.model.reviewed.response.ImageReviewResp;
9 import com.yoho.service.model.sms.response.CommonRspBO; 9 import com.yoho.service.model.sms.response.CommonRspBO;
  10 +import com.yoho.tools.common.beans.Response;
10 import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO; 11 import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
11 import org.apache.commons.collections.CollectionUtils; 12 import org.apache.commons.collections.CollectionUtils;
12 import org.apache.commons.lang3.StringUtils; 13 import org.apache.commons.lang3.StringUtils;
@@ -14,6 +15,10 @@ import org.slf4j.Logger; @@ -14,6 +15,10 @@ import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory; 15 import org.slf4j.LoggerFactory;
15 import org.springframework.beans.factory.annotation.Autowired; 16 import org.springframework.beans.factory.annotation.Autowired;
16 import org.springframework.beans.factory.annotation.Value; 17 import org.springframework.beans.factory.annotation.Value;
  18 +import org.springframework.core.ParameterizedTypeReference;
  19 +import org.springframework.http.HttpEntity;
  20 +import org.springframework.http.HttpMethod;
  21 +import org.springframework.http.ResponseEntity;
17 import org.springframework.stereotype.Service; 22 import org.springframework.stereotype.Service;
18 import org.springframework.web.client.RestTemplate; 23 import org.springframework.web.client.RestTemplate;
19 24
@@ -36,8 +41,8 @@ public class OcrCertPhotoService { @@ -36,8 +41,8 @@ public class OcrCertPhotoService {
36 @Value("${yoho.reviewed.controller.url}") 41 @Value("${yoho.reviewed.controller.url}")
37 private String messageUrl; 42 private String messageUrl;
38 43
39 - public ImageReviewResp ocrCheck(RealNameAuthorizeReqVO reqVO , List<ImageBO> imageBOList) {  
40 - ImageReviewResp respVo = null; 44 + public Response<ImageReviewResp> ocrCheck(RealNameAuthorizeReqVO reqVO , List<ImageBO> imageBOList) {
  45 + Response<ImageReviewResp> respVo = null;
41 try{ 46 try{
42 int uid= reqVO.getUid(); 47 int uid= reqVO.getUid();
43 ImageReviewedReq req=new ImageReviewedReq(); 48 ImageReviewedReq req=new ImageReviewedReq();
@@ -52,7 +57,14 @@ public class OcrCertPhotoService { @@ -52,7 +57,14 @@ public class OcrCertPhotoService {
52 57
53 String url = messageUrl + "/imageAudit/imageAudit"; 58 String url = messageUrl + "/imageAudit/imageAudit";
54 logger.info("sendMessage url is {}", url); 59 logger.info("sendMessage url is {}", url);
55 - respVo=restTemplate.postForObject(url, req, ImageReviewResp.class); 60 + //respVo=restTemplate.postForObject(url, req, Response.class);
  61 +
  62 + ParameterizedTypeReference<Response<ImageReviewResp>> typeRef = new ParameterizedTypeReference<Response<ImageReviewResp>>() {};
  63 + HttpEntity httpEntity = new HttpEntity(req);
  64 + ResponseEntity<Response<ImageReviewResp>> responseEntity = restTemplate.exchange(url, HttpMethod.POST,httpEntity, typeRef);
  65 + respVo = responseEntity.getBody();
  66 +
  67 +
56 }catch (Exception e){ 68 }catch (Exception e){
57 logger.warn("OcrCertPhotoService ocrCheck error ",e); 69 logger.warn("OcrCertPhotoService ocrCheck error ",e);
58 } 70 }
@@ -21,6 +21,7 @@ import com.yoho.service.model.reviewed.request.ImageReviewedReq; @@ -21,6 +21,7 @@ import com.yoho.service.model.reviewed.request.ImageReviewedReq;
21 import com.yoho.service.model.reviewed.response.IdCardRspBO; 21 import com.yoho.service.model.reviewed.response.IdCardRspBO;
22 import com.yoho.service.model.reviewed.response.ImageReviewResp; 22 import com.yoho.service.model.reviewed.response.ImageReviewResp;
23 import com.yoho.tools.common.beans.ApiResponse; 23 import com.yoho.tools.common.beans.ApiResponse;
  24 +import com.yoho.tools.common.beans.Response;
24 import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO; 25 import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
25 import com.yohoufo.common.constant.CertPhotoEnum; 26 import com.yohoufo.common.constant.CertPhotoEnum;
26 import com.yohoufo.common.exception.GatewayException; 27 import com.yohoufo.common.exception.GatewayException;
@@ -417,17 +418,22 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { @@ -417,17 +418,22 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
417 long num = cacheService.incrementPhotoCheckCount(dayStr,reqVO.getUid()); 418 long num = cacheService.incrementPhotoCheckCount(dayStr,reqVO.getUid());
418 logger.info("checkCertPhoto call begin reqVO {} ,call redis count {}",reqVO, num); 419 logger.info("checkCertPhoto call begin reqVO {} ,call redis count {}",reqVO, num);
419 420
420 - ImageReviewResp resp =ocrCertPhotoService.ocrCheck(reqVO,imageBOList);  
421 - logger.info("checkCertPhoto call end reqVO {} ,resp {} ",reqVO,JSON.toJSONString(resp)); 421 + Response<ImageReviewResp> imageReviewRespResponse =ocrCertPhotoService.ocrCheck(reqVO,imageBOList);
  422 + logger.info("checkCertPhoto call end reqVO {} ,resp {} ",reqVO,JSON.toJSONString(imageReviewRespResponse));
422 423
423 - if(resp==null||!"success".equals(resp.getResultCode())){  
424 - result.setMessage("验证失败,您上传的证件照片信息不正确"); 424 + if(imageReviewRespResponse==null||imageReviewRespResponse.getCode()!=200){
  425 + result.setMessage("验证图片异常,请重试!");
425 }else{ 426 }else{
  427 + ImageReviewResp reviewResp = imageReviewRespResponse.getData();
  428 + if(reviewResp==null||!"success".equals(reviewResp.getResultCode())){
  429 + throw new UfoServiceException(400, "您上传的证件照片信息不正确,请重新上传!");
  430 + }
  431 +
426 //比较信息 432 //比较信息
427 - JSONObject jo = JSON.parseObject(resp.getResultDatas()); 433 + JSONObject jo = JSON.parseObject(reviewResp.getResultDatas());
428 if(jo!=null&&jo.containsKey("front")&&jo.containsKey("back")){ 434 if(jo!=null&&jo.containsKey("front")&&jo.containsKey("back")){
429 - IdCardRspBO front = jo.getObject("front",IdCardRspBO.class);  
430 - IdCardRspBO back = jo.getObject("back",IdCardRspBO.class); 435 + IdCardRspBO front = JSON.parseObject(jo.getJSONObject("front").getString("resultData"),IdCardRspBO.class);
  436 + IdCardRspBO back = JSON.parseObject(jo.getJSONObject("back").getString("resultData"),IdCardRspBO.class);
431 if(front!=null&&back!=null){ 437 if(front!=null&&back!=null){
432 logger.info("checkCertPhoto front {} ,back {}",front,back); 438 logger.info("checkCertPhoto front {} ,back {}",front,back);
433 String endData = back.getEndDate(); 439 String endData = back.getEndDate();
@@ -435,9 +441,9 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { @@ -435,9 +441,9 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
435 throw new UfoServiceException(400, "身份证照片有效期不合法!"); 441 throw new UfoServiceException(400, "身份证照片有效期不合法!");
436 } 442 }
437 endData = endData.trim(); 443 endData = endData.trim();
438 - if(!"长期".equals(endData)){ 444 + if(!endData.contains("长期")){
439 //转日期 445 //转日期
440 - Date end = DateUtil.getDate(endData,"yyyy.MM.dd"); 446 + Date end = DateUtil.getDate(endData,"yyyyMMdd");
441 if(end==null||end.getTime() <= new Date().getTime()){ 447 if(end==null||end.getTime() <= new Date().getTime()){
442 throw new UfoServiceException(400, "身份证照片不在有效期!"); 448 throw new UfoServiceException(400, "身份证照片不在有效期!");
443 } 449 }
@@ -446,6 +452,10 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { @@ -446,6 +452,10 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
446 ||!reqVO.getCertNo().equals(front.getCode())){ 452 ||!reqVO.getCertNo().equals(front.getCode())){
447 throw new UfoServiceException(400, "名字或者身份证号不匹配!"); 453 throw new UfoServiceException(400, "名字或者身份证号不匹配!");
448 } 454 }
  455 +
  456 + //验证成功
  457 + result.setPass(CertPhotoEnum.valid.isCheckPass());
  458 + result.setPhotoValidStatus(CertPhotoEnum.valid.getStatus());
449 } 459 }
450 } 460 }
451 461