...
|
...
|
@@ -9,8 +9,10 @@ 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.yoho.error.exception.ServiceException;
|
|
|
import com.yoho.tools.common.beans.ApiResponse;
|
|
|
import com.yoho.tools.common.service.IQNUploadService;
|
|
|
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
|
|
|
import com.yohoufo.common.exception.GatewayException;
|
|
|
import com.yohoufo.common.exception.UfoServiceException;
|
...
|
...
|
@@ -25,16 +27,28 @@ 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;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
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;
|
|
|
import java.time.ZoneOffset;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
...
|
...
|
@@ -58,6 +72,12 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
@Autowired
|
|
|
private HttpClient httpClient;
|
|
|
|
|
|
@Value("${file.saveDir}")
|
|
|
private String saveDir;
|
|
|
|
|
|
@Autowired
|
|
|
private IQNUploadService iqnUploadService;
|
|
|
|
|
|
@Value("${zhimacert.switch:true}")
|
|
|
private boolean zhiMaCertSwitch;
|
|
|
/* @Autowired
|
...
|
...
|
@@ -353,6 +373,123 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
System.out.println(getStringDate());
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public List<String> zhiMaCertUploadPhotoAndCheck(MultipartFile[] multipartFiles, String bucket, Integer limitType, RealNameAuthorizeReqVO reqVO) throws Exception{
|
|
|
List<String> imgUrls = new ArrayList<>();
|
|
|
//判断file数组不能为空并且长度大于0
|
|
|
if(multipartFiles==null||multipartFiles.length!=2){
|
|
|
throw new GatewayException(400, "请上传身份证正反面!");
|
|
|
}
|
|
|
|
|
|
//循环获取file数组中得文件
|
|
|
UploadModel frontUploadModel=null;
|
|
|
UploadModel 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());
|
|
|
if(i==0){
|
|
|
frontUploadModel = uploadModel;
|
|
|
}else{
|
|
|
backUploadModel = uploadModel;
|
|
|
}
|
|
|
}
|
|
|
//调用接口,ocr验证
|
|
|
boolean pass = checkCertPhoto(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;
|
|
|
}
|
|
|
|
|
|
public UploadModel getUploadImagePath(MultipartFile multipartFile, String bucket, String uid, Integer limitType) throws Exception {
|
|
|
//文件为空
|
|
|
if (multipartFile.isEmpty()) {
|
|
|
logger.warn("upload file is empty");
|
|
|
throw new FileNotFoundException("上传文件为空");
|
|
|
}
|
|
|
|
|
|
// bucket必须为系统已定义常量
|
|
|
if (!"yohocard".equals(bucket)) {
|
|
|
logger.warn("can't find upload bucket {}", bucket);
|
|
|
throw new Exception("上传Bucket:" + bucket + "无效");
|
|
|
}
|
|
|
|
|
|
String imageFileName = multipartFile.getOriginalFilename();
|
|
|
long imageFileSize = multipartFile.getSize();
|
|
|
//产品需求:百度云要求图片大小4M
|
|
|
boolean flag = StringUtils.contains(imageFileName, ".jpeg") ||
|
|
|
StringUtils.contains(imageFileName, ".jpg") || StringUtils.contains(imageFileName, ".png");
|
|
|
if(!flag){
|
|
|
logger.warn("upload file type not correct {}",imageFileName);
|
|
|
throw new FileNotFoundException("上传文件为空");
|
|
|
}
|
|
|
if (imageFileSize >= 4*1024*1024) {
|
|
|
logger.warn("upload images exceeded imageSize {}", imageFileSize);
|
|
|
DecimalFormat decimalFormat = new DecimalFormat("#.00");
|
|
|
throw new Exception("上传图片实际大小:" + decimalFormat.format(imageFileSize / 1024.0) + "KB,超过了图片默认值" );
|
|
|
}
|
|
|
|
|
|
String fileMode = "01";
|
|
|
logger.info("upload image bucket is {}, fileMode is {}", bucket, fileMode);
|
|
|
|
|
|
String saveName = new SimpleDateFormat("/yyyy/MM/dd/HH/").format(new Date());
|
|
|
String fileName = fileMode
|
|
|
+ DigestUtils.md5Hex(uid + "_" + System.currentTimeMillis() + multipartFile.getOriginalFilename())
|
|
|
+ multipartFile.getOriginalFilename().substring(multipartFile.getOriginalFilename().indexOf("."));
|
|
|
// 文件保存路径
|
|
|
String filePath = saveDir + File.separator + fileName;
|
|
|
File uploadFile = new File(filePath);
|
|
|
multipartFile.transferTo(uploadFile);
|
|
|
|
|
|
checkFilePixels(uploadFile, limitType);
|
|
|
|
|
|
String imgUrl = iqnUploadService.upload(uploadFile, bucket, saveName + fileName);
|
|
|
|
|
|
UploadModel uploadModel = new UploadModel();
|
|
|
uploadModel.setUploadFile(uploadFile);
|
|
|
uploadModel.setImgUrl(imgUrl);
|
|
|
///// uploadFile.delete(); 暂时先不删除,等身份证校验完毕再删
|
|
|
return uploadModel;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据配置,校验每种场景的图片是否符合规范
|
|
|
*
|
|
|
* @param uploadFile
|
|
|
* @param limitType
|
|
|
*/
|
|
|
private void checkFilePixels(File uploadFile, Integer limitType) throws Exception {
|
|
|
if (null == limitType) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
logger.info("method checkFilePixels exceute.");
|
|
|
|
|
|
BufferedImage sourceImg = null;
|
|
|
|
|
|
try {
|
|
|
sourceImg = ImageIO.read(java.nio.file.Files.newInputStream(uploadFile.toPath()));
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
logger.warn("ImageIO read find wrong uploadFile {}",uploadFile , e);
|
|
|
throw new GatewayException( 400,"上传文件失败");
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public AuthorizeResultRespVO zhiMaCertWithPhotoInit(RealNameAuthorizeReqVO reqVO){
|
|
|
logger.info("real name zhiMaCertWithPhotoInit reqVO {}", reqVO);
|
...
|
...
|
@@ -376,11 +513,6 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
|
|
|
logger.info("real name zhiMaCertWithPhotoInit reqVO {} ,justCheckPhoto {}", reqVO,justCheckPhoto);
|
|
|
|
|
|
boolean pass = checkCertPhoto(reqVO);
|
|
|
if(!pass){
|
|
|
throw new UfoServiceException(400, "身份证照片验证不通过!");
|
|
|
}
|
|
|
|
|
|
String imgUrl = reqVO.getFrontImageUrl()+","+reqVO.getBackImageUrl();
|
|
|
|
|
|
if(justCheckPhoto){
|
...
|
...
|
@@ -397,7 +529,8 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
return vo;
|
|
|
}
|
|
|
|
|
|
private boolean checkCertPhoto(RealNameAuthorizeReqVO reqVO){
|
|
|
private boolean checkCertPhoto(UploadModel frontUploadModel,UploadModel backUploadModel,RealNameAuthorizeReqVO reqVO){
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
...
|
...
|
|