微信自动回复机器人
程序员文章站
2022-07-13 08:52:17
...
# 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()
print(r)
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和requests两个包,运行程序之后,手机扫码,然后就可以了,当有人给你发消息的时候,就会自动回复了。