Appearance
发送链接卡片消息(包含视频号)
发送图文链接卡片;sph_feed_h5_message 子对象用于视频号卡片。
说明与注意
- 响应只回显 imageUrl/title/description,不回显 linkUrl。
请求参数
| 参数 | 必填 | 类型 | 说明 |
|---|---|---|---|
appid | 是 | string | 实例 appid,标识操作哪个已登录账号。示例:we_xxxxxxxxxxxxxxx |
conversationId | 是 | int64 | 会话 id:单聊传对方 userId,群聊传 roomId,给自己发传当前账号 uin;必须是 JSON number。示例:10786447466811918 |
content | 是 | object | 消息内容,子字段见下。示例:{"linkUrl":"https://example.com/page","imageUrl":"https:/… |
content 字段
| 字段 | 类型 | 说明 |
|---|---|---|
content.linkUrl | string | 普通链接卡片四要素 |
content.imageUrl | string | 普通链接卡片四要素 |
content.title | string | 普通链接卡片四要素 |
content.description | string | 普通链接卡片四要素 |
content.sph_feed_h5_message | object | 视频号卡片专用;其中 coverUrl/avatar/nickname/desc/url/exportNewUrl 为 base64 编码字符串,feedType 4,useH5 true |
content.sph_feed_h5_message.feedType | int64 | 视频号内容类型 |
content.sph_feed_h5_message.coverUrl | string | 封面图 url |
content.sph_feed_h5_message.avatar | string | 头像 url |
content.sph_feed_h5_message.nickname | string | 视频号卡片中的昵称 |
content.sph_feed_h5_message.desc | string | |
content.sph_feed_h5_message.url | string | 链接 / 资源地址 |
content.sph_feed_h5_message.exportNewUrl | string | |
content.sph_feed_h5_message.useH5 | boolean |
请求示例
http
POST {BASE_URL}/wx-api/api/message/sendLink
Authorization: Bearer <你的 App Token>
Content-Type: application/json
{
"appid": "we_xxxxxxxxxxxxxxx",
"conversationId": 10786447466811918,
"content": {
"linkUrl": "https://example.com/page",
"imageUrl": "https://example.com/cover.jpg",
"title": "卡片标题",
"description": "卡片描述",
"sph_feed_h5_message": {
"feedType": 4,
"coverUrl": "<base64>",
"avatar": "<base64>",
"nickname": "<base64>",
"desc": "<base64>",
"url": "<base64>",
"exportNewUrl": "<base64>",
"useH5": true
}
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
bash
curl -X POST '{BASE_URL}/wx-api/api/message/sendLink' \
-H 'Authorization: Bearer <你的 App Token>' \
-H 'Content-Type: application/json' \
--data-raw '{
"appid": "we_xxxxxxxxxxxxxxx",
"conversationId": 10786447466811918,
"content": {
"linkUrl": "https://example.com/page",
"imageUrl": "https://example.com/cover.jpg",
"title": "卡片标题",
"description": "卡片描述",
"sph_feed_h5_message": {
"feedType": 4,
"coverUrl": "<base64>",
"avatar": "<base64>",
"nickname": "<base64>",
"desc": "<base64>",
"url": "<base64>",
"exportNewUrl": "<base64>",
"useH5": true
}
}
}'1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
python
import requests
url = "{BASE_URL}/wx-api/api/message/sendLink"
headers = {"Authorization": "Bearer <你的 App Token>", "Content-Type": "application/json"}
body = """{
"appid": "we_xxxxxxxxxxxxxxx",
"conversationId": 10786447466811918,
"content": {
"linkUrl": "https://example.com/page",
"imageUrl": "https://example.com/cover.jpg",
"title": "卡片标题",
"description": "卡片描述",
"sph_feed_h5_message": {
"feedType": 4,
"coverUrl": "<base64>",
"avatar": "<base64>",
"nickname": "<base64>",
"desc": "<base64>",
"url": "<base64>",
"exportNewUrl": "<base64>",
"useH5": true
}
}
}"""
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
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
java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
String url = "{BASE_URL}/wx-api/api/message/sendLink";
String body = "{\n" +
" \"appid\": \"we_xxxxxxxxxxxxxxx\",\n" +
" \"conversationId\": 10786447466811918,\n" +
" \"content\": {\n" +
" \"linkUrl\": \"https://example.com/page\",\n" +
" \"imageUrl\": \"https://example.com/cover.jpg\",\n" +
" \"title\": \"卡片标题\",\n" +
" \"description\": \"卡片描述\",\n" +
" \"sph_feed_h5_message\": {\n" +
" \"feedType\": 4,\n" +
" \"coverUrl\": \"<base64>\",\n" +
" \"avatar\": \"<base64>\",\n" +
" \"nickname\": \"<base64>\",\n" +
" \"desc\": \"<base64>\",\n" +
" \"url\": \"<base64>\",\n" +
" \"exportNewUrl\": \"<base64>\",\n" +
" \"useH5\": true\n" +
" }\n" +
" }\n" +
"}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
.header("Authorization", "Bearer <你的 App Token>")
.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
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
php
<?php
$url = '{BASE_URL}/wx-api/api/message/sendLink';
$body = <<<'JSON'
{
"appid": "we_xxxxxxxxxxxxxxx",
"conversationId": 10786447466811918,
"content": {
"linkUrl": "https://example.com/page",
"imageUrl": "https://example.com/cover.jpg",
"title": "卡片标题",
"description": "卡片描述",
"sph_feed_h5_message": {
"feedType": 4,
"coverUrl": "<base64>",
"avatar": "<base64>",
"nickname": "<base64>",
"desc": "<base64>",
"url": "<base64>",
"exportNewUrl": "<base64>",
"useH5": true
}
}
}
JSON;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer <你的 App Token>',
'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
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
响应示例
响应结构与发送文本消息相同
成功时 data 就是刚发出的完整消息,字段见发送文本消息的响应示例。data.content 回显你发送的内容或上传字段,形状随消息类型不同,见消息模块总览的码表。
响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
code | int64 | 统一封套状态码:0=成功,负数=失败 |
detail | string | 附加明细,通常为空 |
message | string | 文案:成功为 ok;失败形如 -码|描述 |
time | string | 服务端处理时间 YYYY-MM-DD HH:MM:SS |
常见错误
下表为企微错误码。业务失败时顶层 code=-1,具体错误码在 message 的 | 前,例如 -3004|参数错误;鉴权与网关错误见错误码。
| 错误码 | 含义 | 怎么办 |
|---|---|---|
-4014 | 过期或错误的 uin 作 conversationId | 先 personal/getInfo 取当前 uin |
-3020 | 用自聊伪房间 roomId 作发送目标 | 给自己发用当前账号 uin |
-3004 | 参数错误 | 检查字段名与类型,数字 id 不能传字符串 |