|
|
@@ -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,29 +10,30 @@ 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.config.thread.ThreadPoolExecutorUtil;
|
|
|
+import me.zhengjie.base.util.FileUploadUtil;
|
|
|
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.FaceCompareRepository;
|
|
|
import me.zhengjie.dao.mybatis.entity.*;
|
|
|
import me.zhengjie.dao.mybatis.mapper.ContractOrderMapper;
|
|
|
import me.zhengjie.dao.mybatis.mapper.FileInfoMapper;
|
|
|
import me.zhengjie.dao.mybatis.mapper.SysUserMapper;
|
|
|
-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.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
|
|
import static com.arcsoft.face.toolkit.ImageFactory.getRGBData;
|
|
|
|
|
|
@@ -41,63 +43,70 @@ import static com.arcsoft.face.toolkit.ImageFactory.getRGBData;
|
|
|
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;
|
|
|
-
|
|
|
- private final ThirdPartyInterfaceRepository thirdPartyInterfaceRepository;
|
|
|
-
|
|
|
+ private final FaceCompareRepository thirdPartyInterfaceRepository;
|
|
|
//以下为测试部署环境
|
|
|
- private static final String APPID = "6F5JVsCCeSEbBSLSXWVwPki71yK5Y4Jf7oUjA4Y3mLtu";
|
|
|
- private static final String SDKKEY = "5qKM4a9oNSXNhXdwd7Ycrvnxdw2JXjcyeccYmb4zND7S";
|
|
|
- private static final String LIBPATH = "/home/tom/nt-test/lib/so";
|
|
|
+ @Value("${hongruan.appid}")
|
|
|
+ private String appid;
|
|
|
+ @Value("${hongruan.sdkkey}")
|
|
|
+ private String sdkkey;
|
|
|
+ @Value("${hongruan.libpath}")
|
|
|
+ private String libpath;
|
|
|
+
|
|
|
|
|
|
- //以下为本地测试
|
|
|
-/* private static final String APPID = "H6Er8ksqAcKc7Dk4Yum9Rkz4g9Gm77ZXAEMgvenjkTQQ";
|
|
|
- private static final String SDKKEY = "Abd9D8xZQUqG8vDtU2a1tEkdfThkK1tZppjXzydGwEd6";
|
|
|
- private static final String LIBPATH = "D:\\arcsoft_lib";*/
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取base64取消文件头
|
|
|
+ *
|
|
|
* @param base64
|
|
|
* @return
|
|
|
*/
|
|
|
- public String getBase64(String base64){
|
|
|
+ public String getBase64(String base64) {
|
|
|
String[] base64s = base64.split("base64");
|
|
|
- if (base64s!=null && base64s.length>1){
|
|
|
+ if (base64s != null && base64s.length > 1) {
|
|
|
base64 = base64s[1];
|
|
|
}
|
|
|
return base64;
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* app端的人脸核身
|
|
|
+ *
|
|
|
* @param compareImageDomain
|
|
|
* @return
|
|
|
*/
|
|
|
- public ResultCode appCompareFace(CompareImageDomain compareImageDomain){
|
|
|
+ public ResultCode appCompareFace(CompareImageDomain compareImageDomain) {
|
|
|
String base64 = compareImageDomain.getBase64();
|
|
|
- if (base64==null){
|
|
|
+ if (base64 == null) {
|
|
|
return ResultCode.PARAM_IS_BLANK;
|
|
|
}
|
|
|
base64 = getBase64(base64);
|
|
|
String idCard = compareImageDomain.getIdCard();
|
|
|
String nickName = compareImageDomain.getName();
|
|
|
- //当事人的人脸核身
|
|
|
- QueryWrapper<UserAXQInfoEntity> userAXQInfoEntityQueryWrapper = new QueryWrapper<>();
|
|
|
- userAXQInfoEntityQueryWrapper.eq("id_card",idCard).eq("nick_name",nickName);
|
|
|
- UserAXQInfoEntity userAXQInfoEntity = userAXQInfoMapper.selectOne(userAXQInfoEntityQueryWrapper);
|
|
|
- if (ObjectUtils.isEmpty(userAXQInfoEntity)){
|
|
|
- return ResultCode.PARAM_IS_INVALID;
|
|
|
+ //根据业务编号获取订单 判断当事人名字
|
|
|
+ String businessNo = compareImageDomain.getBusinessNo();
|
|
|
+ QueryWrapper<ContractOrderEntity> contractOrderEntityQueryWrapper = new QueryWrapper<>();
|
|
|
+ contractOrderEntityQueryWrapper.eq("business_no", businessNo);
|
|
|
+ ContractOrderEntity contractOrderEntity = contractOrderMapper.selectOne(contractOrderEntityQueryWrapper);
|
|
|
+ Integer id = null;
|
|
|
+ //看是哪个当事人
|
|
|
+ if (nickName.equals(contractOrderEntity.getName())) {
|
|
|
+ id = contractOrderEntity.getCompareImgId();
|
|
|
+ } else if (nickName.equals(contractOrderEntity.getJointName())) {
|
|
|
+ id = contractOrderEntity.getJointCompareImgId();
|
|
|
+ }
|
|
|
+ //后面需要的三个参数 base64 身份证号 姓名
|
|
|
+ String redisCount = "idCard:" + idCard + ":COUNT:";
|
|
|
+ Integer count = null;
|
|
|
+ if (redis.hasKey(redisCount)) {
|
|
|
+ count = (Integer) redis.get(redisCount);
|
|
|
+ System.err.println("redis存入次数" + count);
|
|
|
}
|
|
|
- //做过安心签的用户 直接人脸核身 保存图片
|
|
|
|
|
|
- ThirdPartyInterfaceEntity thirdPartyInterfaceEntity = JuheServiceUtil.URLPost(idCard, nickName, base64);
|
|
|
File base = null;
|
|
|
try {
|
|
|
base = File.createTempFile("compare", ".jpeg");
|
|
|
@@ -110,21 +119,51 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
return ResultCode.FACEAUTH_FAIL;
|
|
|
}
|
|
|
|
|
|
- FileInfoEntity fileInfo = saveCompareImage(base);
|
|
|
- fileInfoMapper.insert(fileInfo);
|
|
|
- thirdPartyInterfaceEntity.setFileId(fileInfo.getId()+"");
|
|
|
- thirdPartyInterfaceEntity.setBusinessNo(compareImageDomain.getBusinessNo());
|
|
|
- if (thirdPartyInterfaceEntity.getResult()==1){
|
|
|
- UserAXQInfoEntity userAxq = new UserAXQInfoEntity();
|
|
|
- userAxq.setId(userAXQInfoEntity.getId());
|
|
|
- userAxq.setCompareImgId(fileInfo.getId());
|
|
|
- userAXQInfoMapper.updateById(userAxq);
|
|
|
- log.info("当事人人脸核身通过");
|
|
|
+
|
|
|
+ FileInfoEntity fileInfo = uploadFaceFile(base64);
|
|
|
+ boolean redisFlag = (count != null && count >= 2);
|
|
|
+ if (ObjectUtils.isEmpty(id) || redisFlag) {
|
|
|
+ if (! imageCenter(base)){
|
|
|
+ return ResultCode.IMAGE_NOT_STANDARD;
|
|
|
+ }
|
|
|
+ //要做人脸核身
|
|
|
+ FaceCompareEntity thirdPartyInterfaceEntity = JuheServiceUtil.URLPost(idCard, nickName, base64);
|
|
|
+ thirdPartyInterfaceEntity.setFileId(fileInfo.getId() + "");
|
|
|
+ thirdPartyInterfaceEntity.setBusinessNo(compareImageDomain.getBusinessNo());
|
|
|
+ thirdPartyInterfaceEntity.setConsultNo(contractOrderEntity.getConsultNo());
|
|
|
thirdPartyInterfaceRepository.insert(thirdPartyInterfaceEntity);
|
|
|
- return ResultCode.SUCCESS;
|
|
|
+ if (thirdPartyInterfaceEntity.getResult() == 1) {
|
|
|
+ ContractOrderEntity orderEntity = new ContractOrderEntity();
|
|
|
+ orderEntity.setId(contractOrderEntity.getId());
|
|
|
+ //判断是共同责任人还是当事人
|
|
|
+ if (nickName.equals(contractOrderEntity.getName())) {
|
|
|
+ orderEntity.setCompareImgId(fileInfo.getId());
|
|
|
+ }
|
|
|
+ if (nickName.equals(contractOrderEntity.getJointName())) {
|
|
|
+ orderEntity.setJointCompareImgId(fileInfo.getId());
|
|
|
+ }
|
|
|
+ contractOrderMapper.updateById(orderEntity);
|
|
|
+ log.info("当事人人脸核身通过");
|
|
|
+ redis.del(redisCount);
|
|
|
+ return ResultCode.SUCCESS;
|
|
|
+ }
|
|
|
+ return ResultCode.LIVE_VIDEO_INVALID;
|
|
|
}
|
|
|
- thirdPartyInterfaceRepository.insert(thirdPartyInterfaceEntity);
|
|
|
- return ResultCode.LIVE_VIDEO_INVALID;
|
|
|
+ //要做照片比对
|
|
|
+ /*if (!compareImage(base, id, redisCount, count)) {
|
|
|
+ return ResultCode.LIVE_VIDEO_INVALID;
|
|
|
+ }*/
|
|
|
+
|
|
|
+ ResultCode resultCode = compareImage(base, id, redisCount, count);
|
|
|
+
|
|
|
+ if (resultCode.code()==100){
|
|
|
+ if (count != null) {
|
|
|
+ redis.del(redisCount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return resultCode;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -136,23 +175,31 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
*/
|
|
|
public ResultCode compareFace(CompareImageDomain compareImageDomain) {
|
|
|
String base64 = compareImageDomain.getBase64();
|
|
|
- if (base64==null){
|
|
|
+ if (base64 == null) {
|
|
|
return ResultCode.PARAM_IS_BLANK;
|
|
|
}
|
|
|
base64 = getBase64(base64);
|
|
|
//先判断是银行客户经理还是当事人
|
|
|
String roleId = compareImageDomain.getRoleId();
|
|
|
SysUserEntity sysUserEntity = null;
|
|
|
- UserAXQInfoEntity userAXQInfoEntity = null;
|
|
|
String idCard = compareImageDomain.getIdCard();
|
|
|
String nickName = compareImageDomain.getName();
|
|
|
+
|
|
|
+ QueryWrapper<ContractOrderEntity> orderEntityQueryWrapper = new QueryWrapper<>();
|
|
|
+ orderEntityQueryWrapper.eq("business_no", compareImageDomain.getBusinessNo());
|
|
|
+ ContractOrderEntity contractOrder = contractOrderMapper.selectOne(orderEntityQueryWrapper);
|
|
|
+ if (ObjectUtils.isEmpty(contractOrder)) {
|
|
|
+ return ResultCode.PARAM_IS_INVALID;
|
|
|
+ }
|
|
|
+ Integer compareImageId = null;
|
|
|
boolean flag = "-1".equals(roleId);
|
|
|
if (flag) {
|
|
|
//说明是银行客户经理
|
|
|
QueryWrapper<ContractOrderEntity> contractOrderEntityQueryWrapper = new QueryWrapper<>();
|
|
|
- contractOrderEntityQueryWrapper.eq("business_no",compareImageDomain.getBusinessNo()).eq("customer_name",compareImageDomain.getName());
|
|
|
+ //通过business_no 和 客户经理姓名 判断是不是当前客户经理
|
|
|
+ contractOrderEntityQueryWrapper.eq("business_no", compareImageDomain.getBusinessNo()).eq("customer_name", compareImageDomain.getName());
|
|
|
ContractOrderEntity contractOrderEntity = contractOrderMapper.selectOne(contractOrderEntityQueryWrapper);
|
|
|
- if (ObjectUtils.isEmpty(contractOrderEntity)){
|
|
|
+ if (ObjectUtils.isEmpty(contractOrderEntity)) {
|
|
|
return ResultCode.ACCOUNT_MANAGER_NO_ASSIGNED;
|
|
|
}
|
|
|
QueryWrapper<SysUserEntity> sysUserEntityQueryWrapper = new QueryWrapper<>();
|
|
|
@@ -160,13 +207,13 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
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;
|
|
|
+ if (nickName.equals(contractOrder.getName())) {
|
|
|
+ compareImageId = contractOrder.getCompareImgId();
|
|
|
+ } else if (nickName.equals(contractOrder.getJointName())) {
|
|
|
+ compareImageId = contractOrder.getJointCompareImgId();
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
//后面需要的三个参数 base64 身份证号 姓名
|
|
|
String redisCount = "idCard:" + idCard + ":COUNT:";
|
|
|
Integer count = null;
|
|
|
@@ -174,8 +221,10 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
count = (Integer) redis.get(redisCount);
|
|
|
System.err.println("redis存入次数" + count);
|
|
|
}
|
|
|
- //将base64转成图片
|
|
|
- File base = null;
|
|
|
+ if (compareImageDomain.getBase64()==null){
|
|
|
+ return ResultCode.PARAM_IS_BLANK;
|
|
|
+ }
|
|
|
+ File base = null;
|
|
|
try {
|
|
|
base = File.createTempFile("compare", ".jpeg");
|
|
|
base.deleteOnExit();
|
|
|
@@ -186,18 +235,20 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
log.info("base64转图片异常");
|
|
|
return ResultCode.FACEAUTH_FAIL;
|
|
|
}
|
|
|
- FileInfoEntity fileInfo = saveCompareImage(base);
|
|
|
- fileInfoMapper.insert(fileInfo);
|
|
|
-
|
|
|
boolean redisFlag = (count != null && count >= 2);
|
|
|
if (flag) {
|
|
|
//说明是客户经理
|
|
|
if (sysUserEntity.getCompareImgId() == null || redisFlag) {
|
|
|
+ if (! imageCenter(base)){
|
|
|
+ return ResultCode.IMAGE_NOT_STANDARD;
|
|
|
+ }
|
|
|
//说明客户经理需要做人脸核身
|
|
|
- ThirdPartyInterfaceEntity thirdPartyInterfaceEntity = JuheServiceUtil.URLPost(idCard, nickName, base64);
|
|
|
- thirdPartyInterfaceEntity.setFileId(fileInfo.getId()+"");
|
|
|
+ FileInfoEntity fileInfo = uploadFaceFile(base64);
|
|
|
+ FaceCompareEntity thirdPartyInterfaceEntity = JuheServiceUtil.URLPost(idCard, nickName, base64);
|
|
|
+ thirdPartyInterfaceEntity.setFileId(fileInfo.getId() + "");
|
|
|
+ thirdPartyInterfaceEntity.setConsultNo(contractOrder.getConsultNo());
|
|
|
thirdPartyInterfaceEntity.setBusinessNo(compareImageDomain.getBusinessNo());
|
|
|
- if (StringUtils.isNotBlank(thirdPartyInterfaceEntity.getMessage())){
|
|
|
+ if (thirdPartyInterfaceEntity.getResult() == 1) {
|
|
|
//上传图片到minio FileInfo
|
|
|
SysUserEntity bank = new SysUserEntity();
|
|
|
bank.setUserId(sysUserEntity.getUserId());
|
|
|
@@ -212,28 +263,36 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
thirdPartyInterfaceRepository.insert(thirdPartyInterfaceEntity);
|
|
|
return ResultCode.LIVE_VIDEO_INVALID;
|
|
|
}
|
|
|
- } else {
|
|
|
- //说明是当事人
|
|
|
- if (userAXQInfoEntity.getCompareImgId() == null || redisFlag) {
|
|
|
- //说明当事人需要做人脸核身
|
|
|
- ThirdPartyInterfaceEntity thirdPartyInterfaceEntity = JuheServiceUtil.URLPost(idCard, nickName, base64);
|
|
|
- thirdPartyInterfaceEntity.setFileId(fileInfo.getId()+"");
|
|
|
- thirdPartyInterfaceEntity.setBusinessNo(compareImageDomain.getBusinessNo());
|
|
|
- if (thirdPartyInterfaceEntity.getResult()==1){
|
|
|
- //上传图片到minio FileInfo
|
|
|
- UserAXQInfoEntity userAxq = new UserAXQInfoEntity();
|
|
|
- userAxq.setId(userAXQInfoEntity.getId());
|
|
|
- userAxq.setCompareImgId(fileInfo.getId());
|
|
|
- userAXQInfoMapper.updateById(userAxq);
|
|
|
- log.info("当事人人脸核身通过");
|
|
|
- redis.del(redisCount);
|
|
|
- thirdPartyInterfaceRepository.insert(thirdPartyInterfaceEntity);
|
|
|
- return ResultCode.SUCCESS;
|
|
|
+ } else if (ObjectUtils.isEmpty(compareImageId) || redisFlag) {
|
|
|
+ if (! imageCenter(base)){
|
|
|
+ return ResultCode.IMAGE_NOT_STANDARD;
|
|
|
+ }
|
|
|
+
|
|
|
+ //说明当事人需要做人脸核身
|
|
|
+ FileInfoEntity fileInfo = uploadFaceFile(base64);
|
|
|
+ FaceCompareEntity thirdPartyInterfaceEntity = JuheServiceUtil.URLPost(idCard, nickName, base64);
|
|
|
+ thirdPartyInterfaceEntity.setFileId(fileInfo.getId() + "");
|
|
|
+ thirdPartyInterfaceEntity.setBusinessNo(compareImageDomain.getBusinessNo());
|
|
|
+ thirdPartyInterfaceEntity.setConsultNo(contractOrder.getConsultNo());
|
|
|
+ thirdPartyInterfaceRepository.insert(thirdPartyInterfaceEntity);
|
|
|
+ if (thirdPartyInterfaceEntity.getResult() == 1) {
|
|
|
+ //上传图片到minio FileInfo;
|
|
|
+ ContractOrderEntity orderEntity = new ContractOrderEntity();
|
|
|
+ orderEntity.setId(contractOrder.getId());
|
|
|
+ //判断是共同责任人还是当事人
|
|
|
+ if (nickName.equals(contractOrder.getName())) {
|
|
|
+ orderEntity.setCompareImgId(fileInfo.getId());
|
|
|
}
|
|
|
- log.info("当事人人脸核身失败");
|
|
|
- thirdPartyInterfaceRepository.insert(thirdPartyInterfaceEntity);
|
|
|
- return ResultCode.LIVE_VIDEO_INVALID;
|
|
|
+ if (nickName.equals(contractOrder.getJointName())) {
|
|
|
+ orderEntity.setJointCompareImgId(fileInfo.getId());
|
|
|
+ }
|
|
|
+ redis.del(redisCount);
|
|
|
+ contractOrderMapper.updateById(orderEntity);
|
|
|
+ log.info("当事人人脸核身通过");
|
|
|
+ return ResultCode.SUCCESS;
|
|
|
}
|
|
|
+ log.info("当事人人脸核身失败");
|
|
|
+ return ResultCode.LIVE_VIDEO_INVALID;
|
|
|
}
|
|
|
//如果不用做人脸核身 那么就去做照片比对
|
|
|
//获取比较图片的id
|
|
|
@@ -241,37 +300,120 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
if (!ObjectUtils.isEmpty(sysUserEntity)) {
|
|
|
id = sysUserEntity.getCompareImgId();
|
|
|
}
|
|
|
- if (!ObjectUtils.isEmpty(userAXQInfoEntity)) {
|
|
|
- id = userAXQInfoEntity.getCompareImgId();
|
|
|
+ if (!ObjectUtils.isEmpty(compareImageId)) {
|
|
|
+ id = compareImageId;
|
|
|
}
|
|
|
- if (! compareImage(base, id,redisCount,count)) {
|
|
|
+ //要做照片比对
|
|
|
+ /*if (!compareImage(base, id, redisCount, count)) {
|
|
|
return ResultCode.LIVE_VIDEO_INVALID;
|
|
|
+ }*/
|
|
|
+
|
|
|
+ ResultCode resultCode = compareImage(base, id, redisCount, count);
|
|
|
+
|
|
|
+ if (resultCode.code()==100){
|
|
|
+ if (count != null) {
|
|
|
+ redis.del(redisCount);
|
|
|
+ }
|
|
|
}
|
|
|
- if (count != null) {
|
|
|
- redis.del(redisCount);
|
|
|
+ return resultCode;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证照片是否居中
|
|
|
+ * @param base
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean imageCenter(File base) {
|
|
|
+ //从官网获取
|
|
|
+ FaceEngine faceEngine = new FaceEngine(libpath);
|
|
|
+ //激活引擎
|
|
|
+ int errorCode = faceEngine.activeOnline(appid, sdkkey);
|
|
|
+ if (errorCode != ErrorInfo.MOK.getValue() && errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {
|
|
|
+ base.delete();
|
|
|
+ throw new RuntimeException("引擎激活失败");
|
|
|
}
|
|
|
- return ResultCode.SUCCESS;
|
|
|
+ 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("获取激活文件信息失败");
|
|
|
+ }
|
|
|
+ //引擎配置
|
|
|
+ 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()) {
|
|
|
+ base.delete();
|
|
|
+ throw new RuntimeException("初始化引擎失败");
|
|
|
+ }
|
|
|
+ //人脸检测
|
|
|
+ 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);
|
|
|
+ if (CollectionUtils.isEmpty(face3DAngleList)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ //俯仰角
|
|
|
+ float pitch = Math.abs(face3DAngleList.get(0).getPitch());
|
|
|
+ //偏向角
|
|
|
+ float yaw = Math.abs(face3DAngleList.get(0).getYaw());
|
|
|
+ log.info("俯仰角:{}", pitch);
|
|
|
+ log.info("偏向角:{}", yaw);
|
|
|
+ if (pitch >= 10 || yaw >= 10) {
|
|
|
+ //照片不符合标准
|
|
|
+ log.info("图片不符合标准");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 虹软的人脸照片比对
|
|
|
- * @param base 照片
|
|
|
- * @param id 文件库中照片的id
|
|
|
+ *
|
|
|
+ * @param base 照片
|
|
|
+ * @param id 文件库中照片的id
|
|
|
* @param redisCount 数据库中的键
|
|
|
- * @param count redis当中的次数
|
|
|
+ * @param count redis当中的次数
|
|
|
* @return
|
|
|
*/
|
|
|
- public boolean compareImage(File base, Integer id,String redisCount,Integer count) {
|
|
|
+ public ResultCode compareImage(File base, Integer id, String redisCount, Integer count) {
|
|
|
//从官网获取
|
|
|
- FaceEngine faceEngine = new FaceEngine(LIBPATH);
|
|
|
+ FaceEngine faceEngine = new FaceEngine(libpath);
|
|
|
//激活引擎
|
|
|
- int errorCode = faceEngine.activeOnline(APPID, SDKKEY);
|
|
|
+ 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("获取激活文件信息失败");
|
|
|
}
|
|
|
//引擎配置
|
|
|
@@ -293,6 +435,7 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
//初始化引擎
|
|
|
errorCode = faceEngine.init(engineConfiguration);
|
|
|
if (errorCode != ErrorInfo.MOK.getValue()) {
|
|
|
+ base.delete();
|
|
|
throw new RuntimeException("初始化引擎失败");
|
|
|
}
|
|
|
//人脸检测
|
|
|
@@ -307,15 +450,47 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
//3D信息检测
|
|
|
List<Face3DAngle> face3DAngleList = new ArrayList<Face3DAngle>();
|
|
|
errorCode = faceEngine.getFace3DAngle(face3DAngleList);
|
|
|
+ if (CollectionUtils.isEmpty(face3DAngleList)){
|
|
|
+ return ResultCode.IMAGE_NOT_STANDARD;
|
|
|
+ }
|
|
|
//俯仰角
|
|
|
float pitch = Math.abs(face3DAngleList.get(0).getPitch());
|
|
|
//偏向角
|
|
|
float yaw = Math.abs(face3DAngleList.get(0).getYaw());
|
|
|
- if (pitch > 10 || yaw > 10) {
|
|
|
+ log.info("俯仰角:{}",pitch);
|
|
|
+ log.info("偏向角:{}",yaw);
|
|
|
+ if (pitch >= 10 || yaw >= 10) {
|
|
|
//照片不符合标准
|
|
|
log.info("图片不符合标准");
|
|
|
+ return ResultCode.IMAGE_NOT_STANDARD;
|
|
|
+ }
|
|
|
+ //活体检测
|
|
|
+ /*List<LivenessInfo> livenessInfoList = new ArrayList<LivenessInfo>();
|
|
|
+ errorCode = faceEngine.getLiveness(livenessInfoList);
|
|
|
+ if (CollectionUtils.isEmpty(livenessInfoList)){
|
|
|
+ log.info("活体验证失败");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ System.out.println("活体:" + livenessInfoList.get(0).getLiveness());
|
|
|
+
|
|
|
+ //IR属性处理
|
|
|
+ ImageInfo imageInfoGray = getGrayData(base);
|
|
|
+ List<FaceInfo> faceInfoListGray = new ArrayList<FaceInfo>();
|
|
|
+ errorCode = faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoListGray);
|
|
|
+
|
|
|
+ FunctionConfiguration configuration2 = new FunctionConfiguration();
|
|
|
+ configuration2.setSupportIRLiveness(true);
|
|
|
+ errorCode = faceEngine.processIr(imageInfoGray.getImageData(), imageInfoGray.getWidth(), imageInfoGray.getHeight(), imageInfoGray.getImageFormat(), faceInfoListGray, configuration2);
|
|
|
+ //IR活体检测
|
|
|
+ List<IrLivenessInfo> irLivenessInfo = new ArrayList<>();
|
|
|
+ errorCode = faceEngine.getLivenessIr(irLivenessInfo);
|
|
|
+ if (CollectionUtils.isEmpty(irLivenessInfo)){
|
|
|
+ log.info("活体验证失败");
|
|
|
return false;
|
|
|
}
|
|
|
+ System.out.println("IR活体:" + irLivenessInfo.get(0).getLiveness());*/
|
|
|
+
|
|
|
+
|
|
|
//特征提取
|
|
|
FaceFeature faceFeature = new FaceFeature();
|
|
|
errorCode = faceEngine.extractFaceFeature(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList.get(0), faceFeature);
|
|
|
@@ -326,7 +501,7 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
String filePath = fileInfoEntity.getPath();
|
|
|
File file = null;
|
|
|
try {
|
|
|
- file = minioFileHandle.getFileWithPath(filePath);
|
|
|
+ file=FileUploadUtil.getFileWithPath(filePath);
|
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
@@ -345,33 +520,53 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
FaceSimilar faceSimilar = new FaceSimilar();
|
|
|
errorCode = faceEngine.compareFaceFeature(targetFaceFeature, sourceFaceFeature, faceSimilar);
|
|
|
//如果通过 上传文件 修改用户绑定id 如果没通过 返回null证明失败了
|
|
|
+ //引擎卸载
|
|
|
+ errorCode = faceEngine.unInit();
|
|
|
if (faceSimilar.getScore() > 0.8) {
|
|
|
log.info("人脸照片比对通过");
|
|
|
- return true;
|
|
|
- }
|
|
|
- if (count == null) {
|
|
|
- redis.set(redisCount, 1, 30, TimeUnit.MINUTES);
|
|
|
- } else {
|
|
|
- redis.set(redisCount, count + 1, 30, TimeUnit.MINUTES);
|
|
|
+ base.delete();
|
|
|
+ file.delete();
|
|
|
+ redis.del(redisCount);
|
|
|
+ return ResultCode.SUCCESS;
|
|
|
}
|
|
|
- log.info("人脸照片比对未通过");;
|
|
|
- return false;
|
|
|
+ redis.increment(redisCount);
|
|
|
+ log.info("人脸照片比对未通过");
|
|
|
+ base.delete();
|
|
|
+ file.delete();
|
|
|
+ return ResultCode.LIVE_VIDEO_INVALID;
|
|
|
}
|
|
|
|
|
|
- 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 void uploadFile(String base64,String filePath){
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
+ params.put("base64", base64);
|
|
|
+ params.put("filePath",filePath);
|
|
|
+ HttpClientUtil httpClientUtil = new HttpClientUtil();
|
|
|
+ String xmlData = httpClientUtil.doPost("https://fqgz.flowbb.cn:6001/sp/upload/uploadFaceImage",params.toString(),"utf-8");
|
|
|
+ JSONObject result = JSONObject.parseObject(xmlData);
|
|
|
+ String code = result.getString("code");
|
|
|
+ if ("100".equals(code)){
|
|
|
+ log.info("上传成功");
|
|
|
}
|
|
|
+ }
|
|
|
+ public FileInfoEntity uploadFaceFile(String base64){
|
|
|
+ String s = FileUploadUtil.saveFaceImage(base64);
|
|
|
+ ThreadPoolExecutorUtil.getPoll().execute(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ uploadFile(base64,s);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ 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;
|
|
|
}
|
|
|
}
|