diff --git a/star_lock/android/app/build.gradle b/star_lock/android/app/build.gradle index 11d3360c..c76b4c6c 100644 --- a/star_lock/android/app/build.gradle +++ b/star_lock/android/app/build.gradle @@ -31,10 +31,15 @@ android { // 这里“debug”不是一个自定义变量,而是一个特定的关键词,凡是使用--debug模式,都会引用到这里 // 目前看来,debug模式没办法在buildTypes里面按flavors指定编译签名,所有口味的debug模式只能用同一个签名 debug { - storeFile file("starlock.keystore") - storePassword '123456' - keyAlias = 'starlock' - keyPassword '123456' +// storeFile file("starlock.keystore") +// storePassword '123456' +// keyAlias = 'starlock' +// keyPassword '123456' + + storeFile file("sky.jks") + storePassword 'sky2028' + keyAlias = 'upload' + keyPassword 'sky2028' } // 下面的local、pre、sky、xhj 都是自定义变量,自身不起任何作用,而是看哪里引用了它们 local { diff --git a/star_lock/ios/Runner/Runner.entitlements b/star_lock/ios/Runner/Runner.entitlements index ccc11436..c6bac332 100644 --- a/star_lock/ios/Runner/Runner.entitlements +++ b/star_lock/ios/Runner/Runner.entitlements @@ -4,6 +4,8 @@ aps-environment development + com.apple.developer.associated-domains + com.apple.external-accessory.wireless-configuration diff --git a/star_lock/lib/mine/mall/lockMall_logic.dart b/star_lock/lib/mine/mall/lockMall_logic.dart index 43c66f9c..57f62ad8 100644 --- a/star_lock/lib/mine/mall/lockMall_logic.dart +++ b/star_lock/lib/mine/mall/lockMall_logic.dart @@ -1,8 +1,12 @@ +import 'dart:convert'; + import 'package:flutter/material.dart'; +import 'package:fluwx/fluwx.dart'; import 'package:get/get.dart'; import 'package:star_lock/mine/mall/lockMall_entity.dart'; import 'package:star_lock/mine/mall/lockMall_state.dart'; import 'package:star_lock/network/api_repository.dart'; +import 'package:star_lock/tools/pay/wx_pay_tool.dart'; import 'package:star_lock/webview/webview_logic.dart'; import 'package:webview_flutter/webview_flutter.dart'; @@ -40,9 +44,52 @@ class LockMallLogic extends BaseGetXController { ), ); state.mallWebView.loadRequest(Uri.parse(state.lockMallUrl.value)); + // FlutterBridge.postMessage({action:'',data:'{}',callFun:'回调给js的方法'}) + state.mallWebView.addJavaScriptChannel( + "FlutterBridge", + onMessageReceived: (JavaScriptMessage message) async { + flutterBridge(message); + }, + ); + // onMessageReceived } } + //监听webview的调用 + Future flutterBridge(JavaScriptMessage message) async { + final dynamic obj = jsonDecode(message.message); + print(obj); + if (obj is! Map && obj['action'] is String) { + return; + } + String action = obj['action']; + dynamic data = obj['data']; + String? callFun = obj['callFun']; + switch (action) { + case 'WechatPayParams': + //微信支付 + wxPay(data, callFun); + break; + } + } + + //微信支付 + Future wxPay(dynamic data, String? callFun) async { + WxPayTool.pay(WxPayTool.mapToPayment(data), (response) { + if (response is WeChatPaymentResponse) { + Map data = { + 'type': response.type, + 'extData': response.extData, + 'errCode': response.errCode, + 'errStr': response.errStr, + }; + state.mallWebView.runJavaScript( + 'window.$callFun(`${json.encode(data)}`)', + ); + } + }); + } + //判断webview 是否可以有路由可以回退,无则退出当前页面 Future canGoBack(bool didPop) async { bool canGoBack = await state.mallWebView.canGoBack(); diff --git a/star_lock/lib/tools/pay/wx_pay_tool.dart b/star_lock/lib/tools/pay/wx_pay_tool.dart new file mode 100644 index 00000000..fe40b1b3 --- /dev/null +++ b/star_lock/lib/tools/pay/wx_pay_tool.dart @@ -0,0 +1,44 @@ +import 'package:fluwx/fluwx.dart'; + +/// +/// 微信支付 +/// +/// +class WxPayTool { + static bool isInit = false; + static Fluwx fluwx = Fluwx(); + + static init(String appId, String universalLink) { + fluwx.registerApi(appId: appId, universalLink: universalLink); + } + + static Future pay(Payment payment, WeChatResponseSubscriber listener) async { + if (!isInit) { + isInit = true; + await init(payment.appId, '123'); + //回调 + responseListener(WeChatResponse response) { + if (response is WeChatPaymentResponse) { + //支付回调 + listener.call(response); + } + } + //开启监听 + fluwx.addSubscriber(responseListener); + } + fluwx.pay(which: payment); + } + + static Payment mapToPayment(dynamic data) { + Payment payment = Payment( + appId: data['appId'], + partnerId: data['partnerId'], + prepayId: data['prepayId'], + packageValue: data['packageValue'], + nonceStr: data['nonceStr'], + timestamp: int.tryParse(data['timeStamp']) ?? 0, + sign: data['sign'], + ); + return payment; + } +} diff --git a/star_lock/pubspec.yaml b/star_lock/pubspec.yaml index 6ff574dc..96f5c2bb 100644 --- a/star_lock/pubspec.yaml +++ b/star_lock/pubspec.yaml @@ -154,6 +154,7 @@ dependencies: audio_service: ^0.18.12 app_settings: ^5.1.1 flutter_local_notifications: ^17.0.0 + fluwx: ^4.5.5 system_settings: ^2.0.0 dev_dependencies: