Recently I discovered a particularly interesting Python WeChat library itchat, which can realize various functions such as automatic reply. The following article mainly introduces you to the relevant information on using the python WeChat library itchat to realize the automatic reply function of WeChat. Friends who need it You can refer to it for study, let’s take a look below.
Preface
On the forum, I saw using Python to log in to WeChat and realize automatic sign-in, and then I learned about a new Python library: itchat
Using the Python WeChat library itchat, you can realize various functions such as automatic replies. It is so fun that you can’t stop playing. Especially for those who don’t understand computers, they feel a sense of accomplishment, haha! !
The code is as follows:
#coding=utf8 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()
Install itchat and you can run the above program to achieve Interaction with Turing robots.
Related recommendations:
Use python socket to send http(s) request method
Use python to Detailed explanation of converting pictures into excel document format
The above is the detailed content of Use python WeChat library itchat to implement WeChat automatic reply function. For more information, please follow other related articles on the PHP Chinese website!