利用python微信庫itchat實現(xiàn)微信自動回復(fù)功能,pythonitchat
用Python登錄微信并實現(xiàn)自動簽到,才了解到一個新的Python庫: itchat
利用Python 微信庫itchat,可以實現(xiàn)自動回復(fù)等多種功能,好玩到根本停不下來啊,尤其是調(diào)戲調(diào)戲不懂計算機的,特別有成就感,哈哈??!
代碼如下:
# _*_ coding:utf-8 _*_
import requests
import itchat
KEY = '8edce3ce905a4c1dbb965e6b35c3834d'
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'])
return reply or defaultReply
itchat.auto_login(hotReload=True)
itchat.run()
安裝一下 itchat即可跑上面程序,實現(xiàn)與圖靈機器人的交互。