import itchat
import requests
def get_respoinse(msg):
apiUrl = 'http://www.tuling123.com/openapi/api'
data = {
'key': 'dc3586d008f14d4ea7a301b02247f6c1',
'info': msg
}
r = requests.post(apiUrl, data=data).json()
return r.get('text')
@itchat.msg_register(itchat.content.TEXT)
def print_content(msg):
return get_respoinse(msg['Text'])
#这里注释的代码是群聊自动回复,测试时推荐先关掉
#@itchat.msg_register([itchat.content.TEXT], isGroupChat=True)
#def print_content(msg):
# return get_respoinse(msg['Text'])
itchat.auto_login(True)
itchat.run()
编辑器是pyCharm,运行时需先安装依赖,运行成功会弹出一个二维码,微信扫描即可登录,实现机器人聊天