|
|
@ -1,7 +1,11 @@ |
|
|
|
|
|
import 'dart:io'; |
|
|
|
|
|
|
|
|
import 'package:dio/dio.dart'; |
|
|
import 'package:dio/dio.dart'; |
|
|
import 'package:flutter_dotenv/flutter_dotenv.dart'; |
|
|
import 'package:flutter_dotenv/flutter_dotenv.dart'; |
|
|
import 'package:get/get.dart' hide Response; |
|
|
import 'package:get/get.dart' hide Response; |
|
|
|
|
|
|
|
|
|
|
|
import '../../models/channel_app_model.dart'; |
|
|
|
|
|
import '../version_update_service.dart'; |
|
|
import 'auth_interceptor.dart'; |
|
|
import 'auth_interceptor.dart'; |
|
|
import 'nw_method.dart'; |
|
|
import 'nw_method.dart'; |
|
|
|
|
|
|
|
|
@ -10,12 +14,29 @@ class DioManager { |
|
|
factory DioManager() => _shared; |
|
|
factory DioManager() => _shared; |
|
|
|
|
|
|
|
|
late Dio dio; |
|
|
late Dio dio; |
|
|
|
|
|
|
|
|
|
|
|
// 获取当前渠道信息,优先从版本服务获取,降级到平台判断和.env |
|
|
|
|
|
UserChannel get _currentChannel { |
|
|
|
|
|
try { |
|
|
|
|
|
if (Get.isRegistered<VersionUpdateService>()) { |
|
|
|
|
|
// print("lxm---${VersionUpdateService.to.cachedChannel}"); |
|
|
|
|
|
return VersionUpdateService.to.cachedChannel; |
|
|
|
|
|
} |
|
|
|
|
|
} catch (_) {} |
|
|
|
|
|
// 版本服务未就绪时,根据平台判断 |
|
|
|
|
|
if (Platform.isIOS) { |
|
|
|
|
|
return UserChannel.GLOBAL_APPLE; |
|
|
|
|
|
} |
|
|
|
|
|
final channelName = dotenv.env['Channel'] ?? 'OFFICIAL'; |
|
|
|
|
|
return UserChannel.fromName(channelName); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 根据地区获取服务器URL |
|
|
// 根据地区获取服务器URL |
|
|
String get baseUrl { |
|
|
String get baseUrl { |
|
|
final countryCode = Get.deviceLocale?.countryCode?.toUpperCase(); |
|
|
final countryCode = Get.deviceLocale?.countryCode?.toUpperCase(); |
|
|
final isChinaMainland = countryCode == 'CN'; |
|
|
final isChinaMainland = countryCode == 'CN'; |
|
|
final channel = dotenv.env['Channel'] ?? 'OFFICIAL'; |
|
|
final channel = _currentChannel; |
|
|
if (!isChinaMainland || channel == "GLOBAL_GOOGLE") { |
|
|
if (!isChinaMainland || channel == UserChannel.GLOBAL_GOOGLE) { |
|
|
return dotenv.env['HW_SERVER_URL'] ?? ''; |
|
|
return dotenv.env['HW_SERVER_URL'] ?? ''; |
|
|
} else { |
|
|
} else { |
|
|
return dotenv.env['SERVER_URL'] ?? ''; |
|
|
return dotenv.env['SERVER_URL'] ?? ''; |
|
|
|