Authored by DengXinFei

支付宝刷脸认证

... ... @@ -39,14 +39,17 @@ public class CertificationController {
public ApiResponse alipayCertification(RealNameAuthorizeReqVO reqVO) throws GatewayException {
logger.info("CertificationController.alipayCertification: Enter alipayCertification param reqVO is {}", reqVO);
//(1) 必要参数的校验
if (reqVO == null || reqVO.getUid()<=0){
if(reqVO == null || reqVO.getUid() <= 0){
throw new GatewayException(400, "uid不能为空!");
}
if ( StringUtils.isEmpty(reqVO.getCertNo())|| StringUtils.isEmpty(reqVO.getCertName())){
if(StringUtils.isEmpty(reqVO.getCertNo()) || StringUtils.isEmpty(reqVO.getCertName())){
logger.warn("alipayCertification: certNO or cert name can not be empty. uid is {}, certNO is {}, certName is {}", reqVO.getUid(), reqVO.getCertNo(), reqVO.getCertName());
throw new GatewayException(400, "身份证号、姓名不能为空!");
}
//(2)
//(2)获取认证记录,判断是否已经认证。
... ...
... ... @@ -2,6 +2,7 @@ package com.yohoufo.user.service;
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
import com.yohoufo.dal.user.model.ZhiMaCert;
import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
/**
* 实名认证服务
... ... @@ -17,8 +18,8 @@ public interface ICertificationService {
/**
* 开始实名认证(图片OCR识别 + 支付宝实名认证)
*
* @param uid 用户UID
* @param realNameAuthorizeReqVO 实名认证用户信息(包含身份证照片,姓名,身份证号码)
* @return 认证结果
*/
AuthorizeResultRespVO beginCertificate(int uid);
AuthorizeResultRespVO beginCertificate(RealNameAuthorizeReqVO realNameAuthorizeReqVO);
}
... ...
... ... @@ -2,8 +2,10 @@ package com.yohoufo.user.service.impl;
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
import com.yohoufo.common.constant.CertPhotoEnum;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.dal.user.IZhiMaCertDao;
import com.yohoufo.dal.user.model.ZhiMaCert;
import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
import com.yohoufo.user.service.ICertificationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -28,19 +30,41 @@ public class CertificationServiceImpl implements ICertificationService {
private IZhiMaCertDao zhiMaCertDao;
@Override
public AuthorizeResultRespVO beginCertificate(int uid) {
logger.info("getValidCertificationRecord: Begin select valid certification record. uid is {}", uid);
public AuthorizeResultRespVO beginCertificate(RealNameAuthorizeReqVO reqVO) {
logger.info("beginCertificate: Begin select valid certification record. reqVO is {}", reqVO);
//(1) 直接查询当前UID实名认证的记录
//(1)直接查询当前UID实名认证的记录
int uid = reqVO.getUid();
ZhiMaCert zhiMaCert = zhiMaCertDao.selectLatestCertificateByUid(uid);
logger.info("beginCertificate: get user certification history by uid. uid is {}, zhiMaCert is {}", uid, zhiMaCert);
//(2)是否已经认证通过,认证通过的直接返回
if(null != zhiMaCert && CertPhotoEnum.isValidStatus(zhiMaCert.getValidPhoto()) && 1 == zhiMaCert.getValidStatus()){
logger.info("beginCertificate: user has certification already. uid is {}", uid);
throw new UfoServiceException(400, "已实名认证!");
}
//(3)如果客户端传入的身份信息是隐位信息,那么将身份信息进行补全。
if(null != zhiMaCert && (reqVO.getCertName().contains("*") || reqVO.getCertNo().contains("*"))){
reqVO.setCertName(zhiMaCert.getCertName());
reqVO.setCertNo(zhiMaCert.getCertNo());
logger.info("beginCertificate:zhiMaCertWithPhotoCheckInit reset mask ,zhiMaCert {} ,new reqVO is {}", zhiMaCert ,reqVO);
}
//(4) 判断用户新传入的身份信息,是否与历史认证一致,如果不一致,需要重新进行OCR识别+支付宝刷脸认证。
if(null != zhiMaCert && (!reqVO.getCertName().equals(zhiMaCert.getCertName()) || !reqVO.getCertNo().equals(zhiMaCert.getCertNo()))){
logger.info("beginCertificate: request cert info not matched in db. reqVO is {}, zhiMaCert is {}", reqVO, zhiMaCert);
zhiMaCert = null;
}
//----------------------以下是需要实名认证(身份证OCR识别 + 支付宝刷脸认证)-------------------------------
//(3)身份证OCR识别(已经识别过将不会继续识别)
if(null == zhiMaCert || !CertPhotoEnum.isValidStatus(zhiMaCert.getValidPhoto())){
//身份证识别
}
//(4)支付宝实名认证(如果已经认证过了,将不会继续认证)
... ... @@ -51,4 +75,7 @@ public class CertificationServiceImpl implements ICertificationService {
return null;
}
}
... ...
... ... @@ -5,6 +5,13 @@ import com.yoho.service.model.reviewed.request.ImageBO;
import com.yoho.service.model.reviewed.request.ImageReviewedReq;
import com.yoho.service.model.reviewed.response.ImageReviewResp;
import com.yoho.tools.common.beans.Response;
import com.yohoufo.common.constant.CertPhotoEnum;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.dal.user.model.ZhiMaCert;
import com.yohoufo.user.component.CertPhotoSwitchComponent;
import com.yohoufo.user.requestVO.PhotoCheckResultVO;
import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -19,9 +26,12 @@ import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.List;
/**
* 进行身份证识别服务(识别身份证信息+身份证信息校验)
*
* Created by craig.qin on 2018/10/19.
* 身份证图片的ocr
*/
... ... @@ -32,12 +42,75 @@ public class OcrCertPhotoService {
@Autowired
private RestTemplate restTemplate;
@Autowired
private CertPhotoSwitchComponent certPhotoSwitchComponent;
@Autowired
private OcrCertPhotoService ocrCertPhotoService;
private final String YOHO_IDCARD_PRE = "http://yhgidcard.static.yhbimg.com/yohocard";
@Value("${web.context}")
private String contextPath;
@Value("${yoho.reviewed.controller.url}")
private String messageUrl;
/**
* 实名认证中的身份证识别认证(OCR身份证识别)
*
* @param reqVO 上传的身份证图片 + 用户姓名以及身份证号码
* @param zhiMaCert 已经认证的记录。
* @return
* @throws GatewayException
*/
public PhotoCheckResultVO IDOCRIdentification(RealNameAuthorizeReqVO reqVO, ZhiMaCert zhiMaCert) throws GatewayException {
logger.info("IDOCRIdentification: begin ID card identification. reqVO is {}, zhiMaCert is {}", reqVO, zhiMaCert);
//(1) 身份证信息的基本校验,身份证正反面必传,且不能为空。
if(StringUtils.isBlank(reqVO.getFrontImageUrl()) || StringUtils.isBlank(reqVO.getBackImageUrl()) ||
"null".equalsIgnoreCase(reqVO.getFrontImageUrl().trim()) || "null".equalsIgnoreCase(reqVO.getBackImageUrl().trim())){
throw new GatewayException(400, "身份证照片不能为空!");
}
//(2) 开关判断,控制是否需要进行OCR认证(防止在OCR识别异常的情况下,流程正常进行)
PhotoCheckResultVO result = new PhotoCheckResultVO();
result.setPass(false);
if(!certPhotoSwitchComponent.getCertPhotoSwitch()){
logger.info("IDOCRIdentification: OCR switch is off. reqVO is {}", reqVO);
result.setPass(CertPhotoEnum.valid_but_uncheck.isCheckPass());
result.setPhotoValidStatus(CertPhotoEnum.valid_but_uncheck.getStatus());
return result;
}
//-----------------------------------开始身份证图片的OCR识别-----------------------------------------------
//(3) 上传身份证图片加私有云前缀。
reqVO.setFrontImageUrl(YOHO_IDCARD_PRE + reqVO.getFrontImageUrl());
reqVO.setBackImageUrl(YOHO_IDCARD_PRE + reqVO.getBackImageUrl());
//(4) 组装身份证图片信息进行OCR识别
List<ImageBO> imageBoList = new ArrayList<>();
ImageBO frontUploadModel = new ImageBO();
frontUploadModel.setImageSide("front");
frontUploadModel.setImageUrl(ZhiMaCallUtil.signPrivateUrl(reqVO.getFrontImageUrl())); //私有云图片解密
imageBoList.add(frontUploadModel);
logger.info("IDOCRIdentification. prepare param to call ocr. reqVO is {}, frontUploadModel is {}", reqVO, frontUploadModel);
//(5)
Response<ImageReviewResp> imageReviewRespResponse = ocrCertPhotoService.ocrCheck(reqVO.getUid(), imageBoList);
return null;
}
public Response<ImageReviewResp> ocrCheck(int uid , List<ImageBO> imageBOList) {
Response<ImageReviewResp> respVo = null;
try{
... ...