|
|
|
1
|
+import 'dart:ui' as ui;
|
|
|
|
2
|
+
|
|
1
|
import 'package:dio/dio.dart';
|
3
|
import 'package:dio/dio.dart';
|
|
|
|
4
|
+import 'package:get/get.dart';
|
|
2
|
|
5
|
|
|
3
|
-import '../../constants/app_const.dart';
|
|
|
|
4
|
import '../../constants/network_const.dart';
|
6
|
import '../../constants/network_const.dart';
|
|
5
|
import '../dio_extra.dart';
|
7
|
import '../dio_extra.dart';
|
|
6
|
import '../user_agent_provider.dart';
|
8
|
import '../user_agent_provider.dart';
|
|
@@ -17,6 +19,10 @@ class TokenInterceptor extends Interceptor { |
|
@@ -17,6 +19,10 @@ class TokenInterceptor extends Interceptor { |
|
17
|
NetworkConst.headerUserAgent,
|
19
|
NetworkConst.headerUserAgent,
|
|
18
|
() => _buildUserAgent(),
|
20
|
() => _buildUserAgent(),
|
|
19
|
);
|
21
|
);
|
|
|
|
22
|
+ options.headers.putIfAbsent(
|
|
|
|
23
|
+ NetworkConst.headerAcceptLanguage,
|
|
|
|
24
|
+ () => _buildAcceptLanguage(),
|
|
|
|
25
|
+ );
|
|
20
|
|
26
|
|
|
21
|
if (options.extra[DioExtra.noToken] == true) {
|
27
|
if (options.extra[DioExtra.noToken] == true) {
|
|
22
|
handler.next(options);
|
28
|
handler.next(options);
|
|
@@ -43,6 +49,17 @@ class TokenInterceptor extends Interceptor { |
|
@@ -43,6 +49,17 @@ class TokenInterceptor extends Interceptor { |
|
43
|
handler.next(options);
|
49
|
handler.next(options);
|
|
44
|
}
|
50
|
}
|
|
45
|
|
51
|
|
|
|
|
52
|
+ String _buildAcceptLanguage() {
|
|
|
|
53
|
+ try {
|
|
|
|
54
|
+ final currentLocale = Get.locale ?? ui.PlatformDispatcher.instance.locale;
|
|
|
|
55
|
+ final tag = currentLocale.toLanguageTag();
|
|
|
|
56
|
+ if (tag.isNotEmpty && tag != 'und') {
|
|
|
|
57
|
+ return tag;
|
|
|
|
58
|
+ }
|
|
|
|
59
|
+ } catch (_) {}
|
|
|
|
60
|
+ return 'en';
|
|
|
|
61
|
+ }
|
|
|
|
62
|
+
|
|
46
|
/// 构建完整 User-Agent,格式与 Android 端 [DeviceInfoUtils.userAgent] 完全一致:
|
63
|
/// 构建完整 User-Agent,格式与 Android 端 [DeviceInfoUtils.userAgent] 完全一致:
|
|
47
|
/// `{systemWebViewUA} doublefeel/{versionCode}({versionName})({manufacturer}##{brand}##{model}; Android{sdkInt}; {height}x{width})(huawei)`
|
64
|
/// `{systemWebViewUA} doublefeel/{versionCode}({versionName})({manufacturer}##{brand}##{model}; Android{sdkInt}; {height}x{width})(huawei)`
|
|
48
|
///
|
65
|
///
|