Browse Source

1.更新meui获取的方式

tags/0.0.12+4
“yanghuaxuan” 3 years ago
parent
commit
5833d32f94
2 changed files with 24 additions and 32 deletions
  1. +19
    -27
      lib/util/net_util.dart
  2. +5
    -5
      pubspec.yaml

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

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


static Map<String, dynamic> headParam; static Map<String, dynamic> headParam;



/// 同步请求 /// 同步请求
static Future<dynamic> post(String path, 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 { {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(); NetUtil.headParam = await _getMustHeadParams();
} }



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


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


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

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


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,
@@ -243,12 +234,12 @@ class NetUtil {
/// 异步请求 /// 异步请求
static void request(String path, static void request(String path,
{NetMethod method = NetMethod.GET, {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 ?? {}}; var paramsData = {'postData': params ?? {}, 'queryParameters': queryParameters ?? {}};


// 根据请求参数,获取缓存的Key // 根据请求参数,获取缓存的Key
@@ -260,11 +251,7 @@ class NetUtil {
} }


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


static void getImei() async { 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 View File

@@ -43,15 +43,15 @@ dependencies:
flutter_alibc: flutter_alibc:
# path: ../zhiying_flutter_alibc # path: ../zhiying_flutter_alibc
git: git:
ref: 0.0.7
ref: 0.0.11
url: http://192.168.0.138:3000/FnuoOS_ZhiYing/zhiying_flutter_alibc.git 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.3 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 # mob 分享sdk
sharesdk_plugin: sharesdk_plugin:
git: git:


Loading…
Cancel
Save