From 5833d32f946f56165ecbc0fc65a097cbb7496a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cyanghuaxuan=E2=80=9D?= <“646903573@qq.com”> Date: Sat, 10 Apr 2021 18:58:39 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=9B=B4=E6=96=B0meui=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/util/net_util.dart | 46 +++++++++++++++++------------------------- pubspec.yaml | 10 ++++----- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/lib/util/net_util.dart b/lib/util/net_util.dart index 0130160..3bfd0e6 100644 --- a/lib/util/net_util.dart +++ b/lib/util/net_util.dart @@ -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 headParam; - /// 同步请求 static Future post(String path, {Map params, Map 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 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 params, - Map queryParameters, - OnSuccess onSuccess, - OnError onError, - OnCache onCache, - bool showToast = true}) async { + Map params, + Map 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 _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; + } + } } - } /** diff --git a/pubspec.yaml b/pubspec.yaml index 79ec3ff..f36aed3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: