import itchat
import requests
# 设置图灵机器人的密钥
KEY = ''
def get_response(msg):
# 设置图灵机器人接口
apiUrl = 'http://www.tuling123.com/openapi/api'
data = {
'key': KEY,
'info': msg,
'userid': 'auto-reply'
}
try:
# 发送Post请求
r = requests.post(apiUrl, data=data).json()
# 得到返回值
return r.get('text')
except:
return
@itchat.msg_register(itchat.content.TEXT)
def tuling_reply(msg):
# 设置默认回复
DefaultReply = "你发错了吧!"
# 图灵机器人回复
# reply = get_response(msg['Text'])
# return reply or DefaultReply
return DefaultReply
itchat.auto_login()
itchat.run()