From 852e62208a39e05d1158abf08cc5ec4ca201f96d Mon Sep 17 00:00:00 2001 From: majintao Date: Wed, 4 Jun 2025 15:06:30 +0800 Subject: [PATCH] =?UTF-8?q?=E9=92=89=E9=92=89=E5=8F=91=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E5=8A=A0@?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yinjihaun/util/DingDingMessageUtil.groovy | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/yinjihaun/util/DingDingMessageUtil.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/yinjihaun/util/DingDingMessageUtil.groovy index 39b9e53d2..9bb1b003a 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/yinjihaun/util/DingDingMessageUtil.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/yinjihaun/util/DingDingMessageUtil.groovy @@ -30,6 +30,28 @@ class DingDingMessageUtil { } } + static void sendTextMessageAndAt(String access_token, String msg, String atMobile) throws Exception { + HttpRequest request = new HttpRequest(); + HttpPost httppost = new HttpPost("https://oapi.dingtalk.com/robot/send?access_token=" + access_token); + httppost.addHeader("Content-Type", "application/json; charset=utf-8"); + + // 创建消息体,只包含一个手机号 + String textMsg = "{ " + + "\"msgtype\": \"text\", " + + "\"text\": {\"content\": \"" + msg + "\"}, " + + "\"at\": {\"atMobiles\": [\"" + atMobile + "\"]}" + // 只 @ 一个手机号 + "}"; + + StringEntity se = new StringEntity(textMsg, "utf-8"); + httppost.setEntity(se); + HttpResponse response = request.getHttpClient().execute(httppost); + + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + String result = EntityUtils.toString(response.getEntity(), "utf-8"); + System.out.println("消息发送结果:" + result); + } + } + static void sendMarkdownMessage(String access_token, String title, String msg){ HttpRequest request = new HttpRequest() JSONObject requestBody = new JSONObject()