DingTalk group message push

1. Add DingTalk group robot

  • Log in on PC (the current version of mobile phone cannot set push keywords), group settings --> robot --> webhook
  • Make security settings
  • Copy the url corresponding to the webhook

2. Group message push

DingTalk group messages support plain text and markdown types

2.1 Call the sample source code

import com.alibaba.fastjson.JSONObject;
import com.hz.utils.HttpUtils;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

/**
 * 钉钉消息推送
 *
 * @author pp_lan
 */
public class MessagePusher {

    /**
     * 推送url
     */
    public static final String Webhook = "https://oapi.dingtalk.com/robot******thisisyourowngroupinfo";

    @Test
    public void testSimpleMessage() {

        JSONObject text = new JSONObject();
        text.put("content", "【预警】SimpleMessage");

        JSONObject params = new JSONObject();
        params.put("msgtype", "text");
        params.put("text", text);

        HttpUtils.sendPost(Webhook, params.toJSONString(), null);
    }

    @Test
    public void testMarkdownMessage() {

        JSONObject markdown = new JSONObject();
        markdown.put("title", "【预警】MarkdownMessage");
        markdown.put("text", "* collections 类集\n* classloader <font color=\"red\">类加载器</font>");

        JSONObject params = new JSONObject();
        params.put("msgtype", "markdown");
        params.put("markdown", markdown);

        HttpUtils.sendPost(Webhook, params.toJSONString(), null);
    }
}

2.2 Call instructions

The message needs to contain the safe word set by the group robot (here is an early warning), otherwise it will be filtered

2.3 Successful examples

Guess you like

Origin blog.csdn.net/pp_lan/article/details/132063890