diff --git a/example/android/app/src/main/java/cn/zhios/zhiying_comm_example/MainActivity.java b/example/android/app/src/main/java/cn/zhios/zhiying_comm_example/MainActivity.java index fde250f..f0db6ea 100644 --- a/example/android/app/src/main/java/cn/zhios/zhiying_comm_example/MainActivity.java +++ b/example/android/app/src/main/java/cn/zhios/zhiying_comm_example/MainActivity.java @@ -49,7 +49,7 @@ public class MainActivity extends FlutterActivity implements ZhiyingFlutterCommN @Override public void initSuccess() { - + } @Override diff --git a/lib/util/net_util.dart b/lib/util/net_util.dart index 856884f..d3bd139 100644 --- a/lib/util/net_util.dart +++ b/lib/util/net_util.dart @@ -93,12 +93,17 @@ class NetUtil { } /// 同步请求 - static Future post(String path, {Map params, Map queryParameters, NetMethod method = NetMethod.POST, bool cache = false, bool showToast = true}) async { - if (params == null) { - params = {}; - } + static Future post(String path, + {Map params, Map 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 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 params,Map 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 params, Map 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); } diff --git a/pubspec.yaml b/pubspec.yaml index 7e20efa..11ff2ae 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -40,9 +40,10 @@ dependencies: # app更新dialogUI(用于IOS,以便统一样式) flutter_update_dialog: 1.0.0 flutter_alibc: - git: - ref: 0.0.3 - url: http://192.168.0.138:3000/FnuoOS_ZhiYing/zhiying_flutter_alibc.git + path: ../zhiying_flutter_alibc +# git: +# ref: 0.0.3 +# url: http://192.168.0.138:3000/FnuoOS_ZhiYing/zhiying_flutter_alibc.git url_launcher: ^5.6.0 #图片预览控件 photo_view: ^0.10.2 @@ -80,9 +81,10 @@ dependencies: dio_cookie_manager: ^1.0.0 #支付宝支付flutterSDK tobias: + # path: ../tobias git: url: 'http://192.168.0.138:3000/FnuoOS_ZhiYing/tobias.git' - ref: '0.0.1' + ref: '0.0.2' event_bus: 1.1.1