本指南 ( https://pro-bravia.sony.net/develop/integrate/ip-control/ ) 描述了如何通过在 TV 菜单中设置预共享 key 并将此 key 与请求头 ( X-Auth-PSK: [Pre-Shared Key]
) 一起发送来使用 IP 控制 API。
除了我的应用程序之外,其他应用程序会在网络上发现我的电视,然后电视上会弹出一个(一次)引脚,然后由用户在客户端(如远程应用程序)输入。此身份验证流程如何工作?我怎样才能自己实现它?
最佳答案
您可以通过执行以下代码来调用身份验证,首先在浏览器中打开一个选项卡并输入电视的 IP 地址,这样当您通过控制台执行此代码时,您就不会收到 CORS 错误。
var tvIPAddress = '192.168.0.16'; // the IP of the TV
var id = 1001; // random integer number ( that will be assigned to your control device )
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://'+tvIPAddress+'/sony/accessControl');
xhr.send(JSON.stringify(
{method: "actRegister",
version: "1.0",
id: id,
params: [{ clientid: "DEVICE NAME: RANDOM-CLIENT-ID-XXXXXXXXXX" , nickname: "YOUR-DEVICE-NAME" },[{function:"WOL",value:"no"}]]
}
));
然后在弹出窗口中输入来自电视的 PIN 码作为密码。将用户名字段留空。
然后你可以像这样发送 IRCC 命令:
var code = "AAAAAQAAAAEAAAASAw=="; // volume up
xhr.open('POST', 'http://192.168.0.16/sony/IRCC');
xhr.setRequestHeader('SOAPACTION', "urn:schemas-sony-com:service:IRCC:1#X_SendIRCC");
xhr.send('<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:X_SendIRCC xmlns:u="urn:schemas-sony-com:service:IRCC:1"><IRCCCode>'+code+'</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>');
你可以在这里找到更多信息:
https://pro-bravia.sony.net/develop/integrate/ircc-ip/overview/index.html
关于api - 如何在没有预共享 key 的情况下使用 Sony Bravia TV IP Control 进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57745785/