- 积分
- 653
- 金钱
- 539
- 威望
- 0
- 贡献
- 0
- HASS币
- 0
高级会员
- 积分
- 653
- 金钱
- 539
- HASS币
- 0
|
楼主 |
发表于 2024-5-7 15:55:58
|
显示全部楼层
加一个节点,定义一个openid的变量,在原来cookies的位置引用
[{"id":"34c7f95ab091b563","type":"function","z":"46a4dfa57d6a5b6e","name":"提取openid","func":"var payload = msg.payload;\nvar cookieString = payload.Cookies;\n\nvar regex = /[^;\\s]+=[^;]+/g;\nvar matches = cookieString ? cookieString.match(regex) : null;\n\nvar openid, openid1, openid2;\n\n// 如果找到了匹配项\nif (matches && matches.length >= 2) {\n openid1 = matches[3].trim(); // 第一个匹配项,去除首尾空格\n openid2 = matches[2].trim(); // 第二个匹配项,去除首尾空格\n\n // 如果 openid1 包含 \"openid=\",则不需要进行互换操作\n if (!openid1.includes('openid=')) {\n // 交换 openid1 和 openid2 的值\n var temp = openid1;\n openid1 = openid2;\n openid2 = temp;\n }\n} else {\n // 处理没有匹配项或匹配项少于两个的情况,这里可以添加适当的处理逻辑或者直接留空\n}\n\nopenid = openid1 + \";\" + openid2;\nflow.set(\"openid\", openid);\nreturn msg;\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":220,"wires":[["808cfbcebbdfceaa"]]}] |
|