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, 'https://lock.skychip.top/apple-app-site-association.json'); //回调 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; } }