175 lines
6.6 KiB
PHP
175 lines
6.6 KiB
PHP
<?php
|
|
/**
|
|
* 🧪 TEST API - WhatsApp Bot
|
|
* Prueba específica de endpoints de la API
|
|
*/
|
|
|
|
// Headers para mostrar errores
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', 1);
|
|
|
|
echo "<!DOCTYPE html><html><head><meta charset='UTF-8'>";
|
|
echo "<title>🧪 Test API</title>";
|
|
echo "<style>body{font-family:monospace;margin:20px;background:#000;color:#00ff00}";
|
|
echo ".ok{color:#00ff00}.error{color:#ff0040}.warning{color:#ffaa00}";
|
|
echo ".section{background:#111;padding:15px;margin:10px 0;border:1px solid #333}";
|
|
echo "pre{background:#222;padding:10px;color:#ccc;overflow:auto;max-height:200px}";
|
|
echo ".endpoint{background:#333;padding:10px;margin:5px 0;border-left:3px solid #ffaa00}";
|
|
echo "</style></head><body>";
|
|
|
|
echo "<h1>🧪 TEST DE LA API</h1>";
|
|
|
|
// Lista de endpoints para probar
|
|
$endpoints = [
|
|
'get_settings.php' => 'Obtener configuración del sistema',
|
|
'get_stats.php' => 'Obtener estadísticas',
|
|
'get_users.php' => 'Obtener usuarios',
|
|
'get_menus.php' => 'Obtener menús',
|
|
'get_templates.php' => 'Obtener plantillas'
|
|
];
|
|
|
|
echo "<div class='section'>";
|
|
echo "<h2>🚀 PROBANDO ENDPOINTS DE LA API...</h2>";
|
|
|
|
foreach ($endpoints as $endpoint => $description) {
|
|
echo "<div class='endpoint'>";
|
|
echo "<strong>🔗 $endpoint</strong> - $description<br>";
|
|
|
|
$api_url = 'api/' . $endpoint;
|
|
|
|
// Verificar que el archivo existe
|
|
if (!file_exists($api_url)) {
|
|
echo "<div class='error'>❌ Archivo no encontrado: $api_url</div>";
|
|
continue;
|
|
}
|
|
|
|
echo "<div class='ok'>✅ Archivo existe</div>";
|
|
|
|
// Intentar ejecutar el endpoint usando output buffering
|
|
ob_start();
|
|
|
|
try {
|
|
// Simular REQUEST_METHOD para endpoints que lo requieran
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_HOST'] ?? 'localhost';
|
|
|
|
// Capturar cualquier error
|
|
$error_before = error_get_last();
|
|
|
|
// Incluir el archivo de la API
|
|
include $api_url;
|
|
|
|
// Obtener la salida
|
|
$output = ob_get_contents();
|
|
|
|
// Verificar errores
|
|
$error_after = error_get_last();
|
|
|
|
if ($error_after && $error_after !== $error_before) {
|
|
echo "<div class='error'>❌ Error PHP: " . htmlspecialchars($error_after['message']) . "</div>";
|
|
echo "<div class='error'>Línea: " . $error_after['line'] . " en " . basename($error_after['file']) . "</div>";
|
|
} else {
|
|
// Verificar si la salida parece ser JSON válido
|
|
if (!empty($output)) {
|
|
$json_data = json_decode($output, true);
|
|
if (json_last_error() === JSON_ERROR_NONE) {
|
|
echo "<div class='ok'>✅ Respuesta JSON válida (" . strlen($output) . " caracteres)</div>";
|
|
|
|
// Mostrar estructura básica
|
|
if (is_array($json_data)) {
|
|
$keys = array_keys($json_data);
|
|
$preview_keys = array_slice($keys, 0, 3);
|
|
echo "<div class='warning'>📋 Claves: " . implode(', ', $preview_keys);
|
|
if (count($keys) > 3) echo " (+" . (count($keys) - 3) . " más)";
|
|
echo "</div>";
|
|
}
|
|
} else {
|
|
echo "<div class='warning'>⚠️ Salida no es JSON válido</div>";
|
|
if (strlen($output) < 200) {
|
|
echo "<div class='warning'>Salida: " . htmlspecialchars(substr($output, 0, 100)) . "</div>";
|
|
}
|
|
}
|
|
} else {
|
|
echo "<div class='warning'>⚠️ Sin salida</div>";
|
|
}
|
|
}
|
|
|
|
} catch (ParseError $e) {
|
|
echo "<div class='error'>❌ Error de sintaxis: " . htmlspecialchars($e->getMessage()) . "</div>";
|
|
echo "<div class='error'>Línea: " . $e->getLine() . "</div>";
|
|
} catch (Error $e) {
|
|
echo "<div class='error'>❌ Error fatal: " . htmlspecialchars($e->getMessage()) . "</div>";
|
|
echo "<div class='error'>Archivo: " . basename($e->getFile()) . " línea " . $e->getLine() . "</div>";
|
|
} catch (Exception $e) {
|
|
echo "<div class='error'>❌ Excepción: " . htmlspecialchars($e->getMessage()) . "</div>";
|
|
} finally {
|
|
ob_end_clean();
|
|
}
|
|
|
|
echo "</div>";
|
|
}
|
|
|
|
echo "</div>";
|
|
|
|
// Test directo de carga de configuración desde API
|
|
echo "<div class='section'>";
|
|
echo "<h2>⚙️ TEST DIRECTO DE CONFIGURACIÓN...</h2>";
|
|
|
|
echo "<div class='warning'>🔄 Simulando carga desde directorio API...</div>";
|
|
|
|
// Cambiar al directorio API temporalmente
|
|
$original_dir = getcwd();
|
|
|
|
try {
|
|
chdir('api');
|
|
echo "<div class='ok'>✅ Cambiado a directorio API</div>";
|
|
|
|
// Intentar cargar la configuración
|
|
if (file_exists('../config/config.php')) {
|
|
echo "<div class='ok'>✅ ../config/config.php existe desde API</div>";
|
|
|
|
try {
|
|
require_once '../config/config.php';
|
|
echo "<div class='ok'>✅ Configuración cargada exitosamente</div>";
|
|
|
|
// Verificar algunas constantes
|
|
$test_constants = ['DB_HOST', 'DB_NAME', 'DB_USER', 'SECRET_KEY'];
|
|
foreach ($test_constants as $const) {
|
|
if (defined($const)) {
|
|
echo "<div class='ok'>✅ $const definida</div>";
|
|
} else {
|
|
echo "<div class='error'>❌ $const no definida</div>";
|
|
}
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
echo "<div class='error'>❌ Error cargando config: " . htmlspecialchars($e->getMessage()) . "</div>";
|
|
}
|
|
|
|
} else {
|
|
echo "<div class='error'>❌ ../config/config.php NO existe desde API</div>";
|
|
}
|
|
|
|
} finally {
|
|
chdir($original_dir);
|
|
}
|
|
|
|
echo "</div>";
|
|
|
|
// Resumen final
|
|
echo "<div class='section'>";
|
|
echo "<h2>📊 RESUMEN</h2>";
|
|
|
|
echo "<div class='ok'>✅ Rutas de API corregidas</div>";
|
|
echo "<div class='ok'>✅ Todos los archivos usan '../config/config.php'</div>";
|
|
|
|
echo "<br><div class='warning'><strong>PRÓXIMOS PASOS:</strong></div>";
|
|
echo "<div class='warning'>1. Verificar que las tablas existan: <a href='test_config.php' style='color:#ffaa00'>test_config.php</a></div>";
|
|
echo "<div class='warning'>2. Si faltan tablas, ejecutar: <a href='instalar_bd.php' style='color:#ffaa00'>instalar_bd.php</a></div>";
|
|
echo "<div class='warning'>3. Probar login: <a href='login.php' style='color:#ffaa00'>login.php</a></div>";
|
|
echo "<div class='warning'>4. Probar panel: <a href='index.php' style='color:#ffaa00'>index.php</a></div>";
|
|
|
|
echo "</div>";
|
|
|
|
echo "</body></html>";
|
|
?>
|