图灵机器人:
官网:http://www.turingapi.com/
官方教程:https://www.kancloud.cn/turing/www-tuling123-com/718227
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 19 22:07:22 2019
@author: dell
"""
import itchat
import requests
import json
itchat.auto_login(hotReload=True)
friends = itchat.get_friends()
def getResponse(msg):
url = "http://openapi.tuling123.com/openapi/api/v2"
data = {
"reqType":0,
"perception": {
"inputText": {
"text": msg
},
"inputImage": {
"url": "imageUrl"
}
},
"userInfo": {
"apiKey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"userId": "Geclipse"
}
}
data = json.dumps(data)
r = requests.post(url,data).json()
return r['results'][0]['values']['text']
@itchat.msg_register(itchat.content.TEXT) #读取接受到的消息的TEXT部分内容,存储进默认的msg
def auto_reply(msg):
friends_message = msg['Text']
name = msg['FromUserName']
reply = getResponse(friends_message)
itchat.send(reply,toUserName=name)
itchat.run()