用python的itchat库做微信智能回复

来源:互联网 发布:计算机算法设计难么 编辑:程序博客网 时间:2024/05/28 17:08

版本:py3

调用图灵智能的智能服务;


#coding=utf8import requestsimport itchatKEY = 'd013d2a0c5564918b1270855582d5d4f'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 defaultReplyitchat.auto_login(hotReload=True)itchat.run()