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.
53 lines
1.4 KiB
53 lines
1.4 KiB
import 'package:dio/dio.dart';
|
|
import '../models/recommend_bean.dart';
|
|
|
|
const String _getRecommend = "http://47.122.57.108:8888/recommend";
|
|
|
|
/// 音乐推荐
|
|
class GetRecommend {
|
|
final Dio dio = Dio();
|
|
|
|
/// 获取推荐歌曲列表
|
|
Future<RecommendBean> getRecommendList({
|
|
required String Authorization,
|
|
required int uid,
|
|
}) async {
|
|
try {
|
|
print('发送推荐请求: $_getRecommend');
|
|
print('用户Token: $Authorization');
|
|
print('用户ID: $uid');
|
|
|
|
Response response = await dio.post(
|
|
'$_getRecommend?uid=$uid',
|
|
data: {
|
|
},
|
|
options: Options(
|
|
headers: {
|
|
'Authorization': Authorization,
|
|
'Content-Type': 'application/json;charset=UTF-8'
|
|
},
|
|
),
|
|
);
|
|
|
|
print("推荐歌曲响应数据: ${response.data}");
|
|
|
|
if (response.statusCode == 200) {
|
|
return RecommendBean.fromMap(response.data);
|
|
} else {
|
|
throw Exception("获取推荐歌曲失败");
|
|
}
|
|
} catch (e) {
|
|
if (e is DioException) {
|
|
print('请求失败:');
|
|
print('状态码: ${e.response?.statusCode}');
|
|
print('响应数据: ${e.response?.data}');
|
|
print('请求配置: ${e.requestOptions.uri}');
|
|
print('请求头: ${e.requestOptions.headers}');
|
|
print('请求数据: ${e.requestOptions.data}');
|
|
}
|
|
print("获取推荐歌曲时发生错误: $e");
|
|
rethrow;
|
|
}
|
|
}
|
|
}
|