Python微信自动回复机器人
程序员文章站
2022-07-13 08:51:59
...
import requests
import itchat # 这是一个用于微信回复的库
KEY = '1c5db2d4cf18494eb966e7caf43ee6b6' #这是我的机器人,你也可以利用图灵机器人获取自己的key
# 向api发送请求
def get_response(msg):
api_url = 'http://www.tuling123.com/openapi/api'
data = {
'key': KEY,
'info': msg,
}
try:
r = requests.post(api_url, data).json()
print(msg)
return r.get('text')
except Exception as mas:
print(mas)
return
@itchat.msg_register(itchat.content.TEXT)
def reply(msg):
default_reply = 'I received: ' + msg['Text']
reply_msg = get_response(msg['Text'])
print(reply_msg)
return reply_msg or default_reply
itchat.auto_login(hotReload=False)
itchat.run()