Blame view

lib/common/request/token_interceptor.dart 663 Bytes
056970d8   Key   feat: api
1
  import 'package:dio/dio.dart';
94342c3f   Key   feat: user util
2
  import 'package:wow_english/common/core/user_util.dart';
056970d8   Key   feat: api
3
  
caec5687   吴启风   feat:header传应用版本号
4
5
  import '../core/app_config_helper.dart';
  
056970d8   Key   feat: api
6
7
  class TokenInterceptor extends Interceptor {
    @override
caec5687   吴启风   feat:header传应用版本号
8
    void onRequest(RequestOptions options, RequestInterceptorHandler handler) async {
05f9b20a   Key   fixed: api调用方式,未完善
9
      // 判断token不为空插入, todo token的取法应该跟user在一起,这里取不到user
278208b8   吴启风   feat:1、用户访问权限调整;2...
10
11
      if (UserUtil.isLogined()) {
        options.headers["Auth-token"] = UserUtil.getUserToken();
05f9b20a   Key   fixed: api调用方式,未完善
12
      }
caec5687   吴启风   feat:header传应用版本号
13
14
15
      // 在发送请求之前获取版本号
      String version = await AppConfigHelper.getAppVersion();
      options.headers["version"] = version;
056970d8   Key   feat: api
16
17
18
      super.onRequest(options, handler);
    }
  }