收藏
回答

请帮助看一下为什么程序不能发送模板消息?

微信模板发送消息程序如下,发送回调res 显示200,但微信断没有任何显示。

#-*- coding:utf-8 -*-
# 正式上线微信报警程序
import requests

url = 'https://api.weixin.qq.com/cgi-bin/token'
params = {
    'grant_type': 'client_credential',
    'appid': 'wxcd2f2f5a5861234',  # 小程序id
    'secret': '5294a03f36193193d3d3db6033d61234',
}
try:
    response = requests.get(url=url, params=params)
    res = response.json()
    access_token = res['access_token']
    print('access_token',access_token)
except Exception as e:
    print(e)

# https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN
url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='+access_token
print('url',url)
params = {
    "touser":"oMe5a5Vde5r8uNfHNI86nD5w1234",
    "template_id":"SYnaga93yBdJFR5U1LAXHYcAQ0p4lUuX38W925aORjE",
    "url":"http://weixin.qq.com/download",
    "topcolor":"#FF0000",
    "data": {
        "first": {
            "value": "您的设备已触发设备报警。"
        },
        "keyword1": {
            "value": "1222032091"
        },
        "keyword2": {
            "value": "温湿度恒温箱"
        },
        "keyword3": {
            "value": "2023年04月07日19时24分"
        },
        "keyword4": {
            "value": "温度超标 45°C"
        },
        "remark": {
            "value": "2023年04月07日19时24分"
        }
        }
    }
res = requests.post(url, json=params, timeout=5)
print('res',res)


回答关注问题邀请回答
收藏
登录 后发表内容
问题标签