Appearance
发送引用消息
引用一条消息回复,对方看到的是「发送人:原文」加你的回复。
说明与注意
message要把被引用的消息对象整个原样传:发送接口返回的data、同步消息或推送里的消息都行;只传id报unexpected end of JSON input。message.content必须是[{type, text}]数组,不能是 base64 原文;content也是数组,传字符串报类型错。- 引用前缀「发送人:原文」由服务端拼好,返回的
content变成 4 段,flag为512;不要自己在content里写前缀。
请求参数
| 参数 | 必填 | 类型 | 说明 |
|---|---|---|---|
appid | 是 | string | 实例 appid,标识操作哪个已登录账号。示例:we_xxxxxxxxxxxxxxx |
conversationId | 是 | int64 | 被引用消息所在的会话:单聊填对方 userId,群聊填 roomId;必须是 JSON number。示例:7881300000000002 |
senderAvatarUrl | 否 | string | 发送人头像地址,可传空串 |
content | 是 | array<object> | 回复正文,[{type, text}] 数组。示例:[{"type":0,"text":"收到,马上处理"}] |
message | 是 | object | 被引用的原始消息对象,整个原样传 |
content[] 字段
| 字段 | 类型 | 说明 |
|---|---|---|
content[].type | integer | 0 文本 |
content[].text | string | 文本内容 |
message 字段
| 字段 | 类型 | 说明 |
|---|---|---|
message.id | int64 | 消息 id |
message.fromUserId | int64 | 原消息发送方 |
message.toUserId | int64 | 原消息接收方 |
message.roomId | int64 | 群会话 id,单聊为 0 |
message.contentType | integer | 原消息类型码 |
message.sendTime | int64 | 原消息发送时间,秒级时间戳 |
message.senderName | string | 原消息发送人的名字,决定引用前缀里显示的名字 |
message.content | array<object> | 原消息内容,[{type, text}] 数组 |
请求示例
http
POST {BASE_URL}/api/message/sendQuote
Authorization: Bearer <你的调用凭证>
Content-Type: application/json
{
"appid": "we_xxxxxxxxxxxxxxx",
"conversationId": 7881300000000002,
"senderAvatarUrl": "",
"content": [
{
"type": 0,
"text": "收到,马上处理"
}
],
"message": {
"id": 1001088,
"messageType": 0,
"fromUserId": 7881300000000002,
"toUserId": 1688850000000001,
"roomId": 0,
"contentType": 0,
"sendTime": 1794475969,
"senderName": "李**",
"content": [
{
"type": 0,
"text": "发票什么时候能开?"
}
]
}
}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
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
bash
curl -X POST '{BASE_URL}/api/message/sendQuote' \
-H 'Authorization: Bearer <你的调用凭证>' \
-H 'Content-Type: application/json' \
--data-raw '{
"appid": "we_xxxxxxxxxxxxxxx",
"conversationId": 7881300000000002,
"senderAvatarUrl": "",
"content": [
{
"type": 0,
"text": "收到,马上处理"
}
],
"message": {
"id": 1001088,
"messageType": 0,
"fromUserId": 7881300000000002,
"toUserId": 1688850000000001,
"roomId": 0,
"contentType": 0,
"sendTime": 1794475969,
"senderName": "李**",
"content": [
{
"type": 0,
"text": "发票什么时候能开?"
}
]
}
}'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
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
python
import requests
url = "{BASE_URL}/api/message/sendQuote"
headers = {"Authorization": "Bearer <你的调用凭证>", "Content-Type": "application/json"}
body = """{
"appid": "we_xxxxxxxxxxxxxxx",
"conversationId": 7881300000000002,
"senderAvatarUrl": "",
"content": [
{
"type": 0,
"text": "收到,马上处理"
}
],
"message": {
"id": 1001088,
"messageType": 0,
"fromUserId": 7881300000000002,
"toUserId": 1688850000000001,
"roomId": 0,
"contentType": 0,
"sendTime": 1794475969,
"senderName": "李**",
"content": [
{
"type": 0,
"text": "发票什么时候能开?"
}
]
}
}"""
resp = requests.post(url, headers=headers, data=body.encode("utf-8"))
print(resp.text)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
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
java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
String url = "{BASE_URL}/api/message/sendQuote";
String body = "{\n" +
" \"appid\": \"we_xxxxxxxxxxxxxxx\",\n" +
" \"conversationId\": 7881300000000002,\n" +
" \"senderAvatarUrl\": \"\",\n" +
" \"content\": [\n" +
" {\n" +
" \"type\": 0,\n" +
" \"text\": \"收到,马上处理\"\n" +
" }\n" +
" ],\n" +
" \"message\": {\n" +
" \"id\": 1001088,\n" +
" \"messageType\": 0,\n" +
" \"fromUserId\": 7881300000000002,\n" +
" \"toUserId\": 1688850000000001,\n" +
" \"roomId\": 0,\n" +
" \"contentType\": 0,\n" +
" \"sendTime\": 1794475969,\n" +
" \"senderName\": \"李**\",\n" +
" \"content\": [\n" +
" {\n" +
" \"type\": 0,\n" +
" \"text\": \"发票什么时候能开?\"\n" +
" }\n" +
" ]\n" +
" }\n" +
"}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
.header("Authorization", "Bearer <你的调用凭证>")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());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
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
php
<?php
$url = '{BASE_URL}/api/message/sendQuote';
$body = <<<'JSON'
{
"appid": "we_xxxxxxxxxxxxxxx",
"conversationId": 7881300000000002,
"senderAvatarUrl": "",
"content": [
{
"type": 0,
"text": "收到,马上处理"
}
],
"message": {
"id": 1001088,
"messageType": 0,
"fromUserId": 7881300000000002,
"toUserId": 1688850000000001,
"roomId": 0,
"contentType": 0,
"sendTime": 1794475969,
"senderName": "李**",
"content": [
{
"type": 0,
"text": "发票什么时候能开?"
}
]
}
}
JSON;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer <你的调用凭证>',
'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;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
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
响应示例
json
{
"code": 0,
"data": {
"id": 1001090,
"messageType": 0,
"fromUserId": 1688850000000001,
"toUserId": 7881300000000002,
"roomId": 0,
"contentType": 0,
"sendTime": 1794475969,
"content": [
{
"type": 0,
"text": "“李**:\n"
},
{
"type": 0,
"text": "发票什么时候能开?"
},
{
"type": 0,
"text": "”\n------\n"
},
{
"type": 0,
"text": "收到,马上处理"
}
],
"flag": 512
},
"detail": "",
"message": "ok",
"time": "2026-11-12 17:32:53"
}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
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
响应字段
响应字段(14 项)
| 字段 | 类型 | 说明 |
|---|---|---|
code | int64 | 统一封套状态码:0=成功,负数=失败 |
data | object | 刚发出的引用消息 |
data.id | int64 | 消息 id |
data.messageType | integer | 消息大类,0 普通消息 |
data.fromUserId | int64 | 发送方,即当前账号 |
data.toUserId | int64 | 接收方 |
data.roomId | int64 | 群会话 id,单聊为 0 |
data.contentType | integer | 0 |
data.sendTime | int64 | 发送时间,秒级时间戳 |
data.content | array<object> | 4 段:引用前缀、原文、分隔线、你的回复 |
data.flag | integer | 512 表示引用消息 |
detail | string | 附加明细,通常为空 |
message | string | 文案:成功为 ok;失败形如 -码|描述 |
time | string | 服务端处理时间 YYYY-MM-DD HH:MM:SS |
常见错误
下表为企微错误码。业务失败时顶层 code=-1,具体错误码在 message 的 | 前,例如 -3004|参数错误;鉴权与网关错误见错误码。
| 错误码 | 含义 | 怎么办 |
|---|---|---|
-4014 | conversationId 不属于当前账号:过期或错误的 uin,或不是本账号的联系人、群 | 先调获取个人信息取当前 uin,核对会话 id |
-3020 | 把自聊会话的 roomId 当成了发送目标 | 给自己发用当前账号 uin |
-3004 | 参数错误 | 检查字段名与类型,数字 id 不能传字符串 |