|
|
@@ -46,7 +46,7 @@ class NetUtil { |
|
|
|
if (_dio == null) { |
|
|
|
var setting = await NativeUtil.getSetting(); |
|
|
|
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; |
|
|
|
} |
|
|
@@ -86,12 +86,12 @@ class NetUtil { |
|
|
|
|
|
|
|
/// 同步请求 |
|
|
|
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) { |
|
|
|
params = {}; |
|
|
|
} |
|
|
|
// 根据请求参数,获取缓存的Key |
|
|
|
String cacheKey = _getRequestParamsCachedKey(params, path); |
|
|
|
String cacheKey = getRequestParamsCachedKey(params, path); |
|
|
|
// 参数签名 TODO 加密? |
|
|
|
Map<String, dynamic> sign = await signParams(params); |
|
|
|
|
|
|
@@ -108,7 +108,9 @@ class NetUtil { |
|
|
|
// TODO 解密? |
|
|
|
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; |
|
|
|
// 缓存返回的数据 |
|
|
|
} |
|
|
@@ -134,7 +136,7 @@ class NetUtil { |
|
|
|
} |
|
|
|
|
|
|
|
// 根据请求参数,获取缓存的Key |
|
|
|
String cacheKey = _getRequestParamsCachedKey(params, path); |
|
|
|
String cacheKey = getRequestParamsCachedKey(params, path); |
|
|
|
// // 读取缓存回调 |
|
|
|
if (onCache != null) { |
|
|
|
await _onCallBackCacheData(onCache, cacheKey); |
|
|
@@ -226,9 +228,7 @@ class NetUtil { |
|
|
|
|
|
|
|
// 站长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; |
|
|
|
} |
|
|
|
|
|
|
@@ -289,7 +289,7 @@ class NetUtil { |
|
|
|
|
|
|
|
/// 根据请求参数,获取缓存的数据 |
|
|
|
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) && |
|
|
|
cacheMap.containsKey(GlobalConfig.HTTP_RESPONSE_KEY_CODE) && |
|
|
|
(cacheMap[GlobalConfig.HTTP_RESPONSE_KEY_CODE] == |
|
|
@@ -318,7 +318,7 @@ class NetUtil { |
|
|
|
} |
|
|
|
|
|
|
|
/// 根据请求参数,获取缓存的Key |
|
|
|
static String _getRequestParamsCachedKey( |
|
|
|
static String getRequestParamsCachedKey( |
|
|
|
Map<String, dynamic> map, String path) { |
|
|
|
if (EmptyUtil.isEmpty(map)) { |
|
|
|
return EncodeUtil.generateMd5(path); |
|
|
|