xiangpei
2025-06-09 764a0fb1f27f9d7e3634686af47580a6f42b1ae3
framework/src/main/java/cn/lili/common/security/context/UserContext.java
@@ -26,6 +26,20 @@
public class UserContext {
    /**
     * 根据request获取用户id
     *
     * @return 授权用户
     */
    public static String getCurrentUserId() {
        if (RequestContextHolder.getRequestAttributes() != null) {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            String accessToken = request.getHeader(SecurityEnum.HEADER_TOKEN.getValue());
            return getAuthUser(accessToken).getId();
        }
        return null;
    }
    /**
     * 根据request获取用户信息
     *
     * @return 授权用户