public static void dingding(String token, String content) throws Exception {
PrintWriter out = null;
URL serverUrl = new URL("https://oapi.dingtalk.com/robot/send?access_token=" + token);
HttpURLConnection conn = (HttpURLConnection) serverUrl.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setDoInput(true);
conn.setDoOutput(true);
Map<String, Object> date = new HashMap<>();
date.put("msgtype", "text");
Map<String, Object> text = new HashMap<>();
text.put("content", content);
date.put("text", text);
// 获取URLConnection对象对应的输出流
out = new PrintWriter(conn.getOutputStream());
// 发送请求参数
JSONObject json = new JSONObject(date);
out.print(json.toJSONString());
// flush输出流的缓冲
out.flush();
conn.setInstanceFollowRedirects(false);
conn.connect();
String result = getReturn(conn);
}
钉钉推送方法记录
最新推荐文章于 2024-04-03 10:54:26 发布