11 changed files with 567 additions and 526 deletions
@ -1,78 +0,0 @@ |
|||
<?php |
|||
/** |
|||
* 文件上传测试脚本 |
|||
* 用于测试文档上传功能 |
|||
*/ |
|||
|
|||
// 创建一个测试文件 |
|||
$testContent = "这是一个测试文档\n创建时间: " . date('Y-m-d H:i:s'); |
|||
$testFile = '/tmp/test_document.txt'; |
|||
file_put_contents($testFile, $testContent); |
|||
|
|||
echo "📄 文件上传测试\n"; |
|||
echo "================\n"; |
|||
echo "测试文件: $testFile\n"; |
|||
echo "文件大小: " . filesize($testFile) . " bytes\n\n"; |
|||
|
|||
// 测试上传接口 |
|||
$url = 'http://niucloud_nginx/api/uploadDocument'; |
|||
|
|||
// 创建 CURLFile 对象 |
|||
$cfile = new CURLFile($testFile, 'text/plain', 'test_document.txt'); |
|||
|
|||
$postData = [ |
|||
'file' => $cfile, |
|||
'type' => 'document' |
|||
]; |
|||
|
|||
$ch = curl_init(); |
|||
curl_setopt($ch, CURLOPT_URL, $url); |
|||
curl_setopt($ch, CURLOPT_POST, true); |
|||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); |
|||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|||
curl_setopt($ch, CURLOPT_HTTPHEADER, [ |
|||
'Accept: application/json', |
|||
'token: test_token_for_upload_test', |
|||
// 注意:不要设置 Content-Type,让curl自动设置为 multipart/form-data |
|||
]); |
|||
|
|||
echo "🚀 发送上传请求...\n"; |
|||
$response = curl_exec($ch); |
|||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|||
$error = curl_error($ch); |
|||
curl_close($ch); |
|||
|
|||
echo "HTTP状态码: $httpCode\n"; |
|||
if ($error) { |
|||
echo "CURL错误: $error\n"; |
|||
} |
|||
|
|||
echo "响应内容:\n"; |
|||
echo $response . "\n\n"; |
|||
|
|||
// 解析响应 |
|||
$responseData = json_decode($response, true); |
|||
if ($responseData) { |
|||
if ($responseData['code'] == 1) { |
|||
echo "✅ 上传成功!\n"; |
|||
echo "文件URL: " . $responseData['data']['url'] . "\n"; |
|||
echo "文件名: " . $responseData['data']['name'] . "\n"; |
|||
echo "扩展名: " . $responseData['data']['ext'] . "\n"; |
|||
} else { |
|||
echo "❌ 上传失败: " . $responseData['msg'] . "\n"; |
|||
} |
|||
} else { |
|||
echo "❌ 响应解析失败\n"; |
|||
} |
|||
|
|||
// 清理测试文件 |
|||
unlink($testFile); |
|||
echo "\n🗑️ 测试文件已清理\n"; |
|||
|
|||
echo "\n📋 调试建议:\n"; |
|||
echo "1. 检查前端是否使用了正确的参数名 'file'\n"; |
|||
echo "2. 检查请求是否为 multipart/form-data 格式\n"; |
|||
echo "3. 检查文件大小是否超过限制\n"; |
|||
echo "4. 检查服务器错误日志\n"; |
|||
echo "5. 检查腾讯云COS配置和权限\n"; |
|||
?> |
|||
@ -1,71 +0,0 @@ |
|||
// 测试学员端订单接口
|
|||
const axios = require('axios'); |
|||
|
|||
const BASE_URL = 'http://localhost:20080/api'; |
|||
|
|||
async function testStudentOrdersAPI() { |
|||
console.log('🧪 开始测试学员端订单接口...\n'); |
|||
|
|||
try { |
|||
// 测试订单列表接口
|
|||
console.log('📋 测试订单列表接口...'); |
|||
const listResponse = await axios.get(`${BASE_URL}/xy/student/orders`, { |
|||
params: { |
|||
student_id: 31, |
|||
page: 1, |
|||
limit: 10 |
|||
} |
|||
}); |
|||
|
|||
console.log('✅ 订单列表接口响应:'); |
|||
console.log('状态码:', listResponse.status); |
|||
console.log('响应数据:', JSON.stringify(listResponse.data, null, 2)); |
|||
console.log(''); |
|||
|
|||
// 测试订单统计接口
|
|||
console.log('📊 测试订单统计接口...'); |
|||
const statsResponse = await axios.get(`${BASE_URL}/xy/student/orders/stats`, { |
|||
params: { |
|||
student_id: 31 |
|||
} |
|||
}); |
|||
|
|||
console.log('✅ 订单统计接口响应:'); |
|||
console.log('状态码:', statsResponse.status); |
|||
console.log('响应数据:', JSON.stringify(statsResponse.data, null, 2)); |
|||
console.log(''); |
|||
|
|||
// 如果有订单数据,测试订单详情接口
|
|||
if (listResponse.data.code === 1 && listResponse.data.data && listResponse.data.data.data && listResponse.data.data.data.length > 0) { |
|||
const firstOrder = listResponse.data.data.data[0]; |
|||
console.log('📄 测试订单详情接口...'); |
|||
|
|||
const detailResponse = await axios.get(`${BASE_URL}/xy/student/orders/detail`, { |
|||
params: { |
|||
id: firstOrder.id, |
|||
student_id: 31 |
|||
} |
|||
}); |
|||
|
|||
console.log('✅ 订单详情接口响应:'); |
|||
console.log('状态码:', detailResponse.status); |
|||
console.log('响应数据:', JSON.stringify(detailResponse.data, null, 2)); |
|||
} else { |
|||
console.log('ℹ️ 没有订单数据,跳过详情接口测试'); |
|||
} |
|||
|
|||
console.log('\n🎉 所有接口测试完成!'); |
|||
|
|||
} catch (error) { |
|||
console.error('❌ 接口测试失败:'); |
|||
if (error.response) { |
|||
console.error('状态码:', error.response.status); |
|||
console.error('响应数据:', JSON.stringify(error.response.data, null, 2)); |
|||
} else { |
|||
console.error('错误信息:', error.message); |
|||
} |
|||
} |
|||
} |
|||
|
|||
// 运行测试
|
|||
testStudentOrdersAPI(); |
|||
Loading…
Reference in new issue