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()