{"id":13626506,"url":"https://github.com/dongweiming/wechat-admin","last_synced_at":"2025-04-08T11:14:57.531Z","repository":{"id":47602435,"uuid":"93591699","full_name":"dongweiming/wechat-admin","owner":"dongweiming","description":"Wechat Management System","archived":false,"fork":false,"pushed_at":"2018-05-17T03:36:05.000Z","size":12035,"stargazers_count":1753,"open_issues_count":21,"forks_count":419,"subscribers_count":105,"default_branch":"master","last_synced_at":"2025-04-01T10:09:38.413Z","etag":null,"topics":["bot","celery","chatterbot","flask","itchat","mkdocs","python3","sse","tuling","vue","walrus","wechat","wechat-admin","wxpy"],"latest_commit_sha":null,"homepage":"https://dongweiming.github.io/wechat-admin/","language":"Vue","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dongweiming.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-07T04:14:17.000Z","updated_at":"2025-03-18T06:03:39.000Z","dependencies_parsed_at":"2022-08-23T16:31:01.907Z","dependency_job_id":null,"html_url":"https://github.com/dongweiming/wechat-admin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongweiming%2Fwechat-admin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongweiming%2Fwechat-admin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongweiming%2Fwechat-admin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongweiming%2Fwechat-admin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dongweiming","download_url":"https://codeload.github.com/dongweiming/wechat-admin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247829512,"owners_count":21002997,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot","celery","chatterbot","flask","itchat","mkdocs","python3","sse","tuling","vue","walrus","wechat","wechat-admin","wxpy"],"created_at":"2024-08-01T21:02:20.832Z","updated_at":"2025-04-08T11:14:57.511Z","avatar_url":"https://github.com/dongweiming.png","language":"Vue","readme":"# wechat-admin\n\n\u003e 微信管理系统\n\n![pyversions](https://img.shields.io/badge/python%20-3.5%2B-blue.svg)\n![vueversions](https://img.shields.io/badge/Vue.js-2.3.4-4fc08d.svg)\n![es2015](https://img.shields.io/badge/ECMAScript-6-green.svg)\n![celery](https://img.shields.io/badge/celery-4.0.2-4BC51D.svg)\n![element ui](https://img.shields.io/badge/element-1.3.6-20a0ff.svg)\n![travis](https://img.shields.io/travis/dongweiming/wechat-admin.svg)\n![ver](https://img.shields.io/badge/release-v0.1-red.svg)\n[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)\n[![contributions welcome](https://img.shields.io/badge/contributions-welcome-ff69b4.svg)](https://github.com/dongweiming/wechat-admin/issues)\n\n# Preview\n\n![效果图](https://github.com/dongweiming/wechat-admin/blob/master/screenshots/wechat_admin.png)\n\n\u003ca href=\"https://vimeo.com/227285498\" target=\"_blank\"\u003e\u003cimg src=\"https://github.com/dongweiming/wechat-admin/blob/master/screenshots/web.png\" alt=\"Web效果\" width=\"400\" border=\"10\" /\u003e\u003c/a\u003e\n\n### 欢迎扫码体验：\n\u003cimg src=\"https://github.com/dongweiming/wechat-admin/blob/master/screenshots/chat.png\" alt=\"扫码加群\" width=\"640\" border=\"10\" /\u003e\n\n## 特性\n\n* 支持显示好友列表，可过滤\n* 支持显示群聊列表，可过滤\n* 可以同时给多个用户/群聊成员发送消息，支持发送文件，emoji表情。可预览\n* 如果为群聊创建者，可以删除（多个）成员\n* 可以选择好友/群聊成员创建新群\n* 对自动建群、加群关键词、邀请文本等可配置\n* 永久保存消息，可以通过消息列表页面查看和过滤。接收消息进程停止自动重启\n* 支持消息提醒\n* 支持发送加群聊成员好友请求\n* 自动添加联系人，拉对方入群，群满之后自动创建新群\n* 支持插件系统，内置图灵机器人、ChatterBot、Simsimi等插件\n* 可以指定公众号，当公众号发布文章后自动转发到指定的群聊里\n* 群成员可发起投票踢人，可以灵活的设置投票规则\n\n...\n\n## 使用的技术和库\n\n### 前端\n\n* Vue\n* Axios\n* Element-ui\n* Vue-cli\n\n### 后端\n\n* Flask\n* Celery\n* SSE\n* [Walrus](https://github.com/coleifer/walrus)\n* Gunicorn\n* Flask-Migrate\n* Flask-SQLAlchemy\n* [ItChat](https://github.com/dongweiming/ItChat)\n* [Wxpy](https://github.com/dongweiming/wxpy)\n* PyMySQL\n\n## 使用方法\n\n\n### 通用方案\n\n安装MySQL、Redis，然后创建库（默认是test）：\n\n```bash\n❯ mysql -u root -p\nmysql\u003e drop database test;\nQuery OK, 9 rows affected (0.32 sec)\n\nmysql\u003e create database test;\nQuery OK, 1 row affected (0.01 sec)\n\nmysql\u003e ^DBye\n```\n\n下载源码并安装依赖：\n\n```bash\n❯ git clone https://github.com/dongweiming/wechat-admin\n❯ cd wechat-admin\n❯ virtualenv venv  # 只支持Python 3\n❯ source venv/bin/activate  # 推荐使用autoenv\n❯ venv/bin/pip install -r requirements.txt  # 如果已经激活虚拟环境，`venv/bin/`这样的前缀可不加，下同\n```\n\n设置说明：自定义配置应该存放在local\\_settings.py（需创建）中，可重载config.py中的设置\n\n安装插件（可选）：\n\n```bash\n❯ git clone --recursive https://github.com/dongweiming/wechat-plugins\n# 如果有额外插件配置，需要修改PLUGIN_PATHS和PLUGINS\n```\n\n插件开发请移步：[Plugins Page](https://dongweiming.github.io/wechat-admin/plugins/)\n\n初始化数据库：\n\n```python\n❯ export FLASK_APP=manager.py\n❯ venv/bin/flask initdb\n```\n\n启动服务：\n\n```bash\n❯ venv/bin/gunicorn app:app --bind 0.0.0.0:8100 -w 6 -t 0\n```\n\nPS: 如果是本地运行，可以不使用gunicorn，直接使用Flask的多线程调试模式：\n\n```bash\n❯ python app.py\n```\n\n访问 WEB页面 http://localhost:8100 使用微信扫码登录\n\n登录成功后，启动Celery Beat和Worker：\n\n```bash\n❯ venv/bin/celery -A wechat worker -l info -B\n```\n\n注意：第一次会拉取全部的联系人和各群聊成员列表，需要一点时间。观察终端输出了解初始化任务的完成情况。\n\n### 使用Docker\n\n假设已经安装了Docker，执行如下命令即可。\n\n```bash\n❯ pip install docker-compose\n❯ git clone --recursive https://github.com/dongweiming/wechat-plugins\n❯ venv/bin/docker-compose build\n❯ venv/bin/docker-compose run init  # 只有在第一次才需要执行这步\n❯ venv/bin/docker-compose run --service-ports -d web  # 启动Web，地址也是 http://localhost:8100\n❯ venv/bin/docker-compose run -d celery  # 同样是在扫码登录之后再启动\n```\n\n## 本地开发\n\n### 配置前端开发环境\n\n安装cnpm提高包下载速度：\n\n```bash\n❯ npm install -g cnpm --registry=https://registry.npm.taobao.org\n```\n\n安装需要的包：\n\n```bash\n❯ cnpm i \n```\n\n启动调试环境：\n\n```bash\n❯ npm run dev\n```\n\n启动成功默认会打开 http://localhost:8080 ，后端API依然使用的是 http://localhost:8100/j\n\n本地开发完毕通过如下方式构建：\n\n```bash\n❯ npm run build\n```\n\n刷新 http://localhost:8100 就可以看到最新的效果了。\n\n### 后端开发\n\n要注意修改表结构，每次都要：\n\n```bash\n❯ venv/bin/flask db migrate\n❯ venv/bin/flask db upgrade\n```\n\n## 必看: 常见问题 FAQ\n\n### 为什么在使用一段时间后偶尔会出现`puid not found`这种错误呢？\n\n由于微信的设计，不提供一种唯一且稳定的uid之类的数据，所以wxpy设计了一套登录用户和其相关联系人、群聊、公众号的映射关系，另外我修改了wxpy的实现，可以更多的获得caption (昵称, 性别, 省份, 城市)相关的内容，让对象中的puid更稳定。\n\n由于其中某些人/群的设置的改变，它的puid可能改变，在每次扫码登录之后都会触发一个更新这个映射关系的任务，让这个映射关系更新成最新的。你遇到这种错误说明你需要重新登录，或者，手动触发一下这个任务：\n\n```python\nfrom wechat.tasks import retrieve_data\nretrieve_data.delay()\n```\n\n### 为什么用着用着有时候感觉卡住了，接口不返回了？\n\nIssue: [#9](https://github.com/dongweiming/wechat-admin/issues/9)\n\n感谢 [@zgjhust 的意见](https://github.com/dongweiming/wechat-admin/issues/11)\n\n这是一个小型项目，我没有添加Nginx支持，直接使用了Gunicorn。在用Gunicorn的时候使用了`-t 0`也就是不超时。\n\n这样用的原因是项目中的sse需要一个长连接，而且从用户打开登录页面到扫码完成这个时间不好控制，就索性不超时了，但是也造成了未响应的请求不能及时释放。事实上应该把/stream拿出来特殊处理，其他的路由需要有超时时间设置的（这块，我会择机重构一下）。\n\n现在的解决办法是指定更多的Worker数量，以及经常的重启gunicorn(使用supervisor管理会更方便）：\n\n```bash\ngunicorn app:app --bind 0.0.0.0:8100 -w 10 -t 0\n```\n\n或者不用gunicorn， 直接使用Flask的threaded参数启动：\n\n```bash\n❯ cat app.py\n...\nif __name__ == '__main__':\n     app.run(host='0.0.0.0', port=8100, debug=app.debug, threaded=True)\n     \n❯ python app.py\n```\n\n\n### 为什么有时候发现这个管理系统已经不工作了，如果让这个系统能尽量长的工作呢？\n\n不工作了通常有2个原因：\n\n1. 由于微信的设计，我这个系统、Mac微信、网页微信这三者不能同时在线，否则就会被踢下线。\n2. 这个系统事实上还是使用网页微信，一段时间后（我还没有总结出来这个时间阈值）会自动登出，需要你重新扫码登录。\n\n尽管我在celery上设计的重启任务的功能，但是由于下线后重新重新扫码登录，这一步无法自动化，造成系统不工作了。\n\n如果希望这个系统尽量长的工作，我的建议是：\n\n1. 应该专门购买一张手机卡注册微信使用本系统，这样不会影响个人使用的微信不能登录微信客户端了。\n2. 把程序不要运行在个人电脑上，可以放在vps或者其他服务器上，这样可保持正常情况下的一直在线。\n3. 我给wxpy、ItChat都加了信号(Signals)系统，你可以仿造我的项目代码中的例子，加一个订阅者，能够在它有问题的时候用短信、Slack、邮件等方式第一时间通知你，让你及时处理，举个例子：\n\n```python\nfrom celery.task import periodic_task\nfrom celery.task.control import revoke\n\ndef restart_listener(sender, **kw):\n    task_id = r.get(LISTENER_TASK_KEY)\n    if task_id:\n        revoke(str(task_id, 'utf-8'))\n    task_id = app.send_task('wechat.tasks.listener')\n    r.set(LISTENER_TASK_KEY, task_id)\n\nstopped.connect(restart_listener)\n```\n\n要注意订阅操作应该发生在import wxpy/itchat之前。\n\n### 为什么这个系统功能有限？我看手机微信能做的事情要多得多嘛\n\n是的，这是一个封装wxpy/itchat的项目，说到底还是使用网页微信(wx.qq.com)，所以它的API的功能决定了本系统的能力。\n\n解密手机微信API，把这些未开放的API的集成进来不太好，还可能引起法律方面的问题。\n\n### 如何解决「当前登录环境异常。为了你的帐号安全，暂时不能登录web微信...」的问题？\n\n问题可以看这个[issue](https://github.com/Chatie/wechaty/issues/603)，有不少人遇到了，在被封之后没有办法解决。但是可以注意让它尽量不被封。经过这几天的研究，我找到三条经验：\n\n1. 不要只使用Itchat中的[USER_AGENT](https://github.com/littlecodersh/ItChat/blob/master/itchat/config.py#L10)，可以在几个之间切换（注意要不同浏览器的UA），但是不要每次的UA不一样。\n2. 注意在群内的操作不要太频繁，机器人以及自动欢迎之类的慎用，尽量减少你的回应频率。\n3. 如果发现登录后突然弹出验证码，这是一个前兆，要暂停机器人功能，可以停止进程或者选择像用户那样登录网页微信或者Mac微信客户端一段时间。\n\n## 感谢\n\n* [vue-admin](https://github.com/taylorchen709/vue-admin)\n* [wxpy](https://github.com/youfou/wxpy)\n* [ItChat](https://github.com/littlecodersh/ItChat)\n","funding_links":[],"categories":["Vue"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdongweiming%2Fwechat-admin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdongweiming%2Fwechat-admin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdongweiming%2Fwechat-admin/lists"}