From 5168b23609b0bdc0cb190c9d4f55019f2d57d176 Mon Sep 17 00:00:00 2001 From: userGyl Date: Sun, 4 Jan 2026 16:59:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AF=B7=E6=B1=82=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ln_jq_app/lib/common/token_interceptor.dart | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ln_jq_app/lib/common/token_interceptor.dart b/ln_jq_app/lib/common/token_interceptor.dart index 81a3d7b..fe15a64 100644 --- a/ln_jq_app/lib/common/token_interceptor.dart +++ b/ln_jq_app/lib/common/token_interceptor.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:dio/dio.dart'; import 'package:ln_jq_app/storage_service.dart'; @@ -5,9 +7,10 @@ import 'package:ln_jq_app/storage_service.dart'; class TokenInterceptor extends Interceptor { // 定义您想要使用的 Token Key final String tokenKey; + final String sourceKey; // 构造函数,允许外部传入自定义的 Key,默认为 'Authorization' - TokenInterceptor({this.tokenKey = 'Authorization'}); + TokenInterceptor({this.tokenKey = 'Authorization', this.sourceKey = 'source'}); @override void onRequest(RequestOptions options, RequestInterceptorHandler handler) { @@ -23,6 +26,18 @@ class TokenInterceptor extends Interceptor { } } + String platformSource; + if (Platform.isAndroid) { + platformSource = 'Android'; + } else if (Platform.isIOS) { + platformSource = 'iOS'; + } else { + platformSource = ''; + } + if (!options.headers.containsKey(sourceKey)) { + options.headers[sourceKey] = platformSource; + } + // 调用 handler.next(options) 以继续执行请求 // 这一步至关重要,否则请求会被中断 super.onRequest(options, handler);