Files
kefu/wechat_rpa/implementation_plan.md
T
2026-07-16 12:11:05 +08:00

27 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 企业微信 GUI 自动化实施计划
## 1. 环境准备
- **语言**Python 3.8+
- **核心库**`uiautomation` (封装了 Windows UIAutomation API,专门用于纯视觉的句柄与控件交互)。
- **辅助工具**:需要使用 Windows SDK 自带的 `Inspect.exe``Accessibility Insights` 来精准抓取企业微信不同界面的 `ClassName``Name` 属性。
## 2. 核心架构设计
### 2.1 窗口挂载层 (Window Binding)
利用 `auto.WindowControl` 寻找类名为 `WXWorkWindow` 的顶级进程窗口,并将其强行置于前台激活,确保后续的点击与按键操作不丢失焦点。
### 2.2 信息抓取层 (Data Extraction)
通过 `PaneControl``TextControl` 向下遍历左侧导航栏树形结构,抓取包含个人昵称或企业名称的只读文本节点。此部分强依赖客户端具体版本。
### 2.3 状态轮询层 (Polling Mechanism)
在会话列表 (`ListControl`) 中进行无限循环。
- 通过检测 `ListItemControl` 内部是否出现包含“未读”或“数字”的 `TextControl` 节点来判断是否有新消息。
- 利用内存 `Set` 数据结构记录已回复的会话名称,避免产生死循环回复。
### 2.4 交互动作层 (Interaction Execution)
捕获新消息后,调用 `Click()` 触发会话切换;使用 `EditControl` 定位到聊天输入框,调用 `SendKeys('你好{Enter}')` 模拟真实人类的键盘输入动作。
## 3. 注意事项
- **阻塞问题**:企业微信的 UI 层级深不可测,所有的查找动作必须限制 `searchDepth` 属性。
- **稳定性**:不推荐在工作机上混合运行,键鼠事件争抢容易导致输入错乱。