微信公众号对接个人网站

如何让个人微信公众号能够访问到个人的网站的内容,当输入任意内容就返回一个菜单,输入对应的编号返回个人网站相关的内容链接。

from werobot import WeRoBot
from werobot.replies import ArticlesReply
from werobot.replies import Article
import requests

# 实例化微信机器人
robot = WeRoBot(token='TOKEN')

hello = '''你好, 朋友, 欢迎来到码农社!

   1. 推荐文章
   2. 最新文章
   3. 深度学习
   4. 数据结构
   5. C/C++
   6. Python

请输入对应数字, 获得优质内容!'''

@robot.handler
def welcome(message):
    return hello


# 处理文本消息
@robot.text
def handler_text(message, session):

    if message.content == '1':

        article_tile = '推荐好文'
        article_imge = 'http://mengbaoliang.cn/wp-content/uploads/2022/09/7f88dbbcaa77a1d-2.png'
        article_addr = 'http://mengbaoliang.cn/?page_id=43536'
        article_desc = '推荐好文推荐好文推荐好文推荐好文推荐好文推'

        article_reply = ArticlesReply(message=message)
        article = Article(title=article_tile, description=article_desc, img=article_imge, url=article_addr)
        article_reply.add_article(article)

        return article_reply

    elif message.content == '2':
        return "最新文章"
    elif message.content == '3':
        return "深度学习"
    elif message.content == '4':
        return "数据结构"
    elif message.content == '5':
        return "Linux C/C++"
    elif message.content == '6':
        return "Python"

    return hello

# 处理图片消息
@robot.image
def handler_image(message):
    return "暂无法理解图像内容"

# 处理语音消息
@robot.voice
def handler_voice(message):
    return "暂无法理解语音内容"

# 处理未知消息
@robot.unknown
def handler_unknown(message):
    return "无法理解你的信息"


if __name__ == '__main__':

    robot.config['HOST'] = '0.0.0.0'
    robot.config['PORT'] = 80
    robot.run()

未经允许不得转载:一亩三分地 » 微信公众号对接个人网站
评论 (0)

9 + 1 =