用到了一个微信的hook工具,可以使用代码对微信进行操作,然后才可以进行自动话的操作,本文的目的是在这个的基础上,让用户可以通过简单的拖拽进行微信的管理操作。

操作微信的hook

可以自己去GitHub搜索相关的内容,我这里提供一个是免费的,使用的web协议
https://github.com/danni-cool/wechatbot-webhook

node red

我的所有代码使用的node red 平台,我感觉非常的好用

node-red的教程可以看我之前写的一篇文章

https://www.glwsq.cn/post/node-red

我的文章会介绍很多小例子,只需要导入node-red即可使用,持续更新中。

给用户发消息

例子中封装了一个发微信模块,任何情况下,如果需要发送微信,只需要调用发微信模块就可以了

Image

[{"id":"12c0fe7bd67c602a","type":"group","z":"89a720a4aa2449a9","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["aa10845e2a7078f2","7260af680da1b795","ed357c610edae650"],"x":68,"y":33,"w":1284,"h":434},{"id":"aa10845e2a7078f2","type":"group","z":"89a720a4aa2449a9","g":"12c0fe7bd67c602a","name":"发微信模块","style":{"stroke":"#addb7b","label":true,"color":"#999999"},"nodes":["c72cc9c1d3efebcf","c4590dcd6c564e8f","f002b62b9af37b3e","86e5a2af61a388af","563771160849d349"],"x":674,"y":299,"w":652,"h":142},{"id":"c72cc9c1d3efebcf","type":"http request","z":"89a720a4aa2449a9","g":"aa10845e2a7078f2","name":"WeChatApi","method":"POST","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":1050,"y":340,"wires":[["c4590dcd6c564e8f"]]},{"id":"c4590dcd6c564e8f","type":"debug","z":"89a720a4aa2449a9","g":"aa10845e2a7078f2","name":"API执行结果","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload.data.status","statusType":"msg","x":1210,"y":340,"wires":[]},{"id":"f002b62b9af37b3e","type":"debug","z":"89a720a4aa2449a9","g":"aa10845e2a7078f2","name":"发送的原始内容","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":400,"wires":[]},{"id":"86e5a2af61a388af","type":"link in","z":"89a720a4aa2449a9","g":"aa10845e2a7078f2","name":"发微信","links":["45480d657e514272","cfabe46039bddb60","f68bd80dd2b48b5a"],"x":750,"y":340,"wires":[["f002b62b9af37b3e","563771160849d349"]],"icon":"node-red/comment.svg","l":true},{"id":"563771160849d349","type":"function","z":"89a720a4aa2449a9","g":"aa10845e2a7078f2","name":"设置url","func":"msg.url = global.get(\"wechat-url\")\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":880,"y":340,"wires":[["c72cc9c1d3efebcf"]]},{"id":"7260af680da1b795","type":"group","z":"89a720a4aa2449a9","g":"12c0fe7bd67c602a","name":"发送个人消息","style":{"label":true},"nodes":["a9830932077649e6","b945d407d9f494d5","cfabe46039bddb60"],"x":94,"y":319,"w":552,"h":82},{"id":"a9830932077649e6","type":"inject","z":"89a720a4aa2449a9","g":"7260af680da1b795","name":"触发","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":190,"y":360,"wires":[["b945d407d9f494d5"]]},{"id":"b945d407d9f494d5","type":"function","z":"89a720a4aa2449a9","g":"7260af680da1b795","name":"发送个人消息","func":"let userName = global.get('my-wechat-id')\nif (!userName) {\n    node.error(\"请设置你的wxid\")\n}\n\n\n\nmsg.payload = {\n    \"type\": 10009,\n    \"userName\": userName,\n    \"msgContent\": \"测试内容\",\n    \"insertToDatabase\": false\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":360,"wires":[["cfabe46039bddb60"]]},{"id":"cfabe46039bddb60","type":"link out","z":"89a720a4aa2449a9","g":"7260af680da1b795","name":"发微信","mode":"link","links":["86e5a2af61a388af"],"x":570,"y":360,"wires":[],"icon":"node-red/comment.svg","l":true},{"id":"ed357c610edae650","type":"group","z":"89a720a4aa2449a9","g":"12c0fe7bd67c602a","name":"设置基本信息","style":{"label":true},"nodes":["b592c51daaf32ed7","8a4a6388e87bb7a4","7a6ca18db5076579","644c41d4c037dd11","01bba9f7255e8525"],"x":104,"y":59,"w":622,"h":162},{"id":"b592c51daaf32ed7","type":"change","z":"89a720a4aa2449a9","g":"ed357c610edae650","name":"设置一些基本信息","rules":[{"t":"set","p":"my-wechat-id","pt":"global","to":"wxid_xxx","tot":"str"},{"t":"set","p":"wechat-url","pt":"global","to":"localhost:888/api/","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":180,"wires":[["7a6ca18db5076579"]]},{"id":"8a4a6388e87bb7a4","type":"inject","z":"89a720a4aa2449a9","g":"ed357c610edae650","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":180,"wires":[["b592c51daaf32ed7"]]},{"id":"7a6ca18db5076579","type":"debug","z":"89a720a4aa2449a9","g":"ed357c610edae650","name":"debug 128","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":610,"y":180,"wires":[]},{"id":"644c41d4c037dd11","type":"comment","z":"89a720a4aa2449a9","g":"ed357c610edae650","name":"使用之前先设置基本信息","info":"","x":490,"y":100,"wires":[]},{"id":"01bba9f7255e8525","type":"comment","z":"89a720a4aa2449a9","g":"ed357c610edae650","name":"个人测试的微信id 和 微信的url","info":"","x":500,"y":140,"wires":[]}]

更完善的例子

例子加入了如下功能

  1. 发消息进行了节流,一秒钟只会发送一条消息,当然可以自行更改
  2. 针对一个人一个群,一小时会限制发送的条数
  3. 对群和个人进行相同的处理,只会处理群里面艾特的消息
当然这个例子可以自行修改,只是提供一个思路,也还有很多不完善的地方

Image

[{"id":"cb67b715a1216381","type":"group","z":"89a720a4aa2449a9","name":"","style":{"label":true},"nodes":["7bab22602a2cdc6d","974382a7f9667f69","0f142868c3a6e3cb","475ed58d8e0c1850"],"x":8,"y":1133,"w":1324,"h":814},{"id":"7bab22602a2cdc6d","type":"group","z":"89a720a4aa2449a9","g":"cb67b715a1216381","name":"发送消息","style":{"label":true},"nodes":["6c0eeb4b34a5a9c2","11354c6c41e73507","afb2b4388d22ef1f","3375d0bbd699d8a3","b1cdbf0c489b657c","ab88e3518e838894","81b5fefb4da5730e","ea73b9282528cd9e","353daaa505dc835f","5ca842575134aa4e","167be135c8a56577"],"x":54,"y":1639,"w":1072,"h":282},{"id":"6c0eeb4b34a5a9c2","type":"debug","z":"89a720a4aa2449a9","g":"7bab22602a2cdc6d","name":"发送的内容","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":930,"y":1680,"wires":[]},{"id":"11354c6c41e73507","type":"function","z":"89a720a4aa2449a9","g":"7bab22602a2cdc6d","name":"拼接发送的消息","func":"if (msg.weixin.isChatroomMsg == 1) {\nmsg.payload = {\n    \"type\": 10009,\n    \"userName\": `${msg.weixin.from}`,\n    \"msgContent\": `@${msg.weixin.chatroomMemberInfo.nickName} ${msg.weixin.content}`,\n    \"atUserList\": [\n        msg.weixin.chatroomMemberInfo.userName\n    ],\n    \"insertToDatabase\": true\n}\n\nif (msg.weixin.type = 10002) {\n    msg.payload['msgContent'] = msg.weixin.content\n}\n\n} else {\nmsg.payload = {\n    \"type\": 10009,\n    \"userName\": `${msg.weixin.from}`,\n    \"msgContent\": `${msg.weixin.content}`,\n    \"insertToDatabase\": true\n}\n\n}\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":1740,"wires":[["6c0eeb4b34a5a9c2","afb2b4388d22ef1f"]]},{"id":"afb2b4388d22ef1f","type":"http request","z":"89a720a4aa2449a9","g":"7bab22602a2cdc6d","name":"WeChatApi","method":"POST","ret":"obj","paytoqs":"ignore","url":"weixin2.glwsq.cn/api/","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":670,"y":1800,"wires":[["ab88e3518e838894"]]},{"id":"3375d0bbd699d8a3","type":"debug","z":"89a720a4aa2449a9","g":"7bab22602a2cdc6d","name":"发消息状态","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload.data.status","statusType":"msg","x":990,"y":1760,"wires":[]},{"id":"b1cdbf0c489b657c","type":"function","z":"89a720a4aa2449a9","g":"7bab22602a2cdc6d","name":"发送消息","func":"\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":140,"y":1860,"wires":[["167be135c8a56577"]]},{"id":"ab88e3518e838894","type":"switch","z":"89a720a4aa2449a9","g":"7bab22602a2cdc6d","name":"","property":"payload.data.status","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":830,"y":1800,"wires":[["3375d0bbd699d8a3"],["81b5fefb4da5730e"]]},{"id":"81b5fefb4da5730e","type":"debug","z":"89a720a4aa2449a9","g":"7bab22602a2cdc6d","name":"发消息失败","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload.data.status","statusType":"msg","x":1010,"y":1880,"wires":[]},{"id":"ea73b9282528cd9e","type":"function","z":"89a720a4aa2449a9","g":"7bab22602a2cdc6d","name":"节流函数","func":"function checkRateLimit(topic, maxCount, interval) {\n    // 使用一个对象来存储每个 topic 的状态\n    let topics = context.get('topics') || {};\n    if (!topics[topic]) {\n        topics[topic] = { lastSent: 0, count: 0 };\n    }\n\n    let now = Date.now();\n    let timeSinceLast = (now - topics[topic].lastSent) / 1000 / 60; // 转换为分钟\n\n    if (timeSinceLast >= interval) {\n        topics[topic].count = 0;\n        topics[topic].lastSent = now;\n    }\n\n    if (topics[topic].count < maxCount) {\n        topics[topic].count += 1;\n        context.set('topics', topics);\n        updateNodeStatus(topic, topics[topic].count, maxCount);\n        return true;\n    } else {\n        updateNodeStatus(topic, topics[topic].count, maxCount);\n        return false;\n    }\n}\n\nfunction updateNodeStatus(topic, currentCount, maxCount) {\n    node.status({ fill: \"yellow\", shape: \"ring\", text: `${topic}: ${currentCount}/${maxCount} messages queued` });\n}\n\n// 从消息或者固定设置读取参数\nlet maxMessagesPerMinute = 10; // 默认每分钟最多3条消息\nlet intervalMinutes = 1;      // 时间间隔为1分钟\n\n// 检查当前消息的 topic 是否允许发送\nif (checkRateLimit(msg.topic, maxMessagesPerMinute, intervalMinutes)) {\n    return msg;  // 允许发送\n} else {\n    return null; // 超出频率,抑制消息\n}\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":1680,"wires":[["353daaa505dc835f"]]},{"id":"353daaa505dc835f","type":"function","z":"89a720a4aa2449a9","g":"7bab22602a2cdc6d","name":"节流函数-小时","func":"function checkRateLimit(topic, maxCount, interval) {\n    // 使用一个对象来存储每个 topic 的状态\n    let topics = context.get('topics') || {};\n    if (!topics[topic]) {\n        topics[topic] = { lastSent: 0, count: 0 };\n    }\n\n    let now = Date.now();\n    let timeSinceLast = (now - topics[topic].lastSent) / 1000; // 转换为小时\n\n    if (timeSinceLast >= interval) {\n        topics[topic].count = 0;\n        topics[topic].lastSent = now;\n    }\n\n    if (topics[topic].count < maxCount) {\n        topics[topic].count += 1;\n        context.set('topics', topics);\n        updateNodeStatus(topic, topics[topic].count, maxCount);\n        return true;\n    } else {\n        updateNodeStatus(topic, topics[topic].count, maxCount);\n        return false;\n    }\n}\n\nfunction updateNodeStatus(topic, currentCount, maxCount) {\n    node.status({ fill: \"yellow\", shape: \"ring\", text: `${topic}: ${currentCount}/${maxCount} messages queued` });\n}\n\n// 从消息或者固定设置读取参数\nlet maxMessagesPerMinute = 200; // 默认每小时最多100条消息\nlet intervalMinutes = 1;      // 时间间隔为1小时\n\n// 检查当前消息的 topic 是否允许发送\nif (checkRateLimit(msg.topic, maxMessagesPerMinute, intervalMinutes)) {\n    return msg;  // 允许发送\n} else {\n    return null; // 超出频率,抑制消息\n}\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":1680,"wires":[["5ca842575134aa4e"]]},{"id":"5ca842575134aa4e","type":"function","z":"89a720a4aa2449a9","g":"7bab22602a2cdc6d","name":"节流函数-小时","func":"function checkRateLimit(topic, maxCount, interval) {\n    // 使用一个对象来存储每个 topic 的状态\n    let topics = context.get('topics') || {};\n    if (!topics[topic]) {\n        topics[topic] = { lastSent: 0, count: 0 };\n    }\n\n    let now = Date.now();\n    let timeSinceLast = (now - topics[topic].lastSent) / 1000; // 转换为小时\n\n    if (timeSinceLast >= interval) {\n        topics[topic].count = 0;\n        topics[topic].lastSent = now;\n    }\n\n    if (topics[topic].count < maxCount) {\n        topics[topic].count += 1;\n        context.set('topics', topics);\n        updateNodeStatus(topic, topics[topic].count, maxCount);\n        return true;\n    } else {\n        updateNodeStatus(topic, topics[topic].count, maxCount);\n        return false;\n    }\n}\n\nfunction updateNodeStatus(topic, currentCount, maxCount) {\n    node.status({ fill: \"yellow\", shape: \"ring\", text: `${topic}: ${currentCount}/${maxCount} messages queued` });\n}\n\n// 从消息或者固定设置读取参数\nlet maxMessagesPerMinute = 500; // 默认每小时最多100条消息\nlet intervalMinutes = 8;      // 时间间隔为1小时\n\n// 检查当前消息的 topic 是否允许发送\nif (checkRateLimit(msg.topic, maxMessagesPerMinute, intervalMinutes)) {\n    return msg;  // 允许发送\n} else {\n    return null; // 超出频率,抑制消息\n}\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":700,"y":1680,"wires":[["11354c6c41e73507"]]},{"id":"167be135c8a56577","type":"delay","z":"89a720a4aa2449a9","g":"7bab22602a2cdc6d","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":250,"y":1780,"wires":[["ea73b9282528cd9e"]]},{"id":"974382a7f9667f69","type":"group","z":"89a720a4aa2449a9","g":"cb67b715a1216381","name":"收到微信消息","style":{"label":true},"nodes":["3f531b6365891e75","f7c1edb863433cbf","4a8650fd9453477d","3befd4a9fa1ea2dc","870f181822bb5f60","9b916d9493cdb5d5","16a7fb58e53d1eb8","c29819508cecdcf7","030ff9cce90ed847","63676de6baab75b9","4556dbd37b17b905","1678eaad4b356494","22b3e3b953b6af7f","7bf325331c4649fd","0728e50d529dc2c5"],"x":34,"y":1339,"w":1272,"h":262},{"id":"3f531b6365891e75","type":"debug","z":"89a720a4aa2449a9","g":"974382a7f9667f69","name":"个人消息","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload.data.talkerInfo.nickName","statusType":"msg","x":720,"y":1560,"wires":[]},{"id":"f7c1edb863433cbf","type":"websocket in","z":"89a720a4aa2449a9","g":"974382a7f9667f69","name":"","server":"05ef07fc37b7e6d6","client":"","x":140,"y":1500,"wires":[["1678eaad4b356494"]]},{"id":"4a8650fd9453477d","type":"change","z":"89a720a4aa2449a9","g":"974382a7f9667f69","name":"","rules":[{"t":"set","p":"weixin","pt":"msg","to":"payload.data","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":1440,"wires":[["870f181822bb5f60"]]},{"id":"3befd4a9fa1ea2dc","type":"json","z":"89a720a4aa2449a9","g":"974382a7f9667f69","name":"","property":"payload","action":"obj","pretty":false,"x":430,"y":1500,"wires":[["22b3e3b953b6af7f","4a8650fd9453477d"]]},{"id":"870f181822bb5f60","type":"switch","z":"89a720a4aa2449a9","g":"974382a7f9667f69","name":"","property":"weixin.isChatroomMsg","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"false","repair":false,"outputs":2,"x":590,"y":1440,"wires":[["c29819508cecdcf7","7bf325331c4649fd"],["3f531b6365891e75","63676de6baab75b9"]]},{"id":"9b916d9493cdb5d5","type":"debug","z":"89a720a4aa2449a9","g":"974382a7f9667f69","name":"群消息","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload.data.talkerInfo.nickName","statusType":"msg","x":910,"y":1400,"wires":[]},{"id":"16a7fb58e53d1eb8","type":"function","z":"89a720a4aa2449a9","g":"974382a7f9667f69","name":"分离群消息","func":"msg.weixin.is_room = true\nmsg.weixin.room_name = msg.weixin.from\n// 使用 split 方法,只分割一次\nlet [from_user, ...contentParts] = msg.weixin.content.split(':');\nlet content = contentParts.join(':');\n\nmsg.weixin.from_user = from_user;\nmsg.weixin.content = content;\n\nmsg.weixin.content = msg.weixin.content.replace(`@笔记卡片`, '')\nmsg.weixin.content = msg.weixin.content.trim()\n\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":930,"y":1460,"wires":[["030ff9cce90ed847"]]},{"id":"c29819508cecdcf7","type":"switch","z":"89a720a4aa2449a9","g":"974382a7f9667f69","name":"艾特了","property":"msg.weixin.content","propertyType":"msg","rules":[{"t":"cont","v":"@笔记卡片","vt":"str"},{"t":"cont","v":"<patsuffix><![CDATA[的头说:“咋秃了”]]></patsuffix>","vt":"str"},{"t":"cont","v":"<location","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":730,"y":1440,"wires":[["16a7fb58e53d1eb8","9b916d9493cdb5d5"],["16a7fb58e53d1eb8","9b916d9493cdb5d5"],["16a7fb58e53d1eb8"]]},{"id":"030ff9cce90ed847","type":"function","z":"89a720a4aa2449a9","g":"974382a7f9667f69","name":"发送收到的消息","func":"msg.topic = msg.weixin.from\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":980,"y":1560,"wires":[["4556dbd37b17b905","b1cdbf0c489b657c"]]},{"id":"63676de6baab75b9","type":"function","z":"89a720a4aa2449a9","g":"974382a7f9667f69","name":"function 53","func":"msg.weixin.from_user = msg.weixin.from\nmsg.weixin.is_room = false\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":750,"y":1500,"wires":[["030ff9cce90ed847"]]},{"id":"4556dbd37b17b905","type":"debug","z":"89a720a4aa2449a9","g":"974382a7f9667f69","name":"接收到的消息","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload.data.content","statusType":"msg","x":1180,"y":1500,"wires":[]},{"id":"1678eaad4b356494","type":"switch","z":"89a720a4aa2449a9","g":"974382a7f9667f69","name":"","property":"payload","propertyType":"msg","rules":[{"t":"neq","v":"hello","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":310,"y":1500,"wires":[["3befd4a9fa1ea2dc"]]},{"id":"22b3e3b953b6af7f","type":"debug","z":"89a720a4aa2449a9","g":"974382a7f9667f69","name":"消息类型type","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload.data.type","statusType":"msg","x":530,"y":1560,"wires":[]},{"id":"7bf325331c4649fd","type":"debug","z":"89a720a4aa2449a9","g":"974382a7f9667f69","name":"debug 135","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":740,"y":1380,"wires":[]},{"id":"0728e50d529dc2c5","type":"comment","z":"89a720a4aa2449a9","g":"974382a7f9667f69","name":"websocket建立好链接以后,就会用下面的处理消息了","info":"","x":280,"y":1380,"wires":[]},{"id":"05ef07fc37b7e6d6","type":"websocket-listener","path":"/ws/weixin","wholemsg":"false"},{"id":"0f142868c3a6e3cb","type":"group","z":"89a720a4aa2449a9","g":"cb67b715a1216381","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["bde549d49343287e","af757bfc3946415d","dec77127faf53b73","1c9d6bf40dde88f9","0d1b2b94c0ecbf2b"],"x":54,"y":1159,"w":592,"h":162},{"id":"bde549d49343287e","type":"inject","z":"89a720a4aa2449a9","g":"0f142868c3a6e3cb","name":"处理消息API ws","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":180,"y":1280,"wires":[["dec77127faf53b73"]]},{"id":"af757bfc3946415d","type":"http request","z":"89a720a4aa2449a9","g":"0f142868c3a6e3cb","name":"WeChatApi","method":"POST","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":530,"y":1280,"wires":[[]]},{"id":"dec77127faf53b73","type":"function","z":"89a720a4aa2449a9","g":"0f142868c3a6e3cb","name":"设置url","func":"msg.url = global.get(\"wechat-url\")\nmsg.payload = {\n    \"type\": 1001,\n    \"protocol\": 3,\n    \"url\": \"http://www.nodered.com/ws/weixin\"\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":360,"y":1280,"wires":[["af757bfc3946415d"]]},{"id":"1c9d6bf40dde88f9","type":"comment","z":"89a720a4aa2449a9","g":"0f142868c3a6e3cb","name":"启动以后,需要运行这个建立websocket链接","info":"","x":250,"y":1200,"wires":[]},{"id":"0d1b2b94c0ecbf2b","type":"comment","z":"89a720a4aa2449a9","g":"0f142868c3a6e3cb","name":"需要修改这个url为node red的面板url","info":"","x":480,"y":1240,"wires":[]},{"id":"475ed58d8e0c1850","type":"comment","z":"89a720a4aa2449a9","g":"cb67b715a1216381","name":"这个例子是收到什么回复什么","info":"","x":880,"y":1220,"wires":[]}]

更多例子

Image

[{"id":"aa10845e2a7078f2","type":"group","z":"89a720a4aa2449a9","g":"12c0fe7bd67c602a","name":"发微信模块","style":{"stroke":"#addb7b","label":true,"color":"#999999"},"nodes":["c72cc9c1d3efebcf","c4590dcd6c564e8f","f002b62b9af37b3e","86e5a2af61a388af","563771160849d349"],"x":674,"y":299,"w":652,"h":142},{"id":"c72cc9c1d3efebcf","type":"http request","z":"89a720a4aa2449a9","g":"aa10845e2a7078f2","name":"WeChatApi","method":"POST","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":1050,"y":340,"wires":[["c4590dcd6c564e8f"]]},{"id":"c4590dcd6c564e8f","type":"debug","z":"89a720a4aa2449a9","g":"aa10845e2a7078f2","name":"API执行结果","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload.data.status","statusType":"msg","x":1210,"y":340,"wires":[]},{"id":"f002b62b9af37b3e","type":"debug","z":"89a720a4aa2449a9","g":"aa10845e2a7078f2","name":"发送的原始内容","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":400,"wires":[]},{"id":"86e5a2af61a388af","type":"link in","z":"89a720a4aa2449a9","g":"aa10845e2a7078f2","name":"发微信","links":["45480d657e514272","cfabe46039bddb60","f68bd80dd2b48b5a","a0f80ce51cdccd2c","907443bf1f44dead","bd0234476377fd00"],"x":750,"y":340,"wires":[["f002b62b9af37b3e","563771160849d349"]],"icon":"node-red/comment.svg","l":true},{"id":"563771160849d349","type":"function","z":"89a720a4aa2449a9","g":"aa10845e2a7078f2","name":"设置url","func":"msg.url = global.get(\"wechat-url\")\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":880,"y":340,"wires":[["c72cc9c1d3efebcf"]]},{"id":"7260af680da1b795","type":"group","z":"89a720a4aa2449a9","g":"12c0fe7bd67c602a","name":"发送个人消息","style":{"label":true},"nodes":["a9830932077649e6","b945d407d9f494d5","cfabe46039bddb60"],"x":94,"y":319,"w":552,"h":82},{"id":"a9830932077649e6","type":"inject","z":"89a720a4aa2449a9","g":"7260af680da1b795","name":"触发","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":190,"y":360,"wires":[["b945d407d9f494d5"]]},{"id":"b945d407d9f494d5","type":"function","z":"89a720a4aa2449a9","g":"7260af680da1b795","name":"发送个人消息","func":"let userName = global.get('my-wechat-id')\nif (!userName) {\n    node.error(\"请设置你的wxid\")\n}\n\n\n\nmsg.payload = {\n    \"type\": 10009,\n    \"userName\": userName,\n    \"msgContent\": \"测试内容\",\n    \"insertToDatabase\": false\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":360,"wires":[["cfabe46039bddb60"]]},{"id":"cfabe46039bddb60","type":"link out","z":"89a720a4aa2449a9","g":"7260af680da1b795","name":"发微信","mode":"link","links":["86e5a2af61a388af"],"x":570,"y":360,"wires":[],"icon":"node-red/comment.svg","l":true},{"id":"924e2c14c154d156","type":"group","z":"89a720a4aa2449a9","g":"12c0fe7bd67c602a","name":"发送个人消息-发送图片","style":{"label":true},"nodes":["2d3922f77ba451d9","764fb5ce8214e480","f68bd80dd2b48b5a"],"x":674,"y":459,"w":552,"h":82},{"id":"2d3922f77ba451d9","type":"inject","z":"89a720a4aa2449a9","g":"924e2c14c154d156","name":"触发","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":770,"y":500,"wires":[["764fb5ce8214e480"]]},{"id":"764fb5ce8214e480","type":"function","z":"89a720a4aa2449a9","g":"924e2c14c154d156","name":"发送个人消息","func":"let userName = global.get('my-wechat-id')\nif (!userName) {\n    node.error(\"请设置你的wxid\")\n}\n\n\n\nmsg.payload =  {\n  \"type\": 10010,\n  \"userName\": userName,\n  \"filePath\": \"C:\\\\weixin\\\\位置查询.jpg\"\n } \nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":960,"y":500,"wires":[["f68bd80dd2b48b5a"]]},{"id":"f68bd80dd2b48b5a","type":"link out","z":"89a720a4aa2449a9","g":"924e2c14c154d156","name":"发微信","mode":"link","links":["86e5a2af61a388af"],"x":1150,"y":500,"wires":[],"icon":"node-red/comment.svg","l":true},{"id":"540104d4c61fb5bd","type":"group","z":"89a720a4aa2449a9","g":"12c0fe7bd67c602a","name":"进行拍一拍","style":{"label":true},"nodes":["1d989bbc3ae7eb7f","936ac67086253d7a","a0f80ce51cdccd2c"],"x":94,"y":459,"w":552,"h":82},{"id":"1d989bbc3ae7eb7f","type":"inject","z":"89a720a4aa2449a9","g":"540104d4c61fb5bd","name":"触发","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":190,"y":500,"wires":[["936ac67086253d7a"]]},{"id":"936ac67086253d7a","type":"function","z":"89a720a4aa2449a9","g":"540104d4c61fb5bd","name":"拍一拍","func":"let userName = global.get('my-wechat-id')\nif (!userName) {\n    node.error(\"请设置你的wxid\")\n}\n\n\n\nmsg.payload = {\n    \"type\": 57,\n    \"userName\": userName\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":500,"wires":[["a0f80ce51cdccd2c"]]},{"id":"a0f80ce51cdccd2c","type":"link out","z":"89a720a4aa2449a9","g":"540104d4c61fb5bd","name":"发微信","mode":"link","links":["86e5a2af61a388af"],"x":570,"y":500,"wires":[],"icon":"node-red/comment.svg","l":true},{"id":"600561e4a4dd6be2","type":"group","z":"89a720a4aa2449a9","g":"12c0fe7bd67c602a","name":"拨打微信电话","style":{"label":true},"nodes":["d6dc93ad8a566043","c081cf9a20ca3ba5","907443bf1f44dead"],"x":94,"y":599,"w":552,"h":82},{"id":"d6dc93ad8a566043","type":"inject","z":"89a720a4aa2449a9","g":"600561e4a4dd6be2","name":"触发","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":190,"y":640,"wires":[["c081cf9a20ca3ba5"]]},{"id":"c081cf9a20ca3ba5","type":"function","z":"89a720a4aa2449a9","g":"600561e4a4dd6be2","name":"拨打微信电话","func":"let userName = global.get('my-wechat-id')\nif (!userName) {\n    node.error(\"请设置你的wxid\")\n}\n\n\n\nmsg.payload = {\n    \"type\": 10103,\n    \"userName\": userName,\n    \"inviteType\": 1\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":640,"wires":[["907443bf1f44dead"]]},{"id":"907443bf1f44dead","type":"link out","z":"89a720a4aa2449a9","g":"600561e4a4dd6be2","name":"发微信","mode":"link","links":["86e5a2af61a388af"],"x":570,"y":640,"wires":[],"icon":"node-red/comment.svg","l":true},{"id":"16fc908941a0bded","type":"group","z":"89a720a4aa2449a9","g":"12c0fe7bd67c602a","name":"挂断微信电话","style":{"label":true},"nodes":["0926b761f8d7a05f","e09deba8cebd78eb","bd0234476377fd00"],"x":94,"y":719,"w":552,"h":82},{"id":"0926b761f8d7a05f","type":"inject","z":"89a720a4aa2449a9","g":"16fc908941a0bded","name":"触发","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":190,"y":760,"wires":[["e09deba8cebd78eb"]]},{"id":"e09deba8cebd78eb","type":"function","z":"89a720a4aa2449a9","g":"16fc908941a0bded","name":"挂断微信电话","func":"msg.payload = {\n    \"type\": 10104\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":760,"wires":[["bd0234476377fd00"]]},{"id":"bd0234476377fd00","type":"link out","z":"89a720a4aa2449a9","g":"16fc908941a0bded","name":"发微信","mode":"link","links":["86e5a2af61a388af"],"x":570,"y":760,"wires":[],"icon":"node-red/comment.svg","l":true}]
本教程会持续更新,如果有疑问,可以直接在下面留言