Authored by DengXinFei

支付宝刷脸认证

@@ -39,14 +39,17 @@ public class CertificationController { @@ -39,14 +39,17 @@ public class CertificationController {
39 public ApiResponse alipayCertification(RealNameAuthorizeReqVO reqVO) throws GatewayException { 39 public ApiResponse alipayCertification(RealNameAuthorizeReqVO reqVO) throws GatewayException {
40 logger.info("CertificationController.alipayCertification: Enter alipayCertification param reqVO is {}", reqVO); 40 logger.info("CertificationController.alipayCertification: Enter alipayCertification param reqVO is {}", reqVO);
41 //(1) 必要参数的校验 41 //(1) 必要参数的校验
42 - if (reqVO == null || reqVO.getUid()<=0){ 42 + if(reqVO == null || reqVO.getUid() <= 0){
43 throw new GatewayException(400, "uid不能为空!"); 43 throw new GatewayException(400, "uid不能为空!");
44 } 44 }
45 - if ( StringUtils.isEmpty(reqVO.getCertNo())|| StringUtils.isEmpty(reqVO.getCertName())){ 45 + if(StringUtils.isEmpty(reqVO.getCertNo()) || StringUtils.isEmpty(reqVO.getCertName())){
46 logger.warn("alipayCertification: certNO or cert name can not be empty. uid is {}, certNO is {}, certName is {}", reqVO.getUid(), reqVO.getCertNo(), reqVO.getCertName()); 46 logger.warn("alipayCertification: certNO or cert name can not be empty. uid is {}, certNO is {}, certName is {}", reqVO.getUid(), reqVO.getCertNo(), reqVO.getCertName());
47 throw new GatewayException(400, "身份证号、姓名不能为空!"); 47 throw new GatewayException(400, "身份证号、姓名不能为空!");
48 } 48 }
49 49
  50 + //(2)
  51 +
  52 +
50 //(2)获取认证记录,判断是否已经认证。 53 //(2)获取认证记录,判断是否已经认证。
51 54
52 55
@@ -2,6 +2,7 @@ package com.yohoufo.user.service; @@ -2,6 +2,7 @@ package com.yohoufo.user.service;
2 2
3 import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO; 3 import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
4 import com.yohoufo.dal.user.model.ZhiMaCert; 4 import com.yohoufo.dal.user.model.ZhiMaCert;
  5 +import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
5 6
6 /** 7 /**
7 * 实名认证服务 8 * 实名认证服务
@@ -17,8 +18,8 @@ public interface ICertificationService { @@ -17,8 +18,8 @@ public interface ICertificationService {
17 /** 18 /**
18 * 开始实名认证(图片OCR识别 + 支付宝实名认证) 19 * 开始实名认证(图片OCR识别 + 支付宝实名认证)
19 * 20 *
20 - * @param uid 用户UID 21 + * @param realNameAuthorizeReqVO 实名认证用户信息(包含身份证照片,姓名,身份证号码)
21 * @return 认证结果 22 * @return 认证结果
22 */ 23 */
23 - AuthorizeResultRespVO beginCertificate(int uid); 24 + AuthorizeResultRespVO beginCertificate(RealNameAuthorizeReqVO realNameAuthorizeReqVO);
24 } 25 }
@@ -2,8 +2,10 @@ package com.yohoufo.user.service.impl; @@ -2,8 +2,10 @@ package com.yohoufo.user.service.impl;
2 2
3 import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO; 3 import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
4 import com.yohoufo.common.constant.CertPhotoEnum; 4 import com.yohoufo.common.constant.CertPhotoEnum;
  5 +import com.yohoufo.common.exception.UfoServiceException;
5 import com.yohoufo.dal.user.IZhiMaCertDao; 6 import com.yohoufo.dal.user.IZhiMaCertDao;
6 import com.yohoufo.dal.user.model.ZhiMaCert; 7 import com.yohoufo.dal.user.model.ZhiMaCert;
  8 +import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
7 import com.yohoufo.user.service.ICertificationService; 9 import com.yohoufo.user.service.ICertificationService;
8 import org.slf4j.Logger; 10 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory; 11 import org.slf4j.LoggerFactory;
@@ -28,19 +30,41 @@ public class CertificationServiceImpl implements ICertificationService { @@ -28,19 +30,41 @@ public class CertificationServiceImpl implements ICertificationService {
28 private IZhiMaCertDao zhiMaCertDao; 30 private IZhiMaCertDao zhiMaCertDao;
29 31
30 @Override 32 @Override
31 - public AuthorizeResultRespVO beginCertificate(int uid) {  
32 - logger.info("getValidCertificationRecord: Begin select valid certification record. uid is {}", uid); 33 + public AuthorizeResultRespVO beginCertificate(RealNameAuthorizeReqVO reqVO) {
  34 + logger.info("beginCertificate: Begin select valid certification record. reqVO is {}", reqVO);
33 35
34 - //(1) 直接查询当前UID实名认证的记录 36 + //(1)直接查询当前UID实名认证的记录
  37 + int uid = reqVO.getUid();
35 ZhiMaCert zhiMaCert = zhiMaCertDao.selectLatestCertificateByUid(uid); 38 ZhiMaCert zhiMaCert = zhiMaCertDao.selectLatestCertificateByUid(uid);
  39 + logger.info("beginCertificate: get user certification history by uid. uid is {}, zhiMaCert is {}", uid, zhiMaCert);
36 40
37 //(2)是否已经认证通过,认证通过的直接返回 41 //(2)是否已经认证通过,认证通过的直接返回
  42 + if(null != zhiMaCert && CertPhotoEnum.isValidStatus(zhiMaCert.getValidPhoto()) && 1 == zhiMaCert.getValidStatus()){
  43 + logger.info("beginCertificate: user has certification already. uid is {}", uid);
  44 + throw new UfoServiceException(400, "已实名认证!");
  45 + }
  46 +
  47 + //(3)如果客户端传入的身份信息是隐位信息,那么将身份信息进行补全。
  48 + if(null != zhiMaCert && (reqVO.getCertName().contains("*") || reqVO.getCertNo().contains("*"))){
  49 + reqVO.setCertName(zhiMaCert.getCertName());
  50 + reqVO.setCertNo(zhiMaCert.getCertNo());
  51 + logger.info("beginCertificate:zhiMaCertWithPhotoCheckInit reset mask ,zhiMaCert {} ,new reqVO is {}", zhiMaCert ,reqVO);
  52 + }
38 53
  54 + //(4) 判断用户新传入的身份信息,是否与历史认证一致,如果不一致,需要重新进行OCR识别+支付宝刷脸认证。
  55 + if(null != zhiMaCert && (!reqVO.getCertName().equals(zhiMaCert.getCertName()) || !reqVO.getCertNo().equals(zhiMaCert.getCertNo()))){
  56 + logger.info("beginCertificate: request cert info not matched in db. reqVO is {}, zhiMaCert is {}", reqVO, zhiMaCert);
  57 + zhiMaCert = null;
  58 + }
39 59
40 //----------------------以下是需要实名认证(身份证OCR识别 + 支付宝刷脸认证)------------------------------- 60 //----------------------以下是需要实名认证(身份证OCR识别 + 支付宝刷脸认证)-------------------------------
41 //(3)身份证OCR识别(已经识别过将不会继续识别) 61 //(3)身份证OCR识别(已经识别过将不会继续识别)
42 if(null == zhiMaCert || !CertPhotoEnum.isValidStatus(zhiMaCert.getValidPhoto())){ 62 if(null == zhiMaCert || !CertPhotoEnum.isValidStatus(zhiMaCert.getValidPhoto())){
43 //身份证识别 63 //身份证识别
  64 +
  65 +
  66 +
  67 +
44 } 68 }
45 69
46 //(4)支付宝实名认证(如果已经认证过了,将不会继续认证) 70 //(4)支付宝实名认证(如果已经认证过了,将不会继续认证)
@@ -51,4 +75,7 @@ public class CertificationServiceImpl implements ICertificationService { @@ -51,4 +75,7 @@ public class CertificationServiceImpl implements ICertificationService {
51 75
52 return null; 76 return null;
53 } 77 }
  78 +
  79 +
  80 +
54 } 81 }
@@ -5,6 +5,13 @@ import com.yoho.service.model.reviewed.request.ImageBO; @@ -5,6 +5,13 @@ import com.yoho.service.model.reviewed.request.ImageBO;
5 import com.yoho.service.model.reviewed.request.ImageReviewedReq; 5 import com.yoho.service.model.reviewed.request.ImageReviewedReq;
6 import com.yoho.service.model.reviewed.response.ImageReviewResp; 6 import com.yoho.service.model.reviewed.response.ImageReviewResp;
7 import com.yoho.tools.common.beans.Response; 7 import com.yoho.tools.common.beans.Response;
  8 +import com.yohoufo.common.constant.CertPhotoEnum;
  9 +import com.yohoufo.common.exception.GatewayException;
  10 +import com.yohoufo.dal.user.model.ZhiMaCert;
  11 +import com.yohoufo.user.component.CertPhotoSwitchComponent;
  12 +import com.yohoufo.user.requestVO.PhotoCheckResultVO;
  13 +import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
  14 +import org.apache.commons.lang3.StringUtils;
8 import org.slf4j.Logger; 15 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory; 16 import org.slf4j.LoggerFactory;
10 import org.springframework.beans.factory.annotation.Autowired; 17 import org.springframework.beans.factory.annotation.Autowired;
@@ -19,9 +26,12 @@ import org.springframework.util.LinkedMultiValueMap; @@ -19,9 +26,12 @@ import org.springframework.util.LinkedMultiValueMap;
19 import org.springframework.util.MultiValueMap; 26 import org.springframework.util.MultiValueMap;
20 import org.springframework.web.client.RestTemplate; 27 import org.springframework.web.client.RestTemplate;
21 28
  29 +import java.util.ArrayList;
22 import java.util.List; 30 import java.util.List;
23 31
24 /** 32 /**
  33 + * 进行身份证识别服务(识别身份证信息+身份证信息校验)
  34 + *
25 * Created by craig.qin on 2018/10/19. 35 * Created by craig.qin on 2018/10/19.
26 * 身份证图片的ocr 36 * 身份证图片的ocr
27 */ 37 */
@@ -32,12 +42,75 @@ public class OcrCertPhotoService { @@ -32,12 +42,75 @@ public class OcrCertPhotoService {
32 @Autowired 42 @Autowired
33 private RestTemplate restTemplate; 43 private RestTemplate restTemplate;
34 44
  45 + @Autowired
  46 + private CertPhotoSwitchComponent certPhotoSwitchComponent;
  47 +
  48 + @Autowired
  49 + private OcrCertPhotoService ocrCertPhotoService;
  50 +
  51 + private final String YOHO_IDCARD_PRE = "http://yhgidcard.static.yhbimg.com/yohocard";
  52 +
35 @Value("${web.context}") 53 @Value("${web.context}")
36 private String contextPath; 54 private String contextPath;
37 55
38 @Value("${yoho.reviewed.controller.url}") 56 @Value("${yoho.reviewed.controller.url}")
39 private String messageUrl; 57 private String messageUrl;
40 58
  59 + /**
  60 + * 实名认证中的身份证识别认证(OCR身份证识别)
  61 + *
  62 + * @param reqVO 上传的身份证图片 + 用户姓名以及身份证号码
  63 + * @param zhiMaCert 已经认证的记录。
  64 + * @return
  65 + * @throws GatewayException
  66 + */
  67 + public PhotoCheckResultVO IDOCRIdentification(RealNameAuthorizeReqVO reqVO, ZhiMaCert zhiMaCert) throws GatewayException {
  68 + logger.info("IDOCRIdentification: begin ID card identification. reqVO is {}, zhiMaCert is {}", reqVO, zhiMaCert);
  69 + //(1) 身份证信息的基本校验,身份证正反面必传,且不能为空。
  70 + if(StringUtils.isBlank(reqVO.getFrontImageUrl()) || StringUtils.isBlank(reqVO.getBackImageUrl()) ||
  71 + "null".equalsIgnoreCase(reqVO.getFrontImageUrl().trim()) || "null".equalsIgnoreCase(reqVO.getBackImageUrl().trim())){
  72 + throw new GatewayException(400, "身份证照片不能为空!");
  73 + }
  74 +
  75 + //(2) 开关判断,控制是否需要进行OCR认证(防止在OCR识别异常的情况下,流程正常进行)
  76 + PhotoCheckResultVO result = new PhotoCheckResultVO();
  77 + result.setPass(false);
  78 + if(!certPhotoSwitchComponent.getCertPhotoSwitch()){
  79 + logger.info("IDOCRIdentification: OCR switch is off. reqVO is {}", reqVO);
  80 + result.setPass(CertPhotoEnum.valid_but_uncheck.isCheckPass());
  81 + result.setPhotoValidStatus(CertPhotoEnum.valid_but_uncheck.getStatus());
  82 + return result;
  83 + }
  84 +
  85 + //-----------------------------------开始身份证图片的OCR识别-----------------------------------------------
  86 + //(3) 上传身份证图片加私有云前缀。
  87 + reqVO.setFrontImageUrl(YOHO_IDCARD_PRE + reqVO.getFrontImageUrl());
  88 + reqVO.setBackImageUrl(YOHO_IDCARD_PRE + reqVO.getBackImageUrl());
  89 +
  90 + //(4) 组装身份证图片信息进行OCR识别
  91 + List<ImageBO> imageBoList = new ArrayList<>();
  92 + ImageBO frontUploadModel = new ImageBO();
  93 + frontUploadModel.setImageSide("front");
  94 + frontUploadModel.setImageUrl(ZhiMaCallUtil.signPrivateUrl(reqVO.getFrontImageUrl())); //私有云图片解密
  95 + imageBoList.add(frontUploadModel);
  96 + logger.info("IDOCRIdentification. prepare param to call ocr. reqVO is {}, frontUploadModel is {}", reqVO, frontUploadModel);
  97 +
  98 + //(5)
  99 + Response<ImageReviewResp> imageReviewRespResponse = ocrCertPhotoService.ocrCheck(reqVO.getUid(), imageBoList);
  100 +
  101 +
  102 + return null;
  103 + }
  104 +
  105 +
  106 +
  107 +
  108 +
  109 +
  110 +
  111 +
  112 +
  113 +
41 public Response<ImageReviewResp> ocrCheck(int uid , List<ImageBO> imageBOList) { 114 public Response<ImageReviewResp> ocrCheck(int uid , List<ImageBO> imageBOList) {
42 Response<ImageReviewResp> respVo = null; 115 Response<ImageReviewResp> respVo = null;
43 try{ 116 try{