dingtalk.oapi.chat.send (发送群消息)

发送群消息

公共参数

请求参数

名称 类型 是否必须 示例值 更多限制 描述
chatid String 可选 chatxxx 群会话id
action_card ActionCard 可选 actionCard消息
  • └ title
  • String
  • 可选
  • 透出到会话列表和通知的文案
  • 透出到会话列表和通知的文案
  • └ markdown
  • String
  • 可选
  • 消息内容
  • 消息内容
  • └ single_title
  • String
  • 可选
  • 111
  • 使用整体跳转ActionCard样式时的标题,必须与single_url同时设置
  • └ single_url
  • String
  • 可选
  • url
  • 使用整体跳转ActionCard样式时的链接url,必须与single_title同时设置
  • └ btn_orientation
  • String
  • 可选
  • 1
  • 使用独立跳转ActionCard样式时的按钮排列方式,竖直排列(0),横向排列(1);必须与btn_json_list同时设置
  • btn_json_list
  • BtnJson []
  • 可选
  • 使用独立跳转ActionCard样式时的按钮列表;必须与btn_orientation同时设置
  • └ title
  • String
  • 可选
  • 111
  • 使用独立跳转ActionCard样式时的按钮的标题
  • └ action_url
  • String
  • 可选
  • url
  • 使用独立跳转ActionCard样式时的按钮的链接url
  • └ agentid
  • String
  • 可选
  • 111
  • 可选,微应用agentid。默认在角标处显示企业的名称和图标,如果传入agentid则在角标处显示微应用的名称和图标
  • └ hide_avatar
  • Boolean
  • 可选
  • true
  • 是否隐藏发送者头像
oa Oa 可选 OA消息
  • └ message_url
  • String
  • 可选
  • 消息链接
  • 消息链接
  • └ pc_message_url
  • String
  • 可选
  • pc端消息链接
  • pc端消息链接
  • head
  • Head
  • 可选
  • 消息头部
  • └ text
  • String
  • 可选
  • 消息头部标题
  • 消息头部标题
  • └ bgcolor
  • String
  • 可选
  • FFBBBBBB
  • 消息头部背景颜色
  • body
  • Body
  • 可选
  • 消息体
  • └ title
  • String
  • 可选
  • 消息体的标题
  • 消息体的标题
  • └ content
  • String
  • 可选
  • 消息体的内容
  • 消息体的内容,最多显示3行
  • └ image
  • String
  • 可选
  • mediaId
  • 消息体中的图片media_id
  • └ file_count
  • String
  • 可选
  • 1
  • 自定义的附件数目。此数字仅供显示,钉钉不作验证
  • └ author
  • String
  • 可选
  • 自定义的作者名字
  • 自定义的作者名字
  • rich
  • Rich
  • 可选
  • 单行富文本信息
  • └ num
  • String
  • 可选
  • 1
  • 单行富文本信息的单位
  • └ unit
  • String
  • 可选
  • 1
  • 单行富文本信息的数目
  • form
  • Form []
  • 可选
  • 消息体的表单,最多显示6个,超过会被隐藏
  • └ key
  • String
  • 可选
  • key
  • 消息体的关键字
  • └ value
  • String
  • 可选
  • value
  • 消息体的关键字对应的值
voice Voice 可选 语音消息
  • └ media_id
  • String
  • 可选
  • mediaId
  • 语音mediaId
  • └ duration
  • Number
  • 可选
  • 100
  • 语音正整数,小于60,表示音频时长长
file File 可选 文件消息
  • └ media_id
  • String
  • 可选
  • mediaId
  • 文件mediaId
image Image 可选 图片消息
  • └ media_id
  • String
  • 可选
  • mediaId
  • 图片mediaId
link Link 可选 链接消息
  • └ title
  • String
  • 可选
  • 消息标题
  • 消息标题
  • └ text
  • String
  • 可选
  • 消息文本
  • 消息文本
  • └ picUrl
  • String
  • 可选
  • picUrl
  • 图片地址
  • └ messageUrl
  • String
  • 可选
  • messageUrl
  • 消息点击链接地址
text Text 可选 文本消息
  • └ content
  • String
  • 可选
  • 文本消息内容
  • 文本消息内容
msgtype String 可选 text 消息类型
markdown Markdown 可选 markdown消息
  • └ title
  • String
  • 可选
  • 首屏会话透出的展示内容
  • 首屏会话透出的展示内容
  • └ text
  • String
  • 可选
  • markdown格式的消息
  • markdown格式的消息
msg Msg 可选 消息格式
  • text
  • Text
  • 可选
  • 文本消息
  • └ content
  • String
  • 可选
  • txt
  • 消息内容,建议500字符以内
  • └ msgtype
  • String
  • 可选
  • text
  • 消息类型
  • link
  • Link
  • 可选
  • link消息
  • └ messageUrl
  • String
  • 可选
  • messageUrl
  • 消息点击链接地址
  • └ picUrl
  • String
  • 可选
  • picUrl
  • 图片地址
  • └ text
  • String
  • 可选
  • 消息文本
  • 消息文本
  • └ title
  • String
  • 可选
  • 消息标题
  • 消息标题
  • image
  • Image
  • 可选
  • 图片消息
  • └ media_id
  • String
  • 可选
  • @mediaId
  • 图片mediaId
  • file
  • File
  • 可选
  • 文件消息
  • └ media_id
  • String
  • 可选
  • @mediaId
  • @mediaId
  • voice
  • Voice
  • 可选
  • 语音消息
  • └ media_id
  • String
  • 可选
  • @mediaId
  • 媒体文件id。2MB,播放长度不超过60s,AMR格式
  • └ duration
  • Number
  • 可选
  • 100
  • 正整数,小于60,表示音频时长
  • oa
  • Oa
  • 可选
  • oa消息
  • head
  • Head
  • 可选
  • 消息头部内容
  • └ bgcolor
  • String
  • 可选
  • bgcolor
  • 消息头部的背景颜色。长度限制为8个英文字符,其中前2为表示透明度,后6位表示颜色值。不要添加0x
  • └ text
  • String
  • 可选
  • text
  • 消息的头部标题 (向普通会话发送时有效,向企业会话发送时会被替换为微应用的名字),长度限制为最多10个字符
  • └ message_url
  • String
  • 可选
  • message_url
  • 消息点击链接地址,当发送消息为小程序时支持小程序跳转链接
  • └ pc_message_url
  • String
  • 可选
  • pc_message_url
  • PC端点击消息时跳转到的地址
  • body
  • Body
  • 可选
  • 消息体
  • form
  • Form []
  • 可选
  • 消息体的表单,最多显示6个,超过会被隐藏
  • └ value
  • String
  • 可选
  • value
  • 消息体的关键字对应的值
  • └ key
  • String
  • 可选
  • key
  • 消息体的关键字
  • rich
  • Rich
  • 可选
  • 单行富文本信息
  • └ unit
  • String
  • 可选
  • unit
  • 单行富文本信息的数目
  • └ num
  • String
  • 可选
  • num
  • 单行富文本信息的数目
  • └ author
  • String
  • 可选
  • author
  • 自定义的作者名字
  • └ file_count
  • String
  • 可选
  • file_count
  • 自定义的附件数目。此数字仅供显示,钉钉不作验证
  • └ image
  • String
  • 可选
  • image
  • 消息体中的图片,支持图片资源@mediaId
  • └ content
  • String
  • 可选
  • content
  • 消息体的内容,最多显示3行
  • └ title
  • String
  • 可选
  • title
  • 消息体的标题,建议50个字符以内
  • action_card
  • ActionCard
  • 可选
  • action_card卡片消息
  • └ agentid
  • String
  • 可选
  • agentid
  • agentid
  • btn_json_list
  • BtnJsonList []
  • 可选
  • 使用独立跳转ActionCard样式时的按钮列表;必须与btn_orientation同时设置
  • └ action_url
  • String
  • 可选
  • action_url
  • 使用独立跳转ActionCard样式时的按钮的标题,最长20个字符
  • └ title
  • String
  • 可选
  • title
  • 使用独立跳转ActionCard样式时的按钮的标题,最长20个字符
  • └ btn_orientation
  • String
  • 可选
  • 0
  • 使用独立跳转ActionCard样式时的按钮排列方式,竖直排列(0),横向排列(1);必须与btn_json_list同时设置
  • └ single_url
  • String
  • 可选
  • single_url
  • 消息点击链接地址,当发送消息为小程序时支持小程序跳转链接,最长500个字符
  • └ single_title
  • String
  • 可选
  • single_title
  • 使用整体跳转ActionCard样式时的标题,必须与single_url同时设置,最长20个字符
  • └ markdown
  • String
  • 可选
  • markdown
  • 消息内容,支持markdown,语法参考标准markdown语法。建议1000个字符以内
  • └ title
  • String
  • 可选
  • title
  • 透出到会话列表和通知的文案,最长64个字符
  • └ hide_avatar
  • Boolean
  • 可选
  • true
  • 是否隐藏发送者头像
  • markdown
  • Markdown
  • 可选
  • markdown消息
  • └ text
  • String
  • 可选
  • text
  • markdown格式的消息
  • └ title
  • String
  • 可选
  • title
  • 首屏会话透出的展示内容

响应参数

名称 类型 示例值 描述
errcode Number 0 errcode
errmsg String ok errmsg
messageId String 111 messageId

请求示例

  • JAVA
  • .NET
  • PHP
  • CURL
  • Python
  • C/C++
  • NodeJS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/chat/send");
OapiChatSendRequest req = new OapiChatSendRequest();
req.setChatid("chatxxx");
ActionCard obj1 = new ActionCard();
obj1.setTitle("透出到会话列表和通知的文案");
obj1.setMarkdown("消息内容");
obj1.setSingleTitle("111");
obj1.setSingleUrl("url");
obj1.setBtnOrientation("1");
List<BtnJson> list3 = new ArrayList<BtnJson>();
BtnJson obj4 = new BtnJson();
list3.add(obj4);
obj4.setTitle("111");
obj4.setActionUrl("url");
obj1.setBtnJsonList(list3);
obj1.setAgentid("111");
obj1.setHideAvatar(true);
req.setActionCard(obj1);
Oa obj5 = new Oa();
obj5.setMessageUrl("消息链接");
obj5.setPcMessageUrl("pc端消息链接");
Head obj6 = new Head();
obj6.setText("消息头部标题");
obj6.setBgcolor("FFBBBBBB");
obj5.setHead(obj6);
Body obj7 = new Body();
obj7.setTitle("消息体的标题");
obj7.setContent("消息体的内容");
obj7.setImage("mediaId");
obj7.setFileCount("1");
obj7.setAuthor("自定义的作者名字");
Rich obj8 = new Rich();
obj8.setNum("1");
obj8.setUnit("1");
obj7.setRich(obj8);
List<Form> list10 = new ArrayList<Form>();
Form obj11 = new Form();
list10.add(obj11);
obj11.setKey("key");
obj11.setValue("value");
obj7.setForm(list10);
obj5.setBody(obj7);
req.setOa(obj5);
Voice obj12 = new Voice();
obj12.setMediaId("mediaId");
obj12.setDuration(100L);
req.setVoice(obj12);
File obj13 = new File();
obj13.setMediaId("mediaId");
req.setFile(obj13);
Image obj14 = new Image();
obj14.setMediaId("mediaId");
req.setImage(obj14);
Link obj15 = new Link();
obj15.setTitle("消息标题");
obj15.setText("消息文本");
obj15.setPicUrl("picUrl");
obj15.setMessageUrl("messageUrl");
req.setLink(obj15);
Text obj16 = new Text();
obj16.setContent("文本消息内容");
req.setText(obj16);
req.setMsgtype("text");
Markdown obj17 = new Markdown();
obj17.setTitle("首屏会话透出的展示内容");
obj17.setText("markdown格式的消息");
req.setMarkdown(obj17);
Msg obj18 = new Msg();
Text obj19 = new Text();
obj19.setContent("txt");
obj18.setText(obj19);
obj18.setMsgtype("text");
Link obj20 = new Link();
obj20.setMessageUrl("messageUrl");
obj20.setPicUrl("picUrl");
obj20.setText("消息文本");
obj20.setTitle("消息标题");
obj18.setLink(obj20);
Image obj21 = new Image();
obj21.setMediaId("@mediaId");
obj18.setImage(obj21);
File obj22 = new File();
obj22.setMediaId("@mediaId");
obj18.setFile(obj22);
Voice obj23 = new Voice();
obj23.setMediaId("@mediaId");
obj23.setDuration(100L);
obj18.setVoice(obj23);
Oa obj24 = new Oa();
Head obj25 = new Head();
obj25.setBgcolor("bgcolor");
obj25.setText("text");
obj24.setHead(obj25);
obj24.setMessageUrl("message_url");
obj24.setPcMessageUrl("pc_message_url");
Body obj26 = new Body();
List<Form> list28 = new ArrayList<Form>();
Form obj29 = new Form();
list28.add(obj29);
obj29.setValue("value");
obj29.setKey("key");
obj26.setForm(list28);
Rich obj30 = new Rich();
obj30.setUnit("unit");
obj30.setNum("num");
obj26.setRich(obj30);
obj26.setAuthor("author");
obj26.setFileCount("file_count");
obj26.setImage("image");
obj26.setContent("content");
obj26.setTitle("title");
obj24.setBody(obj26);
obj18.setOa(obj24);
ActionCard obj31 = new ActionCard();
obj31.setAgentid("agentid");
List<BtnJsonList> list33 = new ArrayList<BtnJsonList>();
BtnJsonList obj34 = new BtnJsonList();
list33.add(obj34);
obj34.setActionUrl("action_url");
obj34.setTitle("title");
obj31.setBtnJsonList(list33);
obj31.setBtnOrientation("0");
obj31.setSingleUrl("single_url");
obj31.setSingleTitle("single_title");
obj31.setMarkdown("markdown");
obj31.setTitle("title");
obj31.setHideAvatar(true);
obj18.setActionCard(obj31);
Markdown obj35 = new Markdown();
obj35.setText("text");
obj35.setTitle("title");
obj18.setMarkdown(obj35);
req.setMsg(obj18);
OapiChatSendResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());

响应示例

  • JSON示例
1
2
3
4
5
{
    "errcode":0,
    "errmsg":"ok",
    "messageId":"111"
}

异常示例

  • JSON示例
1
2
3
4
5
6
7
8
{
    "error_response":{
        "msg":"Remote service error",
        "code":50,
        "sub_msg":"非法参数",
        "sub_code":"isv.invalid-parameter"
    }
}

错误码解释

错误码 错误描述 解决方案

API工具

如何获得此API

FAQ

返回
顶部