『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 10273|回复: 7

[流程系列] 请教,在node-red中的http请求节点如何输入数据

[复制链接]

33

主题

312

帖子

1851

积分

金牌会员

Rank: 6Rank: 6

积分
1851
金钱
1534
HASS币
40
发表于 2019-5-10 09:48:10 | 显示全部楼层 |阅读模式
本帖最后由 lione95678 于 2019-5-10 09:54 编辑

想请教一下如何在node-red中的http请求节点中输入数据
起因,向通过node-red发送http post的请求,用来通过企业微信发送数据。
https://www.52pojie.cn/thread-804477-1-1.html
按照上面的教程,可以在安卓手机上的tasker发送企业微信,看了一下流程,他是先向企业微信发送一个http post,取得企业微信的access_token,
https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=你企业微信的corpid&corpsecret=你企业微信的corpsecret
第二部,在http post 方式,用取得的corpsecret发送消息,在tasker中,是服务器端口填写https://qyapi.weixin.qq.com/,路径填写cgi-bin/message/send?access_token=你取得的access_token,数据文件中填写{"safe": 0,"text": {"content":"短信号码:%SMSRF\n短信日期:%SMSRD %SMSRT\n\n%SMSRB"}, "msgtype": "text", "touser": "@all", "agentid": 你企业的agentid}
我通过node-red的http请求节点,可以取得企业微信的corpsecret,但是我不知道如何把这个corpsecret和需要发送的内容通过http请求的方式发出去,特来请教,下面附上我的node-red流程,也请指教

流程照片

流程照片

函数组件中输入corpid和corpsecret

函数组件中输入corpid和corpsecret

通过switch来截取access_token

通过switch来截取access_token

可以看到获得的access_token

可以看到获得的access_token

也就是在第一个函数节点中输入企业微信的corpid和企业微信的corpsecret,http请求节点选择post,发送网址https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={{{corpid}}}&corpsecret={{{corpsecret}}}来取得access_token,然后split节点把收到的信息拆分显示,在通过switch节点中输入a,这样就能把由包含a字符的access_token单独显示出来。

[{"id":"f27bf446.5712a8","type":"inject","z":"26679f00.0218b2","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":2820,"wires":[["99b41848.dfed18"]]},{"id":"99b41848.dfed18","type":"function","z":"26679f00.0218b2","name":"基础数据","func":"//corpid\nmsg.corpid = '你企业微信的corpid'\n//corpsecret\nmsg.corpsecret = '你企业微信的corpsecret'\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":2820,"wires":[["18a5bee7.bc2891"]]},{"id":"18a5bee7.bc2891","type":"http request","z":"26679f00.0218b2","name":"取得企业微信access_token","method":"POST","ret":"obj","paytoqs":false,"url":"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={{{corpid}}}&corpsecret={{{corpsecret}}}","tls":"","proxy":"","x":500,"y":2740,"wires":[["9eac39c1.613968"]]},{"id":"9eac39c1.613968","type":"split","z":"26679f00.0218b2","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":true,"addname":"topic","x":630,"y":2820,"wires":[["4ff3626a.15c5fc"]]},{"id":"4ff3626a.15c5fc","type":"switch","z":"26679f00.0218b2","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"a","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":810,"y":2820,"wires":[["aac02e57.f8d0b"]]},{"id":"aac02e57.f8d0b","type":"debug","z":"26679f00.0218b2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":990,"y":2820,"wires":[]}]


回复

使用道具 举报

2

主题

54

帖子

496

积分

论坛技术达人

积分
496
金钱
437
HASS币
20
发表于 2019-5-10 12:17:47 | 显示全部楼层
沙发啊,没看懂
回复

使用道具 举报

4

主题

228

帖子

4406

积分

元老级技术达人

积分
4406
金钱
4163
HASS币
40
发表于 2019-5-10 14:53:35 | 显示全部楼层
本帖最后由 81795791 于 2019-5-10 15:03 编辑

我去试试。。。话说  还是不懂楼主要干啥。。。。是要想办法输入你想推送的东西???
回复

使用道具 举报

10

主题

276

帖子

1190

积分

金牌会员

Rank: 6Rank: 6

积分
1190
金钱
914
HASS币
10
发表于 2019-5-10 16:49:13 | 显示全部楼层
本帖最后由 lmy8812 于 2019-5-10 16:54 编辑

你是要用NR给企业微信发信息?昨晚刚好开通企业微信,这会就有代码。在Access_Token里把ID和密码分别替换就好了
[{"id":"9146597d.de1c18","type":"inject","z":"c9f0c79.14de638","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1320,"wires":[["fbf815b6.3268e8"]]},{"id":"fbf815b6.3268e8","type":"http request","z":"c9f0c79.14de638","name":"Access_Token","method":"GET","ret":"obj","url":"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=企业的ID&corpsecret=应用的密码","tls":"","x":360,"y":1320,"wires":[["24e0fa28.890366"]]},{"id":"6a8c9000.fb46c","type":"function","z":"c9f0c79.14de638","name":"msg","func":"msg.token = msg.payload.access_token;\nmsg.payload = {\n    "agentid" : 1000002,\n    "safe" : 0,\n    "touser" : "xxxx",\n    "msgtype" : "textcard",\n    "textcard" : {\n        "url" : msg.picUrl,\n        "description" : "Who's knocking on heaven's door?",\n        "title" : "有人来了"\n    }\n/*\n    "msgtype" : "text",\n    "text" : {\n        "content" : "我就试一下下"\n    },\n*/\n}\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":1360,"wires":[["5dba839a.3ee28c"]]},{"id":"5dba839a.3ee28c","type":"http request","z":"c9f0c79.14de638","name":"Send msg","method":"POST","ret":"obj","url":"https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={{{token}}}","tls":"","x":480,"y":1360,"wires":[["4dda6069.b2708"]]},{"id":"24e0fa28.890366","type":"switch","z":"c9f0c79.14de638","name":"If Worked","property":"payload.errcode","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":520,"y":1320,"wires":[["6a8c9000.fb46c"]]},{"id":"4dda6069.b2708","type":"debug","z":"c9f0c79.14de638","name":"企业微信","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":640,"y":1360,"wires":[]}]



回复

使用道具 举报

22

主题

519

帖子

1608

积分

金牌会员

Rank: 6Rank: 6

积分
1608
金钱
1089
HASS币
10
发表于 2019-5-11 08:59:31 | 显示全部楼层
lmy8812 发表于 2019-5-10 16:49
你是要用NR给企业微信发信息?昨晚刚好开通企业微信,这会就有代码。在Access_Token里把ID和密码分别替换就 ...

高人啊  这么快
回复

使用道具 举报

33

主题

312

帖子

1851

积分

金牌会员

Rank: 6Rank: 6

积分
1851
金钱
1534
HASS币
40
 楼主| 发表于 2019-5-11 14:11:35 | 显示全部楼层
lmy8812 发表于 2019-5-10 16:49
你是要用NR给企业微信发信息?昨晚刚好开通企业微信,这会就有代码。在Access_Token里把ID和密码分别替换就 ...

十分感谢,总算搞懂了
回复

使用道具 举报

0

主题

169

帖子

625

积分

高级会员

Rank: 4

积分
625
金钱
456
HASS币
0
发表于 2020-6-21 23:03:26 | 显示全部楼层
感谢分享,学习中
回复

使用道具 举报

0

主题

2

帖子

16

积分

新手上路

Rank: 1

积分
16
金钱
14
HASS币
0
发表于 2023-3-15 11:22:57 | 显示全部楼层
token 怎么用,放在哪个节点
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-25 12:15 , Processed in 0.132312 second(s), 32 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表