最近用 图灵 + itchat组件库写了一个微信自动回复的机器人,发现很多可以拓展的,仅供参考!
import requests
import itchat
import random
KEY = 'your key'
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']
robots = ['是我啊', '嘻嘻', '爱你']
reply = get_response(msg['Text']) + random.choice(robots)
return reply or defaultReply
itchat.auto_login(enableCmdQR=False)
itchat.run()