first commit

This commit is contained in:
2025-01-10 15:20:33 +08:00
commit 4f5d2aa650
66 changed files with 15921 additions and 0 deletions

View File

@ -0,0 +1,41 @@
<?php
include_once "db_config.php";
date_default_timezone_set('Asia/Shanghai');
header("Content-Type: application/json"); // 返回 JSON 格式的响应
header("Access-Control-Allow-Origin: *"); // 允许跨域请求
header("Access-Control-Allow-Methods: POST, OPTIONS"); // 允许的方法
header("Access-Control-Allow-Headers: Content-Type"); // 允许的请求头
// 处理 OPTIONS 请求
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(204);
exit();
}
// 获取原始 POST 数据
$input = json_decode(file_get_contents("php://input"), true); // 将 JSON 转换为 PHP 数组
// 检查是否成功解析 JSON
if (json_last_error() !== JSON_ERROR_NONE) {
echo json_encode(["error" => "无效的 JSON 数据"]);
exit();
}
$standby = $input["standby"];
$reboot = $input["reboot"];
$humidifier = $input["humidifier"];
$screen = $input["screen"];
$queryString = "UPDATE status SET standby='$standby', reboot='$reboot', humidifier='$humidifier', screen='$screen'";
mysqli_query($conn, $queryString);
if(mysqli_error($conn)){
echo json_encode(["error" => "状态更新失败"]);
}
else{
echo json_encode(["success" => "状态更新成功"]);
}