fix(face): 修复人脸识别环境判断逻辑
parent
62188ae36e
commit
db92cedf0d
|
|
@ -17,6 +17,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
@ -58,7 +59,13 @@ public class StudentSignAddExe {
|
||||||
faceUrl = Base64Util.getBase64String(studentSignE.getFiles()[0]);
|
faceUrl = Base64Util.getBase64String(studentSignE.getFiles()[0]);
|
||||||
log.info("StudentSignAddExe-execute,调用阿里进行人脸识别开始");
|
log.info("StudentSignAddExe-execute,调用阿里进行人脸识别开始");
|
||||||
long startAliTime = System.currentTimeMillis();
|
long startAliTime = System.currentTimeMillis();
|
||||||
studentSignE.compareFace(student.getUserAvatarUrl(), faceUrl, fileUrlConfig.getPrefixUrl());
|
Boolean environment = false;
|
||||||
|
log.info("StudentSignAddExe-execute,fileUrlConfig.getPrefixUrl():{}",fileUrlConfig.getPrefixUrl());
|
||||||
|
if(!"https://jpfz.qhdsafety.com/gbsFileTest/".equals(fileUrlConfig.getPrefixUrl())){
|
||||||
|
environment = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
studentSignE.compareFace(student.getUserAvatarUrl(), faceUrl, fileUrlConfig.getPrefixUrl(),environment);
|
||||||
log.info("StudentSignAddExe-execute,调用阿里进行人脸识别结束,耗时:{}",System.currentTimeMillis() - startAliTime);
|
log.info("StudentSignAddExe-execute,调用阿里进行人脸识别结束,耗时:{}",System.currentTimeMillis() - startAliTime);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ public class FileUrlConfig {
|
||||||
}
|
}
|
||||||
public String getPrefixUrl() {
|
public String getPrefixUrl() {
|
||||||
// 正式环境
|
// 正式环境
|
||||||
return "http://192.168.192.201:8991/file/uploadFiles2/";
|
// return "http://192.168.192.201:8991/file/uploadFiles2/";
|
||||||
// return prefixUrl;
|
return prefixUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,12 @@ package com.zcloud.edu.domain.model.study;
|
||||||
import com.alibaba.cola.exception.BizException;
|
import com.alibaba.cola.exception.BizException;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.jjb.saas.framework.domain.model.BaseE;
|
import com.jjb.saas.framework.domain.model.BaseE;
|
||||||
import com.zcloud.gbscommon.utils.Base64Util;
|
import com.zcloud.gbscommon.utils.Base64Util;
|
||||||
import com.zcloud.gbscommon.utils.FaceUtil;
|
import com.zcloud.gbscommon.utils.FaceUtil;
|
||||||
import com.zcloud.gbscommon.utils.HttpRequestUtil;
|
import com.zcloud.gbscommon.utils.HttpRequestUtil;
|
||||||
import com.zcloud.gbscommon.utils.Tools;
|
import com.zcloud.gbscommon.utils.Tools;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
@ -70,21 +68,25 @@ public class StudentSignE extends BaseE {
|
||||||
//修改人id
|
//修改人id
|
||||||
private Long updateId;
|
private Long updateId;
|
||||||
|
|
||||||
public void compareFace(String templateFaceUrl, String faceUrl, String prefixUrl) throws Exception {
|
public void compareFace(String templateFaceUrl, String faceUrl, String prefixUrl, Boolean environment) throws Exception {
|
||||||
try {
|
try {
|
||||||
String templateFace = Base64Util.urlToBase64(prefixUrl + templateFaceUrl);
|
String templateFace = Base64Util.urlToBase64(prefixUrl + templateFaceUrl);
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
map.put("pic1", templateFace);
|
map.put("pic1", templateFace);
|
||||||
map.put("pic2", faceUrl);
|
map.put("pic2", faceUrl);
|
||||||
String jsonParam = JSON.toJSONString(map);
|
String jsonParam = JSON.toJSONString(map);
|
||||||
|
String compareResultStr;
|
||||||
|
if (environment) {
|
||||||
// 正式环境
|
// 正式环境
|
||||||
String compareResult = HttpRequestUtil.doPost("http://192.168.192.201:8971/gbs-face/face/compareFace", jsonParam);
|
String compareResult = HttpRequestUtil.doPost("http://192.168.192.201:8971/gbs-face/face/compareFace", jsonParam);
|
||||||
JSONObject jsonObject = JSONObject.parseObject(compareResult);
|
JSONObject jsonObject = JSONObject.parseObject(compareResult);
|
||||||
jsonObject.getJSONObject("info").getString("confidence");
|
jsonObject.getJSONObject("info").getString("confidence");
|
||||||
String compareResultStr = jsonObject.getJSONObject("info").getString("confidence");
|
compareResultStr = jsonObject.getJSONObject("info").getString("confidence");
|
||||||
|
} else {
|
||||||
// 测试环境
|
// 测试环境
|
||||||
// String compareResultStr = FaceUtil.compareFace(templateFace, faceUrl);
|
compareResultStr = FaceUtil.compareFace(templateFace, faceUrl);
|
||||||
|
}
|
||||||
|
|
||||||
if (Double.valueOf(compareResultStr) < 75) {
|
if (Double.valueOf(compareResultStr) < 75) {
|
||||||
throw new BizException("人脸不匹配");
|
throw new BizException("人脸不匹配");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue