getUserProfile static method

Future<UserProfileModel?> getUserProfile(
  1. String userId
)

获取用户画像

Implementation

static Future<UserProfileModel?> getUserProfile(String userId) async {
  final url = '${EnvironmentConfig.baseUrl}$_getProfilePath?user_id=$userId';
  print('========== 📤 获取用户画像请求 ==========');
  print('🔗 请求地址: $url');
  print('👤 用户ID: $userId');

  try {
    final response = await http.get(
      Uri.parse(url),
      headers: {
        'Content-Type': 'application/json',
      },
    ).timeout(
      Duration(seconds: EnvironmentConfig.apiTimeout),
      onTimeout: () {
        throw Exception('获取用户画像请求超时');
      },
    );

    print('✅ 收到用户画像响应 (状态码: ${response.statusCode})');
    print('📄 响应体: ${response.body}');

    if (response.statusCode == 200) {
      final Map<String, dynamic> responseData = json.decode(response.body);
      if (responseData['success'] == true && responseData['data'] != null) {
        return UserProfileModel.fromJson(responseData['data']);
      } else {
        print('⚠️ 用户画像不存在或数据为空');
        return null;
      }
    } else {
      print('❌ 获取用户画像失败: ${response.statusCode}');
      return null;
    }
  } catch (e) {
    print('❌ 获取用户画像异常: $e');
    return null;
  }
}