Browse Source

优化百度和face++代码

lideyin 5 years ago
parent
commit
940a5c7b3c

+ 87 - 86
examcloud-core-oe-face-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/face/service/impl/ExamCaptureQueueServiceImpl.java

@@ -32,26 +32,26 @@ import java.util.*;
  */
  */
 @Service("examCaptureQueueService")
 @Service("examCaptureQueueService")
 public class ExamCaptureQueueServiceImpl implements ExamCaptureQueueService {
 public class ExamCaptureQueueServiceImpl implements ExamCaptureQueueService {
-	
-	private static final Logger log = LoggerFactory.getLogger(ExamCaptureQueueServiceImpl.class);
+
+    private static final Logger log = LoggerFactory.getLogger(ExamCaptureQueueServiceImpl.class);
 
 
     @Autowired
     @Autowired
     private ExamCaptureQueueRepo examCaptureQueueRepo;
     private ExamCaptureQueueRepo examCaptureQueueRepo;
-    
-	@Autowired
-	private FaceCloudService faceCloudService;
-    
+
+    @Autowired
+    private FaceCloudService faceCloudService;
+
     /**
     /**
      * 一次启动的线程个数
      * 一次启动的线程个数
      */
      */
     @Value("${$capture.thread.num}")
     @Value("${$capture.thread.num}")
-    private int threadNum; 
-    
+    private int threadNum;
+
     /**
     /**
      * 一次从数据库取出的最大记录数
      * 一次从数据库取出的最大记录数
      */
      */
     @Value("${$capture.queue.limit:200}")
     @Value("${$capture.queue.limit:200}")
-    private int queueLimit; 
+    private int queueLimit;
 
 
 
 
     @Override
     @Override
@@ -78,97 +78,98 @@ public class ExamCaptureQueueServiceImpl implements ExamCaptureQueueService {
     @Override
     @Override
     public void changeExamCaptureQueueStatus() {
     public void changeExamCaptureQueueStatus() {
         long nowTime = System.currentTimeMillis();
         long nowTime = System.currentTimeMillis();
-        int queueTimeOut = PropertyHolder.getInt("$capture.process.timeout",5);
+        int queueTimeOut = PropertyHolder.getInt("$capture.process.timeout", 5);
         List<ExamCaptureQueueEntity> examCaptureQueueList = examCaptureQueueRepo.findByStatusOrderByCreationTimeAsc(ExamCaptureQueueStatus.PROCESSING);
         List<ExamCaptureQueueEntity> examCaptureQueueList = examCaptureQueueRepo.findByStatusOrderByCreationTimeAsc(ExamCaptureQueueStatus.PROCESSING);
         List<ExamCaptureQueueEntity> newExamCaptureQueueList = new ArrayList<ExamCaptureQueueEntity>();
         List<ExamCaptureQueueEntity> newExamCaptureQueueList = new ArrayList<ExamCaptureQueueEntity>();
-        for(ExamCaptureQueueEntity examCaptureQueue:examCaptureQueueList){
-            if(nowTime-examCaptureQueue.getCreationTime().getTime()>queueTimeOut*60*1000){
-            	examCaptureQueue.setStatus(ExamCaptureQueueStatus.PENDING);//重置为 待处理
+        for (ExamCaptureQueueEntity examCaptureQueue : examCaptureQueueList) {
+            if (nowTime - examCaptureQueue.getCreationTime().getTime() > queueTimeOut * 60 * 1000) {
+                examCaptureQueue.setStatus(ExamCaptureQueueStatus.PENDING);//重置为 待处理
                 newExamCaptureQueueList.add(examCaptureQueue);
                 newExamCaptureQueueList.add(examCaptureQueue);
             }
             }
         }
         }
         examCaptureQueueRepo.saveAll(newExamCaptureQueueList);
         examCaptureQueueRepo.saveAll(newExamCaptureQueueList);
     }
     }
 
 
-	@Override
-	public void saveExamCaptureQueueEntityByFailed(ExamCaptureQueueEntity examCaptureQueueEntity,  String errorMsg,ExamCaptureQueueStatus examCaptureQueueStatus) {
-		examCaptureQueueEntity.setErrorMsg(errorMsg);
-		examCaptureQueueEntity.setStatus(examCaptureQueueStatus);
-		examCaptureQueueEntity.setUpdateTime(new Date());
-		int errorNum = examCaptureQueueEntity.getErrorNum()==null?0:examCaptureQueueEntity.getErrorNum();
-		examCaptureQueueEntity.setErrorNum(errorNum+1);
-		examCaptureQueueEntity.setProcessBatchNum("000000");
-		examCaptureQueueRepo.save(examCaptureQueueEntity);
-	}
-
-	@Override
-	public String saveExamCaptureQueue(SaveExamCaptureQueueInfo saveExamCaptureQueueInfo,Long studentId) {
-		//查询学生底照faceToken
-		StudentCacheBean studentCache = CacheHelper.getStudent(studentId);
-		String baseFaceToken = studentCache.getFaceToken();
-		Check.isBlank(baseFaceToken, "学生底照的faceToken为空");
+    @Override
+    public void saveExamCaptureQueueEntityByFailed(ExamCaptureQueueEntity examCaptureQueueEntity,
+                                                   String errorMsg, ExamCaptureQueueStatus examCaptureQueueStatus) {
+        examCaptureQueueEntity.setErrorMsg(errorMsg);
+        examCaptureQueueEntity.setStatus(examCaptureQueueStatus);
+        examCaptureQueueEntity.setUpdateTime(new Date());
+        int errorNum = examCaptureQueueEntity.getErrorNum() == null ? 0 : examCaptureQueueEntity.getErrorNum();
+        examCaptureQueueEntity.setErrorNum(errorNum + 1);
+        examCaptureQueueEntity.setProcessBatchNum("000000");
+        examCaptureQueueRepo.save(examCaptureQueueEntity);
+    }
+
+    @Override
+    public String saveExamCaptureQueue(SaveExamCaptureQueueInfo saveExamCaptureQueueInfo, Long studentId) {
+        //查询学生底照faceToken
+        StudentCacheBean studentCache = CacheHelper.getStudent(studentId);
+        String baseFaceToken = studentCache.getFaceToken();
+        Check.isBlank(baseFaceToken, "学生底照的faceToken为空");
 
 
 //		AES aes = new AES();
 //		AES aes = new AES();
-		//解密fileUrl
+        //解密fileUrl
 //		String fileUrl = aes.decrypt(saveExamCaptureQueueInfo.getFileUrl());
 //		String fileUrl = aes.decrypt(saveExamCaptureQueueInfo.getFileUrl());
-		String fileUrl = UrlUtil.decode(saveExamCaptureQueueInfo.getFileUrl());
-		if(!StringUtil.isAscString(fileUrl)){
-			log.error("The fileUrl is invalid:"+saveExamCaptureQueueInfo.getFileUrl());
-			throw new StatusException("300001","文件路径格式不正确");
-		}
-		String fileName = fileUrl.substring(fileUrl.lastIndexOf("/")+1, fileUrl.length());
-		
-		ExamCaptureQueueEntity examCaptureQueue = new ExamCaptureQueueEntity();
-		examCaptureQueue.setStudentId(studentId);
-		examCaptureQueue.setFileUrl(fileUrl);
-		examCaptureQueue.setFileName(fileName);
-		examCaptureQueue.setBaseFaceToken(baseFaceToken);
-		examCaptureQueue.setExamRecordDataId(saveExamCaptureQueueInfo.getExamRecordDataId());
-		examCaptureQueue.setHasVirtualCamera(saveExamCaptureQueueInfo.getHasVirtualCamera());
-		examCaptureQueue.setCameraInfos(saveExamCaptureQueueInfo.getCameraInfos());
-		examCaptureQueue.setExtMsg(saveExamCaptureQueueInfo.getExtMsg());
+        String fileUrl = UrlUtil.decode(saveExamCaptureQueueInfo.getFileUrl());
+        if (!StringUtil.isAscString(fileUrl)) {
+            log.error("The fileUrl is invalid:" + saveExamCaptureQueueInfo.getFileUrl());
+            throw new StatusException("300001", "文件路径格式不正确");
+        }
+        String fileName = fileUrl.substring(fileUrl.lastIndexOf("/") + 1, fileUrl.length());
+
+        ExamCaptureQueueEntity examCaptureQueue = new ExamCaptureQueueEntity();
+        examCaptureQueue.setStudentId(studentId);
+        examCaptureQueue.setFileUrl(fileUrl);
+        examCaptureQueue.setFileName(fileName);
+        examCaptureQueue.setBaseFaceToken(baseFaceToken);
+        examCaptureQueue.setExamRecordDataId(saveExamCaptureQueueInfo.getExamRecordDataId());
+        examCaptureQueue.setHasVirtualCamera(saveExamCaptureQueueInfo.getHasVirtualCamera());
+        examCaptureQueue.setCameraInfos(saveExamCaptureQueueInfo.getCameraInfos());
+        examCaptureQueue.setExtMsg(saveExamCaptureQueueInfo.getExtMsg());
         examCaptureQueue.setStatus(ExamCaptureQueueStatus.PENDING);
         examCaptureQueue.setStatus(ExamCaptureQueueStatus.PENDING);
         examCaptureQueue.setErrorNum(0);
         examCaptureQueue.setErrorNum(0);
         examCaptureQueue.setCreationTime(new Date());
         examCaptureQueue.setCreationTime(new Date());
         examCaptureQueueRepo.save(examCaptureQueue);
         examCaptureQueueRepo.save(examCaptureQueue);
         return fileName;
         return fileName;
-	}
-
-	public static void main(String[] args) {
-		Map<String, String> maps = new HashMap<String, String>();
-		maps.put("35d2ccfa922c406f45acc7b1bad1d9edf72391cd2208312906129712f5215f75db9c6f1ab31974bf2a7d590e677655d374bbd39e3f9ea015abee61fa4f76633cc25fc7ed1c78e238504ce96d4ae7387c", "3128451");
-		maps.put("35d2ccfa922c406f45acc7b1bad1d9edf72391cd2208312906129712f5215f75db9c6f1ab31974bf2a7d590e677655d374bbd39e3f9ea015abee61fa4f76633c29837bbd269707405ea488f66da1ac62","3128451");
-		maps.put("35d2ccfa922c406f45acc7b1bad1d9edf72391cd2208312906129712f5215f75db9c6f1ab31974bf2a7d590e677655d374bbd39e3f9ea015abee61fa4f76633c6a82cb34ce4255959c94631810163f50","3128451 ");
-		maps.put("35d2ccfa922c406f45acc7b1bad1d9edf72391cd2208312906129712f5215f75db9c6f1ab31974bf2a7d590e677655d374bbd39e3f9ea015abee61fa4f76633c9769c30d115e755f3cbc1f9d0a39e736","3128490 ");
-		maps.put("35d2ccfa922c406f45acc7b1bad1d9edf72391cd2208312906129712f5215f75db9c6f1ab31974bf2a7d590e677655d374bbd39e3f9ea015abee61fa4f76633cf53d05df77c751ff631ed2f2d97e2b6c","3128490 ");
-		maps.put("35d2ccfa922c406f45acc7b1bad1d9edf72391cd2208312906129712f5215f75db9c6f1ab31974bf2a7d590e677655d38781c711ec73032b53bfefd151d9960f0bd747235a4510d179d2e46db7ef1a0e","3128531 ");
-		maps.put("35d2ccfa922c406f45acc7b1bad1d9edf72391cd2208312906129712f5215f75db9c6f1ab31974bf2a7d590e677655d38781c711ec73032b53bfefd151d9960f73c618429fb5902a19e793ab5b1a341f","3128531 ");
-		maps.put("35d2ccfa922c406f45acc7b1bad1d9edf72391cd2208312906129712f5215f75db9c6f1ab31974bf2a7d590e677655d38781c711ec73032b53bfefd151d9960f2145e4f9fd766e07d11784d6eea6708a","3128545 ");
-		maps.put("35d2ccfa922c406f45acc7b1bad1d9edf72391cd2208312906129712f5215f75db9c6f1ab31974bf2a7d590e677655d38781c711ec73032b53bfefd151d9960f5f5045b1a9e92a1a58672a1588112cc4","3128545 ");
-		maps.put("35d2ccfa922c406f45acc7b1bad1d9edf72391cd2208312906129712f5215f75db9c6f1ab31974bf2a7d590e677655d38781c711ec73032b53bfefd151d9960f9cc90589d78a800afa44d9e28f5e0165","3128563 ");
-		maps.put("35d2ccfa922c406f45acc7b1bad1d9edf72391cd2208312906129712f5215f75db9c6f1ab31974bf2a7d590e677655d38781c711ec73032b53bfefd151d9960f56cd9130daba0ba797e74614e3f809d7","3128563 ");
-		
-		Set<String> fileUrls = maps.keySet();
-		Map<String,Integer> countMap = new HashMap<String, Integer>();
-		for(String fileUrl:fileUrls){
-			AES aes = new AES();
-			String url = aes.decrypt(fileUrl.trim());
-			String fileName = url.substring(url.lastIndexOf("/")+1, url.length());
-			String examRecordDataId = maps.get(fileUrl).trim();
-			String sql = "INSERT INTO `ec_oe_exam_capture` (`exam_record_data_id`, `file_name`, `file_url`, `is_stranger`, `is_pass`, `creation_time`, `update_time`,`ext_msg`) "
-						+ " VALUES"
-						+"('"+examRecordDataId+"', '"+fileName+"', '"+url+"', b'0', '1',NOW(),NOW(), '手动修改');";
-			System.out.println(sql);
-			Integer num = countMap.get(examRecordDataId);
-			countMap.put(examRecordDataId, num==null?1:num+1);
-		}
-		
-		Set<String> examRecordDataIdNums = countMap.keySet();
-		for(String examRecordDataId:examRecordDataIdNums){
-			int num = countMap.get(examRecordDataId);
-			String sql = "update ec_oe_exam_record_data set face_total_count = "+num+",face_success_count = "+num+",face_success_percent=100,baidu_face_liveness_success_percent=100 where id = "+examRecordDataId+";";
-			System.out.println(sql);
-		}
-	}
-	
+    }
+
+    public static void main(String[] args) {
+        Map<String, String> maps = new HashMap<String, String>();
+        maps.put("35d2ccfa922c406f45acc7b1bad1d9edf72391cd2208312906129712f5215f75db9c6f1ab31974bf2a7d590e677655d374bbd39e3f9ea015abee61fa4f76633cc25fc7ed1c78e238504ce96d4ae7387c", "3128451");
+        maps.put("35d2ccfa922c406f45acc7b1bad1d9edf72391cd2208312906129712f5215f75db9c6f1ab31974bf2a7d590e677655d374bbd39e3f9ea015abee61fa4f76633c29837bbd269707405ea488f66da1ac62", "3128451");
+        maps.put("35d2ccfa922c406f45acc7b1bad1d9edf72391cd2208312906129712f5215f75db9c6f1ab31974bf2a7d590e677655d374bbd39e3f9ea015abee61fa4f76633c6a82cb34ce4255959c94631810163f50", "3128451 ");
+        maps.put("35d2ccfa922c406f45acc7b1bad1d9edf72391cd2208312906129712f5215f75db9c6f1ab31974bf2a7d590e677655d374bbd39e3f9ea015abee61fa4f76633c9769c30d115e755f3cbc1f9d0a39e736", "3128490 ");
+        maps.put("35d2ccfa922c406f45acc7b1bad1d9edf72391cd2208312906129712f5215f75db9c6f1ab31974bf2a7d590e677655d374bbd39e3f9ea015abee61fa4f76633cf53d05df77c751ff631ed2f2d97e2b6c", "3128490 ");
+        maps.put("35d2ccfa922c406f45acc7b1bad1d9edf72391cd2208312906129712f5215f75db9c6f1ab31974bf2a7d590e677655d38781c711ec73032b53bfefd151d9960f0bd747235a4510d179d2e46db7ef1a0e", "3128531 ");
+        maps.put("35d2ccfa922c406f45acc7b1bad1d9edf72391cd2208312906129712f5215f75db9c6f1ab31974bf2a7d590e677655d38781c711ec73032b53bfefd151d9960f73c618429fb5902a19e793ab5b1a341f", "3128531 ");
+        maps.put("35d2ccfa922c406f45acc7b1bad1d9edf72391cd2208312906129712f5215f75db9c6f1ab31974bf2a7d590e677655d38781c711ec73032b53bfefd151d9960f2145e4f9fd766e07d11784d6eea6708a", "3128545 ");
+        maps.put("35d2ccfa922c406f45acc7b1bad1d9edf72391cd2208312906129712f5215f75db9c6f1ab31974bf2a7d590e677655d38781c711ec73032b53bfefd151d9960f5f5045b1a9e92a1a58672a1588112cc4", "3128545 ");
+        maps.put("35d2ccfa922c406f45acc7b1bad1d9edf72391cd2208312906129712f5215f75db9c6f1ab31974bf2a7d590e677655d38781c711ec73032b53bfefd151d9960f9cc90589d78a800afa44d9e28f5e0165", "3128563 ");
+        maps.put("35d2ccfa922c406f45acc7b1bad1d9edf72391cd2208312906129712f5215f75db9c6f1ab31974bf2a7d590e677655d38781c711ec73032b53bfefd151d9960f56cd9130daba0ba797e74614e3f809d7", "3128563 ");
+
+        Set<String> fileUrls = maps.keySet();
+        Map<String, Integer> countMap = new HashMap<String, Integer>();
+        for (String fileUrl : fileUrls) {
+            AES aes = new AES();
+            String url = aes.decrypt(fileUrl.trim());
+            String fileName = url.substring(url.lastIndexOf("/") + 1, url.length());
+            String examRecordDataId = maps.get(fileUrl).trim();
+            String sql = "INSERT INTO `ec_oe_exam_capture` (`exam_record_data_id`, `file_name`, `file_url`, `is_stranger`, `is_pass`, `creation_time`, `update_time`,`ext_msg`) "
+                    + " VALUES"
+                    + "('" + examRecordDataId + "', '" + fileName + "', '" + url + "', b'0', '1',NOW(),NOW(), '手动修改');";
+            System.out.println(sql);
+            Integer num = countMap.get(examRecordDataId);
+            countMap.put(examRecordDataId, num == null ? 1 : num + 1);
+        }
+
+        Set<String> examRecordDataIdNums = countMap.keySet();
+        for (String examRecordDataId : examRecordDataIdNums) {
+            int num = countMap.get(examRecordDataId);
+            String sql = "update ec_oe_exam_record_data set face_total_count = " + num + ",face_success_count = " + num + ",face_success_percent=100,baidu_face_liveness_success_percent=100 where id = " + examRecordDataId + ";";
+            System.out.println(sql);
+        }
+    }
+
 }
 }

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

@@ -1,6 +1,7 @@
 package cn.com.qmth.examcloud.core.oe.student.face.service.impl;
 package cn.com.qmth.examcloud.core.oe.student.face.service.impl;
 
 
 import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.commons.exception.StatusException;
+import cn.com.qmth.examcloud.commons.helpers.JsonHttpResponseHolder;
 import cn.com.qmth.examcloud.core.oe.common.base.Constants;
 import cn.com.qmth.examcloud.core.oe.common.base.Constants;
 import cn.com.qmth.examcloud.core.oe.common.entity.ExamCaptureEntity;
 import cn.com.qmth.examcloud.core.oe.common.entity.ExamCaptureEntity;
 import cn.com.qmth.examcloud.core.oe.common.entity.ExamCaptureQueueEntity;
 import cn.com.qmth.examcloud.core.oe.common.entity.ExamCaptureQueueEntity;
@@ -15,6 +16,7 @@ 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.ExamRecordPropertyCacheBean;
 import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
 import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
 import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
 import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
+import cn.com.qmth.examcloud.web.facepp.FaceppClient;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.IOUtils;
@@ -23,6 +25,7 @@ import org.apache.commons.logging.LogFactory;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.system.SystemProperties;
 import org.springframework.data.domain.Example;
 import org.springframework.data.domain.Example;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
@@ -96,8 +99,26 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
             captureLog.debug("[DISPOSE_FACE_COMPARE] face++人脸比对开始...");
             captureLog.debug("[DISPOSE_FACE_COMPARE] face++人脸比对开始...");
 
 
             //调用face++API执行人脸比对,得到返回结果
             //调用face++API执行人脸比对,得到返回结果
-            faceCompareResult = faceCompareService.getFaceppCompareResultByUrl(examCaptureQueue.getBaseFaceToken(),
-                    examCaptureQueue.getFileUrl());
+            String backup = PropertyHolder.getString("$upyun.site.1.domain.backup");
+            String main = PropertyHolder.getString("$upyun.site.1.domain");
+            JsonHttpResponseHolder jsonHttpResponseHolder = null;
+            try {
+                jsonHttpResponseHolder = FaceppClient.getClient().
+                        compareWithTokenAndImageUrl(examCaptureQueue.getBaseFaceToken(),
+                                examCaptureQueue.getFileUrl(), examCaptureQueue.getFileUrl().replace(main, backup));
+                faceCompareResult = jsonHttpResponseHolder.getRespBody();
+            } catch (StatusException e) {
+                //如果错误码是801,802,803直接结束,不重试
+                if (e.getCode().equals("801") || e.getCode().equals("802") || e.getCode().equals("803")) {
+                    examCaptureQueue.setFaceCompareResult(e.getDesc());
+                    saveExamCaptureAndDeleteQueue(examCaptureQueue);
+
+                    captureLog.debug("[DISPOSE_FACE_COMPARE] face++人脸比对无法处理的图片地址,保存人脸检测最终结果并删除队列,errMsg=" + e.getDesc());
+                    return;
+                }
+                throw e;
+            }
+
             if (captureLog.isDebugEnabled()) {
             if (captureLog.isDebugEnabled()) {
                 captureLog.debug("[DISPOSE_FACE_COMPARE] 调用face++API执行人脸比对,得到返回结果faceCompareResult:" + faceCompareResult);
                 captureLog.debug("[DISPOSE_FACE_COMPARE] 调用face++API执行人脸比对,得到返回结果faceCompareResult:" + faceCompareResult);
             }
             }
@@ -109,7 +130,7 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
                 //如果API并发次数超过上限,则保存错误信息到队列,并抛出异常,用于协调满载队列线程
                 //如果API并发次数超过上限,则保存错误信息到队列,并抛出异常,用于协调满载队列线程
                 if (errMsg.contains(Constants.FACE_COMPARE_CONCURRENCY_LIMIT_EXCEEDED)) {
                 if (errMsg.contains(Constants.FACE_COMPARE_CONCURRENCY_LIMIT_EXCEEDED)) {
                     examCaptureQueueService.saveExamCaptureQueueEntityByFailed(examCaptureQueue,
                     examCaptureQueueService.saveExamCaptureQueueEntityByFailed(examCaptureQueue,
-                            faceCompareResult.toString(), ExamCaptureQueueStatus.PROCESS_FACE_COMPARE_FAILED);
+                            "SatusCode:" + jsonHttpResponseHolder.getStatusCode() + " | " + faceCompareResult.toString(), ExamCaptureQueueStatus.PROCESS_FACE_COMPARE_FAILED);
 
 
                     captureLog.debug("[DISPOSE_FACE_COMPARE] face++人脸比对接口超过最大并发次数");
                     captureLog.debug("[DISPOSE_FACE_COMPARE] face++人脸比对接口超过最大并发次数");
 
 
@@ -155,7 +176,8 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
                 captureLog.debug("[DISPOSE_FACE_COMPARE] face++人脸比对出现错误,即将重试,errMsg:" + errMsg);
                 captureLog.debug("[DISPOSE_FACE_COMPARE] face++人脸比对出现错误,即将重试,errMsg:" + errMsg);
                 // 其它错误类型,保存错误信息到队列中,待自动重新服务处理
                 // 其它错误类型,保存错误信息到队列中,待自动重新服务处理
                 examCaptureQueueService.saveExamCaptureQueueEntityByFailed(examCaptureQueue,
                 examCaptureQueueService.saveExamCaptureQueueEntityByFailed(examCaptureQueue,
-                        faceCompareResult.toString(), ExamCaptureQueueStatus.PROCESS_FACE_COMPARE_FAILED);
+                        "SatusCode:" + jsonHttpResponseHolder.getStatusCode() + " | " + faceCompareResult.toString(), ExamCaptureQueueStatus.PROCESS_FACE_COMPARE_FAILED);
+                ExamCaptureProcessStatisticController.increaseFaceCompareFailedCount();//增加错误次数
             } else {
             } else {
                 //face++的结果检测到人脸,才执行百度活体检测
                 //face++的结果检测到人脸,才执行百度活体检测
                 if (faceCompareResult.containsKey("confidence")) {
                 if (faceCompareResult.containsKey("confidence")) {
@@ -274,6 +296,7 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
                 // 其它错误类型,保存错误信息到队列中,待自动重新服务处理
                 // 其它错误类型,保存错误信息到队列中,待自动重新服务处理
                 examCaptureQueueService.saveExamCaptureQueueEntityByFailed(examCaptureQueue,
                 examCaptureQueueService.saveExamCaptureQueueEntityByFailed(examCaptureQueue,
                         faceLivenessResultJson.toString(), ExamCaptureQueueStatus.PROCESS_FACELIVENESS_FAILED);
                         faceLivenessResultJson.toString(), ExamCaptureQueueStatus.PROCESS_FACELIVENESS_FAILED);
+                ExamCaptureProcessStatisticController.increaseFaceLivenessDetectFailedCount();//增加错误次数
 
 
             }
             }
             //百度活体检测成功,则保存最终检测结果,并删除临时的图片处理队列
             //百度活体检测成功,则保存最终检测结果,并删除临时的图片处理队列
@@ -367,10 +390,24 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
     public CompareFaceSyncInfo compareFaceSyncByFileUrl(Long studentId, String baseFaceToken, String fileUrl) {
     public CompareFaceSyncInfo compareFaceSyncByFileUrl(Long studentId, String baseFaceToken, String fileUrl) {
         CompareFaceSyncInfo compareFaceSyncInfo = new CompareFaceSyncInfo();
         CompareFaceSyncInfo compareFaceSyncInfo = new CompareFaceSyncInfo();
         compareFaceSyncInfo.setStudentId(studentId);
         compareFaceSyncInfo.setStudentId(studentId);
-        JSONObject facePPResult = faceCompareService.getFaceppCompareResultByUrl(baseFaceToken, fileUrl);
+        JSONObject facePPResult = null;
+        JsonHttpResponseHolder jsonHttpResponseHolder = null;
+        try {
+            String backup = PropertyHolder.getString("$upyun.site.1.domain.backup");
+            String main = PropertyHolder.getString("$upyun.site.1.domain");
+            jsonHttpResponseHolder = FaceppClient.getClient().
+                    compareWithTokenAndImageUrl(baseFaceToken,
+                            fileUrl, fileUrl.replace(main, backup));
+            facePPResult = jsonHttpResponseHolder.getRespBody();
+        } catch (StatusException e) {
+            compareFaceSyncInfo.setIsPass(false);
+            compareFaceSyncInfo.setErrorMsg(e.getDesc());
+            return compareFaceSyncInfo;
+        }
         if (facePPResult.containsKey(Constants.ERROR_MSG)) {
         if (facePPResult.containsKey(Constants.ERROR_MSG)) {
             compareFaceSyncInfo.setIsPass(false);
             compareFaceSyncInfo.setIsPass(false);
             compareFaceSyncInfo.setErrorMsg(facePPResult.toString());
             compareFaceSyncInfo.setErrorMsg(facePPResult.toString());
+            return compareFaceSyncInfo;
         } else {
         } else {
             if (facePPResult.containsKey("confidence")) {
             if (facePPResult.containsKey("confidence")) {
                 double confidence = facePPResult.getDouble("confidence");
                 double confidence = facePPResult.getDouble("confidence");
@@ -384,9 +421,10 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
                 compareFaceSyncInfo.setIsPass(false);
                 compareFaceSyncInfo.setIsPass(false);
                 compareFaceSyncInfo.setErrorMsg(facePPResult.toString());
                 compareFaceSyncInfo.setErrorMsg(facePPResult.toString());
             }
             }
+            return compareFaceSyncInfo;
         }
         }
 
 
-        return compareFaceSyncInfo;
+
     }
     }
 
 
     private File getUploadFile(MultipartFile file) {
     private File getUploadFile(MultipartFile file) {

+ 2 - 6
examcloud-core-oe-face-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/face/service/impl/FaceCompareServiceImpl.java

@@ -33,11 +33,6 @@ import java.net.URI;
 @Service("faceCompareService")
 @Service("faceCompareService")
 public class FaceCompareServiceImpl implements FaceCompareService {
 public class FaceCompareServiceImpl implements FaceCompareService {
     private static final Logger log = LoggerFactory.getLogger(FaceCompareServiceImpl.class);
     private static final Logger log = LoggerFactory.getLogger(FaceCompareServiceImpl.class);
-    private static URI COMPARE_URI;
-
-    static {
-        COMPARE_URI = URI.create("https://api-cn.faceplusplus.com/facepp/v3/compare");
-    }
 
 
     @Value("${$facepp.apiKey}")
     @Value("${$facepp.apiKey}")
     private String faceppApiKey;
     private String faceppApiKey;
@@ -46,6 +41,7 @@ public class FaceCompareServiceImpl implements FaceCompareService {
 
 
     @Override
     @Override
     public JSONObject getFaceppCompareResultByUrl(String baseFaceToken, String image_url2) {
     public JSONObject getFaceppCompareResultByUrl(String baseFaceToken, String image_url2) {
+
         CloseableHttpClient httpClient = HttpPoolUtil.getHttpClient();
         CloseableHttpClient httpClient = HttpPoolUtil.getHttpClient();
         CloseableHttpResponse httpResponse = null;
         CloseableHttpResponse httpResponse = null;
 
 
@@ -157,10 +153,10 @@ public class FaceCompareServiceImpl implements FaceCompareService {
             if (null != value) {
             if (null != value) {
                 String url = value.toString();
                 String url = value.toString();
                 log.debug("[getFaceCompareUri] .sysProperty.getValue()=" + sysProperty.getValue());
                 log.debug("[getFaceCompareUri] .sysProperty.getValue()=" + sysProperty.getValue());
+                System.setProperty("facepp.compare.url",url);
                 return URI.create(url);
                 return URI.create(url);
             }
             }
         }
         }
         throw new StatusException("300004", "未找到face++人脸比对的配置路径");
         throw new StatusException("300004", "未找到face++人脸比对的配置路径");
-//        return COMPARE_URI;
     }
     }
 }
 }

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

@@ -3,8 +3,10 @@ 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.Constants;
 import cn.com.qmth.examcloud.core.oe.common.base.utils.baiduFaceVerify.BaiduFaceVerifyUtil;
 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.core.oe.student.face.service.FaceLivenessService;
+import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 /**
 /**
@@ -16,7 +18,6 @@ import org.springframework.stereotype.Service;
 @Service("faceLivenessService")
 @Service("faceLivenessService")
 public class FaceLivenessServiceImpl implements FaceLivenessService {
 public class FaceLivenessServiceImpl implements FaceLivenessService {
 
 
-
     /**
     /**
      * 获取百度在线活体检测
      * 获取百度在线活体检测
      *
      *
@@ -26,7 +27,8 @@ public class FaceLivenessServiceImpl implements FaceLivenessService {
     @Override
     @Override
     public JSONObject getBaiduFaceLivenessResultJson(String fileUrl) {
     public JSONObject getBaiduFaceLivenessResultJson(String fileUrl) {
         JSONObject errorMsgJson = new JSONObject();
         JSONObject errorMsgJson = new JSONObject();
-        String accessTokenResult = BaiduFaceVerifyUtil.getAccessToken();
+        String accessTokenResult = BaiduFaceVerifyUtil.getAccessToken(PropertyHolder.getString("$baidu.apiKey"),
+                PropertyHolder.getString("$$.$baidu.secretKey"));
         //拿不到token
         //拿不到token
         if (StringUtils.isBlank(accessTokenResult)) {
         if (StringUtils.isBlank(accessTokenResult)) {
             errorMsgJson.put(Constants.BAIDU_ERROR_CODE, "APP100001");
             errorMsgJson.put(Constants.BAIDU_ERROR_CODE, "APP100001");