|
|
@@ -7,8 +7,8 @@ import 'package:device_info/device_info.dart'; |
|
|
|
import 'package:dio/adapter.dart'; |
|
|
|
import 'package:dio/dio.dart'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter_alibc/flutter_alibc.dart'; |
|
|
|
import 'package:fluttertoast/fluttertoast.dart'; |
|
|
|
import 'package:imei_plugin/imei_plugin.dart'; |
|
|
|
import 'package:package_info/package_info.dart'; |
|
|
|
import 'package:provider/provider.dart'; |
|
|
|
import 'package:zhiying_comm/util/empty_util.dart'; |
|
|
@@ -94,7 +94,6 @@ class NetUtil { |
|
|
|
|
|
|
|
static Map<String, dynamic> headParam; |
|
|
|
|
|
|
|
|
|
|
|
/// 同步请求 |
|
|
|
static Future<dynamic> post(String path, |
|
|
|
{Map<String, dynamic> params, Map<String, dynamic> queryParameters, NetMethod method = NetMethod.POST, bool cache = false, bool showToast = true}) async { |
|
|
@@ -111,7 +110,6 @@ class NetUtil { |
|
|
|
NetUtil.headParam = await _getMustHeadParams(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// token 读取SP缓存中的用户token |
|
|
|
String token = await SharedPreferencesUtil.getStringValue(GlobalConfig.SHARED_KEY_TOKEN); |
|
|
|
|
|
|
@@ -129,20 +127,13 @@ class NetUtil { |
|
|
|
NetUtil.headParam['Authorization'] = 'Bearer ' + token; |
|
|
|
} |
|
|
|
|
|
|
|
//获取imei |
|
|
|
if (!NetUtil.headParam.containsKey('imei') && path.contains("/api/v1/app/push_dialog")) { |
|
|
|
getImei(); |
|
|
|
} |
|
|
|
|
|
|
|
if (NetUtil.headParam['token'] == null) {} |
|
|
|
// 请求头参数 |
|
|
|
Map<String, dynamic> headParam = NetUtil.headParam; |
|
|
|
|
|
|
|
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, |
|
|
@@ -243,12 +234,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 |
|
|
@@ -260,11 +251,7 @@ 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) { |
|
|
@@ -276,8 +263,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) { |
|
|
@@ -457,7 +444,7 @@ class NetUtil { |
|
|
|
/// 获取Android imei |
|
|
|
static Future<String> _getImei() async { |
|
|
|
try { |
|
|
|
return await ImeiPlugin.getImei(shouldShowRequestPermissionRationale: true); |
|
|
|
return await FlutterAlibc.getUdid(); |
|
|
|
} catch (e, s) { |
|
|
|
Logger.error(e, s); |
|
|
|
} |
|
|
@@ -575,9 +562,14 @@ class NetUtil { |
|
|
|
} |
|
|
|
|
|
|
|
static void getImei() async { |
|
|
|
NetUtil.headParam['imei'] = await _getImei(); |
|
|
|
if (!NetUtil.headParam.containsKey('imei')) { |
|
|
|
String imei = await _getImei(); |
|
|
|
print("获取到udid"+imei??""); |
|
|
|
if (imei != null) { |
|
|
|
NetUtil.headParam['imei'] = imei; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|