WeChat图灵机器人

简介

基于python2.7 或 python3.X 接入图灵机器人自动回复微信消息,实现类似小黄鸡的功能,可在此基础上修改为自动回复群消息或指定人、指定群组自动回复消息…

itchat安装

pip install itchat

程序Demo

#coding=utf8
import requests
import itchat
import time

# 注册 tuling获取KEY
KEY = 'e5ccc9c7c8834ec3b08940e290ff1559'

def get_response(msg):
    apiUrl = 'http://www.tuling123.com/openapi/api'
    data = {
        'key'    : KEY,
        'info'   : msg,
        'userid' : 'wechat-robot',
    }
    try:
        r = requests.post(apiUrl, data=data).json()
        return r.get('text')
    except:
        return

@itchat.msg_register(itchat.content.TEXT)
def tuling_reply(msg):
    defaultReply = 'I received: ' + msg['Text']
    reply = get_response(msg['Text'])
    time.sleep(1)
    return reply or defaultReply

# 登陆(hotReload=True )
itchat.auto_login(hotReload=True)

# 运行itchat
itchat.run()

你可能感兴趣的:(WeChat图灵机器人)