——————————DescriptionStart——————————
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明



基于javaweb的SpringBoot人脸识别登录系统(java+springboot+maven+mysql)
实现的功能有:
管理员后台录入人脸信息、前台用户登录时选择人脸识别方式登录。
PS:用到了百度人脸识别的API接口,包括人脸检测、人脸识别对比等。
*本项目需要使用电脑摄像头,运行前先测试下摄像头是否正常:https://www.bchrt.com/tools/webcam-test/
——————————CodeStart——————————
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| HttpSession session = getSession(); if(session != null){ session.setAttribute(key,object); } }
public static User getLoginedUser(){ HttpSession session = getSession(); if(session != null){ Object attribute = session.getAttribute(SessionConstant.SESSION_USER_LOGIN_KEY); return attribute == null ? null : (User)attribute; } return null; } } package com.yuanlrc.base.controller.common;
@RequestMapping("photo") @Controller public class PhotoController { @Autowired private ResourceLoader resourceLoader; @Value("${ylrc.upload.photo.path}") private String uploadPhotoPath;
@RequestMapping(value="/view") @ResponseBody public ResponseEntity<?> viewPhoto(@RequestParam(name="filename",required=true)String filename){
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| menuService.delete(id); } catch (Exception e) { return Result.error(CodeMsg.ADMIN_MENU_DELETE_ERROR); } operaterLogService.add("删除菜单信息,菜单ID【" + id + "】"); return Result.success(true); } } package com.yuanlrc.base.controller.admin;
@RequestMapping("/role") @Controller
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| try { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "GB2312")); String buf = null; try { while ((buf = bufferedReader.readLine()) != null) { string += buf; } } catch (Exception e) { e.printStackTrace(); } finally { try { bufferedReader.close(); } catch (IOException e) { e.printStackTrace(); } } } catch (Exception e) { } return string; }
public static String getFormatterDate(String date, String formatter, int minites) { SimpleDateFormat sdf = new SimpleDateFormat(formatter); String ret = null; try { Date parse = sdf.parse(date); Calendar calendar = Calendar.getInstance(); calendar.setTime(parse); calendar.add(Calendar.MINUTE, minites); ret = sdf.format(calendar.getTime()); } catch (ParseException e) { e.printStackTrace(); } return ret; }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| photo.transferTo(new File(uploadPhotoPath+"/"+filename)); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } log.info("图片上传成功,保存位置:" + uploadPhotoPath + filename); return Result.success(filename); } } package com.yuanlrc.base.controller.common;
@Controller @RequestMapping("/cpacha") public class CpachaController {
private Logger log = LoggerFactory.getLogger(CpachaController.class);
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| } mac = sb.toString(); } catch (Exception e) { e.printStackTrace(); } return mac.toUpperCase(); }
public static boolean authOrder(String orderSn, String phone) {
return true; }
public static String readFileToString(File file) { String string = ""; if (file != null) { try { BufferedReader br = new BufferedReader(new FileReader(file)); String line = null; while ((line = br.readLine()) != null) { string += line; } br.close(); } catch (Exception e) { } } return string; } } package com.yuanlrc.base.controller.admin;
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| if (user == null) { return Result.error(CodeMsg.ADMIN_USERNAME_NO_EXIST); } if (StringUtils.isEmpty(user.getFace())) { return Result.error(CodeMsg.ADMIN_USER_FACE_EMPTY); } if (user.getStatus() == User.ADMIN_USER_STATUS_UNABLE) { return Result.error(CodeMsg.ADMIN_USER_UNABLE); } if (user.getRole() == null || user.getRole().getStatus() == Role.ADMIN_ROLE_STATUS_UNABLE) { return Result.error(CodeMsg.ADMIN_USER_ROLE_UNABLE); } if (user.getRole().getAuthorities() == null || user.getRole().getAuthorities().size() == 0) { return Result.error(CodeMsg.ADMIN_USER_ROLE_AUTHORITES_EMPTY); } String faceMatch = BaiduApi.faceMatch(user.getFace(), face); log.info(faceMatch); JSONObject parseObject = JSONObject.parseObject(faceMatch); if (parseObject.getIntValue("error_code") != 0) { CodeMsg codeMsg = CodeMsg.DATA_ERROR; codeMsg.setMsg(parseObject.getString("error_msg")); return Result.error(codeMsg); } JSONObject result = parseObject.getJSONObject("result"); if (result.getBigDecimal("score").compareTo(new BigDecimal(80)) < 0) { return Result.error(CodeMsg.ADMIN_USER_FACE_NOT_MATCH); } SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, user); operaterLogService.add("用户【" + user.getUsername() + "】于【" + StringUtil.getFormatterDate(new Date(), "yyyy-MM-dd HH:mm:ss") + "】人脸识别登录系统!"); log.info("用户成功登录,user = " + user); return Result.success(true); }
@RequestMapping(value = "/face_login_check", method = RequestMethod.POST) @ResponseBody public Result<Boolean> faceLoginCheck(@RequestParam(name = "username", required = true) String username) {
|
——————————PayStart——————————
项目链接:
https://javayms.github.io?id=321422302105200gk
https://javayms.pages.dev?id=321422302105200gk