lxw
2023-05-25 f3c27fb78447449a950ba73c5e72ceda64ad8a12
src/main/java/com/whyc/controller/FaceController.java
@@ -3,6 +3,7 @@
import com.arcsoft.face.FaceEngine;
import com.arcsoft.face.toolkit.ImageFactory;
import com.arcsoft.face.toolkit.ImageInfo;
import com.whyc.constant.YamlProperties;
import com.whyc.dto.Response;
import com.whyc.factory.FaceEngineFactory;
import com.whyc.pojo.PermitGroup;
@@ -50,8 +51,18 @@
    @ApiOperation(value = "在线激活人脸识别引擎",notes = "只需要刚开始时调用一次,会导致appId与硬件设备绑定,必须有外部网络,否则激活会失败!" +
            "后续使用无需再调用激活,可以离线使用")
    public Response activeOnline(){
        Response model = new Response();
        boolean b = FaceIdentifyUtil.activeOnline();
        boolean b = FaceIdentifyUtil.active(1);
        if(b){
            return new Response().set(1,true,"引擎激活成功");
        }else{
            return new Response().set(1,false,"引擎激活失败,请检查网络是否为外网并确认appId和key是否正确!");
        }
    }
    @GetMapping("activeOffline")
    @ApiOperation(value = "离线激活人脸识别引擎,增值版使用")
    public Response activeOffline(){
        boolean b = FaceIdentifyUtil.active(2);
        if(b){
            return new Response().set(1,true,"引擎激活成功");
        }else{
@@ -102,7 +113,12 @@
                File jarFile = applicationHome.getDir();
                //存储人脸图片的文件夹
                String fileDirName = jarFile.getParentFile().toString()+File.separator+"fg_photo";
                String fileDirName;
                if(YamlProperties.runModel == 1) {
                    fileDirName = jarFile.getParentFile().toString() + File.separator + "fg_photo";
                }else{
                    fileDirName = jarFile.toString() + File.separator + "fg_photo";
                }
                File file = new File(fileDirName);
                //不存在则创建该文件夹
@@ -173,7 +189,12 @@
                File jarFile = applicationHome.getDir();
                //存储人脸图片的文件夹
                String fileDirName = jarFile.getParentFile().toString()+File.separator+"fg_photo";
                String fileDirName;
                if(YamlProperties.runModel == 1) {
                    fileDirName = jarFile.getParentFile().toString() + File.separator + "fg_photo";
                }else{
                    fileDirName = jarFile.toString() + File.separator + "fg_photo";
                }
                File file = new File(fileDirName);
                //不存在则创建该文件夹
@@ -267,8 +288,14 @@
     */
    @PostMapping("faceCompare2N")
    @ApiOperation(value = "人脸识别对比")
    public Response faceCompare2N(@RequestBody String fileData){
    public Response faceCompare2N(@RequestBody String fileData,@RequestParam String uKeyId){
        Response res = new Response();
        //先验证uKeyId对应的用户
        UserInf userByUKeyId = userService.getUserByUKeyId(uKeyId);
        if (userByUKeyId == null){
            return res.set(1,false,"Ukey没有绑定用户");
        }
        /*====获取图片并校验活体,角度,像素大小====*/
        //由于图片字符串是由base64编码的,解码成字节数组
        fileData = fileData.replaceAll(" ", "+");
@@ -297,10 +324,21 @@
                    }else{
                        for (UserInf temp:userInfList){
                            String filePath = temp.getFace().getUrl();
                            ImageInfo imageInfo2 = ImageFactory.getRGBData(new File(filePath));
                            Response res3 = FaceIdentifyUtil.faceCompare(faceEngine, imageInfo, imageInfo2);
                            File file = new File(filePath);
                            //不存在则不继续执行
                            if(!file.exists()){
                                continue;
                            }
                            ImageInfo imageInfo2 = ImageFactory.getRGBData(file);
                            res = FaceIdentifyUtil.faceCompare(faceEngine, imageInfo, imageInfo2);
                            //对比成功,记录用户登录信息
                            if(res3.getCode()==1){
                            if(res.getCode()==1){
                                //Ukey对应用户和人脸对应用户验证
                                if(!temp.getUId().equals(userByUKeyId.getUId())){
                                    return res.set(1,false,"UKey对应用户和当前人脸对应用户不匹配");
                                }
                                res.setData2(temp);
                                // 将登陆成功的用户存入session
                                ActionUtil.getSession().setAttribute("user", temp);
@@ -311,7 +349,8 @@
                                if (permitList!=null && permitList.size()!=0) {
                                    ActionUtil.getSession().setAttribute("permits", permitList);
                                } else {
                                    res.setCode(0);
                                    res.setCode(1);
                                    res.setData(false);
                                    res.setMsg("还未分配权限");
                                }
                                //将新登录的用户存入application