Blame view

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