梳理token解析逻辑

main
wangqing 11 months ago
parent 85435785be
commit 11cb0abdf4

@ -62,9 +62,10 @@ public class UserController {
if (user == null) { if (user == null) {
return new Result(false,StatusCode.LOGINERROR,"登录失败"); 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 map = new HashMap();
map.put("userid",user.getId()); map.put("userid",user.getId());
map.put("mobile",user.getMobile());
map.put("token",token); map.put("token",token);
map.put("name",user.getLoginname()); map.put("name",user.getLoginname());
map.put("avatar",user.getAvatar()); map.put("avatar",user.getAvatar());

@ -30,6 +30,9 @@ public class JwtInterceptor implements HandlerInterceptor {
} }
if (roles != null || !roles.equals("user")) { if (roles != null || !roles.equals("user")) {
request.setAttribute("claims_user",token); request.setAttribute("claims_user",token);
request.setAttribute("userid",claims.getId());
request.setAttribute("mobile",claims.getSubject());
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("令牌不正确!"); throw new RuntimeException("令牌不正确!");

@ -64,6 +64,20 @@ public class UserService {
@Autowired @Autowired
private JwtUtil jwtUtil; 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 * @return

Loading…
Cancel
Save