收藏
回答

后台发送模板消息,微信没有收到任何消息?

发送后提示消息:

Starting new HTTPS connection (1): api.weixin.qq.com:443

2023-04-11 13:56:14,910 - /home/DeviceAlarm/AlarmMessage/Alarm_venv/lib/python3.8/site-packages/urllib3/connectionpool.py[line:456] - DEBUG: https://api.weixin.qq.com:443 "POST /cgi-bin/message/template/send?access_token=67_7Imu1xkXh--QXKu2q7VFfJH32bA2xRp1giGku5Kqg6nKmKoYAn8qF_vm_YFq7KC0SmrxyGCN9M4dRfLYZqay_SrrksOkHtMy2_XdnWyjHAqHdfsJIgsCp65KHogOMMiAHAYWW HTTP/1.1" 200 77

下面是发送代码

# 发送模板消息
def post_data(self, device):
    access_token = self.get_token()
    time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    # 统一服务消息
    # 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
    # url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=" + access_token
    params = {
        "touser": 'oMe5a5Vde5r8uNfHNI86nD5wL0Nv',
        
        "template_id": self.template_id,
        "data": {
            "first": {
                "value": device['first']
                # "value": "您的设备已触发设备报警。"
            },
            "keyword1": {
                "value": device['device_num']
                # "value": "1222032091"
            },
            "keyword2": {
                "value": device['device_name']
                # "value": "温湿度恒温箱"
            },
            "keyword3": {
                "value": device['get_time']
                # "value": "2021年06月07日19时24分"
            },
            "keyword4": {
                "value": device['content']
                # "value": "温度超标 45°C"
            },
            "remark": {
                "value": time
            }
        }
    }
    response = requests.post(url, json=params)


回答关注问题邀请回答
收藏

1 个回答

  • 智敏
    智敏
    2023-04-11

    统一服务消息和模板消息有什么不同,模板库是否有区别。

    2023-04-11
    有用
    回复
登录 后发表内容
问题标签