You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ss-visit/test_api_endpoints.php

88 lines
2.6 KiB

<?php
// API接口测试脚本
echo "=== 访客系统API接口测试 ===\n\n";
// 测试门岗端接口
echo "1. 测试门岗端接口:\n";
// 测试拜访列表接口
$url = 'http://localhost:8000/api/gate/visits';
$response = @file_get_contents($url);
if ($response !== false) {
$data = json_decode($response, true);
if (isset($data['code']) && isset($data['message']) && isset($data['data'])) {
echo "✅ GET /api/gate/visits - 拜访列表接口正常\n";
echo " 响应格式: code={$data['code']}, message={$data['message']}\n";
} else {
echo "❌ GET /api/gate/visits - 响应格式不正确\n";
}
} else {
echo "❌ GET /api/gate/visits - 接口无法访问\n";
}
// 测试拜访详情接口
$url = 'http://localhost:8000/api/gate/visits/1';
$response = @file_get_contents($url);
if ($response !== false) {
$data = json_decode($response, true);
if (isset($data['code']) && isset($data['message'])) {
echo "✅ GET /api/gate/visits/{id} - 拜访详情接口正常\n";
echo " 响应格式: code={$data['code']}, message={$data['message']}\n";
} else {
echo "❌ GET /api/gate/visits/{id} - 响应格式不正确\n";
}
} else {
echo "❌ GET /api/gate/visits/{id} - 接口无法访问\n";
}
// 测试多语言支持
echo "\n2. 测试多语言支持:\n";
// 测试中文响应
$context = stream_context_create([
'http' => [
'header' => 'Accept-Language: zh-CN'
]
]);
$url = 'http://localhost:8000/api/gate/visits';
$response = @file_get_contents($url, false, $context);
if ($response !== false) {
echo "✅ 中文语言支持正常\n";
} else {
echo "❌ 中文语言支持异常\n";
}
// 测试英文响应
$context = stream_context_create([
'http' => [
'header' => 'Accept-Language: en'
]
]);
$response = @file_get_contents($url, false, $context);
if ($response !== false) {
echo "✅ 英文语言支持正常\n";
} else {
echo "❌ 英文语言支持异常\n";
}
// 测试后台管理接口
echo "\n3. 测试后台管理接口:\n";
$url = 'http://localhost:8000/api/admin/visits/index';
$response = @file_get_contents($url);
if ($response !== false) {
$data = json_decode($response, true);
if (isset($data['code']) && $data['code'] == 401) {
echo "✅ GET /api/admin/visits/index - 认证保护正常\n";
} else {
echo "⚠️ GET /api/admin/visits/index - 认证保护可能有问题\n";
}
} else {
echo "❌ GET /api/admin/visits/index - 接口无法访问\n";
}
echo "\n=== 测试完成 ===\n";
echo "注意: 此测试需要Laravel开发服务器运行在 localhost:8000\n";
echo "启动命令: php artisan serve\n";