0
点赞
收藏
分享

微信扫一扫

钉钉自定义机器人接入

zhyuzh3d 2022-03-30 阅读 48

用钉钉机器人,可以做一些通知,比如说程序的预警,风控啊。
官方描述
看官网描述,很强大,支持文本,链接,Markdown。

如果报错如下:
{"errcode":310000,"errmsg":"sign not match, more: [https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq]"}
那是因为勾选了 加密
在这里插入图片描述

加签之后需要将 url拼接上&timestamp= XX&sign=XX
通过下面方法可将加密后的参数拼接到url即可;

    private String sign(Long timestamp,String secret){
        try {
            String stringToSign = timestamp + "\n" + secret;
            Mac mac = Mac.getInstance("HmacSHA256");
            mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
            byte[] signData = mac.doFinal(stringToSign.getBytes(StandardCharsets.UTF_8));
            return URLEncoder.encode(new String(Base64.encodeBase64(signData)),"UTF-8");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

其他主题注意,必填参数缺失回报这个错。

{"errcode":400503,"errmsg":"miss param :XXXX"}

在这里插入图片描述

        OapiRobotSendRequest.Actioncard actionCard = new OapiRobotSendRequest.Actioncard();
        actionCard.setTitle("乔布斯 20 年前想打造一间苹果咖啡厅,而它正是 Apple Store 的前身");
        actionCard.setText("![screenshot](https://gw.alicdn.com/tfs/TB1ut3xxbsrBKNjSZFpXXcXhFXa-846-786.png) \n" +
                " ### 乔布斯 20 年前想打造的苹果咖啡厅 \n" +
                " Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划");
        actionCard.setBtnOrientation("0");
        actionCard.setSingleTitle("阅读全文");
        actionCard.setSingleURL("singleURL");
        actionCard.setHideAvatar("12");
        OapiRobotSendRequest.Btns btns = new OapiRobotSendRequest.Btns();
        btns.setTitle("21212");
        ArrayList<OapiRobotSendRequest.Btns> btns1 = new ArrayList<>();
        actionCard.setBtns(btns1);
//将主题封装带要执行的request
      request.setActionCard(actionCard);
      //执行
      OapiRobotSendResponse response = client.execute(request);
举报

相关推荐

0 条评论