Authored by qinchao

身份证图片

... ... @@ -15,6 +15,11 @@
<dependencies>
<dependency>
<groupId>com.yoho.service.model</groupId>
<artifactId>reviewed-service-model</artifactId>
</dependency>
<dependency>
<groupId>com.yohoufo.fore</groupId>
<artifactId>yohoufo-fore-dal</artifactId>
</dependency>
... ...
package com.yohoufo.user.service.impl;
import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
... ... @@ -9,8 +10,11 @@ import com.alipay.api.request.AlipayUserInfoShareRequest;
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
import com.alipay.api.response.AlipayUserInfoShareResponse;
import com.alipay.api.response.ZhimaCustomerCertificationQueryResponse;
import com.yoho.core.common.helpers.ImagesHelper;
import com.google.common.collect.Lists;
import com.yoho.error.exception.ServiceException;
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.ApiResponse;
import com.yoho.tools.common.service.IQNUploadService;
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
... ... @@ -27,9 +31,7 @@ import com.yohoufo.user.common.AlipayConfigInfo;
import com.yohoufo.user.helper.HideDataUtil;
import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
import com.yohoufo.user.service.IRealNameAuthorizeService;
import lombok.Data;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -43,7 +45,6 @@ import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
... ... @@ -383,37 +384,61 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
}
//循环获取file数组中得文件
UploadModel frontUploadModel=null;
UploadModel backUploadModel=null;
ImageBO frontUploadModel=null;
ImageBO backUploadModel=null;
for (int i = 0; i < multipartFiles.length; i++) {
MultipartFile multipartFile = multipartFiles[i];
//保存文件
UploadModel uploadModel = getUploadImagePath(multipartFile, bucket, String.valueOf(reqVO.getUid()), limitType);
imgUrls.add(uploadModel.getImgUrl());
ImageBO tmpBO = getUploadImagePath(multipartFile, bucket, String.valueOf(reqVO.getUid()), limitType);
imgUrls.add(tmpBO.getImageUrl());
if(i==0){
frontUploadModel = uploadModel;
tmpBO.setImageSide("front");
frontUploadModel = tmpBO;
}else{
backUploadModel = uploadModel;
tmpBO.setImageSide("back");
backUploadModel = tmpBO;
}
}
//调用接口,ocr验证
boolean pass = checkCertPhoto(frontUploadModel ,backUploadModel ,reqVO);
boolean pass = checkCertPhoto(Lists.newArrayList(frontUploadModel ,backUploadModel) ,reqVO);
if(!pass){
throw new GatewayException(400, "身份证图片校验不通过!");
}
//删除图片
frontUploadModel.getUploadFile().delete();
backUploadModel.getUploadFile().delete();
return imgUrls;
}
@Data
static class UploadModel{
File uploadFile ;
String imgUrl;
/**
* 调用通用的图片验证ocr
* @param imageBOList
* @param reqVO
* @return
*/
private boolean checkCertPhoto(List<ImageBO> imageBOList,RealNameAuthorizeReqVO reqVO){
try{
ImageReviewedReq req=new ImageReviewedReq();
req.setUid(reqVO.getUid());
req.setImageBOList(imageBOList);
//调用校验,然后直接返回
logger.info("checkCertPhoto call begin reqVO {} ,req {}",reqVO, JSON.toJSONString(req));
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,"图片检查异常");
}finally {
//无论成功与否,都删除本地文件
imageBOList.forEach(bo->bo.getFile().delete());
}
return true;
}
public UploadModel getUploadImagePath(MultipartFile multipartFile, String bucket, String uid, Integer limitType) throws Exception {
public ImageBO getUploadImagePath(MultipartFile multipartFile, String bucket, String uid, Integer limitType) throws Exception {
//文件为空
if (multipartFile.isEmpty()) {
logger.warn("upload file is empty");
... ... @@ -457,9 +482,9 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
String imgUrl = iqnUploadService.upload(uploadFile, bucket, saveName + fileName);
UploadModel uploadModel = new UploadModel();
uploadModel.setUploadFile(uploadFile);
uploadModel.setImgUrl(imgUrl);
ImageBO uploadModel = new ImageBO();
uploadModel.setFile(uploadFile);
uploadModel.setImageUrl(imgUrl);
///// uploadFile.delete(); 暂时先不删除,等身份证校验完毕再删
return uploadModel;
}
... ... @@ -529,10 +554,6 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
return vo;
}
private boolean checkCertPhoto(UploadModel frontUploadModel,UploadModel backUploadModel,RealNameAuthorizeReqVO reqVO){
return true;
}
@Override
public AuthorizeResultRespVO zhiMaCertInit(RealNameAuthorizeReqVO reqVO) {
... ...