PHP_SMART_HOME_V3/app/api/GoogleHomeApi.php

47 lines
1.5 KiB
PHP
Raw Normal View History

2020-05-16 15:18:27 +00:00
<?php
2020-05-16 23:27:06 +00:00
class GoogleHomeApi{
2020-05-16 15:18:27 +00:00
static function response(){
2020-05-16 23:27:06 +00:00
//$this->requireAuth();
2020-05-16 15:18:27 +00:00
$json = file_get_contents('php://input');
$obj = json_decode($json, true);
2020-05-20 07:07:27 +00:00
$apiLogManager = new LogManager('../logs/google-home/'. date("Y-m-d").'.log');
2020-05-16 15:18:27 +00:00
header('Content-Type: application/json');
switch ($obj['inputs'][0]['intent']) {
case 'action.devices.SYNC':
GoogleHome::sync($obj['requestId']);
$apiLogManager->write("[Google Home] action.devices.SYNC", LogRecordType::INFO);
break;
case 'action.devices.QUERY':
GoogleHome::query($obj['requestId'], $obj['inputs'][0]['payload']);
//$apiLogManager->write("[Google Home] action.devices.QUERY", LogRecordType::INFO);
break;
case 'action.devices.EXECUTE':
GoogleHome::execute($obj['requestId'], $obj['inputs'][0]['payload']);
$apiLogManager->write("[Google Home] action.devices.EXECUTE", LogRecordType::INFO);
break;
}
}
static function autorize(){
$json = file_get_contents('php://input');
$obj = json_decode($json, true);
2020-05-20 07:07:27 +00:00
$apiLogManager = new LogManager('../logs/google-home/'. date("Y-m-d").'.log');
2020-05-16 15:18:27 +00:00
$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);
$get = [
"access_token"=>"2222255888",
"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>';
}
}