import requests
import itchat
def lc():
print("Finash Login!")
def jiqiren(xinxi):
url = 'http://api.qingyunke.com/api.php?key=free&appid=0&msg='+xinxi
r = requests.get(url)
# print(r.json()['content'])
reg=r.json()['content']
return reg
@itchat.msg_register(itchat.content.TEXT)#监听好友发送的信息内容
def send_msg(msg):
info=msg['Content']
url = 'http://openapi.tuling123.com/openapi/api/v2'
data = {"reqType": 0,
"perception": {
"inputText": {
"text": str(info)
}
},
"userInfo": {
#该内容需要注册登录图灵官网,创建机器人之后返回的内容
"apiKey": "username",
"userId": "123456"
}
}
headers = {
'Content-Type': 'application/json',
'Host': 'openapi.tuling123.com',
'User-Agent': 'Mozilla/5.0 (Wi`ndows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3486.0 '
'Safari/537.36 '
}
r = requests.post(url, headers=headers, json=data)
messige = r.json()['results'][0]['values']['text']#接收图灵机器人发送的信息
#把接收到的机器人回复的信息发送给好友
itchat.send_msg(messige, msg['FromUserName'])
#登录微信登录成功之后,调用lc方法
itchat.auto_login(loginCallback=lc)
#一直监听微信信息
itchat.run()