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

 找回密码
 立即注册
查看: 7095|回复: 5

[教程系列] 利用一般节点实现对百度等API应用

[复制链接]

43

主题

412

帖子

3806

积分

元老级技术达人

积分
3806
金钱
3389
HASS币
136
发表于 2021-1-20 13:00:31 | 显示全部楼层 |阅读模式
本帖最后由 hunterfox 于 2021-1-20 16:07 编辑

我们现在人脸识别和人体识别,人体数量识别,等都是大佬们辛苦写好节点,我们直接 提供必要参数,就可以应用了。
但是一直不知道怎么运作的,为什么一点,结果就出来了。 所以我自己拆分折腾了一下。
实际很多应用节点,都是一个一个小应用慢慢传递得出的。


下面是折腾的结果,如果这个弄明白了。
百度的很多其他应用都可以直接使用了。而不是等现成的节点了


通过API应用,结合百度提供的技术文档,就可以知道运行机制,以后自己需要什么,就改改就能实现自己的目地。
逻辑方法同样适合萤石云api请求。替换必要参数就可以,可以实现对萤石的管理。
1.png 2.png 3.png
下面是流文件,要替换部分自己的信息
里面很多流程只是为了获取一张图信息,关键节点就几个。
[{"id":"476c46d5.7cf908","type":"function","z":"fc6822e6.d8853","name":"百度应用替换刚获取到的TOKEN","func":"var newMsg = {\n    "headers": {\n        "Content-Type" : "application/x-www-form-urlencoded"\n    },\n    "payload": {\n        "access_token" : "替换刚获取到的TOKEN",\n          "image": msg.payload    \n        \n    }\n}\nreturn newMsg","outputs":1,"noerr":0,"x":810,"y":1640,"wires":[["40cab7d5.8ed138"]]},{"id":"40cab7d5.8ed138","type":"http request","z":"fc6822e6.d8853","name":"替换想要的API","method":"POST","ret":"obj","paytoqs":true,"url":"https://aip.baidubce.com/rest/2.0/image-classify/v1/body_analysis","tls":"","proxy":"","authType":"","x":880,"y":1720,"wires":[["a1e154de.304c18"]]},{"id":"b5c4331f.cf59d","type":"base64","z":"fc6822e6.d8853","name":"获取图片","action":"","property":"payload","x":580,"y":1640,"wires":[["476c46d5.7cf908"]]},{"id":"a1e154de.304c18","type":"debug","z":"fc6822e6.d8853","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":810,"y":1780,"wires":[]},{"id":"6857a0f9.7d426","type":"http request","z":"fc6822e6.d8853","name":"得到小姐姐图片地址","method":"GET","ret":"bin","paytoqs":false,"url":"","tls":"","proxy":"","authType":"","x":380,"y":1640,"wires":[["e5674659.be4628","b5c4331f.cf59d"]]},{"id":"e5674659.be4628","type":"image","z":"fc6822e6.d8853","name":"","width":"150","data":"payload","dataType":"msg","thumbnail":false,"active":true,"pass":false,"outputs":0,"x":220,"y":1720,"wires":[]},{"id":"3fab5365.f83b6c","type":"function","z":"fc6822e6.d8853","name":"设置请求头","func":"msg.headers = {};\nmsg.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36';\nreturn msg;","outputs":1,"noerr":0,"x":170,"y":1640,"wires":[["6857a0f9.7d426"]]},{"id":"823022b2.7685a","type":"change","z":"fc6822e6.d8853","name":"数据转换","rules":[{"t":"move","p":"payload.results.0.url","pt":"msg","to":"url","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":1560,"wires":[["3fab5365.f83b6c"]]},{"id":"f0170c9b.28303","type":"http request","z":"fc6822e6.d8853","name":"小姐姐API","method":"GET","ret":"obj","paytoqs":false,"url":"","tls":"","proxy":"","authType":"","x":650,"y":1560,"wires":[["823022b2.7685a"]]},{"id":"37ccce8c.9fe642","type":"function","z":"fc6822e6.d8853","name":"设置请求头","func":"msg.url = `http://gank.io/api/data/%E7%A6%8F%E5%88%A9/1/${msg.payload}`;\n\nmsg.headers = {};\nmsg.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36';\n\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":1560,"wires":[["f0170c9b.28303"]]},{"id":"dcadfe37.10118","type":"random","z":"fc6822e6.d8853","name":"","low":"1","high":"79","inte":"true","property":"payload","x":300,"y":1560,"wires":[["37ccce8c.9fe642"]]},{"id":"e757f218.86165","type":"inject","z":"fc6822e6.d8853","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1560,"wires":[["dcadfe37.10118"]]},{"id":"d6a63dda.e1b22","type":"function","z":"fc6822e6.d8853","name":"获取百度Token(替换一下client_id  client_secret)","func":"var newMsg = {\n    "headers": {\n        "Content-Type" : "application/x-www-form-urlencoded"\n        \n    },\n    "payload": {\n        "grant_type" : "client_credentials",\n        "client_id" : "换成你的client_id",\n        "client_secret" : "换成你的client_secret"\n    \n        \n    }\n}\nreturn newMsg","outputs":1,"noerr":0,"x":470,"y":1880,"wires":[["eeccaa50.142ca8"]]},{"id":"106b8844.245308","type":"inject","z":"fc6822e6.d8853","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":1880,"wires":[["d6a63dda.e1b22"]]},{"id":"eeccaa50.142ca8","type":"http request","z":"fc6822e6.d8853","name":"获取TokenAPI","method":"POST","ret":"obj","paytoqs":true,"url":"https://aip.baidubce.com/oauth/2.0/token","tls":"","proxy":"","authType":"","x":780,"y":1880,"wires":[["70a6b51c.932a0c"]]},{"id":"70a6b51c.932a0c","type":"debug","z":"fc6822e6.d8853","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":950,"y":1860,"wires":[]},{"id":"c6d41f81.f9f46","type":"comment","z":"fc6822e6.d8853","name":"获取access_token","info":"","x":210,"y":1820,"wires":[]},{"id":"88290870.857ba8","type":"comment","z":"fc6822e6.d8853","name":"上图图片进行api处理","info":"","x":180,"y":1500,"wires":[]}]
flows.json (4.6 KB, 下载次数: 21)

流文件已更新


评分

参与人数 1金钱 +20 HASS币 +10 收起 理由
+ 20 + 10 厉害了word楼主!

查看全部评分

回复

使用道具 举报

73

主题

1165

帖子

6641

积分

论坛元老

Rank: 8Rank: 8

积分
6641
金钱
5471
HASS币
30
发表于 2021-1-20 13:43:43 | 显示全部楼层
请问一下,复制了你的流文件,无法导入,报错。
回复

使用道具 举报

40

主题

3056

帖子

1万

积分

超级版主

Nero

Rank: 8Rank: 8

积分
11149
金钱
8042
HASS币
182
发表于 2021-1-20 14:13:13 | 显示全部楼层
感谢楼主分享,最好还是将 json 打包发出来,论坛的code 标签有时候还是会改掉字符~
Nero
回复

使用道具 举报

43

主题

412

帖子

3806

积分

元老级技术达人

积分
3806
金钱
3389
HASS币
136
 楼主| 发表于 2021-1-20 16:08:34 | 显示全部楼层
neroxps 发表于 2021-1-20 14:13
感谢楼主分享,最好还是将 json 打包发出来,论坛的code 标签有时候还是会改掉字符~ ...

确实,文件异常,我重新上传了流文件,代码有异常
回复

使用道具 举报

43

主题

412

帖子

3806

积分

元老级技术达人

积分
3806
金钱
3389
HASS币
136
 楼主| 发表于 2021-1-20 16:09:38 | 显示全部楼层
xuyang 发表于 2021-1-20 13:43
请问一下,复制了你的流文件,无法导入,报错。

确实,文件异常,我重新上传了流文件,代码有异常
回复

使用道具 举报

1

主题

94

帖子

1031

积分

金牌会员

Rank: 6Rank: 6

积分
1031
金钱
937
HASS币
0
发表于 2021-1-26 20:54:08 | 显示全部楼层
感谢分享
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-21 23:14 , Processed in 0.479032 second(s), 32 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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