|
@@ -46,7 +46,7 @@ class NetUtil { |
|
|
if (_dio == null) { |
|
|
if (_dio == null) { |
|
|
var setting = await NativeUtil.getSetting(); |
|
|
var setting = await NativeUtil.getSetting(); |
|
|
String domain = setting['domain']; //'http://www.hairuyi.com/'; |
|
|
String domain = setting['domain']; //'http://www.hairuyi.com/'; |
|
|
// _config(domain, proxyUrl: '192.168.0.66:8866'); |
|
|
|
|
|
|
|
|
_config(domain, proxyUrl: '192.168.0.66:8866'); |
|
|
} |
|
|
} |
|
|
return _dio; |
|
|
return _dio; |
|
|
} |
|
|
} |
|
@@ -86,12 +86,12 @@ class NetUtil { |
|
|
|
|
|
|
|
|
/// 同步请求 |
|
|
/// 同步请求 |
|
|
static Future<dynamic> post(String path, |
|
|
static Future<dynamic> post(String path, |
|
|
{Map<String, dynamic> params, NetMethod method = NetMethod.POST}) async { |
|
|
|
|
|
|
|
|
{Map<String, dynamic> params, NetMethod method = NetMethod.POST, bool cache = true}) async { |
|
|
if (params == null) { |
|
|
if (params == null) { |
|
|
params = {}; |
|
|
params = {}; |
|
|
} |
|
|
} |
|
|
// 根据请求参数,获取缓存的Key |
|
|
// 根据请求参数,获取缓存的Key |
|
|
String cacheKey = _getRequestParamsCachedKey(params, path); |
|
|
|
|
|
|
|
|
String cacheKey = getRequestParamsCachedKey(params, path); |
|
|
// 参数签名 TODO 加密? |
|
|
// 参数签名 TODO 加密? |
|
|
Map<String, dynamic> sign = await signParams(params); |
|
|
Map<String, dynamic> sign = await signParams(params); |
|
|
|
|
|
|
|
@@ -108,7 +108,9 @@ class NetUtil { |
|
|
// TODO 解密? |
|
|
// TODO 解密? |
|
|
if (isSuccess(result)) { |
|
|
if (isSuccess(result)) { |
|
|
// 缓存成功的数据 |
|
|
// 缓存成功的数据 |
|
|
_setCallBackCacheData(cacheKey, response.data is Map ? jsonEncode(response.data) : response.data); |
|
|
|
|
|
|
|
|
if(cache) { |
|
|
|
|
|
_setCallBackCacheData(cacheKey, response.data is Map ? jsonEncode(response.data) : response.data); |
|
|
|
|
|
} |
|
|
return result; |
|
|
return result; |
|
|
// 缓存返回的数据 |
|
|
// 缓存返回的数据 |
|
|
} |
|
|
} |
|
@@ -134,7 +136,7 @@ class NetUtil { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 根据请求参数,获取缓存的Key |
|
|
// 根据请求参数,获取缓存的Key |
|
|
String cacheKey = _getRequestParamsCachedKey(params, path); |
|
|
|
|
|
|
|
|
String cacheKey = getRequestParamsCachedKey(params, path); |
|
|
// // 读取缓存回调 |
|
|
// // 读取缓存回调 |
|
|
if (onCache != null) { |
|
|
if (onCache != null) { |
|
|
await _onCallBackCacheData(onCache, cacheKey); |
|
|
await _onCallBackCacheData(onCache, cacheKey); |
|
@@ -226,9 +228,7 @@ class NetUtil { |
|
|
|
|
|
|
|
|
// 站长ID |
|
|
// 站长ID |
|
|
String masterId = setting['master_id']; |
|
|
String masterId = setting['master_id']; |
|
|
if (null != null && |
|
|
|
|
|
masterId != '' && |
|
|
|
|
|
(!params.containsKey('master_id') || params['master_id'] == '')) { |
|
|
|
|
|
|
|
|
if (null != masterId && masterId != '' && (!params.containsKey('master_id') || params['master_id'] == '')) { |
|
|
params['master_id'] = masterId; |
|
|
params['master_id'] = masterId; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -289,7 +289,7 @@ class NetUtil { |
|
|
|
|
|
|
|
|
/// 根据请求参数,获取缓存的数据 |
|
|
/// 根据请求参数,获取缓存的数据 |
|
|
static Future<dynamic> getRequestCachedData(String url, {Map<String, dynamic> params}) async{ |
|
|
static Future<dynamic> getRequestCachedData(String url, {Map<String, dynamic> params}) async{ |
|
|
Map<String, dynamic> cacheMap = await SharedPreferencesUtil.getNetCacheResult(_getRequestParamsCachedKey(params, url)); |
|
|
|
|
|
|
|
|
Map<String, dynamic> cacheMap = await SharedPreferencesUtil.getNetCacheResult(getRequestParamsCachedKey(params, url)); |
|
|
if (!EmptyUtil.isEmpty(cacheMap) && |
|
|
if (!EmptyUtil.isEmpty(cacheMap) && |
|
|
cacheMap.containsKey(GlobalConfig.HTTP_RESPONSE_KEY_CODE) && |
|
|
cacheMap.containsKey(GlobalConfig.HTTP_RESPONSE_KEY_CODE) && |
|
|
(cacheMap[GlobalConfig.HTTP_RESPONSE_KEY_CODE] == |
|
|
(cacheMap[GlobalConfig.HTTP_RESPONSE_KEY_CODE] == |
|
@@ -318,7 +318,7 @@ class NetUtil { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// 根据请求参数,获取缓存的Key |
|
|
/// 根据请求参数,获取缓存的Key |
|
|
static String _getRequestParamsCachedKey( |
|
|
|
|
|
|
|
|
static String getRequestParamsCachedKey( |
|
|
Map<String, dynamic> map, String path) { |
|
|
Map<String, dynamic> map, String path) { |
|
|
if (EmptyUtil.isEmpty(map)) { |
|
|
if (EmptyUtil.isEmpty(map)) { |
|
|
return EncodeUtil.generateMd5(path); |
|
|
return EncodeUtil.generateMd5(path); |
|
|