yangdamao 11 ヶ月 前
コミット
b681739882

+ 7 - 0
zhongzheng-api/src/main/java/com/zhongzheng/controller/face/FaceController.java

@@ -41,6 +41,12 @@ public class FaceController extends BaseController {
         return AjaxResult.success(iFaceService.CompareFace(bo));
     }
 
+    @ApiOperation("人脸匹配测试")
+    @GetMapping("/certification/ceshi")
+    public AjaxResult<Integer> detectLiveFaceCheckTwo(@RequestParam("url")String url){
+        return AjaxResult.success(iFaceService.detectLiveFaceCheckTwo(url));
+    }
+
     @ApiOperation("身份证识别")
     @PostMapping("/certification/IDCardOCR")
     public AjaxResult IDCardOCR(@RequestBody FaceQueryBo bo){
@@ -76,4 +82,5 @@ public class FaceController extends BaseController {
         bo.setUserId(loginUser.getUser().getUserId());
         return AjaxResult.success(iFaceService.idCardCompareFace(bo));
     }
+
 }

+ 18 - 9
zhongzheng-framework/src/main/java/com/zhongzheng/framework/web/service/WxLoginService.java

@@ -1525,17 +1525,23 @@ public class WxLoginService implements IWxLoginService {
     }
 
     public Map<String, String> checkGzh_openId(WxLoginBody loginBody) {
-        initData();
         Map<String, String> map = new HashMap<>();
-        String param = String.format(gzh_wxAuthParam, gzh_appid, gzh_appsrcret, loginBody.getCode());
-        String resultString = HttpUtils.sendGet(gzh_wxAuthUrl, param);
-        //解析json
-        JSONObject jsonObject = (JSONObject) JSONObject.parse(resultString);
-        String access_token = String.valueOf(jsonObject.get("access_token"));
-        if(access_token.equals("null")){
-            throw new CustomException( String.valueOf(jsonObject.get("errmsg")));
+        String openId = "";
+        if (StringUtils.isNotBlank(loginBody.getGzhOpenid())){
+            openId = loginBody.getGzhOpenid();
+        }else {
+            initData();
+            String param = String.format(gzh_wxAuthParam, gzh_appid, gzh_appsrcret, loginBody.getCode());
+            String resultString = HttpUtils.sendGet(gzh_wxAuthUrl, param);
+            //解析json
+            JSONObject jsonObject = (JSONObject) JSONObject.parse(resultString);
+            String access_token = String.valueOf(jsonObject.get("access_token"));
+            if(access_token.equals("null")){
+                throw new CustomException( String.valueOf(jsonObject.get("errmsg")));
+            }
+            openId = String.valueOf(jsonObject.get("openid"));
         }
-        String openId = String.valueOf(jsonObject.get("openid"));
+
         //通过域名获取商户ID
         SysConfig config = iSysConfigService.getOne(new LambdaQueryWrapper<SysConfig>()
                 .eq(SysConfig::getConfigValue, scanLoginHost)
@@ -1584,17 +1590,20 @@ public class WxLoginService implements IWxLoginService {
             loginUser.setUser(user);
             map.put(Constants.TOKEN, wxTokenService.createToken(loginUser));
             map.put("gzhStatus", "1");
+            map.put("gzhOpenid", openId);
             return map;
         }
         //校验公众号openId
         User user = iUserService.getUserByGzhOpenId(openId);
         if (ObjectUtils.isNull(user)){
             map.put("gzhStatus", "0");
+            map.put("gzhOpenid", openId);
             return map;
         }
         ClientLoginUser loginUser = new ClientLoginUser();
         loginUser.setUser(user);
         map.put(Constants.TOKEN, wxTokenService.createToken(loginUser));
+        map.put("gzhOpenid", openId);
         map.put("gzhStatus", "1");
         return map;
     }

+ 2 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/system/domain/SysTenant.java

@@ -131,4 +131,6 @@ private static final long serialVersionUID=1L;
     private Integer wxSign;
     /** 手机验证码登录标识:1隐藏 0显示 */
     private Integer telSign;
+    /** 活体检测标签:1开启 0关闭*/
+    private Integer detectLiveSign;
 }

+ 2 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/tencentcloud/service/IFaceOcrService.java

@@ -24,4 +24,6 @@ public interface IFaceOcrService {
     Map<String,Object> ImageRecognition(FaceQueryBo bo);
 
     Integer idCardCompareFace(FaceQueryBo bo);
+
+    Integer detectLiveFaceCheckTwo(String url);
 }

+ 38 - 6
zhongzheng-system/src/main/java/com/zhongzheng/modules/tencentcloud/service/impl/FaceOcrServiceImpl.java

@@ -19,12 +19,15 @@ 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.common.utils.ServletUtils;
 import com.zhongzheng.modules.alioss.bo.OssRequest;
 import com.zhongzheng.modules.alioss.service.OssService;
 import com.zhongzheng.modules.base.bo.UserProfileFit;
 import com.zhongzheng.modules.base.bo.UserProfileQueryBo;
 import com.zhongzheng.modules.base.service.IUserProfileService;
 import com.zhongzheng.modules.base.vo.UserProfileVo;
+import com.zhongzheng.modules.system.domain.SysTenant;
+import com.zhongzheng.modules.system.service.ISysTenantService;
 import com.zhongzheng.modules.tencentcloud.bo.FaceQueryBo;
 import com.zhongzheng.modules.tencentcloud.bo.InvoiceQueryBo;
 import com.zhongzheng.modules.tencentcloud.service.IFaceOcrService;
@@ -72,6 +75,9 @@ public class FaceOcrServiceImpl implements IFaceOcrService {
     @Autowired
     private IUserProfileService iUserProfileService;
 
+    @Autowired
+    private ISysTenantService iSysTenantService;
+
     private static Logger log = LoggerFactory.getLogger(FaceOcrServiceImpl.class);
     /**
      * 学习拍照比对
@@ -107,7 +113,12 @@ public class FaceOcrServiceImpl implements IFaceOcrService {
     //        String oneInchPhotos = JSONObject.parseObject(String.valueOf(maps.get("recent_photos")), UserProfileFit.class).getValue(); //审核资料一寸照片
             if(DetectFace(bo)){
                 //活体检测
-                detectLiveFaceCheck(bo);
+                String tenantId = ServletUtils.getRequest().getHeader("TenantId");
+                SysTenant tenant = iSysTenantService.getById(Long.valueOf(tenantId));
+                if (ObjectUtils.isNotNull(tenant) && tenant.getDetectLiveSign() == 1){
+                    //机构开启活体检测
+                    detectLiveFaceCheck(bo);
+                }
                 String oneInchPhotos =ossHost+"/"+userVo.getOneInchPhotos();
                 Credential cred = new Credential(SecretId, SecretKey);
                 ClientProfile clientProfile = new ClientProfile();
@@ -148,8 +159,8 @@ public class FaceOcrServiceImpl implements IFaceOcrService {
         }
         try {
             DetectLiveFaceResponse response = iaiClient.DetectLiveFace(faceRequest);
-            if (response.getScore().intValue() < 87){
-                addUserPhotoRecord(bo.getUserId(),bo.getUrlA(),bo.getOrderGoodsId(),3,bo.getDeviceName());
+            if (response.getIsLiveness()){
+                addUserPhotoRecord(bo.getUserId(),bo.getUrlA(),bo.getOrderGoodsId(),3,bo.getDeviceName()+",活体检测分数:"+response.getScore());
                 throw new CustomException("活体检测不通过,请重新拍照!",606);
             }
         }catch (TencentCloudSDKException e){
@@ -158,6 +169,26 @@ public class FaceOcrServiceImpl implements IFaceOcrService {
 
     }
 
+
+    public Integer detectLiveFaceCheckTwo(String url) {
+        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();
+        faceRequest.setUrl(url);
+        try {
+            DetectLiveFaceResponse response = iaiClient.DetectLiveFace(faceRequest);
+            if (response.getScore().intValue() < 87){
+                throw new CustomException("活体检测不通过,请重新拍照!活体检测分数:"+response.getScore().intValue(),606);
+            }
+            return response.getScore().intValue();
+        }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();
@@ -175,8 +206,9 @@ public class FaceOcrServiceImpl implements IFaceOcrService {
     private void deviceCheck(FaceQueryBo bo) {
         //校验白黑名单
         UserDeviceWhite deviceWhite = iUserDeviceWhiteService.getOne(new LambdaQueryWrapper<UserDeviceWhite>()
-                .eq(UserDeviceWhite::getUserId, bo.getUserId())
-                .eq(UserDeviceWhite::getDeviceName, bo.getDeviceName()));
+//                .eq(UserDeviceWhite::getUserId, bo.getUserId())
+                .eq(UserDeviceWhite::getDeviceName, bo.getDeviceName())
+                .last("limit 1"));
         if (ObjectUtils.isNotNull(deviceWhite)){
             if (deviceWhite.getStatus() == 1){
                 //白名单
@@ -193,7 +225,7 @@ public class FaceOcrServiceImpl implements IFaceOcrService {
         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()){
+        if (!matcher.find()){
             addUserPhotoRecord(bo.getUserId(),bo.getUrlA(),bo.getOrderGoodsId(),1, bo.getDeviceName());
             throw new CustomException("您有疑是使用虚拟摄像头学习,请更换高清摄像头设备或手机学习!",606);
         }

+ 1 - 1
zhongzheng-system/src/main/java/com/zhongzheng/modules/wx/bo/WxLoginBody.java

@@ -57,7 +57,7 @@ public class WxLoginBody {
     @ApiModelProperty("业务员ID")
     private Long sellerId;
 
-    @ApiModelProperty("openid")
+    @ApiModelProperty("gzhOpenid")
     private String gzhOpenid;
 
     @ApiModelProperty("union_id")