Authored by qinchao

add method

@@ -9,6 +9,7 @@ import com.yohoufo.common.utils.UserInfoHiddenHelper; @@ -9,6 +9,7 @@ import com.yohoufo.common.utils.UserInfoHiddenHelper;
9 import com.yohoufo.dal.user.model.ZhiMaCert; 9 import com.yohoufo.dal.user.model.ZhiMaCert;
10 import com.yohoufo.user.common.IDCardUtils; 10 import com.yohoufo.user.common.IDCardUtils;
11 import com.yohoufo.user.helper.HideDataUtil; 11 import com.yohoufo.user.helper.HideDataUtil;
  12 +import com.yohoufo.user.requestVO.PhotoCheckResultVO;
12 import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO; 13 import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
13 import com.yohoufo.user.service.IRealNameAuthorizeService; 14 import com.yohoufo.user.service.IRealNameAuthorizeService;
14 import org.apache.commons.lang3.StringUtils; 15 import org.apache.commons.lang3.StringUtils;
@@ -236,7 +237,7 @@ public class RealNameAuthorizeController { @@ -236,7 +237,7 @@ public class RealNameAuthorizeController {
236 throw new GatewayException(400, "身份证正反面图片不能为空!"); 237 throw new GatewayException(400, "身份证正反面图片不能为空!");
237 } 238 }
238 239
239 - Map<String,Object> result = realNameAuthorizeService.zhiMaCertPhotoCheck(reqVO); 240 + PhotoCheckResultVO result = realNameAuthorizeService.zhiMaCertPhotoCheck(reqVO);
240 241
241 return new ApiResponse(200, "上传图片验证完成", result); 242 return new ApiResponse(200, "上传图片验证完成", result);
242 } catch (Exception e) { 243 } catch (Exception e) {
@@ -246,6 +247,40 @@ public class RealNameAuthorizeController { @@ -246,6 +247,40 @@ public class RealNameAuthorizeController {
246 } 247 }
247 } 248 }
248 249
  250 + @RequestMapping(params = "method=ufo.user.zhiMaCertWithPhotoCheckInit")
  251 + public ApiResponse zhiMaCertWithPhotoCheckInit(RealNameAuthorizeReqVO reqVO) throws GatewayException {
  252 + logger.info("enter realNameAuthorize.zhiMaCertWithPhotoCheckInit param reqVO is {}", reqVO);
  253 + //(1) 优先校验请求的参数
  254 + if (reqVO == null || reqVO.getUid()<=0){
  255 + throw new GatewayException(400, "uid不能为空!");
  256 + }
  257 +
  258 + if ( StringUtils.isEmpty(reqVO.getCertNo())|| StringUtils.isEmpty(reqVO.getCertName())){
  259 + throw new GatewayException(400, "身份证号、姓名不能为空!");
  260 + }
  261 +
  262 + //身份证格式校验IDCardUtils
  263 + if(!IDCardUtils.validate(reqVO.getCertNo())){
  264 + throw new GatewayException(400, "身份证号格式不正确!");
  265 + }
  266 +
  267 + //身份证图片,必须
  268 + if(StringUtils.isBlank(reqVO.getFrontImageUrl())||StringUtils.isBlank(reqVO.getBackImageUrl())){
  269 + throw new GatewayException(400, "身份证正反面图片不能为空!");
  270 + }
  271 +
  272 + //调用芝麻,得到回调url
  273 + AuthorizeResultRespVO resultVo=realNameAuthorizeService.zhiMaCertWithPhotoInit(reqVO,true);
  274 + logger.info("realNameAuthorize.zhiMaCertWithPhotoCheckInit result vo {} ",resultVo);
  275 + ApiResponse apiResponse=new ApiResponse();
  276 + if(resultVo==null){
  277 + apiResponse.setCode(201);
  278 + apiResponse.setMessage("异常结果为空");
  279 + }
  280 + apiResponse.setData(resultVo);
  281 + return apiResponse;
  282 + }
  283 +
249 /** 284 /**
250 * 6.9.1版本 ,芝麻认证要求上传图片 285 * 6.9.1版本 ,芝麻认证要求上传图片
251 * 原接口保持不变,芝麻认证用新的接口 286 * 原接口保持不变,芝麻认证用新的接口
@@ -280,7 +315,7 @@ public class RealNameAuthorizeController { @@ -280,7 +315,7 @@ public class RealNameAuthorizeController {
280 } 315 }
281 316
282 //调用芝麻,得到回调url 317 //调用芝麻,得到回调url
283 - AuthorizeResultRespVO resultVo=realNameAuthorizeService.zhiMaCertWithPhotoInit(reqVO); 318 + AuthorizeResultRespVO resultVo=realNameAuthorizeService.zhiMaCertWithPhotoInit(reqVO,false);
284 logger.info("realNameAuthorize.zhiMaCertInit result vo {} ",resultVo); 319 logger.info("realNameAuthorize.zhiMaCertInit result vo {} ",resultVo);
285 ApiResponse apiResponse=new ApiResponse(); 320 ApiResponse apiResponse=new ApiResponse();
286 if(resultVo==null){ 321 if(resultVo==null){
  1 +package com.yohoufo.user.requestVO;
  2 +
  3 +import lombok.Data;
  4 +import lombok.ToString;
  5 +
  6 +@Data
  7 +@ToString
  8 +public class PhotoCheckResultVO {
  9 + private boolean pass;
  10 + private int photoValidStatus;
  11 + private String message;
  12 +}
@@ -6,7 +6,9 @@ import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO; @@ -6,7 +6,9 @@ import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
6 import com.yohoufo.common.exception.GatewayException; 6 import com.yohoufo.common.exception.GatewayException;
7 import com.yohoufo.dal.user.model.UserAuthorizeInfo; 7 import com.yohoufo.dal.user.model.UserAuthorizeInfo;
8 import com.yohoufo.dal.user.model.ZhiMaCert; 8 import com.yohoufo.dal.user.model.ZhiMaCert;
  9 +import com.yohoufo.user.requestVO.PhotoCheckResultVO;
9 import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO; 10 import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
  11 +import com.yohoufo.user.service.impl.RealNameAuthorizeServiceImpl;
10 12
11 import java.util.Map; 13 import java.util.Map;
12 14
@@ -27,12 +29,12 @@ public interface IRealNameAuthorizeService { @@ -27,12 +29,12 @@ public interface IRealNameAuthorizeService {
27 29
28 //boolean isPhotoCheckExceedLimit(Integer uid); 30 //boolean isPhotoCheckExceedLimit(Integer uid);
29 31
30 - Map<String,Object> zhiMaCertPhotoCheck(RealNameAuthorizeReqVO reqVO); 32 + PhotoCheckResultVO zhiMaCertPhotoCheck(RealNameAuthorizeReqVO reqVO);
31 33
32 //@Deprecated 34 //@Deprecated
33 //List<String> zhiMaCertUploadPhotoAndCheck(MultipartFile[] multipartFile, String bucket, Integer limitType, RealNameAuthorizeReqVO reqVO) throws Exception ; 35 //List<String> zhiMaCertUploadPhotoAndCheck(MultipartFile[] multipartFile, String bucket, Integer limitType, RealNameAuthorizeReqVO reqVO) throws Exception ;
34 36
35 - AuthorizeResultRespVO zhiMaCertWithPhotoInit(RealNameAuthorizeReqVO reqVO); 37 + AuthorizeResultRespVO zhiMaCertWithPhotoInit(RealNameAuthorizeReqVO reqVO,boolean ocrPhotoCheck);
36 38
37 AuthorizeResultRespVO zhiMaCertInit(RealNameAuthorizeReqVO reqVO); 39 AuthorizeResultRespVO zhiMaCertInit(RealNameAuthorizeReqVO reqVO);
38 40
@@ -32,8 +32,11 @@ import com.yohoufo.user.cache.CacheService; @@ -32,8 +32,11 @@ import com.yohoufo.user.cache.CacheService;
32 import com.yohoufo.user.common.AlipayConfigInfo; 32 import com.yohoufo.user.common.AlipayConfigInfo;
33 import com.yohoufo.user.component.CertPhotoSwitchComponent; 33 import com.yohoufo.user.component.CertPhotoSwitchComponent;
34 import com.yohoufo.user.helper.HideDataUtil; 34 import com.yohoufo.user.helper.HideDataUtil;
  35 +import com.yohoufo.user.requestVO.PhotoCheckResultVO;
35 import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO; 36 import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
36 import com.yohoufo.user.service.IRealNameAuthorizeService; 37 import com.yohoufo.user.service.IRealNameAuthorizeService;
  38 +import lombok.Data;
  39 +import lombok.ToString;
37 import org.apache.commons.lang.StringUtils; 40 import org.apache.commons.lang.StringUtils;
38 import org.slf4j.Logger; 41 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory; 42 import org.slf4j.LoggerFactory;
@@ -368,13 +371,9 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { @@ -368,13 +371,9 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
368 } 371 }
369 372
370 @Override 373 @Override
371 - public Map<String,Object> zhiMaCertPhotoCheck(RealNameAuthorizeReqVO reqVO){ 374 + public PhotoCheckResultVO zhiMaCertPhotoCheck(RealNameAuthorizeReqVO reqVO){
372 //每天:记录一个累加的次数 ,超过一定的数量不允许继续调 375 //每天:记录一个累加的次数 ,超过一定的数量不允许继续调
373 String dayStr = getStringDate("yyyyMMdd"); 376 String dayStr = getStringDate("yyyyMMdd");
374 - if(isPhotoCheckExceedLimit(dayStr,reqVO.getUid())){  
375 - throw new UfoServiceException(400, "今日的认证次数已经用完!");  
376 - }  
377 -  
378 ImageBO frontUploadModel=new ImageBO(); 377 ImageBO frontUploadModel=new ImageBO();
379 frontUploadModel.setImageSide("front"); 378 frontUploadModel.setImageSide("front");
380 frontUploadModel.setImageUrl(reqVO.getFrontImageUrl()); 379 frontUploadModel.setImageUrl(reqVO.getFrontImageUrl());
@@ -382,15 +381,61 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { @@ -382,15 +381,61 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
382 backUploadModel.setImageSide("back"); 381 backUploadModel.setImageSide("back");
383 backUploadModel.setImageUrl(reqVO.getBackImageUrl()); 382 backUploadModel.setImageUrl(reqVO.getBackImageUrl());
384 //调用接口,ocr验证 383 //调用接口,ocr验证
385 - CertPhotoEnum certPhotoCheckResult = checkCertPhoto(dayStr,Lists.newArrayList(frontUploadModel ,backUploadModel) ,reqVO); 384 + PhotoCheckResultVO certPhotoCheckResult = checkCertPhoto(dayStr,Lists.newArrayList(frontUploadModel ,backUploadModel) ,reqVO);
  385 + return certPhotoCheckResult;
  386 + }
  387 +
  388 + /**
  389 + * 调用通用的图片验证ocr
  390 + * @param imageBOList
  391 + * @param reqVO
  392 + * @return
  393 + */
  394 + private PhotoCheckResultVO checkCertPhoto(String dayStr,List<ImageBO> imageBOList,RealNameAuthorizeReqVO reqVO){
  395 + if(isPhotoCheckExceedLimit(dayStr,reqVO.getUid())){
  396 + throw new UfoServiceException(400, "今日的认证次数已经用完!");
  397 + }
  398 + PhotoCheckResultVO result=new PhotoCheckResultVO();
  399 + result.setPass(false);
  400 +
  401 + try{
  402 + ImageReviewedReq req=new ImageReviewedReq();
  403 + req.setUid(reqVO.getUid());
  404 + req.setImageBOList(imageBOList);
  405 + req.setBusinessLine("ufo");
  406 + req.setSceneName("SELLER_IDCARD_RECOGNIZE");
  407 + req.setContext(contextPath);
  408 +
  409 + //调用校验,然后直接返回
  410 + logger.info("checkCertPhoto call begin reqVO {} ,req {}",reqVO, JSON.toJSONString(req));
  411 +
  412 + //如果图像认证开关关闭,直接返回成功
  413 + boolean open = certPhotoSwitchComponent.getCertPhotoSwitch();
  414 + if(!open){
  415 + logger.info("zhiMaCertPhotoCheck switch is {},reqVO {} ",open,reqVO);
  416 + result.setPass(CertPhotoEnum.valid_but_uncheck.isCheckPass());
  417 + result.setPhotoValidStatus(CertPhotoEnum.valid_but_uncheck.getStatus());
  418 + return result;
  419 + }
  420 +
  421 + //次数加1
  422 + long num = cacheService.incrementPhotoCheckCount(dayStr,reqVO.getUid());
  423 + logger.info("checkCertPhoto call begin reqVO {} ,call redis count {}",reqVO, num);
  424 +
  425 + ImageReviewResp resp =null;
  426 + logger.info("checkCertPhoto call end reqVO {} ,req {} ,resp {} ",reqVO,JSON.toJSONString(req),JSON.toJSONString(resp));
  427 + //比较信息
  428 +
  429 + }catch (Exception e){
  430 + logger.warn("checkCertPhoto error reqVO {}",reqVO,e);
  431 + throw new UfoServiceException(400, "您上传的证件照片信息不正确,请重新上传!");
  432 + }
386 433
387 - Map<String,Object> map= Maps.newHashMap();  
388 - map.put("pass",certPhotoCheckResult.isCheckPass());  
389 - map.put("photoValidStatus",certPhotoCheckResult.getStatus());  
390 - return map; 434 + return result;
391 } 435 }
392 436
393 437
  438 +
394 /* 439 /*
395 @Deprecated 440 @Deprecated
396 @Override 441 @Override
@@ -436,47 +481,6 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { @@ -436,47 +481,6 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
436 } 481 }
437 */ 482 */
438 483
439 - /**  
440 - * 调用通用的图片验证ocr  
441 - * @param imageBOList  
442 - * @param reqVO  
443 - * @return  
444 - */  
445 - private CertPhotoEnum checkCertPhoto(String dayStr,List<ImageBO> imageBOList,RealNameAuthorizeReqVO reqVO){  
446 - try{  
447 - ImageReviewedReq req=new ImageReviewedReq();  
448 - req.setUid(reqVO.getUid());  
449 - req.setImageBOList(imageBOList);  
450 - req.setBusinessLine("ufo");  
451 - req.setSceneName("SELLER_IDCARD_RECOGNIZE");  
452 - req.setContext(contextPath);  
453 -  
454 - //调用校验,然后直接返回  
455 - logger.info("checkCertPhoto call begin reqVO {} ,req {}",reqVO, JSON.toJSONString(req));  
456 -  
457 - //如果图像认证开关关闭,直接返回成功  
458 - boolean open = certPhotoSwitchComponent.getCertPhotoSwitch();  
459 - if(!open){  
460 - logger.info("zhiMaCertPhotoCheck switch is {},reqVO {} ",open,reqVO);  
461 - return CertPhotoEnum.valid_but_uncheck;  
462 - }  
463 -  
464 - //次数加1  
465 - long num = cacheService.incrementPhotoCheckCount(dayStr,reqVO.getUid());  
466 - logger.info("checkCertPhoto call begin reqVO {} ,call redis count {}",reqVO, num);  
467 -  
468 - ImageReviewResp resp =null;  
469 - logger.info("checkCertPhoto call end reqVO {} ,req {} ,resp {} ",reqVO,JSON.toJSONString(req),JSON.toJSONString(resp));  
470 - //比较信息  
471 -  
472 - }catch (Exception e){  
473 - logger.warn("checkCertPhoto error reqVO {}",reqVO,e);  
474 - throw new UfoServiceException(400, "您上传的证件照片信息不正确,请重新上传!");  
475 - }  
476 -  
477 - return CertPhotoEnum.valid;  
478 - }  
479 -  
480 /* 484 /*
481 public ImageBO getUploadImagePath(MultipartFile multipartFile, String bucket, String uid, Integer limitType) throws Exception { 485 public ImageBO getUploadImagePath(MultipartFile multipartFile, String bucket, String uid, Integer limitType) throws Exception {
482 //文件为空 486 //文件为空
@@ -555,7 +559,7 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { @@ -555,7 +559,7 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
555 559
556 560
557 @Override 561 @Override
558 - public AuthorizeResultRespVO zhiMaCertWithPhotoInit(RealNameAuthorizeReqVO reqVO){ 562 + public AuthorizeResultRespVO zhiMaCertWithPhotoInit(RealNameAuthorizeReqVO reqVO,boolean ocrPhotoCheck){
559 logger.info("real name zhiMaCertWithPhotoInit reqVO {}", reqVO); 563 logger.info("real name zhiMaCertWithPhotoInit reqVO {}", reqVO);
560 boolean justCheckPhoto = false; 564 boolean justCheckPhoto = false;
561 int uid = reqVO.getUid(); 565 int uid = reqVO.getUid();
@@ -577,6 +581,17 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { @@ -577,6 +581,17 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
577 581
578 logger.info("real name zhiMaCertWithPhotoInit reqVO {} ,justCheckPhoto {}", reqVO,justCheckPhoto); 582 logger.info("real name zhiMaCertWithPhotoInit reqVO {} ,justCheckPhoto {}", reqVO,justCheckPhoto);
579 583
  584 + if(ocrPhotoCheck){
  585 + //验证图片
  586 + PhotoCheckResultVO photoCheckResultVO = this.zhiMaCertPhotoCheck(reqVO);
  587 + if(photoCheckResultVO.isPass()){
  588 + //根据校验结果,重设photo_valid_status
  589 + reqVO.setPhotoValidStatus(photoCheckResultVO.getPhotoValidStatus());
  590 + }else{
  591 + throw new UfoServiceException(400, "您上传的证件照片信息不正确,请重新上传!");
  592 + }
  593 + }
  594 +
580 String imgUrl = reqVO.getFrontImageUrl()+","+reqVO.getBackImageUrl(); 595 String imgUrl = reqVO.getFrontImageUrl()+","+reqVO.getBackImageUrl();
581 596
582 if(justCheckPhoto){ 597 if(justCheckPhoto){
@@ -25,3 +25,5 @@ ufo.product.productLimitInfo=10009017,10008631,10008633,10008635,10008637,100086 @@ -25,3 +25,5 @@ ufo.product.productLimitInfo=10009017,10008631,10008633,10008635,10008637,100086
25 ufo.seller.rejoinMaxTimes=1 25 ufo.seller.rejoinMaxTimes=1
26 ufo.invite.isSupportBeenInvited=true 26 ufo.invite.isSupportBeenInvited=true
27 27
  28 +ufo.order.certPhotoSwitchCacheKey=true
  29 +ufo.user.photoCheckLimit=10