0

在将 Shelly2.5 与我的快门连接并接线后,尝试将其与 Siri 连接。决定使用 Scriptable 应用程序执行此操作,然后将 Siri 命令连接到它,这样它就会运行。

目前在从 Scriptable 应用程序发送请求时遇到问题,因为代码如下所示,当我尝试从 Postman 触发它时它可以工作。


// # open shutter

let url = "https://domain.shelly.cloud";
let suffix ="/device/relay/roller/control/";
let auth_key = "AAAABBBBCCCDDDEEEEFFFFFF____EXAMPLE_TOKEN___AAAABBBBCCCDDDEEEEFFFFFF";

let channel = 0;
let turn = "on";

let direction = "open";
let id = "C45bbe75f1bd";


let body = { 
  "auth_key":auth_key, 
  "id": id, 
  "direction":direction
  };
// console.log(body);
let req = new Request(url + suffix); 
// console.log(url+suffix);
req.method = "POST";
req.body = body;

req.headers = { "Content-Type":"application/x-www-form-urlencoded" };


// req.body = JSON.stringify(body)
let json = await req.loadJSON()
console.log(json);

目前的回应:

2021-09-13 11:20:46: {"isok":false,"errors":{"invalid_header":"Unauthorized! Wrong authorization header provided!","invalid_token":"The login information is invalid! Please login again!"}}

请注意,我更改了 shelly 云的真实令牌和真实子域。如果有人知道如何解决这个问题会很高兴,谢谢

4

1 回答 1

0

看起来像 Shelly 期望形式编码的主体。尝试这个

let form  = Object.keys(body).map( k => `${k}=${encodeURIComponent(body[k])}`).join('&')

req.body = form
于 2021-10-22T00:28:30.207 回答