// 发送请求HTTP-POST请求 url:请求地址; entity:json格式请求参数
public static String userPost(String url, String entity,String Token) {
try {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Authorization", "Bearer " + Token);
StringEntity se = new StringEntity(entity, "UTF-8");
se.setContentType("application/json; charset=utf-8");
httpPost.setEntity(se);
CloseableHttpResponse response = httpClient.execute(httpPost);
HttpEntity entity1 = response.getEntity();
String resStr = null;
if (entity1 != null) {
resStr = EntityUtils.toString(entity1, "UTF-8");
}
httpClient.close();
response.close();
return resStr;
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
public static void main(String[] args) {
String Code="HbmB45a9KIlpuqZ3BvOz9f",Token="t-6eaef0f44efc9e830520dd259061f81939a97542";
String result = post("https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal/",
"{\"app_id\":\"" + "cli_a0fd1e209538d00b" + "\",\"app_secret\":\"" + "gERSkHlCqjPCGGeu84jlWhO8FR1x5y7p" + "\"}");
String userResult = userPost("https://open.feishu.cn/open-apis/authen/v1/access_token",
"{\"grant_type\":\"authorization_code\",\"code\":\"" + Code + "\"}",Token);
//System.out.printf("result " + result);
System.out.printf("userResult " + userResult);
}
原文:https://www.cnblogs.com/Bill-Lee/p/14701804.html