模塊
itchat
功能
實現(xiàn)微信回復(fù)機器人(調(diào)用圖靈機器人api)
代碼
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#Author:Eric
import requests
import itchat
def getResponse(_info):
#print(_info)
apiUrl = 'http://www.tuling123.com/openapi/api'
data = {
'key' : '7c1ccc2786df4e1685dda9f7a98c4ec9', # 如果這個Tuling Key不能用,那就換一個
'info' : _info, # 這是我們發(fā)出去的消息
'userid' : 'wechat-robot', # 這里你想改什么都可以
}
# 我們通過如下命令發(fā)送一個post請求
r = requests.post(apiUrl, data=data).json()
# 讓我們打印一下返回的值,看一下我們拿到了什么
return r
@itchat.msg_register(itchat.content.TEXT)
def text_reply(msg):
# print(msg)
return "小小:" + getResponse(msg["Text"])["text"]
# itchat.auto_login(enableCmdQR=True)
#pycharm下使用如下兩條命令
itchat.login()
# itchat.auto_login(enableCmdQR=True)
itchat.run()
#服務(wù)器上使用如下兩條命令
itchat.auto_login(enableCmdQR=2,hotReload=True)
itchat.run(debug=True)
#print(getResponse("早上好"))
使用方法(前提是設(shè)備安裝了python):
本地使用:
輸入pip install itchat pillow,等待安裝完成,輸入python wx.py,用手機微信掃描生成的二維碼,確認登陸即可
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。