VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > python入门教程 >
  • 13行python代码实现对微信进行推送消息

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

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

单人推送

实现步骤:

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

在这里插入图片描述

代码展示

复制代码
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)
复制代码

 

在手机上看一下结果

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

一对多推送

实现步骤

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

在这里插入图片描述

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


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


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)
复制代码

 

效果展示

在这里插入图片描述

至此到这里就完成啦!

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

Python爬虫入门到实战:100个爬虫实战项目!

兄弟们,觉得不错的话,点赞收藏一下呗!

出处:https://www.cnblogs.com/hahaa/p/16583878.html



相关教程