2023-07-27 15:29:37 +08:00
|
|
|
import 'dart:async';
|
2023-08-02 09:22:39 +08:00
|
|
|
import 'dart:convert';
|
2023-07-27 15:29:37 +08:00
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
import 'package:get/get_connect/http/src/request/request.dart';
|
2023-09-11 09:48:47 +08:00
|
|
|
import 'package:star_lock/login/login/entity/LoginData.dart';
|
2023-07-27 15:29:37 +08:00
|
|
|
|
|
|
|
|
import '../tools/platform_info_services.dart';
|
2023-08-02 09:22:39 +08:00
|
|
|
import '../tools/storage.dart';
|
2023-07-27 15:29:37 +08:00
|
|
|
|
2024-04-08 13:32:47 +08:00
|
|
|
//公共获取UA
|
|
|
|
|
String getUserAgent() {
|
|
|
|
|
//赋值变量方便调试
|
|
|
|
|
String ua =
|
2024-06-05 16:13:56 +08:00
|
|
|
'StarLock/${PlatformInfoService.to?.info.version}/${PlatformInfoService.to?.info.buildNumber}/${GetPlatform.isAndroid ? 'Android' : 'iOS'}';
|
2024-04-08 13:32:47 +08:00
|
|
|
return ua;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FutureOr<Request> requestInterceptor(Request request) async {
|
|
|
|
|
request.headers['User-Agent'] = getUserAgent();
|
2024-03-08 13:55:47 +08:00
|
|
|
request.headers['Accept-Language'] = 'zh-CN';
|
2023-11-24 14:23:36 +08:00
|
|
|
// request.headers['Content-Type'] = 'application/json';
|
2023-07-29 09:25:21 +08:00
|
|
|
// request.headers['token'] = StoreService.to.userToken!;
|
2023-08-02 09:22:39 +08:00
|
|
|
String? xToken = '';
|
2024-01-16 15:13:43 +08:00
|
|
|
final data = await Storage.getString(saveUserLoginData);
|
2023-08-16 17:35:43 +08:00
|
|
|
if (data != null && data.isNotEmpty) {
|
2023-09-15 16:04:11 +08:00
|
|
|
xToken = LoginData.fromJson(jsonDecode(data)).accessToken;
|
2023-08-02 09:22:39 +08:00
|
|
|
}
|
|
|
|
|
request.headers['Authorization'] = "Bearer ${xToken ?? ''}";
|
2023-07-27 15:29:37 +08:00
|
|
|
return request;
|
2023-08-16 17:35:43 +08:00
|
|
|
}
|