做一个微信聊天自动回复的机器人
# -*- coding: utf-8 -*- """ Created on Tue Jun 4 18:30:39 2019@author: yyp """#-*- coding:utf-8 -*- import itchat import requestsdef get_response(msg):apiurl = 'http://i.itpk.cn/api.php' #//moli机器人的网址data={"question": msg, #//获取到聊天的文本信息"api_key": "494cb6649ff24eefa464fb546bf50d56",#"api_secret": "n4gxkdyckd7p" }r=requests.post(apiurl,data=data) #//构造网络请求return r.text @itchat.msg_register(itchat.content.TEXT) #//好友消息的处理 def print_content(msg):return get_response(msg['Text']) @itchat.msg_register([itchat.content.TEXT], isGroupChat=True) #//群消息的处理 def print_content(msg):return get_response(msg['Text']) itchat.auto_login(True) #//自动登录 itchat.run() #//启动聊天机器人
显示效果: