65 lines
1.8 KiB
Dart
65 lines
1.8 KiB
Dart
// 2026-04-13 | test_detail_id.dart | 详情页ID测试 | 验证详情页API返回数据
|
||
// 运行: dart run scripts/test_detail_id.dart
|
||
|
||
import 'dart:convert';
|
||
import 'dart:io';
|
||
|
||
const String baseUrl = 'https://eat.wktyl.com/api';
|
||
|
||
Future<void> main() async {
|
||
print('=== 详情页ID测试 ===\n');
|
||
|
||
// 测试ID 32390(从日志中获取)
|
||
const testId = 32390;
|
||
|
||
print('📡 测试ID: $testId');
|
||
await testDetailApi(testId);
|
||
|
||
// 再测试一个有效的ID
|
||
print('\n📡 测试另一个ID: 46518');
|
||
await testDetailApi(46518);
|
||
}
|
||
|
||
Future<void> testDetailApi(int id) async {
|
||
final client = HttpClient();
|
||
try {
|
||
final url = Uri.parse('$baseUrl/api.php?act=full&id=$id&_refresh=1');
|
||
print(' 请求URL: $url');
|
||
|
||
final request = await client.getUrl(url);
|
||
request.headers.set('Accept', 'application/json');
|
||
|
||
final response = await request.close();
|
||
final body = await response.transform(utf8.decoder).join();
|
||
|
||
print(' 状态码: ${response.statusCode}');
|
||
print(' 响应长度: ${body.length}');
|
||
|
||
if (body.isEmpty) {
|
||
print(' ❌ 响应体为空');
|
||
return;
|
||
}
|
||
|
||
final json = jsonDecode(body) as Map<String, dynamic>;
|
||
print(' code: ${json['code']}');
|
||
print(' message: ${json['message']}');
|
||
|
||
final data = json['data'] as Map<String, dynamic>?;
|
||
if (data == null) {
|
||
print(' ❌ data字段为null');
|
||
return;
|
||
}
|
||
|
||
print(' ✅ 数据加载成功');
|
||
print(' id: ${data['id']}');
|
||
print(' title: ${data['title']}');
|
||
print(' pic_id: ${data['pic_id']}');
|
||
print(' cover: ${data['cover']}');
|
||
print(' intro: ${(data['intro'] as String?)?.substring(0, (data['intro'] as String?)?.length.clamp(0, 50) ?? 0)}...');
|
||
} catch (e) {
|
||
print(' ❌ 请求错误: $e');
|
||
} finally {
|
||
client.close();
|
||
}
|
||
}
|