Browse Source

优化百度和face++代码

lideyin 5 years ago
parent
commit
0ee3c882c4

+ 0 - 19
examcloud-core-oe-face-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/face/service/FaceLivenessService.java

@@ -1,19 +0,0 @@
-package cn.com.qmth.examcloud.core.oe.student.face.service;
-
-import com.alibaba.fastjson.JSONObject;
-
-/**
- * @Description 百度活体检测结果类
- * @Author lideyin
- * @Date 2019/8/5 15:38
- * @Version 1.0
- */
-public interface FaceLivenessService {
-
-	/**
-	 * 获取百度活体检测结果
-	 * @param fileUrl 文件路径
-	 * @return JSONObject
-	 */
-	JSONObject getBaiduFaceLivenessResultJson(String fileUrl);
-}

+ 4 - 5
examcloud-core-oe-face-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/face/service/impl/ExamCaptureServiceImpl.java

@@ -10,7 +10,10 @@ import cn.com.qmth.examcloud.core.oe.common.enums.ExamProperties;
 import cn.com.qmth.examcloud.core.oe.common.repository.ExamCaptureQueueRepo;
 import cn.com.qmth.examcloud.core.oe.common.repository.ExamCaptureRepo;
 import cn.com.qmth.examcloud.core.oe.common.service.GainBaseDataService;
-import cn.com.qmth.examcloud.core.oe.student.face.service.*;
+import cn.com.qmth.examcloud.core.oe.student.face.service.ExamCaptureCommonService;
+import cn.com.qmth.examcloud.core.oe.student.face.service.ExamCaptureQueueService;
+import cn.com.qmth.examcloud.core.oe.student.face.service.ExamCaptureService;
+import cn.com.qmth.examcloud.core.oe.student.face.service.FaceCompareService;
 import cn.com.qmth.examcloud.core.oe.student.face.service.bean.CompareFaceSyncInfo;
 import cn.com.qmth.examcloud.support.cache.CacheHelper;
 import cn.com.qmth.examcloud.support.cache.bean.ExamRecordPropertyCacheBean;
@@ -26,7 +29,6 @@ import org.apache.commons.logging.LogFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.system.SystemProperties;
 import org.springframework.data.domain.Example;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
@@ -57,9 +59,6 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
 
     @Autowired
     private ExamCaptureQueueService examCaptureQueueService;
-
-    @Autowired
-    private FaceLivenessService faceLivenessService;
     @Autowired
     private FaceCompareService faceCompareService;
 

+ 0 - 58
examcloud-core-oe-face-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/face/service/impl/FaceLivenessServiceImpl.java

@@ -1,58 +0,0 @@
-package cn.com.qmth.examcloud.core.oe.student.face.service.impl;
-
-import cn.com.qmth.examcloud.core.oe.common.base.Constants;
-import cn.com.qmth.examcloud.core.oe.common.base.utils.baiduFaceVerify.BaiduFaceVerifyUtil;
-import cn.com.qmth.examcloud.core.oe.student.face.service.FaceLivenessService;
-import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
-import com.alibaba.fastjson.JSONObject;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
-
-/**
- * @author chenken
- * @date 2018年10月30日 下午5:17:28
- * @company QMTH
- * @description 百度活体检测执行service
- */
-@Service("faceLivenessService")
-public class FaceLivenessServiceImpl implements FaceLivenessService {
-
-    /**
-     * 获取百度在线活体检测
-     *
-     * @param fileUrl 文件路径
-     * @return JSONObject
-     */
-    @Override
-    public JSONObject getBaiduFaceLivenessResultJson(String fileUrl) {
-        JSONObject errorMsgJson = new JSONObject();
-        String accessTokenResult = BaiduFaceVerifyUtil.getAccessToken(PropertyHolder.getString("$baidu.apiKey"),
-                PropertyHolder.getString("$baidu.secretKey"));
-        //拿不到token
-        if (StringUtils.isBlank(accessTokenResult)) {
-            errorMsgJson.put(Constants.BAIDU_ERROR_CODE, "APP100001");
-            errorMsgJson.put(Constants.BAIDU_ERROR_MSG, "baidu_faceliveness_error:getAccessToken failed");
-            return errorMsgJson;
-        }
-        JSONObject jsonObject;
-        jsonObject = JSONObject.parseObject(accessTokenResult);
-        //拿不到token
-        if (!jsonObject.containsKey("access_token") || StringUtils.isBlank(jsonObject.getString("access_token"))) {
-            errorMsgJson.put(Constants.BAIDU_ERROR_CODE, "APP100002");
-            errorMsgJson.put(Constants.BAIDU_ERROR_MSG, "baidu_faceliveness_error:invalid accessToken result. accessTokenResult:" + accessTokenResult);
-            return errorMsgJson;
-        }
-        String accessToken = jsonObject.getString("access_token");
-        String faceLivenessResult = BaiduFaceVerifyUtil.faceVerify(accessToken, fileUrl);
-        //拿不到结果
-        if (StringUtils.isBlank(faceLivenessResult)) {
-            errorMsgJson.put(Constants.BAIDU_ERROR_CODE, "APP100003");
-            errorMsgJson.put(Constants.BAIDU_ERROR_MSG, "baidu_faceliveness_error:faceLivess failed");
-            return errorMsgJson;
-        }
-        return JSONObject.parseObject(faceLivenessResult);
-
-    }
-
-}