用 Python 实现对微信进行推送消息的工具 pushplus

admin 2022年10月30日04:30:44评论122 views字数 1349阅读4分29秒阅读模式
来自公众号:Python编程时光
本文仅供技术学习。
Python可以实现给QQ邮箱、企业微信、微信等等软件推送消息,今天咱们实现一下Python直接给微信推送消息。

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

单人推送

实现步骤:

1、用微信注册一个此网站的账号
2、将token复制出来,记录到小本本上。

用 Python 实现对微信进行推送消息的工具  pushplus

代码展示

import requests
# Python源码资料电子书领取群 279199867

def send_wechat(msg):
    token = 'XXXXXXXXXXXX'#前边复制到那个token
    title = 'title1'
    content = msg
    template = 'html'
    url = f"https://www.pushplus.plus/send?token={token}&title={title}&content={content}&template={template}"
    print(url)
    r = requests.get(url=url)
    print(r.text)

if __name__ == '__main__':
    msg = 'Life is short I use python'
    send_wechat(msg)

在手机上看一下结果

用 Python 实现对微信进行推送消息的工具  pushplus

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

一对多推送

实现步骤

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

用 Python 实现对微信进行推送消息的工具  pushplus

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

用 Python 实现对微信进行推送消息的工具  pushplus


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


用 Python 实现对微信进行推送消息的工具  pushplus


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


import requests

def send_wechat(msg):
    token = ' XXXXXXXXXXXXXXXXXX' #前边复制到那个token
    title = 'test notice title'
    content = msg
    template = 'html'
    topic = '1'
    url = f"http://www.pushplus.plus/send?token={token}&title={title}&content={content}&template={template}&topic={topic}"
    print(url)
    r = requests.get(url=url)
    print(r.text)

if __name__ == '__main__':
    msg = 'this is a one to more lizi'
    send_wechat(msg)

效果展示

用 Python 实现对微信进行推送消息的工具 -- pushplus

至此到这里就完成啦!

另注:pushplus 分普通用户和会员,他们最大的区别就是:普通用户一天仅可请求200次,会员扩大到1000次。所以普通用户基本上也够用了。真想支持网站作者,就买个会员,一个月也就10块钱。

--- EOF ---


推荐↓↓↓

原文始发于微信公众号(Python编程):用 Python 实现对微信进行推送消息的工具 -- pushplus

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年10月30日04:30:44
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   用 Python 实现对微信进行推送消息的工具 pushplushttp://cn-sec.com/archives/1358249.html

发表评论

匿名网友 填写信息