本周考虑到实现一个微信机器人的功能,研究了一下 wxpy 这个库
参考文档
简单的demo
例子1:获取聊天群里面所有@我的消息,并回复信息
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from wxpy import *
bot = Bot(cache_path=True)
# 机器人账号自身
myself = bot.self
# 给机器人自己发送消息
bot.self.send('Hello World!')
@bot.register(Group, TEXT)
def print_group_msg(msg):
if msg.is_at:
print(msg)
print(msg.text, type(msg.text))
msg.reply(u"你的内容是:**{0}**\n这是排骨的测试~~~".format(msg.text))
embed() # 阻塞进程
例子2:获取群成员,主要是Member这个类的分析
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from wxpy import *
bot = Bot(cache_path=True)
# 机器人账号自身
myself = bot.self
# 给机器人自己发送消息
bot.self.send(u'Hello World!')
group_fzr =