...
|
...
|
@@ -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{
|
...
|
...
|
|