使用python构造一个微信聊天机器人

申请一个图灵的APIKEY http://www.tuling123.com/

python3环境下安装wxpy

pip install wxpy

linux下还需安装pillow

pip install pillow

然后执行以下代码:

#!/usr/bin/python3
# -*- coding: utf-8 -*-
# 导入模块
from wxpy import *
# 初始化机器人,扫码登陆
bot = Bot()
#my_friend = ensure_one(bot.search('a')) 
tuling = Tuling(api_key='ffd3a012cd134f0db64f0b9573c24241')
dir(Tuling)
# 使用图灵机器人自动与指定好友聊天
@bot.register()#装饰器中如果传入参数@bot.register(my_friend)则是和朋友a聊天
def reply_my_friend(msg):
    tuling.do_reply(msg)
embed();#进入命令行,可以一直保持状态

几行代码轻松搞定!

文档地址:http://wxpy.readthedocs.io/zh/latest/bot.html

猜你喜欢

转载自blog.csdn.net/getcomputerstyle/article/details/70175167