一、依赖环境
1.安装wxpy包。wxpy 在 itchat 的基础上,通过大量接口优化提升了模块的易用性,并进行丰富的功能扩展。
从 PYPI 官方源下载安装 (在国内可能比较慢或不稳定):
学习Python中有不明白推荐加入交流群
号:864573496群里有志同道合的小伙伴,互帮互助,群里有不错的视频学习教程和PDF!每晚8:00群里直播
pip install -U wxpy
从豆瓣 PYPI 镜像源下载安装 (推荐国内用户选用):
pip install -U wxpy -i "https://pypi.doubanio.com/simple/"
Attention!
强烈建议仅使用小号运行机器人!
2. 图灵机器人官网注册获取apikey。地址:http://www.tuling123.com/
二、源码
from wxpyimport *
#扫码登录微信
bot = Bot(cache_path=True)#cache_path=True 保留缓存信息
myself = bot.self
tuling = Tuling(api_key='***')# ***填你的图灵api_key
my_friend = ensure_one(bot.search('***'))# ***填写你某个朋友的名字,备注名和微信名均可
group = bot.groups().search('***')[0]#同上
@bot.register(group)#对指定的群自动回复
def reply_my_friend(msg):
tuling.do_reply(msg)
@bot.register( )#对所有消息自动回复
def reply_my_friend(msg):
tuling.do_reply(msg)
@bot.register(my_friend)#对指定的好友回复
def reply_my_friend(msg):
tuling.do_reply(msg)
bot.join()#堵塞线程,让程序一直运行
三、结果图
网友评论