Kaynağa Gözat

1.更新meui获取的方式

tags/0.0.12+4
“yanghuaxuan” 3 yıl önce
ebeveyn
işleme
5833d32f94
2 değiştirilmiş dosya ile 24 ekleme ve 32 silme
  1. +19
    -27
      lib/util/net_util.dart
  2. +5
    -5
      pubspec.yaml

+ 19
- 27
lib/util/net_util.dart Dosyayı Görüntüle

@@ -7,8 +7,8 @@ import 'package:device_info/device_info.dart';
import 'package:dio/adapter.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_alibc/flutter_alibc.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:imei_plugin/imei_plugin.dart';
import 'package:package_info/package_info.dart';
import 'package:provider/provider.dart';
import 'package:zhiying_comm/util/empty_util.dart';
@@ -94,7 +94,6 @@ class NetUtil {

static Map<String, dynamic> headParam;


/// 同步请求
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 {
@@ -111,7 +110,6 @@ class NetUtil {
NetUtil.headParam = await _getMustHeadParams();
}


// token 读取SP缓存中的用户token
String token = await SharedPreferencesUtil.getStringValue(GlobalConfig.SHARED_KEY_TOKEN);

@@ -129,20 +127,13 @@ class NetUtil {
NetUtil.headParam['Authorization'] = 'Bearer ' + token;
}

//获取imei
if (!NetUtil.headParam.containsKey('imei') && path.contains("/api/v1/app/push_dialog")) {
getImei();
}

if (NetUtil.headParam['token'] == null) {}
// 请求头参数
Map<String, dynamic> headParam = NetUtil.headParam;

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,
@@ -243,12 +234,12 @@ 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 {
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
@@ -260,11 +251,7 @@ class NetUtil {
}

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) {
@@ -276,8 +263,8 @@ class NetUtil {
if (onError != null) {
onError(!EmptyUtil.isEmpty(result)
? !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_MSG])
? result[GlobalConfig.HTTP_RESPONSE_KEY_MSG]
: '未知错误'
? result[GlobalConfig.HTTP_RESPONSE_KEY_MSG]
: '未知错误'
: '未知错误');
}
} catch (e) {
@@ -457,7 +444,7 @@ class NetUtil {
/// 获取Android imei
static Future<String> _getImei() async {
try {
return await ImeiPlugin.getImei(shouldShowRequestPermissionRationale: true);
return await FlutterAlibc.getUdid();
} catch (e, s) {
Logger.error(e, s);
}
@@ -575,9 +562,14 @@ class NetUtil {
}

static void getImei() async {
NetUtil.headParam['imei'] = await _getImei();
if (!NetUtil.headParam.containsKey('imei')) {
String imei = await _getImei();
print("获取到udid"+imei??"");
if (imei != null) {
NetUtil.headParam['imei'] = imei;
}
}
}

}

/**


+ 5
- 5
pubspec.yaml Dosyayı Görüntüle

@@ -43,15 +43,15 @@ dependencies:
flutter_alibc:
# path: ../zhiying_flutter_alibc
git:
ref: 0.0.7
ref: 0.0.11
url: http://192.168.0.138:3000/FnuoOS_ZhiYing/zhiying_flutter_alibc.git
url_launcher: ^5.6.0
#图片预览控件
photo_view: ^0.10.3
imei_plugin:
git:
url: 'http://192.168.0.138:3000/FnuoOS_ZhiYing/imei_plugin.git'
ref: '0.0.2'
# imei_plugin:
# git:
# url: 'http://192.168.0.138:3000/FnuoOS_ZhiYing/imei_plugin.git'
# ref: '0.0.2'
# mob 分享sdk
sharesdk_plugin:
git:


Yükleniyor…
İptal
Kaydet