2020-05-16 17:18:27 +02:00
|
|
|
<?php
|
2020-05-17 01:27:06 +02:00
|
|
|
class GoogleHomeApi{
|
2020-05-16 17:18:27 +02:00
|
|
|
static function response(){
|
2020-05-17 01:27:06 +02:00
|
|
|
//$this->requireAuth();
|
2020-05-16 17:18:27 +02:00
|
|
|
$json = file_get_contents('php://input');
|
|
|
|
$obj = json_decode($json, true);
|
|
|
|
|
2020-05-20 09:07:27 +02:00
|
|
|
$apiLogManager = new LogManager('../logs/google-home/'. date("Y-m-d").'.log');
|
2020-07-28 09:02:46 +02:00
|
|
|
$apiLogManager->setLevel(LOGLEVEL);
|
|
|
|
|
2020-05-16 17:18:27 +02:00
|
|
|
header('Content-Type: application/json');
|
|
|
|
|
|
|
|
switch ($obj['inputs'][0]['intent']) {
|
|
|
|
case 'action.devices.SYNC':
|
|
|
|
GoogleHome::sync($obj['requestId']);
|
2020-07-28 09:02:46 +02:00
|
|
|
$apiLogManager->write("[Google Home] action.devices.SYNC", LogRecordTypes::INFO);
|
2020-05-16 17:18:27 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'action.devices.QUERY':
|
|
|
|
GoogleHome::query($obj['requestId'], $obj['inputs'][0]['payload']);
|
2020-07-28 09:02:46 +02:00
|
|
|
$apiLogManager->write("[Google Home] action.devices.QUERY", LogRecordTypes::INFO);
|
|
|
|
$apiLogManager->write("[API] request body\n" . json_encode($obj, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
2020-05-16 17:18:27 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'action.devices.EXECUTE':
|
2020-07-04 20:06:54 +02:00
|
|
|
|
2020-05-16 17:18:27 +02:00
|
|
|
GoogleHome::execute($obj['requestId'], $obj['inputs'][0]['payload']);
|
2020-07-28 09:02:46 +02:00
|
|
|
$apiLogManager->write("[Google Home] action.devices.EXECUTE", LogRecordTypes::INFO);
|
|
|
|
$apiLogManager->write("[API] request body\n" . json_encode($obj, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
2020-06-26 16:57:26 +02:00
|
|
|
|
2020-05-16 17:18:27 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-07-28 15:51:40 +02:00
|
|
|
|
|
|
|
unset($apiLogManager);
|
2020-05-16 17:18:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static function autorize(){
|
|
|
|
$json = file_get_contents('php://input');
|
|
|
|
$obj = json_decode($json, true);
|
|
|
|
|
2020-05-20 09:07:27 +02:00
|
|
|
$apiLogManager = new LogManager('../logs/google-home/'. date("Y-m-d").'.log');
|
2020-07-28 09:02:46 +02:00
|
|
|
$apiLogManager->setLevel(LOGLEVEL);
|
|
|
|
$apiLogManager->write("[API] request body\n" . json_encode($obj, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
|
|
|
$apiLogManager->write("[API] GET body\n" . json_encode($_GET, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
2020-07-29 08:35:00 +02:00
|
|
|
unset($apiLogManager);
|
2020-05-16 17:18:27 +02:00
|
|
|
|
|
|
|
$get = [
|
2020-07-28 15:51:40 +02:00
|
|
|
"access_token"=>"2222255888", //TODO: FIX
|
2020-05-16 17:18:27 +02:00
|
|
|
"token_type"=>"Bearer",
|
|
|
|
"state"=>$_GET["state"],
|
|
|
|
];
|
|
|
|
|
|
|
|
echo $_GET["redirect_uri"] . '#' . http_build_query($get) ;
|
|
|
|
echo '<a href="'.$_GET["redirect_uri"] . '#' . http_build_query($get) . '">FINISH</a>';
|
|
|
|
}
|
|
|
|
}
|