|
@@ -3,7 +3,9 @@ package com.zhongzheng.modules.tencentcloud.service.impl;
|
|
|
|
|
|
import cn.hutool.core.lang.Validator;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.tencentcloudapi.bda.v20200324.models.SegmentPortraitPicRequest;
|
|
|
import com.tencentcloudapi.common.Credential;
|
|
|
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
|
@@ -16,6 +18,7 @@ import com.tencentcloudapi.iai.v20200303.models.*;
|
|
|
import com.tencentcloudapi.ocr.v20181119.OcrClient;
|
|
|
import com.tencentcloudapi.ocr.v20181119.models.*;
|
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
|
+import com.zhongzheng.common.utils.DateUtils;
|
|
|
import com.zhongzheng.modules.alioss.bo.OssRequest;
|
|
|
import com.zhongzheng.modules.alioss.service.OssService;
|
|
|
import com.zhongzheng.modules.base.bo.UserProfileFit;
|
|
@@ -25,6 +28,10 @@ import com.zhongzheng.modules.base.vo.UserProfileVo;
|
|
|
import com.zhongzheng.modules.tencentcloud.bo.FaceQueryBo;
|
|
|
import com.zhongzheng.modules.tencentcloud.bo.InvoiceQueryBo;
|
|
|
import com.zhongzheng.modules.tencentcloud.service.IFaceOcrService;
|
|
|
+import com.zhongzheng.modules.user.domain.UserDeviceWhite;
|
|
|
+import com.zhongzheng.modules.user.domain.UserPhotoDevice;
|
|
|
+import com.zhongzheng.modules.user.service.IUserDeviceWhiteService;
|
|
|
+import com.zhongzheng.modules.user.service.IUserPhotoDeviceService;
|
|
|
import com.zhongzheng.modules.user.service.IUserService;
|
|
|
import com.zhongzheng.modules.user.vo.UserVo;
|
|
|
import org.slf4j.Logger;
|
|
@@ -35,6 +42,8 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
@Service
|
|
|
public class FaceOcrServiceImpl implements IFaceOcrService {
|
|
@@ -54,6 +63,12 @@ public class FaceOcrServiceImpl implements IFaceOcrService {
|
|
|
@Autowired
|
|
|
private IUserService iUserService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IUserPhotoDeviceService iUserPhotoDeviceService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IUserDeviceWhiteService iUserDeviceWhiteService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private IUserProfileService iUserProfileService;
|
|
|
|
|
@@ -73,6 +88,10 @@ public class FaceOcrServiceImpl implements IFaceOcrService {
|
|
|
if(Validator.isEmpty(userVo)){
|
|
|
return 0;
|
|
|
}
|
|
|
+ //照相设备校验
|
|
|
+ if (StringUtils.isNotBlank(bo.getDeviceName())){
|
|
|
+ deviceCheck(bo);
|
|
|
+ }
|
|
|
/* UserProfileQueryBo userProfileQueryBo = new UserProfileQueryBo();
|
|
|
userProfileQueryBo.setUserId(bo.getUserId());
|
|
|
userProfileQueryBo.setOrderGoodsId(bo.getOrderGoodsId());
|
|
@@ -86,8 +105,9 @@ public class FaceOcrServiceImpl implements IFaceOcrService {
|
|
|
// Map<String, String> maps = JSONObject.parseObject(info.getKeyValue(),Map.class);
|
|
|
|
|
|
// String oneInchPhotos = JSONObject.parseObject(String.valueOf(maps.get("recent_photos")), UserProfileFit.class).getValue(); //审核资料一寸照片
|
|
|
-
|
|
|
if(DetectFace(bo)){
|
|
|
+ //活体检测
|
|
|
+ detectLiveFaceCheck(bo);
|
|
|
String oneInchPhotos =ossHost+"/"+userVo.getOneInchPhotos();
|
|
|
Credential cred = new Credential(SecretId, SecretKey);
|
|
|
ClientProfile clientProfile = new ClientProfile();
|
|
@@ -103,6 +123,7 @@ public class FaceOcrServiceImpl implements IFaceOcrService {
|
|
|
faceRequest.setQualityControl(2L);
|
|
|
CompareFaceResponse response = iaiClient.CompareFace(faceRequest);
|
|
|
if (response.getScore().intValue() < 65){
|
|
|
+ addUserPhotoRecord(bo.getUserId(),bo.getUrlA(),bo.getOrderGoodsId(),4,bo.getDeviceName());
|
|
|
throw new CustomException("人脸识别不通过,请重新拍照!",606);
|
|
|
}
|
|
|
return response.getScore().intValue();
|
|
@@ -114,6 +135,70 @@ public class FaceOcrServiceImpl implements IFaceOcrService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void detectLiveFaceCheck(FaceQueryBo bo) {
|
|
|
+ Credential cred = new Credential(SecretId, SecretKey);
|
|
|
+ ClientProfile clientProfile = new ClientProfile();
|
|
|
+ clientProfile.setSignMethod(clientProfile.SIGN_TC3_256);
|
|
|
+ IaiClient iaiClient = new IaiClient(cred,"ap-guangzhou");
|
|
|
+ DetectLiveFaceRequest faceRequest = new DetectLiveFaceRequest();
|
|
|
+ if(Validator.isNotEmpty(bo.getUrlA())){
|
|
|
+ faceRequest.setUrl(ossHost+"/"+bo.getUrlA());
|
|
|
+ }else{
|
|
|
+ faceRequest.setImage(bo.getImageA()); //学习拍照
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ DetectLiveFaceResponse response = iaiClient.DetectLiveFace(faceRequest);
|
|
|
+ if (response.getScore().intValue() < 87){
|
|
|
+ addUserPhotoRecord(bo.getUserId(),bo.getUrlA(),bo.getOrderGoodsId(),3,bo.getDeviceName());
|
|
|
+ throw new CustomException("活体检测不通过,请重新拍照!",606);
|
|
|
+ }
|
|
|
+ }catch (TencentCloudSDKException e){
|
|
|
+ throw new CustomException(e.getMessage(),606);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //保存学员拍照错误记录
|
|
|
+ private void addUserPhotoRecord(Long userId,String photo,Long orderGoodsId,Integer type,String deviceName){
|
|
|
+ UserPhotoDevice add = new UserPhotoDevice();
|
|
|
+ add.setUserId(userId);
|
|
|
+ add.setPhoto(photo);
|
|
|
+ add.setOrderGoodsId(orderGoodsId);
|
|
|
+ add.setType(type);
|
|
|
+ add.setDeviceName(deviceName);
|
|
|
+ add.setCreateTime(DateUtils.getNowTime());
|
|
|
+ add.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ iUserPhotoDeviceService.save(add);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void deviceCheck(FaceQueryBo bo) {
|
|
|
+ //校验白黑名单
|
|
|
+ UserDeviceWhite deviceWhite = iUserDeviceWhiteService.getOne(new LambdaQueryWrapper<UserDeviceWhite>()
|
|
|
+ .eq(UserDeviceWhite::getUserId, bo.getUserId())
|
|
|
+ .eq(UserDeviceWhite::getDeviceName, bo.getDeviceName()));
|
|
|
+ if (ObjectUtils.isNotNull(deviceWhite)){
|
|
|
+ if (deviceWhite.getStatus() == 1){
|
|
|
+ //白名单
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (deviceWhite.getStatus() == 2){
|
|
|
+ //黑名单
|
|
|
+ addUserPhotoRecord(bo.getUserId(),bo.getUrlA(),bo.getOrderGoodsId(),1, bo.getDeviceName());
|
|
|
+ throw new CustomException("您有疑是使用虚拟摄像头学习,请更换高清摄像头设备或手机学习!",606);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //正则校验设备名称
|
|
|
+ String reg_select = "([a-zA-Z0-9_ ]+)\\(([a-zA-Z0-9]+)[:]+([a-zA-Z0-9]+)\\)";
|
|
|
+ Pattern pattern = Pattern.compile(reg_select);
|
|
|
+ Matcher matcher = pattern.matcher(bo.getDeviceName());
|
|
|
+ if (!matcher.matches()){
|
|
|
+ addUserPhotoRecord(bo.getUserId(),bo.getUrlA(),bo.getOrderGoodsId(),1, bo.getDeviceName());
|
|
|
+ throw new CustomException("您有疑是使用虚拟摄像头学习,请更换高清摄像头设备或手机学习!",606);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Boolean DetectFace(FaceQueryBo bo) {
|
|
|
try{
|
|
@@ -187,7 +272,8 @@ public class FaceOcrServiceImpl implements IFaceOcrService {
|
|
|
throw new CustomException("请保证人脸全部在照片范围内!");
|
|
|
}
|
|
|
}
|
|
|
- }catch (TencentCloudSDKException e){
|
|
|
+ }catch (Exception e){
|
|
|
+ addUserPhotoRecord(bo.getUserId(),bo.getUrlA(),bo.getOrderGoodsId(),2, bo.getDeviceName());
|
|
|
throw new CustomException("人脸检测错误:"+e.getMessage());
|
|
|
}
|
|
|
return true;
|