2020-04-29 17:28:33 +00:00
|
|
|
<?php
|
|
|
|
class GoogleHomeApi {
|
2020-05-03 17:29:15 +00:00
|
|
|
static function response(){
|
2020-05-13 08:02:42 +00:00
|
|
|
|
2020-04-30 17:40:34 +00:00
|
|
|
$json = file_get_contents('php://input');
|
|
|
|
$obj = json_decode($json, true);
|
2020-05-02 15:50:18 +00:00
|
|
|
|
|
|
|
$apiLogManager = new LogManager('../logs/api/HA/'. date("Y-m-d").'.log');
|
2020-04-30 17:40:34 +00:00
|
|
|
header('Content-Type: application/json');
|
2020-05-02 11:18:15 +00:00
|
|
|
|
2020-04-30 17:40:34 +00:00
|
|
|
switch ($obj['inputs'][0]['intent']) {
|
|
|
|
case 'action.devices.SYNC':
|
2020-05-13 08:02:42 +00:00
|
|
|
GoogleHome::sync($obj['requestId']);
|
2020-05-02 15:50:18 +00:00
|
|
|
$apiLogManager->write("[Google Home] action.devices.SYNC", LogRecordType::INFO);
|
2020-04-30 17:40:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'action.devices.QUERY':
|
2020-05-13 08:02:42 +00:00
|
|
|
GoogleHome::query($obj['requestId'], $obj['inputs'][0]['payload']);
|
|
|
|
//$apiLogManager->write("[Google Home] action.devices.QUERY", LogRecordType::INFO);
|
2020-04-30 17:40:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'action.devices.EXECUTE':
|
2020-05-13 08:02:42 +00:00
|
|
|
GoogleHome::execute($obj['requestId'], $obj['inputs'][0]['payload']);
|
2020-05-02 15:50:18 +00:00
|
|
|
$apiLogManager->write("[Google Home] action.devices.EXECUTE", LogRecordType::INFO);
|
2020-04-30 17:40:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-03 17:02:27 +00:00
|
|
|
static function autorize(){
|
2020-04-30 17:40:34 +00:00
|
|
|
$json = file_get_contents('php://input');
|
|
|
|
$obj = json_decode($json, true);
|
|
|
|
|
|
|
|
$apiLogManager = new LogManager('../logs/api/HA/'. date("Y-m-d").'.log');
|
|
|
|
$apiLogManager->write("[API] request body\n" . json_encode($obj, JSON_PRETTY_PRINT), LogRecordType::INFO);
|
|
|
|
$apiLogManager->write("[API] GET body\n" . json_encode($_GET, JSON_PRETTY_PRINT), LogRecordType::INFO);
|
|
|
|
|
2020-05-03 17:02:27 +00:00
|
|
|
$get = [
|
2020-05-15 17:48:53 +00:00
|
|
|
"access_token"=>"2222255888",
|
2020-05-03 17:02:27 +00:00
|
|
|
"token_type"=>"Bearer",
|
|
|
|
"state"=>$_GET["state"],
|
|
|
|
];
|
2020-05-02 11:18:15 +00:00
|
|
|
|
2020-05-03 17:02:27 +00:00
|
|
|
echo $_GET["redirect_uri"] . '#' . http_build_query($get) ;
|
|
|
|
echo '<a href="'.$_GET["redirect_uri"] . '#' . http_build_query($get) . '">FINISH</a>';
|
|
|
|
}
|
2020-04-29 17:28:33 +00:00
|
|
|
}
|