|
|
@@ -93,12 +93,17 @@ class NetUtil { |
|
|
|
} |
|
|
|
|
|
|
|
/// 同步请求 |
|
|
|
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 { |
|
|
|
if (params == null) { |
|
|
|
params = {}; |
|
|
|
} |
|
|
|
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 { |
|
|
|
|
|
|
|
var paramsData = { |
|
|
|
'postData': params ?? {}, |
|
|
|
'queryParameters': queryParameters ?? {} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// 根据请求参数,获取缓存的Key |
|
|
|
String cacheKey = getRequestParamsCachedKey(params, path); |
|
|
|
String cacheKey = getRequestParamsCachedKey(paramsData, path); |
|
|
|
// 参数签名 TODO 加密? |
|
|
|
// post请求的参数 |
|
|
|
Map<String, dynamic> bodyParams = params; |
|
|
@@ -107,7 +112,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, |
|
|
@@ -130,12 +137,13 @@ class NetUtil { |
|
|
|
// 缓存返回的数据 |
|
|
|
} else { |
|
|
|
Logger.error('error: ' + result[GlobalConfig.HTTP_RESPONSE_KEY_MSG]); |
|
|
|
|
|
|
|
/// |
|
|
|
/// 401000 验证用户失败(不提示Toast) |
|
|
|
/// 404004 没有找到对应模块(跳空页面,不提示toast) |
|
|
|
/// |
|
|
|
if (result[GlobalConfig.HTTP_RESPONSE_KEY_CODE] != 401000 && result[GlobalConfig.HTTP_RESPONSE_KEY_CODE] != 404004) { |
|
|
|
if(showToast) { |
|
|
|
if (showToast) { |
|
|
|
Fluttertoast.showToast( |
|
|
|
msg: result[GlobalConfig.HTTP_RESPONSE_KEY_MSG], |
|
|
|
toastLength: Toast.LENGTH_SHORT, |
|
|
@@ -164,8 +172,7 @@ class NetUtil { |
|
|
|
/// 403029 账号被禁用 |
|
|
|
/// 提示并且退出登录 |
|
|
|
/// |
|
|
|
if(result[GlobalConfig.HTTP_RESPONSE_KEY_CODE]?.toString() == '403028' || result[GlobalConfig.HTTP_RESPONSE_KEY_CODE]?.toString() == '403029') { |
|
|
|
|
|
|
|
if (result[GlobalConfig.HTTP_RESPONSE_KEY_CODE]?.toString() == '403028' || result[GlobalConfig.HTTP_RESPONSE_KEY_CODE]?.toString() == '403029') { |
|
|
|
try { |
|
|
|
// 提示 |
|
|
|
Fluttertoast.showToast( |
|
|
@@ -191,20 +198,27 @@ 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 { |
|
|
|
if (params == null) { |
|
|
|
params = {}; |
|
|
|
} |
|
|
|
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 { |
|
|
|
var paramsData = { |
|
|
|
'postData': params ?? {}, |
|
|
|
'queryParameters': queryParameters ?? {} |
|
|
|
}; |
|
|
|
|
|
|
|
// 根据请求参数,获取缓存的Key |
|
|
|
String cacheKey = getRequestParamsCachedKey(params, path); |
|
|
|
String cacheKey = getRequestParamsCachedKey(paramsData, path); |
|
|
|
print("缓存Key"+cacheKey); |
|
|
|
// // 读取缓存回调 |
|
|
|
if (onCache != null) { |
|
|
|
await _onCallBackCacheData(onCache, cacheKey); |
|
|
|
} |
|
|
|
|
|
|
|
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) { |
|
|
@@ -355,10 +369,10 @@ class NetUtil { |
|
|
|
// token 读取SP缓存中的用户token |
|
|
|
String token = await SharedPreferencesUtil.getStringValue(GlobalConfig.SHARED_KEY_TOKEN); |
|
|
|
|
|
|
|
if(EmptyUtil.isEmpty(token)&&!bool.fromEnvironment("dart.vm.product")){ |
|
|
|
try{ |
|
|
|
token=setting['token']; |
|
|
|
}catch(e,s){ |
|
|
|
if (EmptyUtil.isEmpty(token) && !bool.fromEnvironment("dart.vm.product")) { |
|
|
|
try { |
|
|
|
token = setting['token']; |
|
|
|
} catch (e, s) { |
|
|
|
print(s); |
|
|
|
print(e); |
|
|
|
} |
|
|
|