|
|
@@ -7,12 +7,10 @@ import com.arcsoft.face.enums.ErrorInfo;
|
|
|
import com.arcsoft.face.toolkit.ImageInfo;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
-import me.zhengjie.application.bank.controller.vo.ImageUploadVO;
|
|
|
import me.zhengjie.base.ResultCode;
|
|
|
import me.zhengjie.base.file.FileHandleVo;
|
|
|
import me.zhengjie.base.file.MinioFileHandle;
|
|
|
import me.zhengjie.base.util.JuheServiceUtil;
|
|
|
-import me.zhengjie.base.util.UUIDGenerator;
|
|
|
import me.zhengjie.base.util.tencent.utils.Img2Base64Util;
|
|
|
import me.zhengjie.dao.mybatis.entity.FileInfoEntity;
|
|
|
import me.zhengjie.dao.mybatis.entity.SysUserEntity;
|
|
|
@@ -22,12 +20,15 @@ import me.zhengjie.dao.mybatis.mapper.SysUserMapper;
|
|
|
import me.zhengjie.dao.mybatis.mapper.UserAXQInfoMapper;
|
|
|
import me.zhengjie.domain.Jvhe.JuheDomain;
|
|
|
import me.zhengjie.domain.Jvhe.ResultDomain;
|
|
|
+import me.zhengjie.domain.img.CompareImageDomain;
|
|
|
import me.zhengjie.domain.notary.NotaryDomain;
|
|
|
import me.zhengjie.sign.converter.JsonObjectMapper;
|
|
|
import me.zhengjie.utils.RedisUtils;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
@@ -45,61 +46,151 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
private final UserAXQInfoMapper userAXQInfoMapper;
|
|
|
private final MinioFileHandle minioFileHandle;
|
|
|
private final FileInfoMapper fileInfoMapper;
|
|
|
-
|
|
|
private final RedisUtils redis;
|
|
|
-
|
|
|
- private static final String APPID = "H6Er8ksqAcKc7Dk4Yum9Rkz4g9Gm77ZXAEMgvenjkTQQ";
|
|
|
- private static final String SDKKEY = "Abd9D8xZQUqG8vDtU2a1tEkdfThkK1tZppjXzydGwEd6";
|
|
|
-
|
|
|
- private static final String LIBPATH = "/home/tom/nt/lib/so";
|
|
|
- private static final String JuHeURl = "http://apis.juhe.cn/verifyface/verify";
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ private static final String APPID = "6F5JVsCCeSEbBSLSXWVwPki71yK5Y4Jf7oUjA4Y3mLtu";
|
|
|
+ private static final String SDKKEY = "5qKM4a9oNSXNhXdwd7Ycrvnxdw2JXjcyeccYmb4zND7S";
|
|
|
+ private static final String LIBPATH = "/home/tom/nt-test/lib/so";
|
|
|
+ //private static final String LIBPATH = "D:\\arcsoft_lib";
|
|
|
|
|
|
/**
|
|
|
- * 银行客户经理的人脸比对
|
|
|
+ * 照片比对
|
|
|
*
|
|
|
- * @param imageUploadVO
|
|
|
- * @param sysUserEntity
|
|
|
+ * @param compareImageDomain
|
|
|
* @return
|
|
|
*/
|
|
|
- @Override
|
|
|
- public ResultCode compareBank(ImageUploadVO imageUploadVO, SysUserEntity sysUserEntity) {
|
|
|
- //判断是做人脸核身还是照片比对
|
|
|
- String bankRedis= "BANK:" + sysUserEntity.getUserId() + "COUNT:";
|
|
|
- Integer count=null;
|
|
|
- if (redis.hasKey(bankRedis)){
|
|
|
- count= (Integer) redis.get(bankRedis);
|
|
|
+ public ResultCode compareFace(CompareImageDomain compareImageDomain) {
|
|
|
+ String base64 = compareImageDomain.getBase64();
|
|
|
+ if (base64==null){
|
|
|
+ return ResultCode.PARAM_IS_BLANK;
|
|
|
+ }
|
|
|
+ String[] base64s = base64.split("base64");
|
|
|
+ if (base64s!=null && base64s.length>1){
|
|
|
+ base64 = base64s[1];
|
|
|
+ }
|
|
|
+ //先判断是银行客户经理还是当事人
|
|
|
+ String roleId = compareImageDomain.getRoleId();
|
|
|
+ SysUserEntity sysUserEntity = null;
|
|
|
+ UserAXQInfoEntity userAXQInfoEntity = null;
|
|
|
+ String idCard = compareImageDomain.getIdCard();
|
|
|
+ String nickName = compareImageDomain.getName();
|
|
|
+ boolean flag = "-1".equals(roleId);
|
|
|
+ if (flag) {
|
|
|
+ //说明是银行客户经理
|
|
|
+ QueryWrapper<SysUserEntity> sysUserEntityQueryWrapper = new QueryWrapper<>();
|
|
|
+ sysUserEntityQueryWrapper.eq("id_card", idCard).eq("nick_name", nickName);
|
|
|
+ sysUserEntity = userMapper.selectOne(sysUserEntityQueryWrapper);
|
|
|
+ } else {
|
|
|
+ //说明是当事人
|
|
|
+ QueryWrapper<UserAXQInfoEntity> userAXQInfoEntityQueryWrapper = new QueryWrapper<>();
|
|
|
+ userAXQInfoEntityQueryWrapper.eq("id_card", idCard).eq("user_name", nickName);
|
|
|
+ userAXQInfoEntity = userAXQInfoMapper.selectOne(userAXQInfoEntityQueryWrapper);
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isEmpty(sysUserEntity) && ObjectUtils.isEmpty(userAXQInfoEntity)) {
|
|
|
+ return ResultCode.PARAM_IS_INVALID;
|
|
|
+ }
|
|
|
+ //后面需要的三个参数 base64 身份证号 姓名
|
|
|
+ String redisCount = "idCard:" + idCard + ":COUNT:";
|
|
|
+ Integer count = null;
|
|
|
+ if (redis.hasKey(redisCount)) {
|
|
|
+ count = (Integer) redis.get(redisCount);
|
|
|
+ System.err.println("redis存入次数" + count);
|
|
|
+ }
|
|
|
+ //将base64转成图片
|
|
|
+ File base = null;
|
|
|
+ try {
|
|
|
+ base = File.createTempFile("compare", ".JPEG");
|
|
|
+ base.deleteOnExit();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
- //接收照片 判断
|
|
|
- File base = new File("/home/tom/nt/test/aaa.jpeg");
|
|
|
- if (!Img2Base64Util.generateImage(imageUploadVO.getBase64(), base.getPath())) {
|
|
|
+ if (!Img2Base64Util.generateImage(base64, base.getPath())) {
|
|
|
+ System.err.println("base64转图片异常");
|
|
|
return ResultCode.FACEAUTH_FAIL;
|
|
|
}
|
|
|
- boolean flag = (count!=null && count==2);
|
|
|
- if (sysUserEntity.getCompareImgId() == null || flag ) {
|
|
|
- //要做人脸核身
|
|
|
- Map<String, Object> params = new HashMap<>();
|
|
|
- params.put("idcard", sysUserEntity.getIdCard());
|
|
|
- params.put("realname", sysUserEntity.getNickName());
|
|
|
- params.put("image", imageUploadVO.getBase64());
|
|
|
- params.put("key", "6db21a71bee88af1eac38480c1574e2a");
|
|
|
- String json = JuheServiceUtil.URLPost(JuHeURl, params);
|
|
|
- ResultCode result = getResult(json);
|
|
|
- if (result.code()==100) {
|
|
|
- FileInfoEntity fileInfo = saveCompareImage(base);
|
|
|
- fileInfo.setStep(imageUploadVO.getStep());
|
|
|
- fileInfoMapper.insert(fileInfo);
|
|
|
- sysUserEntity.setCompareImgId(fileInfo.getId());
|
|
|
- userMapper.updateById(sysUserEntity);
|
|
|
- if (count != null){
|
|
|
- redis.del(bankRedis);
|
|
|
+ boolean redisFlag = (count != null && count >= 2);
|
|
|
+ if (flag) {
|
|
|
+ //说明是客户经理
|
|
|
+ if (sysUserEntity.getCompareImgId() == null || redisFlag) {
|
|
|
+ //说明客户经理需要做人脸核身
|
|
|
+ System.err.println(idCard+nickName);
|
|
|
+ if (JuheServiceUtil.URLPost(idCard, nickName, base64)) {
|
|
|
+ //上传图片到minio FileInfo
|
|
|
+ FileInfoEntity fileInfo = saveCompareImage(base);
|
|
|
+ fileInfoMapper.insert(fileInfo);
|
|
|
+ SysUserEntity bank = new SysUserEntity();
|
|
|
+ bank.setUserId(sysUserEntity.getUserId());
|
|
|
+ bank.setCompareImgId(fileInfo.getId());
|
|
|
+ userMapper.updateById(bank);
|
|
|
+ System.err.println("银行客户经理人脸核身通过");
|
|
|
+ redis.del(redisCount);
|
|
|
+ return ResultCode.SUCCESS;
|
|
|
}
|
|
|
- return ResultCode.SUCCESS;
|
|
|
+ System.err.println("人脸核身失败");
|
|
|
+ return ResultCode.LIVE_VIDEO_INVALID;
|
|
|
}
|
|
|
- return ResultCode.FACEAUTH_FAIL;
|
|
|
+ } else {
|
|
|
+ //说明是当事人
|
|
|
+ if (userAXQInfoEntity.getCompareImgId() == null || redisFlag) {
|
|
|
+ //说明当事人需要做人脸核身
|
|
|
+ if (JuheServiceUtil.URLPost(idCard, nickName, base64)) {
|
|
|
+ //上传图片到minio FileInfo
|
|
|
+ FileInfoEntity fileInfo = saveCompareImage(base);
|
|
|
+ fileInfoMapper.insert(fileInfo);
|
|
|
+ UserAXQInfoEntity userAxq = new UserAXQInfoEntity();
|
|
|
+ userAxq.setId(userAXQInfoEntity.getId());
|
|
|
+ userAxq.setCompareImgId(fileInfo.getId());
|
|
|
+ userAXQInfoMapper.updateById(userAxq);
|
|
|
+ System.err.println("当事人人脸核身通过");
|
|
|
+ redis.del(redisCount);
|
|
|
+ return ResultCode.SUCCESS;
|
|
|
+ }
|
|
|
+ System.err.println("人脸核身失败");
|
|
|
+ return ResultCode.LIVE_VIDEO_INVALID;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //如果不用做人脸核身 那么就去做照片比对
|
|
|
+ //获取比较图片的id
|
|
|
+ Integer id = null;
|
|
|
+ if (!ObjectUtils.isEmpty(sysUserEntity)) {
|
|
|
+ id = sysUserEntity.getCompareImgId();
|
|
|
+ }
|
|
|
+ if (!ObjectUtils.isEmpty(userAXQInfoEntity)) {
|
|
|
+ id = userAXQInfoEntity.getCompareImgId();
|
|
|
+ }
|
|
|
+ Integer fileId = compareImage(base, id,redisCount,count);
|
|
|
+ if (fileId == null) {
|
|
|
+ System.err.println("人脸比对失败");
|
|
|
+ return ResultCode.LIVE_VIDEO_INVALID;
|
|
|
+ }
|
|
|
+ if (!ObjectUtils.isEmpty(sysUserEntity)) {
|
|
|
+ SysUserEntity user = new SysUserEntity();
|
|
|
+ user.setUserId(sysUserEntity.getUserId());
|
|
|
+ user.setCompareImgId(fileId);
|
|
|
+ userMapper.updateById(user);
|
|
|
+ System.err.println("客户经理认证成功");
|
|
|
+ }
|
|
|
+ if (!ObjectUtils.isEmpty(userAXQInfoEntity)) {
|
|
|
+ UserAXQInfoEntity user = new UserAXQInfoEntity();
|
|
|
+ user.setId(userAXQInfoEntity.getId());
|
|
|
+ user.setCompareImgId(fileId);
|
|
|
+ userAXQInfoMapper.updateById(user);
|
|
|
+ System.err.println("当事人认证成功");
|
|
|
}
|
|
|
+ if (count != null) {
|
|
|
+ redis.del(redisCount);
|
|
|
+ }
|
|
|
+ return ResultCode.SUCCESS;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 虹软的人脸照片比对
|
|
|
+ * @param base 照片
|
|
|
+ * @param id 文件库中照片的id
|
|
|
+ * @param redisCount 数据库中的键
|
|
|
+ * @param count redis当中的次数
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Integer compareImage(File base, Integer id,String redisCount,Integer count) {
|
|
|
//从官网获取
|
|
|
FaceEngine faceEngine = new FaceEngine(LIBPATH);
|
|
|
//激活引擎
|
|
|
@@ -151,14 +242,15 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
float yaw = Math.abs(face3DAngleList.get(0).getYaw());
|
|
|
if (pitch > 10 || yaw > 10) {
|
|
|
//照片不符合标准
|
|
|
- return ResultCode.DATA_UPDATE_ERROR;
|
|
|
+ System.err.println("图片不符合标准");
|
|
|
+ return null;
|
|
|
}
|
|
|
//特征提取
|
|
|
FaceFeature faceFeature = new FaceFeature();
|
|
|
errorCode = faceEngine.extractFaceFeature(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList.get(0), faceFeature);
|
|
|
//根据id 查找文件
|
|
|
QueryWrapper<FileInfoEntity> fileInfoQw = new QueryWrapper<>();
|
|
|
- fileInfoQw.eq("id", sysUserEntity.getCompareImgId());
|
|
|
+ fileInfoQw.eq("id", id);
|
|
|
FileInfoEntity fileInfoEntity = fileInfoMapper.selectOne(fileInfoQw);
|
|
|
String filePath = fileInfoEntity.getPath();
|
|
|
File file = null;
|
|
|
@@ -181,187 +273,27 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
sourceFaceFeature.setFeatureData(faceFeature2.getFeatureData());
|
|
|
FaceSimilar faceSimilar = new FaceSimilar();
|
|
|
errorCode = faceEngine.compareFaceFeature(targetFaceFeature, sourceFaceFeature, faceSimilar);
|
|
|
- //如果通过 上传文件 修改用户绑定id 如果没通过 返回失败 次数加1
|
|
|
+ //如果通过 上传文件 修改用户绑定id 如果没通过 返回null证明失败了
|
|
|
if (faceSimilar.getScore() > 0.8) {
|
|
|
FileInfoEntity fileInfo = saveCompareImage(base);
|
|
|
- fileInfo.setStep(imageUploadVO.getStep());
|
|
|
fileInfoMapper.insert(fileInfo);
|
|
|
- sysUserEntity.setCompareImgId(fileInfo.getId());
|
|
|
- userMapper.updateById(sysUserEntity);
|
|
|
- if (count != null){
|
|
|
- redis.del(bankRedis);
|
|
|
- }
|
|
|
- return ResultCode.SUCCESS;
|
|
|
+ return fileInfo.getId();
|
|
|
+ }else {
|
|
|
+ System.out.println("特征值不符合");
|
|
|
}
|
|
|
if (count == null) {
|
|
|
- redis.set(bankRedis, 1, 30, TimeUnit.MINUTES);
|
|
|
- } else {
|
|
|
- redis.set(bankRedis, count + 1, 30, TimeUnit.MINUTES);
|
|
|
- }
|
|
|
- return ResultCode.FACEAUTH_FAIL;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 当事人的人脸比对
|
|
|
- *
|
|
|
- * @param imageUploadVO
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public ResultCode compareParty(ImageUploadVO imageUploadVO) {
|
|
|
- String idCard = imageUploadVO.getIdCard();
|
|
|
- String partyRedis = "PARTY:" + idCard + "COUNT:";
|
|
|
- Integer count=null;
|
|
|
- if (redis.hasKey(partyRedis)){
|
|
|
- count= (Integer) redis.get(partyRedis);
|
|
|
- }
|
|
|
- //通过身份证号得到当事人
|
|
|
- QueryWrapper<UserAXQInfoEntity> userQueryWrapper = new QueryWrapper<>();
|
|
|
- userQueryWrapper.eq("id_card", idCard);
|
|
|
- UserAXQInfoEntity userAXQInfoEntity = userAXQInfoMapper.selectOne(userQueryWrapper);
|
|
|
- //接收照片 判断
|
|
|
- File base = new File("/home/tom/nt/test/aaa.jpeg");
|
|
|
- if (!Img2Base64Util.generateImage(imageUploadVO.getBase64(), base.getPath())) {
|
|
|
- System.err.println("接受文件转换失败");
|
|
|
- return ResultCode.FACEAUTH_FAIL;
|
|
|
- }
|
|
|
- boolean flag = (count!=null && count ==2);
|
|
|
- if (userAXQInfoEntity.getCompareImgId() == null || flag) {
|
|
|
- //要做人脸核身
|
|
|
- Map<String, Object> params = new HashMap<>();
|
|
|
- params.put("idcard", imageUploadVO.getIdCard());
|
|
|
- params.put("realname", userAXQInfoEntity.getUserName());
|
|
|
- params.put("image", imageUploadVO.getBase64());
|
|
|
- params.put("key", "6db21a71bee88af1eac38480c1574e2a");
|
|
|
- String json = JuheServiceUtil.URLPost(JuHeURl, params);
|
|
|
- ResultCode result = getResult(json);
|
|
|
- if (result.code()==100) {
|
|
|
- //人脸核身成功 把对应的照片保存下来
|
|
|
- FileInfoEntity fileInfo = saveCompareImage(base);
|
|
|
- fileInfo.setStep(imageUploadVO.getStep());
|
|
|
- fileInfoMapper.insert(fileInfo);
|
|
|
- userAXQInfoEntity.setCompareImgId(fileInfo.getId());
|
|
|
- userAXQInfoMapper.updateById(userAXQInfoEntity);
|
|
|
- redis.del(partyRedis);
|
|
|
- //人脸核身成功
|
|
|
- return ResultCode.SUCCESS;
|
|
|
- }
|
|
|
- return ResultCode.FACEAUTH_FAIL;
|
|
|
+ redis.set(redisCount, 1, 30, TimeUnit.MINUTES);
|
|
|
} else {
|
|
|
- //从官网获取
|
|
|
- FaceEngine faceEngine = new FaceEngine(LIBPATH);
|
|
|
- //激活引擎
|
|
|
- int errorCode = faceEngine.activeOnline(APPID, SDKKEY);
|
|
|
- if (errorCode != ErrorInfo.MOK.getValue() && errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {
|
|
|
- System.out.println("引擎激活失败");
|
|
|
- }
|
|
|
- ActiveFileInfo activeFileInfo = new ActiveFileInfo();
|
|
|
- errorCode = faceEngine.getActiveFileInfo(activeFileInfo);
|
|
|
- if (errorCode != ErrorInfo.MOK.getValue() && errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {
|
|
|
- System.out.println("获取激活文件信息失败");
|
|
|
- }
|
|
|
- //引擎配置
|
|
|
- EngineConfiguration engineConfiguration = new EngineConfiguration();
|
|
|
- engineConfiguration.setDetectMode(DetectMode.ASF_DETECT_MODE_IMAGE);
|
|
|
- engineConfiguration.setDetectFaceOrientPriority(DetectOrient.ASF_OP_ALL_OUT);
|
|
|
- engineConfiguration.setDetectFaceMaxNum(10);
|
|
|
- engineConfiguration.setDetectFaceScaleVal(16);
|
|
|
- //功能配置
|
|
|
- FunctionConfiguration functionConfiguration = new FunctionConfiguration();
|
|
|
- functionConfiguration.setSupportAge(true);
|
|
|
- functionConfiguration.setSupportFace3dAngle(true);
|
|
|
- functionConfiguration.setSupportFaceDetect(true);
|
|
|
- functionConfiguration.setSupportFaceRecognition(true);
|
|
|
- functionConfiguration.setSupportGender(true);
|
|
|
- functionConfiguration.setSupportLiveness(true);
|
|
|
- functionConfiguration.setSupportIRLiveness(true);
|
|
|
- engineConfiguration.setFunctionConfiguration(functionConfiguration);
|
|
|
- //初始化引擎
|
|
|
- errorCode = faceEngine.init(engineConfiguration);
|
|
|
- if (errorCode != ErrorInfo.MOK.getValue()) {
|
|
|
- System.out.println("初始化引擎失败");
|
|
|
- }
|
|
|
- //人脸检测
|
|
|
- ImageInfo imageInfo = getRGBData(base);
|
|
|
- List<FaceInfo> faceInfoList = new ArrayList<FaceInfo>();
|
|
|
- errorCode = faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList);
|
|
|
- System.out.println(faceInfoList);
|
|
|
- //人脸属性检测
|
|
|
- FunctionConfiguration configuration = new FunctionConfiguration();
|
|
|
- configuration.setSupportFace3dAngle(true);
|
|
|
- errorCode = faceEngine.process(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList, configuration);
|
|
|
- //3D信息检测
|
|
|
- List<Face3DAngle> face3DAngleList = new ArrayList<Face3DAngle>();
|
|
|
- errorCode = faceEngine.getFace3DAngle(face3DAngleList);
|
|
|
- //俯仰角
|
|
|
- float pitch = Math.abs(face3DAngleList.get(0).getPitch());
|
|
|
- //偏向角
|
|
|
- float yaw = Math.abs(face3DAngleList.get(0).getYaw());
|
|
|
- if (pitch > 10 || yaw > 10) {
|
|
|
- //照片不符合标准
|
|
|
- return ResultCode.DATA_UPDATE_ERROR;
|
|
|
- }
|
|
|
- //要做照片认证
|
|
|
- //获取这个图片的特征
|
|
|
- //特征提取
|
|
|
- FaceFeature faceFeature = new FaceFeature();
|
|
|
- errorCode = faceEngine.extractFaceFeature(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList.get(0), faceFeature);
|
|
|
- //根据id查询到用户保存的照片
|
|
|
- QueryWrapper<FileInfoEntity> fileInfoQw = new QueryWrapper<>();
|
|
|
- fileInfoQw.eq("id", userAXQInfoEntity.getCompareImgId());
|
|
|
- FileInfoEntity fileInfoEntity = fileInfoMapper.selectOne(fileInfoQw);
|
|
|
- String filePath = fileInfoEntity.getPath();
|
|
|
- File file = null;
|
|
|
- try {
|
|
|
- file = minioFileHandle.getFileWithPath(filePath);
|
|
|
- } catch (Exception e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- //人脸检测2
|
|
|
- ImageInfo imageInfo2 = getRGBData(file);
|
|
|
- List<FaceInfo> faceInfoList2 = new ArrayList<FaceInfo>();
|
|
|
- errorCode = faceEngine.detectFaces(imageInfo2.getImageData(), imageInfo2.getWidth(), imageInfo2.getHeight(), imageInfo2.getImageFormat(), faceInfoList2);
|
|
|
- System.out.println(faceInfoList2);
|
|
|
- //特征提取2
|
|
|
- FaceFeature faceFeature2 = new FaceFeature();
|
|
|
- errorCode = faceEngine.extractFaceFeature(imageInfo2.getImageData(), imageInfo2.getWidth(), imageInfo2.getHeight(), imageInfo2.getImageFormat(), faceInfoList2.get(0), faceFeature2);
|
|
|
- System.out.println("特征值大小:" + faceFeature2.getFeatureData().length);
|
|
|
- //特征比对
|
|
|
- FaceFeature targetFaceFeature = new FaceFeature();
|
|
|
- targetFaceFeature.setFeatureData(faceFeature.getFeatureData());
|
|
|
- FaceFeature sourceFaceFeature = new FaceFeature();
|
|
|
- sourceFaceFeature.setFeatureData(faceFeature2.getFeatureData());
|
|
|
- FaceSimilar faceSimilar = new FaceSimilar();
|
|
|
- errorCode = faceEngine.compareFaceFeature(targetFaceFeature, sourceFaceFeature, faceSimilar);
|
|
|
- System.out.println("相似度:" + faceSimilar.getScore());
|
|
|
- //如果通过 上传文件 修改用户绑定id 如果没通过 返回失败 次数加1
|
|
|
- if (faceSimilar.getScore() > 0.8) {
|
|
|
- //人脸核身成功 把对应的照片保存下来
|
|
|
- FileInfoEntity fileInfo = saveCompareImage(base);
|
|
|
- fileInfo.setStep(imageUploadVO.getStep());
|
|
|
- fileInfoMapper.insert(fileInfo);
|
|
|
- userAXQInfoEntity.setCompareImgId(fileInfo.getId());
|
|
|
- userAXQInfoMapper.updateById(userAXQInfoEntity);
|
|
|
- redis.del(partyRedis);
|
|
|
- base.delete();
|
|
|
- file.delete();
|
|
|
- return ResultCode.SUCCESS;
|
|
|
- }
|
|
|
- base.delete();
|
|
|
- file.delete();
|
|
|
- if (count == null) {
|
|
|
- redis.set(partyRedis, 1, 30, TimeUnit.MINUTES);
|
|
|
- } else {
|
|
|
- redis.set(partyRedis, count + 1, 30, TimeUnit.MINUTES);
|
|
|
- }
|
|
|
- return ResultCode.FACEAUTH_FAIL;
|
|
|
+ redis.set(redisCount, count + 1, 30, TimeUnit.MINUTES);
|
|
|
}
|
|
|
+ System.err.println("人脸照片比对未通过");
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
private FileInfoEntity saveCompareImage(File base) {
|
|
|
FileHandleVo fileHandleVo = new FileHandleVo();
|
|
|
fileHandleVo.setFilePath(base.getPath());
|
|
|
- fileHandleVo.setSourceFilePath("/compareImage/" + UUIDGenerator.uuid() +".jpeg");
|
|
|
+ fileHandleVo.setSourceFilePath("/compareImage/" + base.getName());
|
|
|
fileHandleVo.setContentType("JPEG");
|
|
|
try {
|
|
|
minioFileHandle.uploadfilePath(fileHandleVo);
|
|
|
@@ -370,42 +302,8 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
}
|
|
|
FileInfoEntity fileInfo = new FileInfoEntity();
|
|
|
fileInfo.setLoanNo("compareImage");
|
|
|
- fileInfo.setFileName(fileHandleVo.getSourceFilePath().replace("/compareImage/",""));
|
|
|
- fileInfo.setPath(fileHandleVo.getSourceFilePath().replaceFirst("/",""));
|
|
|
- fileInfo.setFileType("7");
|
|
|
+ fileInfo.setFileName(base.getName());
|
|
|
+ fileInfo.setPath(fileInfo.getLoanNo() + "/" + base.getName());
|
|
|
return fileInfo;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- public ResultCode getResult(String json) {
|
|
|
- //将人脸核身的结果返回
|
|
|
- JsonObjectMapper jsonObjectMapper = new JsonObjectMapper();
|
|
|
- JuheDomain juheEntity = jsonObjectMapper.readValue(json, JuheDomain.class);
|
|
|
- ResultDomain result = juheEntity.getResult();
|
|
|
- if (result.getRes() == 1) {
|
|
|
- BigDecimal bigDecimal = new BigDecimal(85.0);
|
|
|
- if (result.getScore().compareTo(bigDecimal) == 1 || result.getScore().compareTo(bigDecimal) == 0) {
|
|
|
- return ResultCode.SUCCESS;
|
|
|
- }
|
|
|
- return ResultCode.FACEAUTH_FAIL;
|
|
|
- }
|
|
|
- if (result.getRes() == 2) {
|
|
|
- String code = result.getCode();
|
|
|
- if ("3003".equals(code)) {
|
|
|
- //TODO 响应码
|
|
|
- //人脸库中的照片检测不到人脸
|
|
|
- }
|
|
|
- if ("3004".equals(code)) {
|
|
|
- //用户上传的照片检测不到人脸
|
|
|
- }
|
|
|
- if ("3005".equals(code)) {
|
|
|
- //人脸比对失败
|
|
|
- }
|
|
|
- }
|
|
|
- if (result.getRes() == 3) {
|
|
|
- //身份证和姓名不匹配
|
|
|
- return ResultCode.LIVE_VIDEO_INVALID;
|
|
|
- }
|
|
|
- return ResultCode.FACEAUTH_FAIL;
|
|
|
- }
|
|
|
}
|