diff --git a/circle_app/lib/app/circle/widgets/info_list_view.dart b/circle_app/lib/app/circle/widgets/info_list_view.dart index 242ad91..8226118 100644 --- a/circle_app/lib/app/circle/widgets/info_list_view.dart +++ b/circle_app/lib/app/circle/widgets/info_list_view.dart @@ -1,6 +1,5 @@ import 'package:cached_network_image/cached_network_image.dart'; -import 'package:circle_app/app/call_out/logic.dart'; import 'package:circle_app/app/circle/logic.dart'; import 'package:circle_app/app/circle/state.dart'; import 'package:circle_app/app/circle/widgets/list_logic.dart'; @@ -159,10 +158,12 @@ class _InfoListViewState extends State with AutomaticKeepAliveClie void pushMsgPage(Lists bean, String cicleId) async { - // if (widget.bean.is_limit) { - // showJoinCiclePiker(cicleId,widget.bean.amount.toString(),widget.bean.oldAmount.toString(),2); - // return; - // } + if (widget.bean.is_limit&&widget.bean.amount>0) { + showJoinCiclePiker(cicleId,widget.bean.amount.toString(),widget.bean.oldAmount.toString(),2,(payResult){ + widget.bean.is_limit = false; + }); + return; + } var sp = await SharedPreferencesHelper.getInstance(); String myUserId = sp.getMyUserId(); @@ -181,29 +182,8 @@ class _InfoListViewState extends State with AutomaticKeepAliveClie @override Widget build(BuildContext context) { - TextSpan descSpan; - // widget.bean.intro = widget.bean.intro+widget.bean.intro+widget.bean.intro+widget.bean.intro+widget.bean.intro; - TextSpan span; - if (widget.bean.intro.length > 20) { - String truncatedText = widget.bean.intro.substring(0, 60)+"..."; - descSpan = TextSpan( - text: truncatedText, - style: TextStyle(color: Colors.white, fontSize: 10.sp), - ); - span = TextSpan( - text: '查看更多', - style: TextStyle(color: Color(0xFFFF4DF6), fontSize: 10.sp), - ); - } else { - descSpan = TextSpan( - text: widget.bean.intro, - style: TextStyle(color: Colors.white, fontSize: 10.sp), - ); - span = TextSpan( - text: '', - style: TextStyle(color: Color(0xFFFF4DF6), fontSize: 10.sp), - ); - } + + List urlList = widget.bean.lastJoinUsers; List widgets = []; @@ -272,7 +252,7 @@ class _InfoListViewState extends State with AutomaticKeepAliveClie margin: EdgeInsets.only(bottom: 7.sp), width: Get.width, height: 30.sp, - child: HideText(text: widget.bean.intro,additionText: '查看更多',maxLines: 2,style: TextStyle(color: Colors.white, fontSize: 10.sp),additionStyle: TextStyle(color: Color(0xFFFF4DF6), fontSize: 10.sp),onTap: () { + child: HideText(text: widget.bean.intro,additionText: '查看更多',maxLines: 2,style: TextStyle(color: Colors.white, fontSize: 10.sp),additionStyle: TextStyle(color: const Color(0xFFFF4DF6), fontSize: 10.sp),onTap: () { _showTextContentDialog( context, widget.bean.intro); },), @@ -538,11 +518,10 @@ class _InfoListViewState extends State with AutomaticKeepAliveClie double picHeight = 0.0; - int type = 0; + if (lists.album != null) { if (lists.album!.isNotEmpty) { - Album info = lists.album!.first!; - type = info.type!; + Album info = lists.album!.first; if (info.type == 1) { if (lists.album!.length > 3) { @@ -615,7 +594,7 @@ class _InfoListViewState extends State with AutomaticKeepAliveClie } if (widget.bean.is_limit) { showJoinCiclePiker(widget.bean.id.toString(),widget.bean.amount.toString(),widget.bean.oldAmount.toString(),1,(payResult){ - + widget.bean.is_limit = false; }); return; } @@ -713,7 +692,7 @@ class _InfoListViewState extends State with AutomaticKeepAliveClie child: picHeight == 140.sp ? ClipRRect( borderRadius: BorderRadius.circular(6.sp), - child: VideoItemWidget(lists.album![0]!.url!)) + child: VideoItemWidget(lists.album![0].url!)) : GridView.builder( itemCount: lists.album!.length, physics: const NeverScrollableScrollPhysics(), @@ -822,12 +801,9 @@ class _InfoListViewState extends State with AutomaticKeepAliveClie ); double picHeight = 0.0; - - int type = 0; if (lists.album != null) { if (lists.album!.isNotEmpty) { - Album info = lists.album!.first!; - type = info.type!; + Album info = lists.album!.first; if (info.type == 1) { if (lists.album!.length > 3) { @@ -843,7 +819,7 @@ class _InfoListViewState extends State with AutomaticKeepAliveClie List widgets = []; int index = 0; - lists!.chat!.users!.forEach((element) { + lists.chat!.users!.forEach((element) { widgets.add(Positioned( left: 12.sp * index, child: GestureDetector( @@ -911,9 +887,9 @@ class _InfoListViewState extends State with AutomaticKeepAliveClie Get.toNamed(AppRoutes.UserInfoActivity, arguments: ""); return; } - if (widget.bean.is_limit) { + if (widget.bean.is_limit&&widget.bean.amount > 0) { showJoinCiclePiker(widget.bean.id.toString(),widget.bean.amount.toString(),widget.bean.oldAmount.toString(),1,(payResult){ - + widget.bean.is_limit = false; }); return; } @@ -931,7 +907,7 @@ class _InfoListViewState extends State with AutomaticKeepAliveClie lists.user!.avatar!, width: 40.sp, height: 40.sp, - fit: BoxFit.fill, + fit: BoxFit.cover, ), ) ], @@ -946,7 +922,7 @@ class _InfoListViewState extends State with AutomaticKeepAliveClie Row( children: [ Text( - lists.user!.nickname! ?? '', + lists.user!.nickname!, style: TextStyle( color: Colors.white, fontSize: 18.sp, diff --git a/circle_app/lib/app/report/view.dart b/circle_app/lib/app/report/view.dart index a344973..c0b8c5c 100644 --- a/circle_app/lib/app/report/view.dart +++ b/circle_app/lib/app/report/view.dart @@ -117,7 +117,7 @@ class ReportPage extends StatelessWidget { ), Positioned( // right: 1.sp, - top: 160.sp, + top: 150.sp, child: Text( '${controller.textEditingController.text.length}/200', style: TextStyle( diff --git a/circle_app/lib/common/Widgets/base_tip_widget.dart b/circle_app/lib/common/Widgets/base_tip_widget.dart index ec9d937..e6b7a88 100644 --- a/circle_app/lib/common/Widgets/base_tip_widget.dart +++ b/circle_app/lib/common/Widgets/base_tip_widget.dart @@ -1,6 +1,6 @@ +import 'dart:io'; import 'dart:math'; -import 'package:alipay_kit/alipay_kit.dart'; import 'package:circle_app/util/util.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -10,242 +10,251 @@ import '../../network/api.dart'; import '../../network/dio_manager.dart'; import '../../util/PaymentUtils.dart'; import 'open_vip_tip/logic.dart'; + bool isZfbPrice = true; -joiinCircileTipWdiget(String cicleId,String pirce,String oldPrice,String title,MyCallback myCallback) { - return StatefulBuilder( - builder:(BuildContext context, StateSetter setState) { - return Scaffold( - backgroundColor: Colors.transparent, - body: Container( - width: Get.width, - height: Get.height, + +joiinCircileTipWdiget(String cicleId, String pirce, String oldPrice, + String title, MyCallback myCallback) { + return StatefulBuilder(builder: (BuildContext context, StateSetter setState) { + return Scaffold( + backgroundColor: Colors.transparent, + body: Container( + width: Get.width, + height: Get.height, + alignment: Alignment.center, + child: Stack( alignment: Alignment.center, - child: - Stack( - alignment: Alignment.center, - children: [ - Container( - width: 339.sp, - height: 330.sp, - decoration: BoxDecoration( - image: DecorationImage( - fit: BoxFit.fill, - image: AssetImage(getCircleImage('add_tip_bg'))))), - Positioned( - top: 5.sp, - right: 12.sp, - child: GestureDetector( - onTap: () { - Get.back(); - }, - child: Image.asset( - getCircleImage('close'), - width: 24.sp, - ), - )), - Positioned( - top: 24.sp, - child: Text( - title, - style: TextStyle(color: Colors.white, fontSize: 16.sp), - )), - Positioned( - left: 17.sp, - top: 64.sp, - child: Text( - '为什么要解锁圈子?', - style: TextStyle(color: Colors.white, fontSize: 16.sp), - )), - Positioned( - top: 98.sp, - child: Container( - width: 339.sp, - padding: EdgeInsets.only(left: 17.sp, right: 17.sp), - child: Text( - '为打造纯净的社交环境,更好地服务大家,基于以下几方面考虑:1、平台升级为全天24小时人工审核,保证用户真实,避免骗子、酒托、虚假人士等扰乱平台 ;2、杜绝未入圈用户随意骚扰或影响已入圈的;3、谢绝只会白嫖的猎奇人士。', - style: TextStyle( - color: Color.fromRGBO(247, 250, 250, 0.8), - fontSize: 12.sp)), - )), - Positioned( - bottom: 108.sp, + children: [ + Container( + width: 339.sp, + height: 330.sp, + decoration: BoxDecoration( + image: DecorationImage( + fit: BoxFit.fill, + image: AssetImage(getCircleImage('add_tip_bg'))))), + Positioned( + top: 5.sp, + right: 12.sp, + child: GestureDetector( + onTap: () { + Get.back(); + }, + child: Image.asset( + getCircleImage('close'), + width: 24.sp, + ), + )), + Positioned( + top: 24.sp, + child: Text( + title, + style: TextStyle(color: Colors.white, fontSize: 16.sp), + )), + Positioned( + left: 17.sp, + top: 64.sp, + child: Text( + '为什么要解锁圈子?', + style: TextStyle(color: Colors.white, fontSize: 16.sp), + )), + Positioned( + top: 98.sp, child: Container( - margin: EdgeInsets.only(top: 24.0.sp), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - GestureDetector( - onTap: () { - setState(() { - isZfbPrice = true; - }); - }, - child: Row( - children: [ - Image.asset( - isZfbPrice - ? getMineImage("icon_pay_select") - : getMineImage("icon_pay_is_no_select"), - width: 20.0.sp, - height: 20.0.sp, + width: 339.sp, + padding: EdgeInsets.only(left: 17.sp, right: 17.sp), + child: Text( + '为打造纯净的社交环境,更好地服务大家,基于以下几方面考虑:1、平台升级为全天24小时人工审核,保证用户真实,避免骗子、酒托、虚假人士等扰乱平台 ;2、杜绝未入圈用户随意骚扰或影响已入圈的;3、谢绝只会白嫖的猎奇人士。', + style: TextStyle( + color: Color.fromRGBO(247, 250, 250, 0.8), + fontSize: 12.sp)), + )), + Platform.isIOS + ? Container() + : Positioned( + bottom: 108.sp, + child: Container( + margin: EdgeInsets.only(top: 24.0.sp), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + GestureDetector( + onTap: () { + setState(() { + isZfbPrice = true; + }); + }, + child: Row( + children: [ + Image.asset( + isZfbPrice + ? getMineImage("icon_pay_select") + : getMineImage("icon_pay_is_no_select"), + width: 20.0.sp, + height: 20.0.sp, + ), + SizedBox(width: 8.0.sp), + Image.asset( + getMineImage('icon_cooperate_ali'), + width: 20.0.sp, + height: 20.0.sp, + ), + SizedBox(width: 4.0.sp), + Text( + '支付宝支付', + style: TextStyle( + color: Color(0xFFF7FAFA), + fontSize: 14.0.sp, + ), + ), + SizedBox(width: 4.0.sp), + Image.asset( + getMineImage('icon_recommend_pay_way'), + width: 32.0.sp, + height: 16.0.sp, + ), + ], ), - SizedBox(width: 8.0.sp), - Image.asset( - getMineImage('icon_cooperate_ali'), - width: 20.0.sp, - height: 20.0.sp, + ), + SizedBox(width: 24.0.sp), + GestureDetector( + onTap: () { + setState(() { + isZfbPrice = false; + }); + }, + child: Row( + children: [ + Image.asset( + !isZfbPrice + ? getMineImage("icon_pay_select") + : getMineImage("icon_pay_is_no_select"), + width: 20.0.sp, + height: 20.0.sp, + ), + SizedBox(width: 8.0.sp), + Image.asset( + getMineImage('icon_cooperate_wx'), + width: 20.0.sp, + height: 20.0.sp, + ), + SizedBox(width: 4.0.sp), + Text( + '微信支付', + style: TextStyle( + color: Color(0xFFF7FAFA), + fontSize: 14.0.sp, + ), + ), + ], ), - SizedBox(width: 4.0.sp), - Text( - '支付宝支付', - style: TextStyle( - color: Color(0xFFF7FAFA), - fontSize: 14.0.sp, - ), - ), - SizedBox(width: 4.0.sp), - Image.asset( - getMineImage('icon_recommend_pay_way'), - width: 32.0.sp, - height: 16.0.sp, - ), - ], - ), + ), + ], ), - SizedBox(width: 24.0.sp), - GestureDetector( - onTap: () { - setState(() { - isZfbPrice = false; - }); - }, - child: Row( - children: [ - Image.asset( - !isZfbPrice - ? getMineImage("icon_pay_select") - : getMineImage("icon_pay_is_no_select"), - width: 20.0.sp, - height: 20.0.sp, - ), - SizedBox(width: 8.0.sp), - Image.asset( - getMineImage('icon_cooperate_wx'), - width: 20.0.sp, - height: 20.0.sp, - ), - SizedBox(width: 4.0.sp), - Text( - '微信支付', - style: TextStyle( - color: Color(0xFFF7FAFA), - fontSize: 14.0.sp, - ), - ), - ], + ), + ), + Positioned( + bottom: 18.sp, + child: GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () { + if (Platform.isIOS) { + } else { + unlockingPayment(cicleId, myCallback); + } + }, + child: Container( + width: 168.sp, + height: 42.sp, + alignment: Alignment.center, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(21.sp), + gradient: const LinearGradient( + begin: Alignment.centerLeft, + end: Alignment.centerRight, + colors: [Color(0xff0AFCFF), Color(0xffD739EA)])), + child: Text( + '立即解锁', + style: TextStyle(color: Colors.white, fontSize: 16.sp), + ), + ), + )), + Positioned( + bottom: 72.sp, + child: Container( + child: Row( + children: [ + Text( + '¥$pirce', + style: TextStyle( + color: Color(0xffE845FF), + fontSize: 16.sp, + fontWeight: FontWeight.w600), + ), + SizedBox( + width: 2.sp, + ), + Text( + '(原价$oldPrice)', + style: TextStyle( + color: Colors.white70, + fontSize: 16.sp, + fontWeight: FontWeight.w400, + decoration: TextDecoration.lineThrough, + decorationColor: Colors.white70, ), ), ], ), - ), - ), - - Positioned( - bottom: 18.sp, - child: GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: (){ - unlockingPayment(myCallback); - }, - child: Container( - width: 168.sp, - height: 42.sp, - alignment: Alignment.center, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(21.sp), - gradient: const LinearGradient( - begin: Alignment.centerLeft, - end: Alignment.centerRight, - colors: [Color(0xff0AFCFF), Color(0xffD739EA)])), - child: Text( - '立即解锁', - style: TextStyle(color: Colors.white, fontSize: 16.sp), - ), - ), - )), - Positioned( - bottom: 72.sp, - child: Container( - child: Row( - children: [ - Text( - '¥$pirce', - style: TextStyle( - color: Color(0xffE845FF), - fontSize: 16.sp, - fontWeight: FontWeight.w600), - ), - SizedBox( - width: 2.sp, - ), - Text( - '(原价$oldPrice)', - style: TextStyle( - color: Colors.white70, - fontSize: 16.sp, - fontWeight: FontWeight.w400, - decoration: TextDecoration.lineThrough, - decorationColor: Colors.white70, - ), - ), - ], - ), - )) - ], - ), + )) + ], ), - - ); - }); + ), + ); + }); } - unlockingPayment(MyCallback myCallback)async{ - if (isZfbPrice) { - var data = await DioManager.instance.post(url: Api.postAliPayOrder, params: { - //"product_id": priceBean[index].id, - "type": 1}); - var bean = BaseResponse.fromJson(data, (data) => PayUrlBean.fromJson(data)); - if(bean.isSuccess()){ - var data = await AlipayKitPlatform.instance.pay( - orderInfo: bean.data.payUrl, - isShowLoading :true - ); - }else { - showToast(bean.msg); - } - } else{ - initWxApi(); - var data = await DioManager.instance.post(url: Api.postWxOrder, params: { - // "product_id": priceBean[index].id, - "type": 1}); - var bean = BaseResponse.fromJson(data, (data) => PaymentData.fromJson(data)); - if(bean.isSuccess()){ - openWxPay(bean.data); - }else { - showToast(bean.msg); - } - } - - } +unlockingPayment(String cicleId, MyCallback myCallback) async { + if (isZfbPrice) { + var data = await DioManager.instance.post( + url: Api.postAliPayOrder, params: {"product_id": cicleId, "type": 1}); + var bean = BaseResponse.fromJson( + data, (data) => PayUrlBean.fromJson(data)); + if (bean.isSuccess()) { + openAliPay(bean.data.payUrl, (isSuccess, errorMsg) { + if (isSuccess) { + myCallback(true); + } + }); + // showToast(data.toString()); + } else { + showToast(bean.msg); + } + } else { + var data = await DioManager.instance + .post(url: Api.postWxOrder, params: {"product_id": cicleId, "type": 1}); + var bean = BaseResponse.fromJson( + data, (data) => PaymentData.fromJson(data)); + if (bean.isSuccess()) { + openWxPay(bean.data, (bool isSuccess, String? errorMessage) { + if (isSuccess) { + myCallback(true); + } else { + // 处理支付失败,errorMessage 可能为 null + } + }); + } else { + showToast(bean.msg); + } + } +} typedef void MyCallback(bool payResult); - showJoinCiclePiker(String cicleId,String pirce,String oldPrice,int type,MyCallback payResult) { - - String title = ['解锁圈子才能发布喊话','解锁圈子才能查看主页','解锁圈子才能主动私聊'][type]; +showJoinCiclePiker(String cicleId, String pirce, String oldPrice, int type, + MyCallback payResult) { + String title = ['解锁圈子才能发布喊话', '解锁圈子才能查看主页', '解锁圈子才能主动私聊'][type]; return Get.bottomSheet( - joiinCircileTipWdiget(cicleId,pirce,oldPrice,title,payResult), - isScrollControlled: true, - enableDrag: false - ); -} \ No newline at end of file + joiinCircileTipWdiget(cicleId, pirce, oldPrice, title, payResult), + isScrollControlled: true, + enableDrag: false); +} diff --git a/circle_app/lib/common/Widgets/open_vip_tip/logic.dart b/circle_app/lib/common/Widgets/open_vip_tip/logic.dart index 198517e..aa282cd 100644 --- a/circle_app/lib/common/Widgets/open_vip_tip/logic.dart +++ b/circle_app/lib/common/Widgets/open_vip_tip/logic.dart @@ -1,6 +1,4 @@ -import 'dart:convert'; -import 'package:alipay_kit/alipay_kit.dart'; import 'package:circle_app/util/util.dart'; import 'package:get/get.dart'; @@ -8,7 +6,6 @@ import '../../../network/api.dart'; import '../../../network/dio_manager.dart'; import '../../../util/PaymentUtils.dart'; import 'state.dart'; -import 'package:fluwx/fluwx.dart' as fluwx; class Open_vip_tipLogic extends GetxController { List priceBean = []; @@ -33,20 +30,28 @@ class Open_vip_tipLogic extends GetxController { var data = await DioManager.instance.post(url: Api.postAliPayOrder, params: {"product_id": priceBean[index].id, "type": 2}); var bean = BaseResponse.fromJson(data, (data) => PayUrlBean.fromJson(data)); if(bean.isSuccess()){ - AlipayKitPlatform.instance.pay( - orderInfo: bean.data.payUrl, - isShowLoading :true - ); + openAliPay(bean.data.payUrl,(isSuccess,errorMsg){ + if (isSuccess) { + // 处理支付成功 + } else { + // 处理支付失败,errorMessage 可能为 null + } + }); }else { showToast(bean.msg); } } else{ - initWxApi(); var data = await DioManager.instance.post(url: Api.postWxOrder, params: {"product_id": priceBean[index].id, "type": 2}); var bean = BaseResponse.fromJson(data, (data) => PaymentData.fromJson(data)); if(bean.isSuccess()){ - openWxPay(bean.data); + openWxPay(bean.data,(bool isSuccess, String? errorMessage) { + if (isSuccess) { + // 处理支付成功 + } else { + // 处理支付失败,errorMessage 可能为 null + } + }); }else { showToast(bean.msg); } @@ -55,13 +60,6 @@ class Open_vip_tipLogic extends GetxController { } -//注册微信 -void initWxApi() { - fluwx.registerWxApi( - appId: "wx6c6f4c89465dac4b", - universalLink: "dcc5bd5012a417eb585684700fbd1307", - ); -} diff --git a/circle_app/lib/common/Widgets/open_vip_tip/view.dart b/circle_app/lib/common/Widgets/open_vip_tip/view.dart index efa5023..f7b7f60 100644 --- a/circle_app/lib/common/Widgets/open_vip_tip/view.dart +++ b/circle_app/lib/common/Widgets/open_vip_tip/view.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:circle_app/util/util.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -117,7 +119,7 @@ class Open_vip_tipPage extends StatelessWidget { controller, controller.index == 2, 2), ], ))), - Positioned( + Platform.isIOS ? Container(): Positioned( bottom: 108.sp, child: Container( margin: EdgeInsets.only(top: 24.0.sp), @@ -200,7 +202,12 @@ class Open_vip_tipPage extends StatelessWidget { child: GestureDetector( behavior: HitTestBehavior.opaque, onTap: (){ - controller.startPayment(); + if( Platform.isIOS){ + + }else{ + controller.startPayment(); + } + }, child: Container( width: 168.sp, diff --git a/circle_app/lib/main.dart b/circle_app/lib/main.dart index 8bf6280..d6f8917 100644 --- a/circle_app/lib/main.dart +++ b/circle_app/lib/main.dart @@ -2,6 +2,7 @@ import 'package:circle_app/app/splash/binding.dart'; import 'package:circle_app/router/app_pages.dart'; import 'package:circle_app/router/app_routers.dart'; +import 'package:circle_app/util/PaymentUtils.dart'; import 'package:circle_app/util/util.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -60,6 +61,7 @@ class _MyAppState extends State { @override void initState() { initIM(); + initWxApi(); loadBgImage(); super.initState(); } diff --git a/circle_app/lib/util/PaymentUtils.dart b/circle_app/lib/util/PaymentUtils.dart index ba47155..e9034ce 100644 --- a/circle_app/lib/util/PaymentUtils.dart +++ b/circle_app/lib/util/PaymentUtils.dart @@ -1,17 +1,35 @@ +import 'dart:async'; + +import 'package:alipay_kit/alipay_kit.dart'; import 'package:circle_app/util/util.dart'; import '../common/Widgets/open_vip_tip/logic.dart'; import 'package:fluwx/fluwx.dart' as fluwx; + + + +//注册微信 +void initWxApi() { + fluwx.registerWxApi( + appId: "wx6c6f4c89465dac4b", + universalLink: "dcc5bd5012a417eb585684700fbd1307", + ); +} + //微信支付 -Future openWxPay(PaymentData data) async { - //是否安装微信 +typedef WxPayCallback = void Function(bool isSuccess, String? errorMessage); + +Future openWxPay(PaymentData data, WxPayCallback callback) async { + // 是否安装微信 bool isInstalled = await fluwx.isWeChatInstalled; if (!isInstalled) { showToast("请先安装微信"); + callback(false, "请先安装微信"); return; } - //调起支付 + + // 调起支付 fluwx.payWithWeChat( appId: data.appId, partnerId: data.mchId, @@ -21,12 +39,51 @@ Future openWxPay(PaymentData data) async { timeStamp: int.parse(data.timestamp), sign: data.sign, ); - //监听微信回调 + + // 监听微信回调 fluwx.weChatResponseEventHandler.listen((event) { - if(event.isSuccessful) { + if (event.isSuccessful) { showToast("微信支付成功"); + callback(true, null); } else { - showToast(event.errStr??"微信支付成功"); + showToast(event.errStr ?? "微信支付失败"); + callback(false, event.errStr); } }); -} \ No newline at end of file +} +late final StreamSubscription _paySubs; +/// 返回码,标识支付状态,含义如下: +/// 9000——订单支付成功 下面的result有值 +/// 8000——正在处理中 +/// 4000——订单支付失败 +/// 5000——重复请求 +/// 6001——用户中途取消 +/// 6002——网络连接出错 +void _listenPay(AlipayResp resp) { + final String content = 'pay: ${resp.resultStatus} - ${resp.result}'; + if(resp.resultStatus == 9000){ + callback(true,resp.result); + }else{ + callback(false,resp.result); + } + + print(content ); +} +late WxPayCallback callback ; +openAliPay(String payUrl,WxPayCallback myCallback)async{ + callback = myCallback; + bool isInstalled =await AlipayKitPlatform.instance.isInstalled(); + if (!isInstalled) { + showToast("请先安装支付宝"); + return; + } + if(null==_paySubs){ + _paySubs = AlipayKitPlatform.instance.payResp().listen(_listenPay); + } + + + var data = await AlipayKitPlatform.instance.pay( + orderInfo: payUrl, + isShowLoading :true + ); +}