Authored by qinchao

add method

... ... @@ -9,6 +9,7 @@ import com.yohoufo.common.utils.UserInfoHiddenHelper;
import com.yohoufo.dal.user.model.ZhiMaCert;
import com.yohoufo.user.common.IDCardUtils;
import com.yohoufo.user.helper.HideDataUtil;
import com.yohoufo.user.requestVO.PhotoCheckResultVO;
import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
import com.yohoufo.user.service.IRealNameAuthorizeService;
import org.apache.commons.lang3.StringUtils;
... ... @@ -236,7 +237,7 @@ public class RealNameAuthorizeController {
throw new GatewayException(400, "身份证正反面图片不能为空!");
}
Map<String,Object> result = realNameAuthorizeService.zhiMaCertPhotoCheck(reqVO);
PhotoCheckResultVO result = realNameAuthorizeService.zhiMaCertPhotoCheck(reqVO);
return new ApiResponse(200, "上传图片验证完成", result);
} catch (Exception e) {
... ... @@ -246,6 +247,40 @@ public class RealNameAuthorizeController {
}
}
@RequestMapping(params = "method=ufo.user.zhiMaCertWithPhotoCheckInit")
public ApiResponse zhiMaCertWithPhotoCheckInit(RealNameAuthorizeReqVO reqVO) throws GatewayException {
logger.info("enter realNameAuthorize.zhiMaCertWithPhotoCheckInit param reqVO is {}", reqVO);
//(1) 优先校验请求的参数
if (reqVO == null || reqVO.getUid()<=0){
throw new GatewayException(400, "uid不能为空!");
}
if ( StringUtils.isEmpty(reqVO.getCertNo())|| StringUtils.isEmpty(reqVO.getCertName())){
throw new GatewayException(400, "身份证号、姓名不能为空!");
}
//身份证格式校验IDCardUtils
if(!IDCardUtils.validate(reqVO.getCertNo())){
throw new GatewayException(400, "身份证号格式不正确!");
}
//身份证图片,必须
if(StringUtils.isBlank(reqVO.getFrontImageUrl())||StringUtils.isBlank(reqVO.getBackImageUrl())){
throw new GatewayException(400, "身份证正反面图片不能为空!");
}
//调用芝麻,得到回调url
AuthorizeResultRespVO resultVo=realNameAuthorizeService.zhiMaCertWithPhotoInit(reqVO,true);
logger.info("realNameAuthorize.zhiMaCertWithPhotoCheckInit result vo {} ",resultVo);
ApiResponse apiResponse=new ApiResponse();
if(resultVo==null){
apiResponse.setCode(201);
apiResponse.setMessage("异常结果为空");
}
apiResponse.setData(resultVo);
return apiResponse;
}
/**
* 6.9.1版本 ,芝麻认证要求上传图片
* 原接口保持不变,芝麻认证用新的接口
... ... @@ -280,7 +315,7 @@ public class RealNameAuthorizeController {
}
//调用芝麻,得到回调url
AuthorizeResultRespVO resultVo=realNameAuthorizeService.zhiMaCertWithPhotoInit(reqVO);
AuthorizeResultRespVO resultVo=realNameAuthorizeService.zhiMaCertWithPhotoInit(reqVO,false);
logger.info("realNameAuthorize.zhiMaCertInit result vo {} ",resultVo);
ApiResponse apiResponse=new ApiResponse();
if(resultVo==null){
... ...
package com.yohoufo.user.requestVO;
import lombok.Data;
import lombok.ToString;
@Data
@ToString
public class PhotoCheckResultVO {
private boolean pass;
private int photoValidStatus;
private String message;
}
... ...
... ... @@ -6,7 +6,9 @@ import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.dal.user.model.UserAuthorizeInfo;
import com.yohoufo.dal.user.model.ZhiMaCert;
import com.yohoufo.user.requestVO.PhotoCheckResultVO;
import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
import com.yohoufo.user.service.impl.RealNameAuthorizeServiceImpl;
import java.util.Map;
... ... @@ -27,12 +29,12 @@ public interface IRealNameAuthorizeService {
//boolean isPhotoCheckExceedLimit(Integer uid);
Map<String,Object> zhiMaCertPhotoCheck(RealNameAuthorizeReqVO reqVO);
PhotoCheckResultVO zhiMaCertPhotoCheck(RealNameAuthorizeReqVO reqVO);
//@Deprecated
//List<String> zhiMaCertUploadPhotoAndCheck(MultipartFile[] multipartFile, String bucket, Integer limitType, RealNameAuthorizeReqVO reqVO) throws Exception ;
AuthorizeResultRespVO zhiMaCertWithPhotoInit(RealNameAuthorizeReqVO reqVO);
AuthorizeResultRespVO zhiMaCertWithPhotoInit(RealNameAuthorizeReqVO reqVO,boolean ocrPhotoCheck);
AuthorizeResultRespVO zhiMaCertInit(RealNameAuthorizeReqVO reqVO);
... ...
... ... @@ -32,8 +32,11 @@ import com.yohoufo.user.cache.CacheService;
import com.yohoufo.user.common.AlipayConfigInfo;
import com.yohoufo.user.component.CertPhotoSwitchComponent;
import com.yohoufo.user.helper.HideDataUtil;
import com.yohoufo.user.requestVO.PhotoCheckResultVO;
import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
import com.yohoufo.user.service.IRealNameAuthorizeService;
import lombok.Data;
import lombok.ToString;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -368,13 +371,9 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
}
@Override
public Map<String,Object> zhiMaCertPhotoCheck(RealNameAuthorizeReqVO reqVO){
public PhotoCheckResultVO zhiMaCertPhotoCheck(RealNameAuthorizeReqVO reqVO){
//每天:记录一个累加的次数 ,超过一定的数量不允许继续调
String dayStr = getStringDate("yyyyMMdd");
if(isPhotoCheckExceedLimit(dayStr,reqVO.getUid())){
throw new UfoServiceException(400, "今日的认证次数已经用完!");
}
ImageBO frontUploadModel=new ImageBO();
frontUploadModel.setImageSide("front");
frontUploadModel.setImageUrl(reqVO.getFrontImageUrl());
... ... @@ -382,15 +381,61 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
backUploadModel.setImageSide("back");
backUploadModel.setImageUrl(reqVO.getBackImageUrl());
//调用接口,ocr验证
CertPhotoEnum certPhotoCheckResult = checkCertPhoto(dayStr,Lists.newArrayList(frontUploadModel ,backUploadModel) ,reqVO);
PhotoCheckResultVO certPhotoCheckResult = checkCertPhoto(dayStr,Lists.newArrayList(frontUploadModel ,backUploadModel) ,reqVO);
return certPhotoCheckResult;
}
/**
* 调用通用的图片验证ocr
* @param imageBOList
* @param reqVO
* @return
*/
private PhotoCheckResultVO checkCertPhoto(String dayStr,List<ImageBO> imageBOList,RealNameAuthorizeReqVO reqVO){
if(isPhotoCheckExceedLimit(dayStr,reqVO.getUid())){
throw new UfoServiceException(400, "今日的认证次数已经用完!");
}
PhotoCheckResultVO result=new PhotoCheckResultVO();
result.setPass(false);
try{
ImageReviewedReq req=new ImageReviewedReq();
req.setUid(reqVO.getUid());
req.setImageBOList(imageBOList);
req.setBusinessLine("ufo");
req.setSceneName("SELLER_IDCARD_RECOGNIZE");
req.setContext(contextPath);
//调用校验,然后直接返回
logger.info("checkCertPhoto call begin reqVO {} ,req {}",reqVO, JSON.toJSONString(req));
//如果图像认证开关关闭,直接返回成功
boolean open = certPhotoSwitchComponent.getCertPhotoSwitch();
if(!open){
logger.info("zhiMaCertPhotoCheck switch is {},reqVO {} ",open,reqVO);
result.setPass(CertPhotoEnum.valid_but_uncheck.isCheckPass());
result.setPhotoValidStatus(CertPhotoEnum.valid_but_uncheck.getStatus());
return result;
}
//次数加1
long num = cacheService.incrementPhotoCheckCount(dayStr,reqVO.getUid());
logger.info("checkCertPhoto call begin reqVO {} ,call redis count {}",reqVO, num);
ImageReviewResp resp =null;
logger.info("checkCertPhoto call end reqVO {} ,req {} ,resp {} ",reqVO,JSON.toJSONString(req),JSON.toJSONString(resp));
//比较信息
}catch (Exception e){
logger.warn("checkCertPhoto error reqVO {}",reqVO,e);
throw new UfoServiceException(400, "您上传的证件照片信息不正确,请重新上传!");
}
Map<String,Object> map= Maps.newHashMap();
map.put("pass",certPhotoCheckResult.isCheckPass());
map.put("photoValidStatus",certPhotoCheckResult.getStatus());
return map;
return result;
}
/*
@Deprecated
@Override
... ... @@ -436,47 +481,6 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
}
*/
/**
* 调用通用的图片验证ocr
* @param imageBOList
* @param reqVO
* @return
*/
private CertPhotoEnum checkCertPhoto(String dayStr,List<ImageBO> imageBOList,RealNameAuthorizeReqVO reqVO){
try{
ImageReviewedReq req=new ImageReviewedReq();
req.setUid(reqVO.getUid());
req.setImageBOList(imageBOList);
req.setBusinessLine("ufo");
req.setSceneName("SELLER_IDCARD_RECOGNIZE");
req.setContext(contextPath);
//调用校验,然后直接返回
logger.info("checkCertPhoto call begin reqVO {} ,req {}",reqVO, JSON.toJSONString(req));
//如果图像认证开关关闭,直接返回成功
boolean open = certPhotoSwitchComponent.getCertPhotoSwitch();
if(!open){
logger.info("zhiMaCertPhotoCheck switch is {},reqVO {} ",open,reqVO);
return CertPhotoEnum.valid_but_uncheck;
}
//次数加1
long num = cacheService.incrementPhotoCheckCount(dayStr,reqVO.getUid());
logger.info("checkCertPhoto call begin reqVO {} ,call redis count {}",reqVO, num);
ImageReviewResp resp =null;
logger.info("checkCertPhoto call end reqVO {} ,req {} ,resp {} ",reqVO,JSON.toJSONString(req),JSON.toJSONString(resp));
//比较信息
}catch (Exception e){
logger.warn("checkCertPhoto error reqVO {}",reqVO,e);
throw new UfoServiceException(400, "您上传的证件照片信息不正确,请重新上传!");
}
return CertPhotoEnum.valid;
}
/*
public ImageBO getUploadImagePath(MultipartFile multipartFile, String bucket, String uid, Integer limitType) throws Exception {
//文件为空
... ... @@ -555,7 +559,7 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
@Override
public AuthorizeResultRespVO zhiMaCertWithPhotoInit(RealNameAuthorizeReqVO reqVO){
public AuthorizeResultRespVO zhiMaCertWithPhotoInit(RealNameAuthorizeReqVO reqVO,boolean ocrPhotoCheck){
logger.info("real name zhiMaCertWithPhotoInit reqVO {}", reqVO);
boolean justCheckPhoto = false;
int uid = reqVO.getUid();
... ... @@ -577,6 +581,17 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
logger.info("real name zhiMaCertWithPhotoInit reqVO {} ,justCheckPhoto {}", reqVO,justCheckPhoto);
if(ocrPhotoCheck){
//验证图片
PhotoCheckResultVO photoCheckResultVO = this.zhiMaCertPhotoCheck(reqVO);
if(photoCheckResultVO.isPass()){
//根据校验结果,重设photo_valid_status
reqVO.setPhotoValidStatus(photoCheckResultVO.getPhotoValidStatus());
}else{
throw new UfoServiceException(400, "您上传的证件照片信息不正确,请重新上传!");
}
}
String imgUrl = reqVO.getFrontImageUrl()+","+reqVO.getBackImageUrl();
if(justCheckPhoto){
... ...
... ... @@ -25,3 +25,5 @@ ufo.product.productLimitInfo=10009017,10008631,10008633,10008635,10008637,100086
ufo.seller.rejoinMaxTimes=1
ufo.invite.isSupportBeenInvited=true
ufo.order.certPhotoSwitchCacheKey=true
ufo.user.photoCheckLimit=10
... ...