从cookie中获取token,在根据token获取想要的数据 public String getToken2(HttpServletRequest request) throws Exception { try { Cookie[] cookies = request.getCookies(); if (cookies != null && cookies.length > 0) { for (Cookie cookie : cookies) { if ("token".equals(cookie.getName())) { String token = cookie.getValue(); HttpHeaders headers = new HttpHeaders(); RestTemplate restTemplate = new RestTemplate(); headers.put(HttpHeaders.COOKIE, Collections.singletonList("token=" + token)); HttpEntityrequestEntity = new HttpEntity<>("", headers); ResponseEntity responseEntity = restTemplate.exchange(accessTokenUrl, HttpMethod.GET, requestEntity, String.class); String body = responseEntity.getBody(); JSONObject bodyObj = JSON.parseObject(body); Integer code = bodyObj.getInteger("code"); if (code == 200 ) { JSONObject object = bodyObj.getJSONObject("member"); String uid = object.getString("uid"); return uid; } break; } } } } catch (Exception e) { e.printStackTrace(); } return null; }