要做前后端分离,不在同一个域名下
现在有两个接口:一个登录接口login,一个userInfo接口。前端使用ajax请求
登录代码如下
Subject subject = SecurityUtils.getSubject();
// ThreadContext.bind(subject);
subject.login(token);
SysUser user = (SysUser) subject.getPrincipal();
subject.getSession().setAttribute("user", user);
Cookie cookie = new Cookie("uid", _userInfo(user));
cookie.setMaxAge(3600);
response.addCookie(cookie);
return Outs.ok("登录成功");
登录成功之后,前台页面调用userInfo接口,cookie没有传过来
SysUser user = new SysUser();
HttpServletRequest request = Mvcs.getReq();
Cookie[] cookies = request.getCookies();
for (Cookie cookie : cookies) {
if (cookie.getName().equals("uid")) {
String v = cookie.getValue();
byte[] uv = jedis().get(v.getBytes());
if (uv != null) {
user = (SysUser) ToolKit.unserialize(uv);
}
break;
}
}
请问大神们,有没有好的解决办法