提交 b57c0723 authored 作者: shixiaochen's avatar shixiaochen

1、调试升级接口;2、兼容新旧升级接口;

上级 f3c1e59a
...@@ -21,8 +21,10 @@ class _MyAppState extends State<MyApp> { ...@@ -21,8 +21,10 @@ class _MyAppState extends State<MyApp> {
appBar: AppBar( appBar: AppBar(
title: const Text('Plugin example app'), title: const Text('Plugin example app'),
), ),
body: InkWell( body: Column(
onTap: () { children: [
TextButton(
onPressed: () {
ApkUpdate().checkAppVersion( ApkUpdate().checkAppVersion(
baseUrl: "https://api.clxkj.cn:8088", baseUrl: "https://api.clxkj.cn:8088",
versionNumber: 1, versionNumber: 1,
...@@ -30,9 +32,24 @@ class _MyAppState extends State<MyApp> { ...@@ -30,9 +32,24 @@ class _MyAppState extends State<MyApp> {
onceDay: false, onceDay: false,
appleId: "1585610919"); appleId: "1585610919");
}, },
child: const Center( child: const Text('升级应用(旧)'),
child: Text('Running on: 升级应用'),
), ),
TextButton(
onPressed: () {
ApkUpdate().updateApp(
url:
"https://gateway.devclx.cn/clx-user/app/version/getSystemVersionByNumber",
params: {
"versionNumber": 1,
"productNo": 1,
"productCode": "carrier-driver-app",
},
onceDay: false,
appleId: "1585610919");
},
child: const Text('升级应用(新)'),
),
],
), ),
), ),
); );
......
...@@ -4,7 +4,7 @@ import 'package:flutter/material.dart'; ...@@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
import 'apk_update_platform_interface.dart'; import 'apk_update_platform_interface.dart';
class ApkUpdate { class ApkUpdate {
/// 检测应用版本 /// 检测应用版本(老版本方法)
/// baseUrl /// baseUrl
/// versionNumber 当前应用版本号(versionCode) /// versionNumber 当前应用版本号(versionCode)
/// productNo 产品号 /// productNo 产品号
...@@ -23,8 +23,44 @@ class ApkUpdate { ...@@ -23,8 +23,44 @@ class ApkUpdate {
//App2.vipApp,3,vip-pc。4,马上富通。5,马上富通pc。6,微信货主。7,货主pc。8,马上审。默认为1 //App2.vipApp,3,vip-pc。4,马上富通。5,马上富通pc。6,微信货主。7,货主pc。8,马上审。默认为1
checkVersion( checkVersion(
url: "$baseUrl$getSystemVersionByNumber", url: "$baseUrl$getSystemVersionByNumber",
versionNumber: versionNumber, method: Method.get,
productNo: productNo, params: {"versionNumber": versionNumber, "productNo": productNo},
onceDay: onceDay,
jumpAppStore: () {
// 跳转AppStore
debugPrint("===== jumpAppStore");
ApkUpdatePlatform.instance.jumpAppStore(appleId);
},
installApk: (String? path) {
// 安装Apk
debugPrint("===== installApk");
ApkUpdatePlatform.instance.installApk(path);
},
downloadApkError: () {
// 下载Apk错误
debugPrint("===== downloadApkError");
// 项目中没有依赖toast,自己项目中实现
downloadApkError?.call();
},
);
}
/// 升级版本(新)
/// url 全路径
/// appleId 苹果应用id
/// params {"versionNumber": 1, "product-code": "carrier-driver-app"}
void updateApp({
required String url,
required Map<String, dynamic> params,
bool onceDay = false,
required String appleId,
Function()? downloadApkError, // 下载Apk错误
}) {
checkVersion(
url: url,
method: Method.post,
params: params,
header: {"product-code": params["productCode"]},
onceDay: onceDay, onceDay: onceDay,
jumpAppStore: () { jumpAppStore: () {
// 跳转AppStore // 跳转AppStore
...@@ -43,6 +79,5 @@ class ApkUpdate { ...@@ -43,6 +79,5 @@ class ApkUpdate {
downloadApkError?.call(); downloadApkError?.call();
}, },
); );
// ApkUpdatePlatform.instance.getPlatformVersion();
} }
} }
...@@ -21,8 +21,9 @@ const dateFormat = "yyyy-MM-dd"; ...@@ -21,8 +21,9 @@ const dateFormat = "yyyy-MM-dd";
/// onceDay 一天提示一次(应用首页设置true) /// onceDay 一天提示一次(应用首页设置true)
void checkVersion({ void checkVersion({
required String url, required String url,
required int versionNumber, required Method method,
required int productNo, Map<String, dynamic>? params,
Map<String, dynamic>? header,
bool onceDay = false, bool onceDay = false,
Function()? jumpAppStore, // 跳转AppStore Function()? jumpAppStore, // 跳转AppStore
Function(String? path)? installApk, // 安装Apk Function(String? path)? installApk, // 安装Apk
...@@ -31,22 +32,13 @@ void checkVersion({ ...@@ -31,22 +32,13 @@ void checkVersion({
try { try {
final Response response = await Dio().request( final Response response = await Dio().request(
url, url,
options: Options(method: 'GET'), options: Options(method: method.value, headers: header),
queryParameters: { queryParameters: params,
"versionNumber": versionNumber, data: params,
"productNo": productNo,
},
); );
// 网络请求成功 // 网络请求成功
_printLog(response); // 打印日志
var responseData = response.data; var responseData = response.data;
var requestOptions = response.requestOptions;
var headers = response.headers;
debugPrint("========== 网络请求成功 ==========\n"
"path:${requestOptions.path}\n"
"method:${requestOptions.method}\n"
"queryParameters:${requestOptions.queryParameters}\n"
"headers:${headers.map}\n\n"
"responseData:$responseData\n");
if (responseData.runtimeType == String) { if (responseData.runtimeType == String) {
// 兼容后端数据返回string // 兼容后端数据返回string
responseData = json.decode(responseData); responseData = json.decode(responseData);
...@@ -80,7 +72,7 @@ void checkVersion({ ...@@ -80,7 +72,7 @@ void checkVersion({
Get.dialog( Get.dialog(
UpdateDialog( UpdateDialog(
title: result['versionName'], title: result['versionName'],
content: result['versionContent'], content: result['tipContent'] ?? result['versionContent'],
isUpdateMore: result['versionForce'] == 1, isUpdateMore: result['versionForce'] == 1,
versionPath: result['versionPath'], versionPath: result['versionPath'],
jumpAppStore: jumpAppStore, jumpAppStore: jumpAppStore,
...@@ -89,8 +81,8 @@ void checkVersion({ ...@@ -89,8 +81,8 @@ void checkVersion({
), ),
); );
} on DioException catch (e) { } on DioException catch (e) {
debugPrint( _printLog(e.response); // 打印日志
"===== 网络请求错误:${e.response?.statusCode} ${e.response?.statusMessage}"); ToastUtil.showToast("服务器请求错误");
} }
} }
...@@ -102,3 +94,31 @@ Future<void> openBrowser(String stringUrl) async { ...@@ -102,3 +94,31 @@ Future<void> openBrowser(String stringUrl) async {
throw Exception('Could not launch $url'); throw Exception('Could not launch $url');
} }
} }
enum Method {
get,
post,
put,
patch,
delete,
}
extension MethodExtension on Method {
String get value => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'][index];
}
/// 日志打印
_printLog(Response? response) {
var responseData = response?.data;
var requestOptions = response?.requestOptions;
var headers = response?.headers;
debugPrint("========== 网络请求响应 ==========\n"
"statusCode:${response?.statusCode} \n"
"statusMessage:${response?.statusMessage}\n"
"method:${requestOptions?.method}\n"
"path:${requestOptions?.path}\n"
"headers:${headers?.map}\n\n"
"queryParameters:${requestOptions?.queryParameters}\n"
"data:${requestOptions?.data}\n"
"responseData:$responseData\n");
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论