- 积分
- 687
- 金钱
- 571
- 威望
- 0
- 贡献
- 0
- HASS币
- 0
高级会员
- 积分
- 687
- 金钱
- 571
- HASS币
- 0
|
本帖最后由 snowing 于 2024-4-23 10:18 编辑
参考大神33201和leenkon原贴【node-red】比亚迪汽车通过官方微信API接入HAhttps://bbs.hassbian.com/thread-18154-1-1.html
因Cookies有效期很短,在网上找到了抓包工具,可以通过WebHook推送,nodered已经可以接收到Cookies了。本人编程小白,想通过自动替换Cookies,搜索和用GPT都不行,只能求助大神,感谢
下面是我建的webhook节点,复制的代码导入有问题,缺少\,请不要复制下面的代码。我作为附件上传了。
[{"id":"91d117833116ea62","type":"ha-webhook","z":"89a87322e24a5442","name":"Cookies WebHook","server":"70a6b1f4.22b43","version":3,"exposeAsEntityConfig":"","outputs":1,"webhookId":"1XGRXxqYC6pQWCUAB1twuvp51xbzvFM9","method_get":false,"method_head":false,"method_post":true,"method_put":true,"outputProperties":[{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"},{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"payloadLocation":false,"payloadLocationType":false,"headersLocation":false,"headersLocationType":false,"x":220,"y":180,"wires":[["c9d026c8cd5fdfd6","2eeddbee11099bb8"]]},{"id":"70a6b1f4.22b43","type":"server","name":"Home Assistant","addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","statusSeparator":"","enableGlobalContextStore":false}]
目的是,当Cookies WebHook节点接收到Cookies,格式为HWWAFSESID=1234567890123456789; HWWAFSESTIME=1234567890123; 0ab08166-1234-1234-1234-02ee6710ea63=3807a8bb1a62c923c4da621150f11234; openid=1234579dd08b484ca5993703905706641713832412345的数据时,用openid=1234579dd08b484ca5993703905706641713832412345自动替换下面API参数节点中openid=对应部分,其他部分不做修改。
[{"id":"be4a66ad5a4fd7f8","type":"function","z":"051f5ad5ce40adac","name":"API参数","func":"const userInfo = {\n "cookies": "openid=1234579dd08b484ca5993703905706641713832412345;0ab08166-1234-1234-1234-02ee6710ea63=3807a8bb1a62c923c4da621150f11234"\n}\nif (typeof (msg.payload) === "object" && msg.payload.listInfo[0].vin) {\n global.set("bydUserInfo", Object.assign(userInfo, msg.payload.listInfo[0]));\n}\nmsg.headers = {"cookie":userInfo.cookies}\nif (!global.get("bydUserInfo")) { \n msg.url = `https://bydcloud.byd.com/wechat/getuserinfo?timeStamp=${Math.floor(Date.now())}&random=${global.uuid}`\n return [msg, null];\n} else {\n msg.url = `https://bydcloud.byd.com/wechat/location?caridentifier=${global.get("bydUserInfo").vin}&timeStamp=${Math.floor(Date.now())}&random=${global.uuid}&longitude=0&latitude=0`\n return [null, msg];\n}","outputs":2,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":80,"wires":[["e48fb87f4ea2cfe9"],["3e1d677280357738"]]}]
|
|