企业微信整合服务技能 - 包含普通回调和会话内容存档功能
本技能提供完整的企业微信整合服务,包含两大核心功能:
# 进入技能目录
cd skills/wework-archive-service
# 安装Python依赖
pip3 install flask pycryptodome requests
复制配置文件模板:
cp config/wework_config_template.json config/wework_config.json
编辑配置文件 config/wework_config.json,填写以下信息:
callback_token: 企业微信后台 > 应用管理 > 自建应用 > 接收消息 > Tokencallback_encoding_aes_key: 企业微信后台 > 应用管理 > 自建应用 > 接收消息 > EncodingAESKeycorp_id: 企业ID(我的企业 > 企业信息)agent_id: 应用ID(应用管理 > 自建应用)corp_secret: 应用Secret(应用管理 > 自建应用)archive_token: 会话存档Secret(管理工具 > 会话内容存档 > 开启 > Secret)# 启动服务
./scripts/start_service.sh
# 验证服务状态
./scripts/verify_service.sh
# 停止服务
./scripts/stop_service.sh
http://你的域名/callbackcallback_token 一致callback_encoding_aes_key 一致http://你的域名/archive/callbackarchive_token 一致GET /health - 服务健康状态GET /archive/health - 存档服务健康状态GET /callback - 企业微信回调验证(普通应用)POST /callback - 接收企业微信事件消息POST /archive/callback - 接收会话存档数据GET /messages - 查询所有消息GET /messages/<msg_id> - 查询特定消息GET /messages/user/<user_id> - 查询用户消息GET /messages/room/<room_id> - 查询群聊消息# macOS
brew install cloudflared
# Linux
curl -L --output cloudflared.deb https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
sudo dpkg -i cloudflared.deb
# 验证安装
cloudflared --version
cloudflared tunnel login
在浏览器中完成认证。
# 创建隧道
cloudflared tunnel create wework-tunnel
# 查看隧道ID
cloudflared tunnel list
# 创建配置文件
cloudflared tunnel route dns wework-tunnel wework.yourdomain.com
# 或者手动配置DNS
# 在Cloudflare DNS设置中添加CNAME记录:
# wework.yourdomain.com -> <隧道ID>.cfargotunnel.com
创建配置文件 ~/.cloudflared/config.yml:
tunnel: <隧道ID>
credentials-file: /Users/你的用户名/.cloudflared/<隧道ID>.json
ingress:
- hostname: wework.yourdomain.com
service: http://localhost:8400
- service: http_status:404
# 测试配置
cloudflared tunnel ingress validate
# 启动隧道
cloudflared tunnel run wework-tunnel
# 或作为服务运行
cloudflared service install
sudo systemctl start cloudflared
Cloudflare Tunnel自动提供:
服务首次启动时会自动创建SQLite数据库 wework_combined.db。
messages - 存储所有消息记录attachments - 存储附件信息users - 存储用户信息rooms - 存储群聊信息# 备份数据库
cp wework_combined.db wework_combined_backup_$(date +%Y%m%d).db
# 使用SQLite工具查看
sqlite3 wework_combined.db
# 检查端口占用
lsof -ti:8400
# 检查Python依赖
python3 -c "import flask, Crypto, requests"
# 检查隧道状态
cloudflared tunnel info <隧道ID>
# 查看日志
cloudflared tunnel run wework-tunnel --debug
# 修复数据库
sqlite3 wework_combined.db "VACUUM;"
# 检查数据库完整性
sqlite3 wework_combined.db "PRAGMA integrity_check;"
# 查看服务日志
tail -f wework_service.log
# 查看详细日志
tail -f wework_combined.log
定期更新配置:
网络防护:
数据安全:
监控告警:
如有问题,请参考:
references/ 目录下的详细文档MIT License - 详见 LICENSE 文件
ZIP package — ready to use