|
|
|
import 'dart:ui' as ui;
|
|
|
|
|
|
|
|
import 'package:dio/dio.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
|
|
|
import '../../constants/app_const.dart';
|
|
|
|
import '../../constants/network_const.dart';
|
|
|
|
import '../dio_extra.dart';
|
|
|
|
import '../user_agent_provider.dart';
|
|
...
|
...
|
@@ -17,6 +19,10 @@ class TokenInterceptor extends Interceptor { |
|
|
|
NetworkConst.headerUserAgent,
|
|
|
|
() => _buildUserAgent(),
|
|
|
|
);
|
|
|
|
options.headers.putIfAbsent(
|
|
|
|
NetworkConst.headerAcceptLanguage,
|
|
|
|
() => _buildAcceptLanguage(),
|
|
|
|
);
|
|
|
|
|
|
|
|
if (options.extra[DioExtra.noToken] == true) {
|
|
|
|
handler.next(options);
|
|
...
|
...
|
@@ -43,6 +49,17 @@ class TokenInterceptor extends Interceptor { |
|
|
|
handler.next(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
String _buildAcceptLanguage() {
|
|
|
|
try {
|
|
|
|
final currentLocale = Get.locale ?? ui.PlatformDispatcher.instance.locale;
|
|
|
|
final tag = currentLocale.toLanguageTag();
|
|
|
|
if (tag.isNotEmpty && tag != 'und') {
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
} catch (_) {}
|
|
|
|
return 'en';
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 构建完整 User-Agent,格式与 Android 端 [DeviceInfoUtils.userAgent] 完全一致:
|
|
|
|
/// `{systemWebViewUA} doublefeel/{versionCode}({versionName})({manufacturer}##{brand}##{model}; Android{sdkInt}; {height}x{width})(huawei)`
|
|
|
|
///
|
...
|
...
|
|