|
|
@@ -1,5 +1,6 @@
|
|
|
package me.zhengjie.domain.notary.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.arcsoft.face.*;
|
|
|
import com.arcsoft.face.enums.DetectMode;
|
|
|
import com.arcsoft.face.enums.DetectOrient;
|
|
|
@@ -9,10 +10,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import me.zhengjie.base.ResultCode;
|
|
|
-import me.zhengjie.base.file.FaceMinioFileHandle;
|
|
|
import me.zhengjie.base.file.FileHandleVo;
|
|
|
-import me.zhengjie.base.file.MinioFileHandle;
|
|
|
import me.zhengjie.base.util.JuheServiceUtil;
|
|
|
+import me.zhengjie.base.util.tencent.utils.HttpClientUtil;
|
|
|
import me.zhengjie.base.util.tencent.utils.Img2Base64Util;
|
|
|
import me.zhengjie.dao.mybatis.ThirdPartyInterfaceRepository;
|
|
|
import me.zhengjie.dao.mybatis.entity.*;
|
|
|
@@ -23,9 +23,9 @@ import me.zhengjie.dao.mybatis.mapper.UserAXQInfoMapper;
|
|
|
import me.zhengjie.domain.img.CompareImageDomain;
|
|
|
import me.zhengjie.domain.notary.NotaryDomain;
|
|
|
import me.zhengjie.utils.RedisUtils;
|
|
|
-import me.zhengjie.utils.StringUtils;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
@@ -43,7 +43,6 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
private final SysUserMapper userMapper;
|
|
|
private final UserAXQInfoMapper userAXQInfoMapper;
|
|
|
private final ContractOrderMapper contractOrderMapper;
|
|
|
- private final FaceMinioFileHandle minioFileHandle;
|
|
|
private final FileInfoMapper fileInfoMapper;
|
|
|
private final RedisUtils redis;
|
|
|
|
|
|
@@ -120,9 +119,7 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
log.info("base64转图片异常");
|
|
|
return ResultCode.FACEAUTH_FAIL;
|
|
|
}
|
|
|
- FileInfoEntity fileInfo = saveCompareImage(base);
|
|
|
- fileInfoMapper.insert(fileInfo);
|
|
|
-
|
|
|
+ FileInfoEntity fileInfo = uploadFile(base64);
|
|
|
boolean redisFlag = (count != null && count >= 2);
|
|
|
if (ObjectUtils.isEmpty(id) || redisFlag) {
|
|
|
//要做人脸核身
|
|
|
@@ -230,8 +227,7 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
//说明是客户经理
|
|
|
if (sysUserEntity.getCompareImgId() == null || redisFlag) {
|
|
|
//说明客户经理需要做人脸核身
|
|
|
- FileInfoEntity fileInfo = saveCompareImage(base);
|
|
|
- fileInfoMapper.insert(fileInfo);
|
|
|
+ FileInfoEntity fileInfo = uploadFile(base64);
|
|
|
ThirdPartyInterfaceEntity thirdPartyInterfaceEntity = JuheServiceUtil.URLPost(idCard, nickName, base64);
|
|
|
thirdPartyInterfaceEntity.setFileId(fileInfo.getId() + "");
|
|
|
thirdPartyInterfaceEntity.setBusinessNo(compareImageDomain.getBusinessNo());
|
|
|
@@ -252,8 +248,7 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
}
|
|
|
} else if (ObjectUtils.isEmpty(compareImageId) || redisFlag) {
|
|
|
//说明当事人需要做人脸核身
|
|
|
- FileInfoEntity fileInfo = saveCompareImage(base);
|
|
|
- fileInfoMapper.insert(fileInfo);
|
|
|
+ FileInfoEntity fileInfo = uploadFile(base64);
|
|
|
ThirdPartyInterfaceEntity thirdPartyInterfaceEntity = JuheServiceUtil.URLPost(idCard, nickName, base64);
|
|
|
thirdPartyInterfaceEntity.setFileId(fileInfo.getId() + "");
|
|
|
thirdPartyInterfaceEntity.setBusinessNo(compareImageDomain.getBusinessNo());
|
|
|
@@ -313,11 +308,13 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
//激活引擎
|
|
|
int errorCode = faceEngine.activeOnline(APPID, SDKKEY);
|
|
|
if (errorCode != ErrorInfo.MOK.getValue() && errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {
|
|
|
+ base.delete();
|
|
|
throw new RuntimeException("引擎激活失败");
|
|
|
}
|
|
|
ActiveFileInfo activeFileInfo = new ActiveFileInfo();
|
|
|
errorCode = faceEngine.getActiveFileInfo(activeFileInfo);
|
|
|
if (errorCode != ErrorInfo.MOK.getValue() && errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {
|
|
|
+ base.delete();
|
|
|
throw new RuntimeException("获取激活文件信息失败");
|
|
|
}
|
|
|
//引擎配置
|
|
|
@@ -339,6 +336,7 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
//初始化引擎
|
|
|
errorCode = faceEngine.init(engineConfiguration);
|
|
|
if (errorCode != ErrorInfo.MOK.getValue()) {
|
|
|
+ base.delete();
|
|
|
throw new RuntimeException("初始化引擎失败");
|
|
|
}
|
|
|
//人脸检测
|
|
|
@@ -360,6 +358,7 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
if (pitch > 10 || yaw > 10) {
|
|
|
//照片不符合标准
|
|
|
log.info("图片不符合标准");
|
|
|
+ base.delete();
|
|
|
return false;
|
|
|
}
|
|
|
//特征提取
|
|
|
@@ -372,9 +371,12 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
String filePath = fileInfoEntity.getPath();
|
|
|
File file = null;
|
|
|
try {
|
|
|
- file = minioFileHandle.getFileWithPath(filePath);
|
|
|
+ file = getFileWithPath(filePath);
|
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(e);
|
|
|
+ }finally {
|
|
|
+ base.delete();
|
|
|
+ file.delete();
|
|
|
}
|
|
|
//人脸检测2
|
|
|
ImageInfo imageInfo2 = getRGBData(file);
|
|
|
@@ -393,6 +395,8 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
//如果通过 上传文件 修改用户绑定id 如果没通过 返回null证明失败了
|
|
|
if (faceSimilar.getScore() > 0.8) {
|
|
|
log.info("人脸照片比对通过");
|
|
|
+ base.delete();
|
|
|
+ file.delete();
|
|
|
return true;
|
|
|
}
|
|
|
if (count == null) {
|
|
|
@@ -401,24 +405,50 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
redis.set(redisCount, count + 1, 30, TimeUnit.MINUTES);
|
|
|
}
|
|
|
log.info("人脸照片比对未通过");
|
|
|
- ;
|
|
|
+ base.delete();
|
|
|
+ file.delete();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- private FileInfoEntity saveCompareImage(File base) {
|
|
|
- FileHandleVo fileHandleVo = new FileHandleVo();
|
|
|
- fileHandleVo.setFilePath(base.getPath());
|
|
|
- fileHandleVo.setSourceFilePath("/face/" + base.getName());
|
|
|
- fileHandleVo.setContentType("image/jpeg");
|
|
|
- try {
|
|
|
- minioFileHandle.uploadfilePath(fileHandleVo);
|
|
|
- } catch (Exception e) {
|
|
|
- throw new RuntimeException("照片保存到minio异常");
|
|
|
- }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传对比照片到minio
|
|
|
+ * @param base64
|
|
|
+ */
|
|
|
+ public FileInfoEntity uploadFile(String base64){
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
+ params.put("base64", base64);
|
|
|
+ HttpClientUtil httpClientUtil = new HttpClientUtil();
|
|
|
+ String xmlData = httpClientUtil.doPost("http://192.168.0.140:8831/sp/upload/uploadFaceImage",params.toString(),"utf-8");
|
|
|
+ JSONObject result = JSONObject.parseObject(xmlData);
|
|
|
+ String s = result.getString("imagePath");
|
|
|
+ String[] split = s.split("/");
|
|
|
FileInfoEntity fileInfo = new FileInfoEntity();
|
|
|
- fileInfo.setLoanNo("face");
|
|
|
- fileInfo.setFileName(base.getName());
|
|
|
- fileInfo.setPath(fileInfo.getLoanNo() + "/" + base.getName());
|
|
|
+ fileInfo.setLoanNo(split[0]);
|
|
|
+ fileInfo.setFileName(split[split.length-1]);
|
|
|
+ fileInfo.setPath(s);
|
|
|
+ fileInfoMapper.insert(fileInfo);
|
|
|
return fileInfo;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取人脸照片比对的预览图
|
|
|
+ * @param fileKey
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+
|
|
|
+ /**
|
|
|
+ *根据路径获取文件
|
|
|
+ */
|
|
|
+ public File getFileWithPath(String fileKey){
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
+ params.put("fileKey", fileKey);
|
|
|
+ HttpClientUtil httpClientUtil = new HttpClientUtil();
|
|
|
+ String xmlData = httpClientUtil.doPost("http://192.168.0.140:8831/sp/upload/getFile",params.toString(),"utf-8");
|
|
|
+ System.err.println(xmlData);
|
|
|
+ JSONObject result = JSONObject.parseObject(xmlData);
|
|
|
+ File file = result.getObject("file", File.class);
|
|
|
+ return file;
|
|
|
+ }
|
|
|
+
|
|
|
}
|