feat:webview处理Scheme,和携带公共UA头
This commit is contained in:
parent
4cd6e49564
commit
abbef04d6c
@ -66,7 +66,7 @@ keytool -list -v -keystore android/app/sky.jks
|
||||
|
||||
## 编译
|
||||
```bash
|
||||
flutter build apk --split-per-abi --release --flavor sky -t lib/main_sky.dart
|
||||
flutter build apk --release --flavor sky -t lib/main_sky_full.dart
|
||||
```
|
||||
编译后的包:
|
||||
通用:build/app/outputs/apk/sky/release/app-sky-universal-release.apk
|
||||
|
||||
@ -11,13 +11,16 @@ enum Flavor {
|
||||
class StarLockAMapKey {
|
||||
//iOS平台的key
|
||||
final String iosKey;
|
||||
|
||||
//Android平台的key
|
||||
final String androidKey;
|
||||
|
||||
const StarLockAMapKey({required this.iosKey, required this.androidKey});
|
||||
}
|
||||
|
||||
class F {
|
||||
static Flavor? appFlavor;
|
||||
|
||||
// 是否为精简模式(在一些应用商店场景下,需要精简掉一些功能)
|
||||
static bool isLite = false;
|
||||
|
||||
@ -77,22 +80,20 @@ class F {
|
||||
throw Exception('flavor[$name] apiPrefix not found');
|
||||
}
|
||||
}
|
||||
|
||||
// StarLockAMapKey
|
||||
static StarLockAMapKey get aMapKey {
|
||||
switch (appFlavor) {
|
||||
case Flavor.xie:
|
||||
case Flavor.dev:
|
||||
return const StarLockAMapKey(
|
||||
androidKey: 'b56b681ee89f4db43a5aa1879ae8cbfe',
|
||||
iosKey: 'bd4496e6598ef49796e3a80715035b4d');
|
||||
androidKey: 'b56b681ee89f4db43a5aa1879ae8cbfe', iosKey: 'bd4496e6598ef49796e3a80715035b4d');
|
||||
case Flavor.pre:
|
||||
return const StarLockAMapKey(
|
||||
androidKey: '11d49b3f4fc09c04a02bbb7500925ba2',
|
||||
iosKey: '883a3355d2d77c2fdc2667030dc97ffe');
|
||||
androidKey: '11d49b3f4fc09c04a02bbb7500925ba2', iosKey: '883a3355d2d77c2fdc2667030dc97ffe');
|
||||
case Flavor.sky:
|
||||
return const StarLockAMapKey(
|
||||
androidKey: 'fb0d2a3e4208b36452cf636aa025a24f',
|
||||
iosKey: '86ca725a12a629c280e116a317aaba19');
|
||||
androidKey: 'fb0d2a3e4208b36452cf636aa025a24f', iosKey: '86ca725a12a629c280e116a317aaba19');
|
||||
// case Flavor.xhj:
|
||||
// return const StarLockAMapKey(
|
||||
// androidKey: 'todo',
|
||||
@ -101,5 +102,4 @@ class F {
|
||||
throw Exception('flavor[$name] aMapKey not found');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:star_lock/webview/webview_logic.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
class LockMallState {
|
||||
@ -7,5 +8,16 @@ class LockMallState {
|
||||
var webProgress = 0.0.obs;
|
||||
late WebViewController mallWebView = WebViewController()
|
||||
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
||||
..setBackgroundColor(Colors.white);
|
||||
..setBackgroundColor(Colors.white)
|
||||
..setUserAgent(WebViewLogic.userAgent)
|
||||
..setNavigationDelegate(NavigationDelegate(onNavigationRequest: onNavigationRequest));
|
||||
|
||||
//路由跳转逻辑
|
||||
Future<NavigationDecision> onNavigationRequest(NavigationRequest request) async {
|
||||
if (WebViewLogic.judgePaySchemes(request.url)) {
|
||||
await WebViewLogic.runScheme(request.url);
|
||||
return NavigationDecision.prevent;
|
||||
}
|
||||
return NavigationDecision.navigate;
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,9 +7,16 @@ import 'package:star_lock/login/login/entity/LoginData.dart';
|
||||
import '../tools/platform_info_services.dart';
|
||||
import '../tools/storage.dart';
|
||||
|
||||
FutureOr<Request> requestInterceptor(Request request) async {
|
||||
request.headers['User-Agent'] =
|
||||
//公共获取UA
|
||||
String getUserAgent() {
|
||||
//赋值变量方便调试
|
||||
String ua =
|
||||
'StarLock/${PlatformInfoService.to.info.version}/${PlatformInfoService.to.info.buildNumber}/${GetPlatform.isAndroid ? 'Android' : 'iOS'}';
|
||||
return ua;
|
||||
}
|
||||
|
||||
FutureOr<Request> requestInterceptor(Request request) async {
|
||||
request.headers['User-Agent'] = getUserAgent();
|
||||
request.headers['Accept-Language'] = 'zh-CN';
|
||||
// request.headers['Content-Type'] = 'application/json';
|
||||
// request.headers['token'] = StoreService.to.userToken!;
|
||||
|
||||
35
star_lock/lib/webview/webview_logic.dart
Normal file
35
star_lock/lib/webview/webview_logic.dart
Normal file
@ -0,0 +1,35 @@
|
||||
import 'package:star_lock/network/request_interceptor.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
///
|
||||
/// webview的工具类
|
||||
/// 功能:
|
||||
/// * 管理Schemes的跳转
|
||||
/// * webview的UA表示
|
||||
///
|
||||
class WebViewLogic {
|
||||
//pay的Scheme 列表
|
||||
static const List<String> paySchemes = ['weixin:', 'alipay:'];
|
||||
|
||||
//获取公共UA信息
|
||||
static String get userAgent => getUserAgent();
|
||||
|
||||
//判断是否是支付的Scheme
|
||||
static bool judgePaySchemes(String url) {
|
||||
for (int i = 0, j = paySchemes.length; i < j; i++) {
|
||||
if (url.contains(paySchemes[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//运行支付的Scheme业务逻辑
|
||||
static Future<void> runScheme(String url) async {
|
||||
if (await canLaunchUrl(Uri.parse(url))) {
|
||||
await launchUrl(Uri.parse(url));
|
||||
} else {
|
||||
throw 'Could not launch $url';
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user