0


node-red发送微信公众号消息(模板消息)

前言

node-red可以作为邮件服务,也可以作为微信公众号服务,提供接口调用。模块化你的各个服务。


一、node-red获取token

1.微信公众号获取appID和appsecret

2.node-red节点

3.node-red源文件

[
    {
        "id": "1d34a3ad6b9f412b",
        "type": "tab",
        "label": "获取微信token",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "de4e681d8c6319f4",
        "type": "http request",
        "z": "1d34a3ad6b9f412b",
        "name": "请求微信token",
        "method": "GET",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=改成你的appid&secret=改成你的appsecret",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "senderr": false,
        "x": 500,
        "y": 200,
        "wires": [
            [
                "d3ec16514ab853f8",
                "b92e262f31d0f0c7"
            ]
        ]
    },
    {
        "id": "e83153343e5be6a2",
        "type": "http in",
        "z": "1d34a3ad6b9f412b",
        "name": "发送微信接口",
        "url": "/getWechatToken",
        "method": "get",
        "upload": false,
        "swaggerDoc": "",
        "x": 250,
        "y": 200,
        "wires": [
            [
                "de4e681d8c6319f4"
            ]
        ]
    },
    {
        "id": "b92e262f31d0f0c7",
        "type": "debug",
        "z": "1d34a3ad6b9f412b",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 790,
        "y": 100,
        "wires": []
    },
    {
        "id": "d3ec16514ab853f8",
        "type": "http response",
        "z": "1d34a3ad6b9f412b",
        "name": "",
        "statusCode": "200",
        "headers": {},
        "x": 800,
        "y": 200,
        "wires": []
    }
]

4.测试

浏览器访问http://localhost:1880/getWechatToken

二、node-red发送模板消息

1.微信公众号准备好模板

模板内容如下:

{{result.DATA}} 领奖金额:{{withdrawMoney.DATA}} 领奖 时间: {{withdrawTime.DATA}} 银行信息:{{cardInfo.DATA}} 到账时间: {{arrivedTime.DATA}} {{remark.DATA}}

2.node-red节点

3.node-red源文件

[
    {
        "id": "511e0574d7818792",
        "type": "tab",
        "label": "发送微信消息",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "0bc897428b825519",
        "type": "http in",
        "z": "511e0574d7818792",
        "name": "发送微信接口",
        "url": "/sendWechatMessage",
        "method": "post",
        "upload": false,
        "swaggerDoc": "",
        "x": 130,
        "y": 260,
        "wires": [
            [
                "11cf53eeb1b095c0"
            ]
        ]
    },
    {
        "id": "1d809621ab11f1be",
        "type": "http request",
        "z": "511e0574d7818792",
        "name": "请求微信send",
        "method": "POST",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "senderr": false,
        "x": 840,
        "y": 260,
        "wires": [
            [
                "919b72419f1f4ea4"
            ]
        ]
    },
    {
        "id": "986b6c8e662f35bc",
        "type": "debug",
        "z": "511e0574d7818792",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "url",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 840,
        "y": 360,
        "wires": []
    },
    {
        "id": "a8ed960bfb2b95b0",
        "type": "debug",
        "z": "511e0574d7818792",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 830,
        "y": 100,
        "wires": []
    },
    {
        "id": "919b72419f1f4ea4",
        "type": "http response",
        "z": "511e0574d7818792",
        "name": "",
        "statusCode": "200",
        "headers": {},
        "x": 1100,
        "y": 260,
        "wires": []
    },
    {
        "id": "11cf53eeb1b095c0",
        "type": "http request",
        "z": "511e0574d7818792",
        "name": "",
        "method": "GET",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "http://localhost:1880/getWechatToken",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "senderr": false,
        "x": 360,
        "y": 260,
        "wires": [
            [
                "49fd1dcf731dd41e"
            ]
        ]
    },
    {
        "id": "49fd1dcf731dd41e",
        "type": "function",
        "z": "511e0574d7818792",
        "name": "",
        "func": "msg.url=\"\";\nmsg.url=\"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=\"+msg.payload.access_token;\nmsg.payload = msg.req.body;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 570,
        "y": 260,
        "wires": [
            [
                "1d809621ab11f1be",
                "986b6c8e662f35bc",
                "a8ed960bfb2b95b0"
            ]
        ]
    }
]

三、postman发送请求

1.postman设置

Json如下(示例):

{
    "touser":"发送人的微信号:oGZFh6N5Y0dP1ygJlNs",
    "template_id":"你的微信公号模板消息ID:sC3kXH-UhhXulndf4z0NXGNbifeA7g",
    "url":"http://weixin.qq.com/download",
    "topcolor":"#ff0000",
    "data":{
            "result": {
                "value":"张先生",
                "color":"#173177"
            },
            "withdrawTime":{
                "value":"2022年02月19日 11时00分",
                "color":"#173177"
            },
            "cardInfo": {
                "value":"尾号0426",
                "color":"#173177"
            },
            "remark":{
                "value":"请注意查收。",
                "color":"#173177"
            },
            "withdrawMoney":{
                "value":"人民币360,000.00元",
                "color":"#ff0000"
            },
            "arrivedTime":{
                "value":"2022年02月19日11时01分",
                "color":"#173177"
            }
    }
}

2.postman响应截图

3.微信公众号消息


总结

node-red为所欲为。

标签: 微信 node postman

本文转载自: https://blog.csdn.net/MooreChen_68573397/article/details/123035061
版权归原作者 旋律limi 所有, 如有侵权,请联系我们删除。

“node-red发送微信公众号消息(模板消息)”的评论:

还没有评论