diff --git a/luoo_user/src/main/java/com/luoo/user/controller/UserController.java b/luoo_user/src/main/java/com/luoo/user/controller/UserController.java index 7caccc2..fb11141 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/UserController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/UserController.java @@ -62,9 +62,10 @@ public class UserController { if (user == null) { return new Result(false,StatusCode.LOGINERROR,"登录失败"); } - String token = jwtUtil.createJWT(user.getId(),user.getLoginname(),"user"); + String token = jwtUtil.createJWT(user.getId(),user.getMobile(),"user"); Map map = new HashMap(); map.put("userid",user.getId()); + map.put("mobile",user.getMobile()); map.put("token",token); map.put("name",user.getLoginname()); map.put("avatar",user.getAvatar()); diff --git a/luoo_user/src/main/java/com/luoo/user/interceptor/JwtInterceptor.java b/luoo_user/src/main/java/com/luoo/user/interceptor/JwtInterceptor.java index bec3d82..ad2ad25 100644 --- a/luoo_user/src/main/java/com/luoo/user/interceptor/JwtInterceptor.java +++ b/luoo_user/src/main/java/com/luoo/user/interceptor/JwtInterceptor.java @@ -30,6 +30,9 @@ public class JwtInterceptor implements HandlerInterceptor { } if (roles != null || !roles.equals("user")) { request.setAttribute("claims_user",token); + request.setAttribute("userid",claims.getId()); + request.setAttribute("mobile",claims.getSubject()); + } } catch (Exception e) { throw new RuntimeException("令牌不正确!"); diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserService.java b/luoo_user/src/main/java/com/luoo/user/service/UserService.java index f1ed802..8526912 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserService.java @@ -64,6 +64,20 @@ public class UserService { @Autowired private JwtUtil jwtUtil; + + + /** + * token解析示例 + */ + public void testParseToken() { + + String userid = (String) request.getAttribute("userid"); + String mobile = (String) request.getAttribute("mobile"); + System.out.println("用户ID"+userid); + System.out.println("手机号"+mobile); + } + + /** * 查询全部列表 * @return