[
{
"id": "bf211734494823b3",
"type": "link out",
"z": "ee8f68611c51951f",
"name": "link out 2",
"mode": "link",
"links": [
"1cb87640132f0b42",
"89c4097ee41fd798"
],
"x": 955,
"y": 140,
"wires": []
},
{
"id": "2e9960d3586b145f",
"type": "function",
"z": "ee8f68611c51951f",
"name": "开锁参数",
"func": "var open_token = msg.payload.access_token\nmsg.payload = { \n "header": { \n "namespace": "Iot.Device", \n "name": "Ctrl", \n "messageId": generateUUID(), \n "payloadVersion": 1, \n "secureToken": open_token \n }, \n "payload": { \n "did": "XXXXXXXX", \n "verify": "true", \n "data": "XXXXXXXXXXXXXXX" \n } \n }\n\nfunction generateUUID() {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {\n var r = Math.random() * 16 | 0,\n v = c === 'x' ? r : (r & 0x3 | 0x8);\n return v.toString(16);\n });\n}\nmsg.custom = true; //必不可少\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 800,
"y": 140,
"wires": [
[
"bf211734494823b3"
]
]
},
{
"id": "8912748fee7415aa",
"type": "http request",
"z": "ee8f68611c51951f",
"name": "获取开锁 Token",
"method": "POST",
"ret": "obj",
"paytoqs": "ignore",
"url": "https://h5.kiwik.cn/restapi/users/XXXXXXX/mfa/tokens",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 620,
"y": 140,
"wires": [
[
"2e9960d3586b145f"
]
]
},
{
"id": "01f15ff965a699c7",
"type": "function",
"z": "ee8f68611c51951f",
"name": "开锁信息",
"func": "msg.headers = { \n "Content-Type": "application/json", \n "X-Kiwik-Client-Id": "XXXXXXXXXX" \n };\nmsg.payload = { \n "auth_type": "secure_password", \n "credential": "XXXXXX" \n };\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 440,
"y": 140,
"wires": [
[
"8912748fee7415aa"
]
]
},
{
"id": "8b649ee0eb541afc",
"type": "inject",
"z": "ee8f68611c51951f",
"name": "开锁",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": "5",
"topic": "",
"payload": "",
"payloadType": "date",
"x": 190,
"y": 100,
"wires": [
[
"01f15ff965a699c7"
]
]
},
{
"id": "879aa44438ba4c48",
"type": "change",
"z": "ee8f68611c51951f",
"name": "设置全局变量",
"rules": [
{
"t": "move",
"p": "payload.access_token",
"pt": "msg",
"to": "token",
"tot": "global"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 760,
"y": 200,
"wires": [
[]
]
},
{
"id": "b5235468c69cfca9",
"type": "function",
"z": "ee8f68611c51951f",
"name": "处理参数",
"func": "\n\nmsg.url = "wss://wsapi.kiwiot.com/"\nmsg.token = msg.payload.access_token;\nmsg.pingMsg = {\n "header": {\n "namespace": "Iot.Application",\n "name": "Ping",\n "messageId": generateUUID(),\n "payloadVersion": 1\n }\n};\nmsg.interval = 30000;\n\nfunction generateUUID() {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {\n var r = Math.random() * 16 | 0,\n v = c === 'x' ? r : (r & 0x3 | 0x8);\n return v.toString(16);\n });\n}\n\n\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 760,
"y": 260,
"wires": [
[
"306695d96b0d062e"
]
]
},
{
"id": "80f5d4d360317b3f",
"type": "switch",
"z": "ee8f68611c51951f",
"name": "是否登录",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "hask",
"v": "access_token",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 600,
"y": 260,
"wires": [
[
"b5235468c69cfca9",
"879aa44438ba4c48"
],
[
"0d49a323af311317"
]
]
},
{
"id": "d8ed0625f1743ae4",
"type": "http request",
"z": "ee8f68611c51951f",
"name": "登录",
"method": "POST",
"ret": "obj",
"paytoqs": "ignore",
"url": "https://h5.kiwik.cn/restapi/auth/tokens",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [
{
"keyType": "other",
"keyValue": "x-kiwik-client-id",
"valueType": "other",
"valueValue": "XXXXXXXXXXXXXXX"
}
],
"x": 470,
"y": 260,
"wires": [
[
"80f5d4d360317b3f"
]
]
},
{
"id": "364baedc8d1c34b8",
"type": "function",
"z": "ee8f68611c51951f",
"name": "登陆信息",
"func": "\nmsg.payload = {\n "identifier": "+XXXXXXXX",\n "credential": "XXXXXXXX",\n "auth_type": "password"\n};\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 320,
"y": 260,
"wires": [
[
"d8ed0625f1743ae4"
]
]
},
{
"id": "7f8fb26508d9b8a5",
"type": "inject",
"z": "ee8f68611c51951f",
"name": "登录",
"props": [
{
"p": "payload"
}
],
"repeat": "18000",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 170,
"y": 260,
"wires": [
[
"364baedc8d1c34b8"
]
]
},
{
"id": "0d49a323af311317",
"type": "debug",
"z": "ee8f68611c51951f",
"name": "登录失败",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 620,
"y": 320,
"wires": []
},
{
"id": "306695d96b0d062e",
"type": "live",
"z": "ee8f68611c51951f",
"name": "",
"url": "",
"token": "",
"ping": "",
"interval": "30000",
"x": 820,
"y": 320,
"wires": [
[]
]
},
{
"id": "89c4097ee41fd798",
"type": "link in",
"z": "ee8f68611c51951f",
"name": "link in 3",
"links": [
"bf211734494823b3"
],
"x": 645,
"y": 360,
"wires": [
[
"306695d96b0d062e"
]
]
}
]