Java implements DingTalk custom group chat robot

Reference documentation:

Custom robot access - DingTalk open platform https://open.dingtalk.com/document/orgapp/custom-robot-access

Customized robot security settings - DingTalk open platform currently has 3 security setting methods, please choose one according to your needs. https://open.dingtalk.com/document/robots/customize-robot-security-settings

        1. Add a group chat robot to the group chat (push messages here by adding signatures)

                

If a custom keyword         is set here , the keyword must be included in the sent text content, otherwise the push will be invalid, and there is no need to pass the sign×tamp parameters in the future (detailed instructions are provided in the test session)

2. Save push information for later use

3. Request parameter initialization

public static void main(String[] args) throws Exception{
        Long timestamp = System.currentTimeMillis()+50*60*1000;//保证时间误差不超过1小时
        System.out.println("timestamp:"+timestamp);
        String secret = "加签字符串粘贴到此处";
        String stringToSign = timestamp + "\n" + secret;
        Mac mac = Mac.getInstance("HmacSHA256");
        mac.init(new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA256"));
        byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8"));
        String sign = URLEncoder.encode(new String(Base64.encodeBase64(signData)),"UTF-8");
        System.out.println("sign:"+sign);
    }

The running results are as follows:

 4. Copy the robot's Webhook address, splice the request parameters, and try to send a group message

 5. Instructions for using the message push API

important

  • The permission to use custom robots to send messages has been enabled by default, and there is no need to apply. That is, when sending a request to the Webhook address, there is no need to apply for permission.

  • When initiating a POST request, the character set encoding must be set to UTF-8.

  • Each robot can send up to 20 messages per minute. Sending messages too frequently will seriously affect the user experience of group members. In scenarios where a large number of messages are sent (such as system monitoring alarms), the information can be integrated and sent to the group in summary form through markdown messages.

  • Interface call volume description: The cumulative number of calls of the DingTalk standard version interface is 10,000 times per month, and the current interface will consume the number of calls. If the call volume cannot meet the demand, you can upgrade to DingTalk Professional Edition (Open API call volume 500,000 times/month) or DingTalk Exclusive Edition (Open API call volume 5 million times/month) to expand the number of calls.

 For specific parameter description, please refer to: Use of custom robots in group chat scenarios - DingTalk Open Platform

Guess you like

Origin blog.csdn.net/qq_42697946/article/details/131062680