feat(biz): add wx biz-articles command to query public account messages#33
Open
ChenyqThu wants to merge 3 commits into
Open
feat(biz): add wx biz-articles command to query public account messages#33ChenyqThu wants to merge 3 commits into
ChenyqThu wants to merge 3 commits into
Conversation
加载 biz_message_0.db 提取公众号推送(标题/url/作者/时间)。 - daemon 端通过 DbCache 按需解密 biz_message_0.db(密钥已在 all_keys.json 中) - 新增 IPC 变体 BizArticles(limit/account/since/until 参数) - 新增 query 处理器 q_biz_articles: - 通过 Name2Id 反查 gh_* username → md5 → Msg_<hash> 表映射 - 过滤 local_type & 0xFFFFFFFF = 49(appmsg 公众号文章) - zstd 解压 + extract_cdata 解析 <mmreader>/<item> XML - 支持多文章推送(一条消息含多篇文章) - 输出字段:time/timestamp/recv_time/account/account_username/title/url/digest/cover_url - 新增 CLI 子命令 wx biz-articles,参数:-n / --account / --since / --until / --json - 新增工具函数 extract_cdata(CDATA 块解析)和 parse_biz_xml_items - 新增 8 个单测(biz_tests 模块)覆盖 CDATA 解析和多文章场景 支持工作流: wx biz-articles --since today --json | jq ".[].url" | xargs opencli weixin download Verified: 返朴 ADHD 文章、Datawhale Claude Code 文章、土猛员外知识引擎文章均已正确提取。
只列「有未读的公众号」的最近 1 篇文章 — 与 'wx unread --filter official'
行为一致,便于扫描"哪些公众号还有未读,标题是啥"。
- ipc.rs: BizArticles 加 unread: bool 字段(serde default = false 向后兼容)
- cli/mod.rs: --unread flag
- cli/biz_articles.rs: 透传 unread
- daemon/server.rs: dispatch 加 unread 参数
- daemon/query.rs: q_biz_articles
- 开启 --unread 时先查 session.db 拿 unread_count>0 且
chat_type==official_account 的 username 集合
- 与 --account 取交集(两者都给时进一步缩小范围)
- 空交集提前 return,避免无意义全表扫
- 解析后按 pub_time DESC 排,每个 account_username 只保留首条
- 最后再 truncate(limit)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(biz): add
wx biz-articlescommand to query public account messagesSummary
Adds a new
biz-articlessubcommand that queries locally cached WeChat public account (公众号) article pushes frombiz_message_0.db.This enables a downstream workflow for downloading full article content:
Background
message/biz_message_0.db(SQLCipher 4 encrypted)~/.wx-cli/all_keys.jsonbywx initMsg_{md5(username)}table, following the same convention asmessage_0.db<mmreader>/<item>structures with article metadataNew CLI Interface
Output Fields
Each article item includes:
timetimestamprecv_timerecv_time_straccountaccount_usernametitleurldigestcover_urlImplementation Notes
biz_message_0.dbis loaded on-demand via existingDbCachemechanism (no startup cost unlessbiz-articlesis called)message/biz_message_0.dbis already inall_keys.json, no changes towx initneeded<item>in<mmreader>becomes a separate output rowextract_cdatahelper function strips CDATA wrappers from XML contentpub_timeDESC (article publish time, not message receive time)--unreadsemanticssession.dbforunread_count > 0rows whosechat_type == official_account, intersects with--accountfilter if both providedaccount_usernameafter the global pub_time DESC sort)wx unread --filter officialfor fast "what unread accounts are there + what's the latest title" scanningChanges
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 forBizArticlesTest Results
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_fallbackVerified Output (real WeChat install with ~30 public accounts, 2026-05-10)