HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); // 2. 构建请求参数(与文档示例完全一致) Map<String, Object> requestBody = new HashMap<>(); requestBody.put("grant_type", "client_credential"); // 必须为 client_credential requestBody.put("appid", app.getAppKey()); // 参数名是 appid,不是 appId requestBody.put("secret", app.getAppSecret()); requestBody.put("force_refresh", true); // 根据业务需要选择,普通模式为 false // 3. 将请求体和请求头封装成 HttpEntity HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(requestBody, headers); ResponseEntity<String> stringResponseEntity = restTemplate.postForEntity(app.getAppUrl() + "/cgi-bin/stable_token", requestEntity, String.class); if (!stringResponseEntity.getStatusCode().is2xxSuccessful()){ throw new BadRequestAlertException("请求失败,错误是:"+stringResponseEntity.getBody()); }