微信机器人。

liuwons 70ba8328cf Example and README. 9 years ago
img 3e37d66d60 Bug fix and README change. 9 years ago
.gitignore 1b7010d027 Add README 9 years ago
LICENSE 75bfbf09db Initial commit 9 years ago
README.md 3e37d66d60 Bug fix and README change. 9 years ago
test.py 70ba8328cf Example and README. 9 years ago
wxbot.py 3e37d66d60 Bug fix and README change. 9 years ago

README.md

wxBot star this repo fork this repo python

Python包装WEB微信实现的微信机器人框架。可以很容易地实现微信机器人。

依赖

程序用到了Python requests 和 pyqrcode库,使用之前需要安装这两个库:

pip install requests
pip install pyqrcode

快速开发

代码

利用 wxBot 最简单的方法就是继承WXBot类并实现handle_msg_all函数,然后实例化子类并run,如下的代码对所有的文本消息回复 hi 。

#!/usr/bin/env python
# coding: utf-8

from wxbot import *

class MyWXBot(WXBot):
    def handle_msg_all(self, msg):
        if msg['msg_type_id'] == 5:
            self.send_msg(msg['user_name'], 'hi')

def main():
    bot = MyWXBot()
    bot.DEBUG = True
    bot.run()

if __name__ == '__main__':
    main()

运行

直接用python运行代码(如运行测试代码main.py):

python main.py

登录微信

程序运行之后,会在当前目录下生成二维码图片文件 qr.jpg ,用微信扫描此二维码并按操作指示确认登录网页微信。

1

效果展示

测试代码main.py的运行效果:

向机器人发送消息

后台