mirror of https://github.com/jackwener/wx-cli.git
4.7 KiB
4.7 KiB
feat(biz): add wx biz-articles command to query public account messages
Summary
Adds a new biz-articles subcommand that queries locally cached WeChat public account (公众号) article pushes from biz_message_0.db.
This enables a downstream workflow for downloading full article content:
wx biz-articles --since today --json | jq '.[].url' | xargs opencli weixin download
Background
- WeChat stores public account (官方账号) message pushes in a separate database:
message/biz_message_0.db(SQLCipher 4 encrypted) - This DB was not exposed by any existing wx-cli command
- The encryption key is already scanned and stored in
~/.wx-cli/all_keys.jsonbywx init - Each public account has its own
Msg_{md5(username)}table, following the same convention asmessage_0.db - Message content is zstd-compressed XML containing
<mmreader>/<item>structures with article metadata
New CLI Interface
# Last 50 articles (default)
wx biz-articles
# More articles
wx biz-articles -n 200
# Filter by public account name (fuzzy match on display name)
wx biz-articles --account "返朴"
wx biz-articles --account "Datawhale"
# Time filter (article publish time, YYYY-MM-DD)
wx biz-articles --since 2026-05-10
wx biz-articles --since 2026-05-01 --until 2026-05-10
# Show only accounts with unread messages, one latest article per account
wx biz-articles --unread
wx biz-articles --unread --account "Datawhale" # combine: unread within specific account
# JSON output (for downstream piping)
wx biz-articles --json
wx biz-articles --since 2026-05-10 --json | jq '.[].url'
Output Fields
Each article item includes:
| Field | Description |
|---|---|
time |
Article publish time (formatted) |
timestamp |
Article publish timestamp (seconds) |
recv_time |
Message receive time (when WeChat pushed it) |
recv_time_str |
Message receive time (formatted) |
account |
Public account display name |
account_username |
Public account username (gh_*) |
title |
Article title |
url |
Article URL (mp.weixin.qq.com link) |
digest |
Article summary/excerpt |
cover_url |
Cover image URL |
Implementation Notes
biz_message_0.dbis loaded on-demand via existingDbCachemechanism (no startup cost unlessbiz-articlesis called)- The key for
message/biz_message_0.dbis already inall_keys.json, no changes towx initneeded - Multi-article pushes (图文消息) are expanded: each
<item>in<mmreader>becomes a separate output row - Items without URL or title (e.g., payment notifications from service accounts) are filtered out
- New
extract_cdatahelper function strips CDATA wrappers from XML content - Results sorted by
pub_timeDESC (article publish time, not message receive time)
--unread semantics
- Queries
session.dbforunread_count > 0rows whosechat_type == official_account, intersects with--accountfilter if both provided - Returns at most one latest article per account (dedupe by
account_usernameafter the global pub_time DESC sort) - Aligns with the behavior of
wx unread --filter officialfor fast "what unread accounts are there + what's the latest title" scanning - Empty intersection short-circuits before scanning biz tables
Changes
src/ipc.rs: AddBizArticlesIPC request variantsrc/cli/biz_articles.rs: New CLI command handler (follows sns_feed pattern)src/cli/mod.rs: RegisterBizArticlessubcommand in clap + dispatchsrc/daemon/query.rs: Addq_biz_articlesquery +parse_biz_xml_items+extract_cdatahelpers + 8 unit testssrc/daemon/server.rs: Add dispatch case forBizArticles
Test Results
test result: ok. 49 passed; 0 failed; 0 ignored
New tests (8):
biz_tests::extract_cdata_normalbiz_tests::extract_cdata_emptybiz_tests::extract_cdata_urlbiz_tests::extract_cdata_no_cdata_wrapperbiz_tests::parse_biz_xml_items_single_articlebiz_tests::parse_biz_xml_items_skips_no_urlbiz_tests::parse_biz_xml_items_multi_articlebiz_tests::parse_biz_xml_items_pub_time_fallback
Verified Output (real WeChat install with ~30 public accounts, 2026-05-10)
- account: 返朴
title: 细胞生物学家俞立:从后进生到科学家,一个ADHD孩子的逆袭
url: http://mp.weixin.qq.com/s?__biz=Mzg2MTUyODU2NA==&mid=2247642795&...
- account: Datawhale
title: 刚刚,Claude Code 团队这篇文章爆了!
url: http://mp.weixin.qq.com/s?__biz=MzIyNjM2MzQyNg==&mid=2247722630&...
- account: 土猛的员外
title: AI时代,企业的业务底座正在从数据库变成知识引擎
url: http://mp.weixin.qq.com/s?__biz=MzIyOTA5NTM1OA==&mid=2247485270&...
Branch
ChenyqThu/wx-cli → feat/biz-articles
Waiting for Lucien's review before opening PR.