python使用微信进行消息推送

一对一推送

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页面里,新建群组。并记录下群组编码

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)

效果:

完成~~

经验分享 程序员 微信小程序 职场和发展