Procházet zdrojové kódy

优化百度和face++代码

lideyin před 5 roky
rodič
revize
3b50b06d53

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

@@ -15,6 +15,7 @@ import cn.com.qmth.examcloud.core.oe.student.face.service.bean.CompareFaceSyncIn
 import cn.com.qmth.examcloud.support.cache.CacheHelper;
 import cn.com.qmth.examcloud.support.cache.bean.ExamRecordPropertyCacheBean;
 import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
+import cn.com.qmth.examcloud.web.baidu.BaiduClient;
 import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
 import cn.com.qmth.examcloud.web.facepp.FaceppClient;
 import com.alibaba.fastjson.JSONArray;
@@ -239,7 +240,25 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
             captureLog.debug("[DISPOSE_BAIDUFACELIVENESS] 百度活体检测开始...");
 
             //获取百度活检结果
-            faceLivenessResultJson = faceLivenessService.getBaiduFaceLivenessResultJson(examCaptureQueue.getFileUrl());
+            String backup = PropertyHolder.getString("$upyun.site.1.domain.backup");
+            String main = PropertyHolder.getString("$upyun.site.1.domain");
+            JsonHttpResponseHolder jsonHttpResponseHolder = null;
+            try {
+                jsonHttpResponseHolder = BaiduClient.getClient().verifyFaceLiveness(examCaptureQueue.getFileUrl(),
+                        examCaptureQueue.getFileUrl().replace(main, backup));
+                faceLivenessResultJson = jsonHttpResponseHolder.getRespBody();
+            } catch (StatusException e) {
+                //如果错误码是901,902,903直接结束,不重试
+                if (e.getCode().equals("901") || e.getCode().equals("902") || e.getCode().equals("903")) {
+                    examCaptureQueue.setFacelivenessResult(e.getDesc());
+                    saveExamCaptureAndDeleteQueue(examCaptureQueue);
+
+                    captureLog.debug("[DISPOSE_BAIDUFACELIVENESS] 百度活检无法处理的图片地址,保存人脸检测最终结果并删除队列,errMsg=" + e.getDesc());
+                    return;
+                }
+                throw e;
+            }
+//            faceLivenessResultJson = faceLivenessService.getBaiduFaceLivenessResultJson(examCaptureQueue.getFileUrl());
 
             //如果百度活体检测执行失败,调用队列失败处理,程序退出,失败的数据,后续会有自动服务重新处理
             if (faceLivenessResultJson.containsKey(Constants.BAIDU_ERROR_CODE) &&
@@ -249,7 +268,7 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
                 //如果API并发次数超过上限,则保存错误信息到队列,并抛出异常,用于协调满载队列线程
                 if (errCode.equals(Constants.BAIDU_FACELIVENESS_QPS_LIMIT_EXCEEDED_CODE)) {
                     examCaptureQueueService.saveExamCaptureQueueEntityByFailed(examCaptureQueue,
-                            faceLivenessResultJson.toString(), ExamCaptureQueueStatus.PROCESS_FACELIVENESS_FAILED);
+                            "SatusCode:" + jsonHttpResponseHolder.getStatusCode() + " | " + faceLivenessResultJson.toString(), ExamCaptureQueueStatus.PROCESS_FACELIVENESS_FAILED);
 
                     captureLog.debug("[DISPOSE_BAIDUFACELIVENESS] 百度在线活体API接口超过最大并发次数");
 
@@ -295,7 +314,7 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
                 captureLog.debug("[DISPOSE_BAIDUFACELIVENESS] 百度活体检测出现错误,即将重试,错误码:" + errCode);
                 // 其它错误类型,保存错误信息到队列中,待自动重新服务处理
                 examCaptureQueueService.saveExamCaptureQueueEntityByFailed(examCaptureQueue,
-                        faceLivenessResultJson.toString(), ExamCaptureQueueStatus.PROCESS_FACELIVENESS_FAILED);
+                        "SatusCode:" + jsonHttpResponseHolder.getStatusCode() + " | " + faceLivenessResultJson.toString(), ExamCaptureQueueStatus.PROCESS_FACELIVENESS_FAILED);
                 ExamCaptureProcessStatisticController.increaseFaceLivenessDetectFailedCount();//增加错误次数
 
             }