您现在的位置是:网站首页> 编程资料编程资料
13行python代码实现对微信进行推送消息的示例代码_python_
2023-05-26
462人已围观
简介 13行python代码实现对微信进行推送消息的示例代码_python_
Python可以实现给QQ邮箱、企业微信、微信等等软件推送消息,今天咱们实现一下Python直接给微信推送消息。
这里咱们使用了一个第三方工具pushplus

单人推送
实现步骤:
1、用微信注册一个此网站的账号
2、将token复制出来,记录到小本本上。

代码展示
import requests 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块钱。
到此这篇关于13行python代码实现对微信进行推送消息的示例代码的文章就介绍到这了,更多相关python微信推送消息内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
您可能感兴趣的文章:
相关内容
- Python pygame项目实战监听退出事件_python_
- django中的自定义分页器的实现示例_python_
- python将写好的程序打包成exe可执行文件_python_
- Python名片管理系统+猜拳小游戏案例实现彩(色控制台版)_python_
- Python 局部变量global详解_python_
- opencv python截取圆形区域的实现_python_
- Python pyecharts案例超市4年数据可视化分析_python_
- Python编写车票订购系统 Python实现快递收费系统_python_
- python manim实现排序算法动画示例_python_
- Python 操作pdf pdfplumber读取PDF写入Excel_python_
