46 lines
1.5 KiB
Dart
46 lines
1.5 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:dio/dio.dart';
|
|
import 'package:flutter_kinetra/kt_utils/kt_utils.dart';
|
|
import 'package:flustars/flustars.dart';
|
|
|
|
import '../kt_utils/kt_device_info_utils.dart';
|
|
import '../kt_utils/kt_keys.dart';
|
|
|
|
class RequestInterceptor extends Interceptor {
|
|
@override
|
|
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
|
|
// 不加密
|
|
// bool isRelease = kReleaseMode;
|
|
// if (!isRelease) {
|
|
// options.headers.addAll({'security': false});
|
|
// }
|
|
final deviceInfo = KtDeviceInfoUtil();
|
|
String token = SpUtil.getString(KtKeys.token) ?? '';
|
|
if (token.isNotEmpty) {
|
|
options.headers.addAll({'Authorization': token});
|
|
}
|
|
String idfa = SpUtil.getString(KtKeys.iosIDFA) ?? '';
|
|
String gaid = Platform.isIOS
|
|
? (deviceInfo.deviceIdfv ?? '')
|
|
: SpUtil.getString(KtKeys.googleAid) ?? '';
|
|
options.headers.addAll({
|
|
'security': false,
|
|
'lang-key': 'en',
|
|
'device-id': deviceInfo.deviceId ?? 'unknown',
|
|
'system-type': deviceInfo.systemType ?? 'unknown',
|
|
'model': deviceInfo.deviceModel ?? 'unknown',
|
|
'system-version': deviceInfo.osVersion ?? 'unknown',
|
|
'brand': deviceInfo.deviceBrand ?? 'unknown',
|
|
'app-version': deviceInfo.appVersion ?? 'unknown',
|
|
'app-name': 'PandaLoom',
|
|
"time-zone": KtUtils.getTimeZoneOffset(DateTime.now()),
|
|
'idfa': idfa,
|
|
'idfv': deviceInfo.deviceIdfv,
|
|
"device-gaid": gaid,
|
|
});
|
|
|
|
super.onRequest(options, handler);
|
|
}
|
|
}
|