切换主题
公众号与文章
搜索本地公众号
GET /v2/official-accounts/search 用于按名称、备注或公众号 wxid 查询已缓存的公众号。可选 q(最多 256 UTF-8 字节)、limit(默认 50,范围 1–100)、cursor(上一页的 next_cursor)。
http
GET /v2/official-accounts/search?q=gh_example&limit=10items[] 返回字符串 id、name、nickname、remark、alias、avatar_url。响应还包含 has_more、next_cursor、snapshot、complete、loading 和固定值 search_scope=local_contacts。缓存变化时返回 409,请从第一页重新搜索。覆盖范围为当前实例的公众号联系人缓存。
最近收到的文章
GET /v2/official-accounts/{wxid}/articles 使用公众号 ID,支持 limit(默认 50,范围 1–100)和 cursor。范围为当前会话中已收到的图文卡片,按事件 ID 从新到旧排序。
data 字段 | 用法 |
|---|---|
items | 文章列表,字段见下表。 |
has_more、next_cursor | 后续页标记和游标。 |
source | received_article_cards。 |
complete、gap、history_complete | 当前缓存读取覆盖状态、是否发现事件缺口、是否有完整历史。完整历史当前为 false。 |
session | 本次事件会话,切换后从第一页重读。 |
| 文章字段 | 含义 |
|---|---|
message_id、event_id | 字符串,原生消息 ID 和事件 ID。 |
account_id、account_name | 发送该卡片的公众号及名称。 |
title、summary | 标题和摘要。 |
cover_url、url | 封面地址和文章链接。 |
timestamp | 原消息时间,Unix 秒。 |
http
GET /v2/official-accounts/gh_example/articles?limit=20{8 项}
"items": [1 项],
{9 项}
"message_id": "9007199254740993",
"event_id": "17",
"account_id": "gh_example",
"account_name": "示例公众号",
"title": "服务通知",
"summary": "本周服务安排",
"cover_url": "",
"url": "https://mp.weixin.qq.com/s/example",
"timestamp": 1796176800
}
],
"has_more": false,
"next_cursor": null,
"source": "received_article_cards",
"complete": true,
"history_complete": false,
"gap": false,
"session": "12345-example"
}
文章详情
GET /v2/articles/{message_id} 使用列表中的数字字符串 ID,长度最多 20 位。设置 include_body=0 可只读卡片元数据,默认尝试读取公开 HTML。
http
GET /v2/articles/9007199254740993?include_body=0返回上述文章字段,以及 source=public_article_url、content_format=html、content_available。读取成功时包含 content_html 和上游 http_status,识别到页面标题时还返回 page_title。读取失败时可能有 content_error,卡片仍可用。404 表示文章当前不在缓存。公开页读取限 HTTPS 的 mp.weixin.qq.com/s,最多 3 MiB,超时约 8 秒。展示外部 HTML 前应做净化。