Просмотр исходного кода

1.更新meui获取的方式

tags/0.0.12+3
“yanghuaxuan” 3 лет назад
Родитель
Сommit
7b6481887c
2 измененных файлов: 41 добавлений и 29 удалений
  1. +40
    -28
      lib/util/net_util.dart
  2. +1
    -1
      pubspec.yaml

+ 40
- 28
lib/util/net_util.dart Просмотреть файл

@@ -112,23 +112,27 @@ class NetUtil {
}


// token 读取SP缓存中的用户token
String token = await SharedPreferencesUtil.getStringValue(GlobalConfig.SHARED_KEY_TOKEN);

if (EmptyUtil.isEmpty(token) && !bool.fromEnvironment("dart.vm.product")) {
try {
Map setting = await NativeUtil.getSetting();
token = setting['token'];
} catch (e, s) {
print(s);
print(e);
}
}
if (!EmptyUtil.isEmpty(token)) {
// params['token'] = token;
NetUtil.headParam['Authorization'] = 'Bearer ' + token;
// token 读取SP缓存中的用户token
String token = await SharedPreferencesUtil.getStringValue(GlobalConfig.SHARED_KEY_TOKEN);

if (EmptyUtil.isEmpty(token) && !bool.fromEnvironment("dart.vm.product")) {
try {
Map setting = await NativeUtil.getSetting();
token = setting['token'];
} catch (e, s) {
print(s);
print(e);
}
}
if (!EmptyUtil.isEmpty(token)) {
// params['token'] = token;
NetUtil.headParam['Authorization'] = 'Bearer ' + token;
}

//获取imei
if (!NetUtil.headParam.containsKey('imei') && path.contains("/api/v1/app/push_dialog")) {
getImei();
}

if (NetUtil.headParam['token'] == null) {}
// 请求头参数
@@ -136,7 +140,9 @@ class NetUtil {

Response response;
try {
Dio dio = await NetUtil.getInstance().dio;
Dio dio = await NetUtil
.getInstance()
.dio;
response = await dio.request(
path,
data: !EmptyUtil.isEmpty(bodyParams) ? bodyParams : null,
@@ -237,12 +243,12 @@ class NetUtil {
/// 异步请求
static void request(String path,
{NetMethod method = NetMethod.GET,
Map<String, dynamic> params,
Map<String, dynamic> queryParameters,
OnSuccess onSuccess,
OnError onError,
OnCache onCache,
bool showToast = true}) async {
Map<String, dynamic> params,
Map<String, dynamic> queryParameters,
OnSuccess onSuccess,
OnError onError,
OnCache onCache,
bool showToast = true}) async {
var paramsData = {'postData': params ?? {}, 'queryParameters': queryParameters ?? {}};

// 根据请求参数,获取缓存的Key
@@ -254,7 +260,11 @@ class NetUtil {
}

try {
Map result = await NetUtil.post(path, method: method, params: params, queryParameters: queryParameters, showToast: showToast, cache: onCache != null);
Map result = await NetUtil.post(path, method: method,
params: params,
queryParameters: queryParameters,
showToast: showToast,
cache: onCache != null);
// TODO 解密?
if (isSuccess(result)) {
if (onSuccess != null) {
@@ -266,8 +276,8 @@ class NetUtil {
if (onError != null) {
onError(!EmptyUtil.isEmpty(result)
? !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_MSG])
? result[GlobalConfig.HTTP_RESPONSE_KEY_MSG]
: '未知错误'
? result[GlobalConfig.HTTP_RESPONSE_KEY_MSG]
: '未知错误'
: '未知错误');
}
} catch (e) {
@@ -389,9 +399,6 @@ class NetUtil {
params['device_model'] = androidInfo?.model?.toString();
// 设备Id
params['device_id'] = androidInfo?.androidId?.toString();

// imei
params['imei'] = await _getImei();
}
// 应用版本号
params["app_version_name"] = packageInfo.version?.toString();
@@ -566,6 +573,11 @@ class NetUtil {
Logger.error('未知错误: ${e.toString()}');
}
}

static void getImei() async {
NetUtil.headParam['imei'] = await _getImei();
}

}

/**


+ 1
- 1
pubspec.yaml Просмотреть файл

@@ -51,7 +51,7 @@ dependencies:
imei_plugin:
git:
url: 'http://192.168.0.138:3000/FnuoOS_ZhiYing/imei_plugin.git'
ref: '0.0.1'
ref: '0.0.2'
# mob 分享sdk
sharesdk_plugin:
git:


Загрузка…
Отмена
Сохранить