• 用 Python 实现微信推送消息


    本文由 简悦 SimpRead 转码, 原文地址 mp.weixin.qq.com

    Python 可以实现给 QQ 邮箱、企业微信、微信等等软件推送消息,今天咱们实现一下 Python 直接给微信推送消息。

    这里咱们使用了一个第三方工具pushplus

    # 单人推送

    实现步骤:

    1、用微本本上。

    代码展示

    import requests
    
    def send_wechat(msg):
        token = 'XXXXXXXXXXXX' #前边复制到那个token
        title = 'title1'
        content = msg
        url = 'http://www.pushplus.plus/send?token=' + token + '&title=' + title + '&content=' + content
        print(url)
        r = requests.get(url)
        print(r.text)
    
    if __name__ == '__main__':
        msg = 'Life is short I use python'
        send_wechat(msg)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    在手机上看一下结果

    局限性:这个只能给自己推送,别人推送不了。那怎么给别人推送呢?

    # 一对多推送

    实现步骤

    1、在一对多推送的 tab 页面里,新建群组,并记录下群组编码。

    2、点击生成二维码,将二维码发给要接受消息的人。让他们用微信扫码。


    3、扫码后,看看订阅人,扫码之后的人,会显示在这里。给这个群组发送的消息,这里的人都会接收到。


    4、写代码发送消息到微信

    import requests
    
    def send_wechat_all(msg):
        token = 'XXXXXXXXXXXX' #前边复制到那个token
        title = 'test notice title'
        content = msg
        topic = '1'
        url = 'http://www.pushplus.plus/send?token=' + token + '&title=' + title + '&content=' + content + '&topic=' + topic
        print(url)
        r = requests.get(url)
        print(r.text)
    
    if __name__ == '__main__':
        msg = 'this is a one to more lizi'
        send_wechat_all(msg)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    效果展示

    至此到这里就完成啦!

  • 相关阅读:
    FreeRTOS_中断配置和临界段
    vite-electron 静默打印功能实现
    C++内存池
    三位球形模型应用
    设计原则与思想:面向对象
    python常用知识梳理(必看篇)
    MYSQL的慢查询
    博图Modbus组态及参数设定源码
    合成孔径雷达地面运动目标检测技术研究——基于概率图(Matlab代码实现)
    你真的懂反馈吗?
  • 原文地址:https://blog.csdn.net/qq_34035956/article/details/127435070