Skip to content

引用与卡片 ​

以下接口支持 contact 和 group 目标。目标、受理和验证响应的基础字段见 发送目标与响应。

引用回复 ​

POST /v2/messages/refer。用于回复一条已有消息,并保留可定位的引用。

字段类型说明
targetobject必填,id 与原消息的 conversation.id 相同。
textstring必填,非空正文,最多 2048 UTF-8 字节。
reference.message_idstring必填,非零 uint64 十进制字符串,取源事件 message.id。
JSON
{3 项}
"target": {2 项},
"type": "contact",
"id": "filehelper"
},
"text": "补充说明",
"reference": {1 项}
"message_id": "9007199254740993"
}
}

使用原事件所属账号的端口。兼容请求使用以下字段。

JSON
{2 项}
"type": "sendReferText",
"data": {3 项}
"wxid": "filehelper",
"msg": "补充说明",
"msgId": "9007199254740993"
}
}

返回 message.type=reference_text、message.reference.message_id 和 retry_safe=false。当前账号或目标会话找不到消息时返回 404 reference_not_found,微信不允许引用时返回 422 reference_not_allowed。

网页分享卡片 ​

POST /v2/messages/share 和 POST /v2/messages/share/validate。用于分享一个可点击的 HTTP(S) 网页。

v2 字段sendShareUrl.data说明
targetwxid必填,收件人。
titletitle必填,最多 768 UTF-8 字节。
descriptioncontent最多 2048 UTF-8 字节,兼容请求必填。
urljumpUrl必填,网页 HTTP(S) 直链,最多 2048 字节。
app_idapp可选,wx 加 16 位十六进制。
thumbnailpath可选,HTTP(S) 图片直链,最多 2048 字节。
JSON
{5 项}
"target": {2 项},
"type": "contact",
"id": "filehelper"
},
"title": "服务说明",
"description": "点开查看",
"url": "https://example.com/",
"thumbnail": "https://example.com/cover.png"
}

兼容请求示例。

JSON
{2 项}
"type": "sendShareUrl",
"data": {5 项}
"wxid": "filehelper",
"title": "服务说明",
"content": "点开查看",
"jumpUrl": "https://example.com/",
"path": "https://example.com/cover.png"
}
}

响应 message 返回 type=share 及 title、description、url、app_id、thumbnail。

小程序卡片 ​

POST /v2/messages/applet 和 POST /v2/messages/applet/validate。用于把指定小程序页面分享给联系人或群。

v2 字段sendApplet.data类型和规则
targetwxid必填,收件人。
title、descriptiontitle、content字符串,最多 768 和 2048 字节。标题必填,兼容请求的描述必填。
usernamegh必填,小程序原始 ID,gh_ 前缀,可加 @app。
page_pathjumpPath必填,相对页面路径,可含查询,最多 2048 字节。
app_idapp_id可选,wx 加 16 位十六进制。缺省时尝试从同账号收到的卡片补齐。
nicknamenickname可选,小程序名称,最多 256 字节。
icon_urlicon_url可选 HTTP(S) 图标直链。
thumbnailpath可选 HTTP(S) 图片直链或本机绝对路径。
version、service_type同名可选 JSON 整数,0–2147483647。
JSON
{6 项}
"target": {2 项},
"type": "contact",
"id": "filehelper"
},
"title": "预约服务",
"username": "gh_example@app",
"page_path": "pages/index/index.html",
"app_id": "wx0123456789abcdef",
"thumbnail": "https://example.com/cover.png"
}

兼容请求示例。

JSON
{2 项}
"type": "sendApplet",
"data": {6 项}
"wxid": "filehelper",
"title": "预约服务",
"content": "打开预约页面",
"gh": "gh_example",
"jumpPath": "pages/index/index.html",
"app_id": "wx0123456789abcdef"
}
}

本地封面支持 1 B–4 MiB 单帧 PNG、JPEG 或 BMP,宽高各最多 4096,总像素最多 16,777,216。HTTP(S) 地址最多 2048 字节。

响应 message 中有 type=applet、title、username、page_path、app_id,另有 data.metadata_source=request|received_card。资料不足时返回 409 applet_metadata_required。需要真实小程序信息,示例标识为占位值。网络封面已在修复版 1.1.8-dev 实测手机显示与打开,本地封面的修复版手机端仍待补测。

音乐卡片 ​

POST /v2/messages/music 和 POST /v2/messages/music/validate。用于分享可打开或播放的歌曲,播放取决于来源及权限。

v2 字段sendMusic.data含义
targetwxid收件人。
title、artistname、author歌名和歌手,各最多 768 UTF-8 字节。
app_idapp应用标识,wx 加 16 位十六进制。
url、audio_url、thumbnail_urljumpUrl、musicUrl、imageUrl详情页、音频和封面直链,均为 HTTP(S),各最多 2048 字节。

全部字段必填。兼容请求示例。

JSON
{2 项}
"type": "sendMusic",
"data": {7 项}
"wxid": "filehelper",
"name": "示例歌曲",
"author": "示例歌手",
"app": "wx0123456789abcdef",
"jumpUrl": "https://example.com/song",
"musicUrl": "https://example.com/audio.mp3",
"imageUrl": "https://example.com/cover.jpg"
}
}
JSON
{7 项}
"target": {2 项},
"type": "contact",
"id": "filehelper"
},
"title": "示例歌曲",
"artist": "示例歌手",
"app_id": "wx0123456789abcdef",
"url": "https://example.com/song",
"audio_url": "https://example.com/audio.mp3",
"thumbnail_url": "https://example.com/cover.jpg"
}

响应 message 返回 type=music、title、artist、app_id。适用于提供链接的音频卡片。