exec('CREATE TABLE IF NOT EXISTS notes ( room TEXT, content TEXT, created_at INTEGER )'); return $db; } // 清理过期数据(1小时) function clean_expired($db) { $expire = time() - 3600; $db->exec('DELETE FROM notes WHERE created_at < ' . $expire); } // 处理API请求 if (isset($_GET['api'])) { header('Content-Type: application/json'); $db = init_db(); clean_expired($db); $room = $_POST['room'] ?? $_GET['room'] ?? 'default'; if ($_GET['api'] === 'get') { $stmt = $db->prepare('SELECT content FROM notes WHERE room = :room ORDER BY created_at DESC LIMIT 1'); $stmt->bindValue(':room', $room, SQLITE3_TEXT); $res = $stmt->execute()->fetchArray(SQLITE3_ASSOC); echo json_encode(['content' => $res['content'] ?? '']); exit; } elseif ($_GET['api'] === 'set') { $content = $_POST['content'] ?? ''; $stmt = $db->prepare('INSERT INTO notes (room, content, created_at) VALUES (:room, :content, :created_at)'); $stmt->bindValue(':room', $room, SQLITE3_TEXT); $stmt->bindValue(':content', $content, SQLITE3_TEXT); $stmt->bindValue(':created_at', time(), SQLITE3_INTEGER); $stmt->execute(); echo json_encode(['ok' => true]); exit; } echo json_encode(['error' => 'Invalid API']); exit; } // 前端页面 ?> 简易记事本 - 多设备同步

简易记事本 (1小时自动清除)

(同一房间号可多设备同步)
请记住你的房间号,1小时内内容有效。