wechat-group-digest.md 11.6 KB

title: WeChat Group Daily Digest description: Read WeChat group messages, extract public account articles and video content, and summarize article contents from URLs. Also covers WeChat message sending reverse engineering. name: wechat-group-digest

trigger: When user asks for WeChat group digest, wants to read/send WeChat messages, or reverse engineer WeChat internals.

WeChat Group Daily Digest & RE Skill

WeChat Message Sending Architecture (2026-06-30)

WeChat messages use Tencent's mars networking framework (native C++), NOT HTTP REST:

Java UI: ChattingUI → sk.p0(String msg, int type, String extra)
    ↓ writes to DB (status=2, history only)
mars Bridge: libMMProtocalJni.so → protobuf + ECDH/AES encrypt
mars Native: libmarscomm.so (queue), libmarsquic.so (QUIC transport)
    ↓ TCP/QUIC
WeChat Server

Attack Vector Analysis (5 paths, by ban risk)

Rank Path Ban Risk Status
1 A. DB Injection 🟢 Low ❌ mars uses in-memory queue
2 D. HTTP CGI Fallback 🟢 Low ❌ CGI through mars tunnel
3 B. LSPosed Hook sk.p0() 🟡 Low-Med ✅ Viable, skeleton ready
4 C. mars Queue Injection 🟠 Med Needs Frida native
5 E. Frida Native Protocol 🔴 High Tencent anti-Frida SDK

Path A: DB Injection — BLOCKED

  • message table is history-only; mars has in-memory task queue
  • Status codes: 2=sent(37), 3=delivered(2692). No status=0/1 messages exist
  • massendinfo is media upload queue only (not text)

Path D: HTTP CGI — BLOCKED

  • CGI EXISTS: POST /cgi-bin/micromsg-bin/newsendmsg, FuncID 522
  • Request: ez5 { d:int, e:LinkedList<ll4> } protobuf
  • Transported through mars::stn ECDH tunnel, NOT direct HTTP

Path B: LSPosed Hook — VIABLE

  • Target: com.tencent.mm.ui.chatting.component.sk.p0(String, int, String)
  • Module skeleton: ~/WeChatHook/
  • ON-DEVICE compilation: Full toolchain at ~/tmp/android-sdk/build-tools/36.0.0/ (d8, apksigner, zipalign), ~/tmp/android.jar (27MB), ~/tmp/api-82.jar. Gradle 9.6 + Java 17 in Termux.
  • Risk: WeChat historically tolerant of Xposed modules

Key File Paths

w11/r0.smali          — NetSceneSendMsg (CGI path + protobuf)
w11/e0.smali          — NetSceneNewSync (CGI: /cgi-bin/micromsg-bin/newsync)
r45/ez5.smali         — SendMsgRequest protobuf
r45/fz5.smali         — SendMsgResponse protobuf
r45/ll4.smali         — Individual message protobuf

WeChat Viewer Web App (2026-07-08)

项目路径: ~/wechat-viewer/。架构原则:日报生成和图片生成走 Hermes CLI 子进程 + skill,不写死 Python。用户原话:"应该调用 Hermes 子任务来完成。不是写死 Python 代码,未来 skill 变化时没法迭代。"

  • Page 1 (/): 会话列表 → 点击跳转 /chat/<talker> 独立聊天页。每个群聊右侧有 📋 生成日报按钮
  • Page 2 (/circle): 本地 SQLite 加工数据中心
  • Page 3 (/reports): 日报列表 → 生成日报按钮 flush → Hermes CLI 子进程加载 wechat-group-digest skill → LLM 归纳话题 → Markdown 入库。每条日报有「生成图片」和「删除」按钮
  • Page 4 (/report-images): 日报图片列表 → 每个日报点「生成图片」→ Hermes CLI 加载 gpt-image-gen skill → GPT Image 2 API → WSJ 风格图。有「发送微信」按钮(弹窗选联系人 → 直接调 send_image_via_hook)
  • 聊天页: 无限滚动(最新在上),图片/语音/文章卡片/视频号卡片。右上角 📋 生成日报按钮

启动: bash ~/wechat-viewer/restart.sh

发图到微信: 不走 Hermes 子进程,直接 from wechat_hook_send import send_image_via_hook 在 daemon thread 里调。因为 MCP tool 在 hermes chat -t terminal 里不可用。

详见 skill wechat-web-viewer。 启动: bash ~/wechat-viewer/restart.sh(先 kill 旧进程再启动,避免端口冲突通知轰炸)

关键技术细节 (详见 references/wechat-message-content-format.md)

  • sqlcipher 输出 ok\n 前缀 → output[2:].strip() 后再 json.loads
  • Flask 无法直接读 WeChat 数据目录 (PermissionError) → _safe_exists() + su -c "cp ... /tmp && chmod 644"
  • 图片: THUMBNAIL_DIRPATH://th_<hash> → image2/{hash[:2]}/{hash[2:4]}/<hash>.jpg (原图优先, 56-123KB) 或 th_<hash> (缩略图回退, 2-12KB)。同 hash 的 .jpg 文件是微信在本地缓存的原始分辨率版本——不是在微信内打开过就不会有。
  • 语音: 用 su -c find 查 voice2/ 下的 msg_<hash>.amr, 文件路径含非 hash 前缀子目录
  • 视频号 CDATA: re.sub(r"<!\\[CDATA\\[(.*?)\\]\\]>", r"\\1", content) 后才能提取 nickname/desc/coverUrl

Digest Pipeline (Core Workflow)

  1. Query WeChat group messages via MCP: mcp_android_phone_query_wechat(sql)
  2. Extract articles (type=49), discussions (type=1)
  3. Article summary reuse (2026-07-08): a. Collect all article URLs + titles into a list b. Call POST http://127.0.0.1:5000/api/articles/check-summaries with JSON {"urls": [{"url": "...", "title": "..."}, ...], "type": "summary"} c. The API returns {results: {dedup_key: {id, content, ...}}, missing: [{url, title, dedup_key}]} d. Already-summarized articles: directly include their content in the report, marked [已缓存] e. Missing articles: curl the article URL + generate a summary, then call POST http://127.0.0.1:5000/api/articles/summarize with {"url": "...", "title": "..."} to persist the new summary into daily_reports for next time
  4. Generate complete Markdown report (titles + summaries + sources + keywords)
  5. Generate infographic (newspaper style, Chinese-only, no fictional content)
  6. Send via ADBKeyboard workflow (search-and-tap + broadcast)

Article Summary Reuse API (批量查询去重)

Endpoint: POST http://127.0.0.1:5000/api/articles/check-summaries

Request:

{
  "urls": [
    {"url": "https://mp.weixin.qq.com/s/...", "title": "文章标题"},
    ...
  ],
  "type": "summary"   // "summary" | "learn" | "" (any)
}

Response:

{
  "ok": true,
  "data": {
    "results": {
      "biz|mid|idx|sn": {
        "id": 42,
        "content": "# 标题 摘要\n\n核心观点...",
        "report_date": "summary",
        "created_at": "2026-07-08 10:30:00"
      }
    },
    "missing": [
      {"url": "https://...", "title": "未缓存文章", "dedup_key": "abc|123|1|def"}
    ]
  }
}

To persist a freshly-generated summary so it's reusable:

curl -s -X POST http://127.0.0.1:5000/api/articles/summarize \
  -H 'Content-Type: application/json' \
  -d '{"url": "ARTICLE_URL", "title": "ARTICLE_TITLE"}'

This endpoint auto-returns cached results if already exists; only spawns a Hermes subprocess for new summaries.

Critical Rules

  • Report-first: Always generate complete Markdown report before infographic
  • Content-only: Never invent fictional sections in infographics
  • Chinese-only: All infographic text in Chinese
  • Complete extraction: Every article title + summary + source
  • Discussion summarization: Topics + participants + viewpoints

Group Identification

  • Use rcontact.nickname for group name (reliable)
  • chatroom.displayname for member verification only

Message Types

Type Meaning
1 Text
3 Image
34 Voice
43 Video
47 Emoji
49 Article/link
10000 System
754974769 Unsupported / Finder (解析 <finderFeed> 里的 nickname/desc/coverUrl/videoPlayDuration 做视频号卡片)
822083633 Referenced reply (appmsg with refermsg)

FinderFeed (视频号) 解析要点: 内容包裹在 <finderFeed> XML 内,关键字段被 CDATA 包裹(如 <nickname><![CDATA[知安物语]]></nickname>)。解析前必须先 re.sub(r"<!\\[CDATA\\[(.*?)\\]\\]>", r"\\1", content) 去掉 CDATA,否则 regex 匹配不到具体值。可用字段:<nickname>, <desc>, <avatar>, <coverUrl>, <media><url> (视频下载链接), <videoPlayDuration> (秒)。

See references/wechat-message-content-format.md for complete content format reference.

  • Chatroom message sender:\n prefix stripping
  • Image path resolution from imgPath (hash subdirectories, THUMBNAIL_DIRPATH://)
  • Voice path resolution (complex directory structure, use find)
  • SQLCipher CLI quirks ("ok\n" prefix, multi-line JSON, su permission handling)
  • Group name resolution (rcontact.nickname vs chatroom.displayname)

Sending Messages (ADBKeyboard Workflow)

WARNING: The MCP tool send_wechat_message / send_wechat_message_ui() calls am force-stop com.tencent.mm before every send (wechat_send.py:363). This kills tablet login. If tablet login is active, use the manual ADBKeyboard workflow below and SKIP the force-stop step.

  1. Open WeChat → search-and-tap target chat
  2. Set ADBKeyboard: ime set com.android.adbkeyboard/.AdbIME
  3. Clear field: ADB_INPUT_CODE 67 × 10-15
  4. Type: ADB_INPUT_TEXT --es msg "text"
  5. OCR-find send button, tap
  6. Verify in DB: SELECT ... FROM message WHERE isSend=1 ORDER BY createTime DESC LIMIT 1
  7. Restore keyboard

Pitfall: mcp_android_phone_send_wechat_message unreliable for ALL chat types AND kills tablet login. Use manual ADBKeyboard workflow.

File Locations

  • CGI analysis: references/wechat-sendmsg-cgi-analysis.md
  • LSPosed module design: references/wechat-lsposed-send-module.md
  • On-Device LSPosed build: references/on-device-xposed-build.md
  • LSPosed DB config: references/lsposed-module-config.md
  • SQLCipher DB access: references/sqlcipher-wechat-db-access.md
  • MCP parsing guide: references/mcp-output-parsing-guide.md
  • ADBKeyboard workflow: references/adbkeyboard-manual-send-workflow.md
  • Infographic v4: references/newspaper_infographic_v4.py

Pitfalls

  1. WeChat timestamps are in ms since epoch, convert to Beijing time (UTC+8)
  2. Group name in rcontact.nickname, not chatroom.chatroomnick (usually NULL)
  3. mcp_android_phone_send_wechat_message unreliable for ALL chat types
  4. ADBKeyboard accumulates text — always clear field with backspace before typing
  5. Report-first workflow: NEVER generate infographic directly from raw messages
  6. Chinese-only infographics: titles, section names, dates all in Chinese
  7. Content-only rule: no fictional sections in generated images
  8. Outer screen send coordinates differ from inner screen — always OCR for send button
  9. Dozing state blocks screenshots — use keyevent 26 (power key) to wake
  10. Foldable screens require long display IDs for screencap
  11. MCP output is double-escaped JSON — use json.loads() not string replace
  12. WeChat CGI endpoints are mars-transported, NOT plain HTTP
  13. On-device Android compilation IS possible — toolchain at ~/tmp/android-sdk/
  14. TABLET LOGIN FATAL: send_wechat_message_ui() calls am force-stop com.tencent.mm before every send (wechat_send.py:363). This KILLS the tablet login session. NEVER use this function if tablet login is active. Use manual ADBKeyboard workflow WITHOUT force-stop instead.
  15. LSPosed DAEMON FATAL: killall lspd permanently kills the daemon on JingMatrix Vector A16 — it does NOT auto-restart. Only reboot restores it. Never kill lspd.
  16. LSPosed DB FATAL: Writing to /data/adb/lspd/config/modules_config.db via sqlcipher/sqlite3 can trigger LSPosed's FileObserver to delete module entries. Never toggle the enabled field via SQL — use LSPosed Manager UI only.
  17. Check tablet login before any WeChat operation: verify lspd running (pgrep -f lspd), WeChatHook injected (grep /proc//maps for lspd .so), and WeChat not on login screen. → Full root cause analysis: references/tablet-login-protection.md