|
@@ -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);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-}
|