使用WeRoBot实现一个简单的关键字回复

#coding:utf-8 from werobot import WeRoBot import random from werobot.replies import ArticlesReply, Article import requests url = "https://v1.alapi.cn/api/dog" #舔狗api url1 = "https://v1.alapi.cn/api/qinghua" #土味情话 url2 = "https://v1.alapi.cn/api/soul" #鸡汤 payload = "format=text" headers = {'Content-Type': "application/x-www-form-urlencoded"} robot = WeRoBot(token='wexin') #微信token # 明文模式不需要下面三项 #robot.config["APP_ID"]='wx5c69aee2dd' #robot.config["APP_SECRET"]='16e1852d73e5b562c23346b445' #robot.config['ENCODING_AES_KEY'] = 'TWSUwkl3LHzZW2lkUNZhcBI2gunlQi25eU7B' # 被关注 @robot.subscribe def subscribe(message): return '''欢迎关注舔狗公众号,食用方法,回复关键字: 舔狗, 情话, 鸡汤, 开始做一个舔狗!!! ''' # blog 回复个人博客 @robot.filter('blog','博客','个人博客') def blog(message): reply = ArticlesReply(message=message) article = Article( title="我的博客", description="我的个人博客", img="https://www.529i.com/wx.jpg", url="https://www.529i.com/" ) reply.add_article(article) return reply @robot.filter('舔狗') @robot.location def music(message): music1 = music_data() return music1 def music_data(): response = requests.request("POST", url, data=payload, headers=headers) dog=response.text return dog @robot.filter('情话') def qinghua(message): qinghua1 = qinghua2() return qinghua1 def qinghua2(): response = requests.request("POST", url=url1, data=payload, headers=headers) q=response.text return q @robot.filter('鸡汤') def jitang(message): jitang1 = jitang2() return jitang1 def jitang2(): response = requests.request("POST", url=url2, data=payload, headers=headers) j=response.text return j # 文本消息返回原文 #@robot.text #def echo(message): # return message.content # 其他消息返回 @robot.handler def hello(message): return '食用方法,回复关键字: 舔狗, 情话, 鸡汤,开始做一个舔狗!!!' robot.config['HOST'] = '127.0.0.1' robot.config['PORT'] = 39508 robot.run()
如果觉得我的文章对你有用,请随意赞赏