Browse Source

1.更新支付宝插件版本

2.优化缓存key的策略
tags/0.0.4+1
“yanghuaxuan” 3 years ago
parent
commit
b5b3e28662
3 changed files with 40 additions and 24 deletions
  1. +1
    -1
      example/android/app/src/main/java/cn/zhios/zhiying_comm_example/MainActivity.java
  2. +33
    -19
      lib/util/net_util.dart
  3. +6
    -4
      pubspec.yaml

+ 1
- 1
example/android/app/src/main/java/cn/zhios/zhiying_comm_example/MainActivity.java View File

@@ -49,7 +49,7 @@ public class MainActivity extends FlutterActivity implements ZhiyingFlutterCommN


@Override @Override
public void initSuccess() { public void initSuccess() {
} }


@Override @Override


+ 33
- 19
lib/util/net_util.dart View File

@@ -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 // 根据请求参数,获取缓存的Key
String cacheKey = getRequestParamsCachedKey(params, path);
String cacheKey = getRequestParamsCachedKey(paramsData, path);
// 参数签名 TODO 加密? // 参数签名 TODO 加密?
// post请求的参数 // post请求的参数
Map<String, dynamic> bodyParams = params; Map<String, dynamic> bodyParams = params;
@@ -107,7 +112,9 @@ class NetUtil {


Response response; Response response;
try { try {
Dio dio = await NetUtil.getInstance().dio;
Dio dio = await NetUtil
.getInstance()
.dio;
response = await dio.request( response = await dio.request(
path, path,
data: !EmptyUtil.isEmpty(bodyParams) ? bodyParams : null, data: !EmptyUtil.isEmpty(bodyParams) ? bodyParams : null,
@@ -130,12 +137,13 @@ class NetUtil {
// 缓存返回的数据 // 缓存返回的数据
} else { } else {
Logger.error('error: ' + result[GlobalConfig.HTTP_RESPONSE_KEY_MSG]); Logger.error('error: ' + result[GlobalConfig.HTTP_RESPONSE_KEY_MSG]);

/// ///
/// 401000 验证用户失败(不提示Toast) /// 401000 验证用户失败(不提示Toast)
/// 404004 没有找到对应模块(跳空页面,不提示toast) /// 404004 没有找到对应模块(跳空页面,不提示toast)
/// ///
if (result[GlobalConfig.HTTP_RESPONSE_KEY_CODE] != 401000 && result[GlobalConfig.HTTP_RESPONSE_KEY_CODE] != 404004) { if (result[GlobalConfig.HTTP_RESPONSE_KEY_CODE] != 401000 && result[GlobalConfig.HTTP_RESPONSE_KEY_CODE] != 404004) {
if(showToast) {
if (showToast) {
Fluttertoast.showToast( Fluttertoast.showToast(
msg: result[GlobalConfig.HTTP_RESPONSE_KEY_MSG], msg: result[GlobalConfig.HTTP_RESPONSE_KEY_MSG],
toastLength: Toast.LENGTH_SHORT, toastLength: Toast.LENGTH_SHORT,
@@ -164,8 +172,7 @@ class NetUtil {
/// 403029 账号被禁用 /// 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 { try {
// 提示 // 提示
Fluttertoast.showToast( 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 // 根据请求参数,获取缓存的Key
String cacheKey = getRequestParamsCachedKey(params, path);
String cacheKey = getRequestParamsCachedKey(paramsData, path);
print("缓存Key"+cacheKey);
// // 读取缓存回调 // // 读取缓存回调
if (onCache != null) { if (onCache != null) {
await _onCallBackCacheData(onCache, cacheKey); await _onCallBackCacheData(onCache, cacheKey);
} }


try { 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 解密? // TODO 解密?
if (isSuccess(result)) { if (isSuccess(result)) {
if (onSuccess != null) { if (onSuccess != null) {
@@ -355,10 +369,10 @@ class NetUtil {
// token 读取SP缓存中的用户token // token 读取SP缓存中的用户token
String token = await SharedPreferencesUtil.getStringValue(GlobalConfig.SHARED_KEY_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(s);
print(e); print(e);
} }


+ 6
- 4
pubspec.yaml View File

@@ -40,9 +40,10 @@ dependencies:
# app更新dialogUI(用于IOS,以便统一样式) # app更新dialogUI(用于IOS,以便统一样式)
flutter_update_dialog: 1.0.0 flutter_update_dialog: 1.0.0
flutter_alibc: 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 url_launcher: ^5.6.0
#图片预览控件 #图片预览控件
photo_view: ^0.10.2 photo_view: ^0.10.2
@@ -80,9 +81,10 @@ dependencies:
dio_cookie_manager: ^1.0.0 dio_cookie_manager: ^1.0.0
#支付宝支付flutterSDK #支付宝支付flutterSDK
tobias: tobias:
# path: ../tobias
git: git:
url: 'http://192.168.0.138:3000/FnuoOS_ZhiYing/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 event_bus: 1.1.1




Loading…
Cancel
Save