Commit 8c9ea6ca by ethanlamzs

调试ios的支付

1 parent 02ea609e
......@@ -54,6 +54,6 @@ flutter run --dart-define=env=$env --dart-define=version=$_main_ver$_ver -d 0000
#flutter run --dart-define=env=$env --dart-define=version=$_main_ver$_ver -d 00008030-001C75810E42402E
flutter build ios --build-number=$_ver
#flutter build ios --build-number=$_ver
......@@ -6,6 +6,8 @@ import 'package:appframe/config/locator.dart';
import 'package:appframe/data/repositories/user_auth_repository.dart';
import 'package:appframe/services/dispatcher.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_localization/flutter_localization.dart';
import 'package:appframe/services/subscription_service_ios.dart';
import 'package:fluwx/fluwx.dart';
class XeCreateOrderHandler extends MessageHandler {
......@@ -19,6 +21,8 @@ class XeCreateOrderHandler extends MessageHandler {
// 超时定时器
Timer? _timeoutTimer;
final SubscriptionService _subService = SubscriptionService();
XeCreateOrderHandler() {
_fluwx = getIt.get<Fluwx>();
_userAuthRepository = getIt.get<UserAuthRepository>();
......@@ -26,6 +30,8 @@ class XeCreateOrderHandler extends MessageHandler {
@override
Future<dynamic> handleMessage(params) async {
print("handleMessage "+params);
// 从 params 中提取支付参数
final String chargeCode = params['chargeCode'] as String? ?? '';
final int durationType = params['durationType'] as int? ?? 0;
......@@ -50,13 +56,27 @@ class XeCreateOrderHandler extends MessageHandler {
'phone=$phone, userCode=$userCode, tbxStuId=$tbxStuId, stuId=$stuId, '
'ext=$ext');
// 1. 检查微信是否安装
// 1. 请求后端获取预支付订单信息
final deviceType = 'ios';
if (deviceType == 'andorid'){
await _wx_pay_proc_(userCode, tbxStuId, chargeCode, deviceType, phone, stuId, ext, duration, durationType, totalFee, renew, useCoin);
}else if (deviceType == 'ios'){
// 暂时不支持使用学币扣减
await _ios_pay_proc_(userCode, tbxStuId, chargeCode, deviceType, phone, stuId, ext, duration, durationType, totalFee, renew, 0);
}
}
// 执行微信支付
Future<dynamic> _wx_pay_proc_ (String userCode, tbxStuId, chargeCode,deviceType,phone,stuId,ext,int duration, durationType, totalFee,bool renew, useCoin) async{
// 2. 检查微信是否安装
if (!await _fluwx.isWeChatInstalled) {
throw Exception('设备上未安装微信App,不支持微信支付');
}
// 2. 请求后端获取预支付订单信息
final deviceType = 'android';
var result = await _userAuthRepository.createOrder(userCode, tbxStuId, chargeCode, duration, durationType, totalFee,
renew, phone, stuId, ext, useCoin ? 1 : 0, deviceType);
if (result == null) {
......@@ -83,14 +103,14 @@ class XeCreateOrderHandler extends MessageHandler {
final paySign = data['paySign'] as String;
final wxTradeNo = data['wxTradeNo'] as String;
debugPrint('prepayId: $prepayId');
debugPrint('nonceStr: $nonceStr');
debugPrint('timestamp: $timestamp');
debugPrint('paySign: $paySign');
debugPrint('appId: $appId');
debugPrint('partnerId: $partnerId');
debugPrint('packageValue: $packageValue');
debugPrint('wxTradeNo: $wxTradeNo');
debugPrint('_wx_pay_proc_ => prepayId: $prepayId');
debugPrint('_wx_pay_proc_ => nonceStr: $nonceStr');
debugPrint('_wx_pay_proc_ => timestamp: $timestamp');
debugPrint('_wx_pay_proc_ => paySign: $paySign');
debugPrint('_wx_pay_proc_ => appId: $appId');
debugPrint('_wx_pay_proc_ => partnerId: $partnerId');
debugPrint('_wx_pay_proc_ => packageValue: $packageValue');
debugPrint('_wx_pay_proc_ => wxTradeNo: $wxTradeNo');
if (nonceStr.isEmpty || paySign.isEmpty || wxTradeNo.isEmpty) {
throw Exception('支付参数获取失败');
......@@ -155,6 +175,8 @@ class XeCreateOrderHandler extends MessageHandler {
} finally {
_cleanup();
}
}
/// Fluwx 响应监听器
......@@ -174,4 +196,50 @@ class XeCreateOrderHandler extends MessageHandler {
_timeoutTimer = null;
_payCompleter = null;
}
// 执行ios的微信支付
Future<dynamic> _ios_pay_proc_ (String userCode, tbxStuId, chargeCode,deviceType,phone,stuId,ext,int duration, durationType, totalFee,bool renew, useCoin) async{
var result = await _userAuthRepository.createOrder(userCode, tbxStuId, chargeCode, duration, durationType, totalFee,
renew, phone, stuId, ext, useCoin ? 1 : 0, deviceType);
var data = result['data'] as Map<String, dynamic>?;
if (data == null) {
throw Exception('支付参数获取失败');
}
// 3. 从后端响应中提取预支付ID
final prepayId = data['prepayId'] as String?;
if (prepayId == null || prepayId.isEmpty) {
throw Exception('预支付订单ID获取失败');
}
// 4. 从后端响应中提取支付参数(nonceStr、timestamp、paySign 由后端生成)
final timestamp = data['timeStamp'] as int;
final wxTradeNo = data['wxTradeNo'] as String;
debugPrint('_ios_pay_proc_ => prepayId: $prepayId');
debugPrint('_ios_pay_proc_ => timestamp: $timestamp');
debugPrint('_ios_pay_proc_ => wxTradeNo: $wxTradeNo');
if (wxTradeNo.isEmpty) {
throw Exception('支付参数获取失败');
}
// 执行ios支付
await _subService.initialize();
// 为了调试,先模拟
final product = _subService.products[0];
_subService.buySubscription(product, userCode, tbxStuId,wxTradeNo);
}
}
......@@ -68,11 +68,11 @@ class SubscriptionService {
}
// ---------- 购买订阅 ----------
Future<bool> buySubscription(ProductDetails product, String userId , String tbxStuId) async {
Future<bool> buySubscription(ProductDetails product, String userId , String tbxStuId, String yWOrderId) async {
//final orderId = await api.createPendingOrder(...);
final orderId = "";
final orderId = yWOrderId;
_pendingContexts[product.id] = {'userId': userId,'tbxStuId': tbxStuId,"orderId":orderId};
_orderIdMap[product.id] = orderId; // 按产品 ID 存储
......
......@@ -31,7 +31,7 @@ class _SubscriptionPageState extends State<SubscriptionPage> {
Future<void> _buy(ProductDetails product) async {
if (!_isInitialized) return;
try {
await _subService.buySubscription(product);
await _subService.buySubscription(product,"","","");
} catch (e) {
// 显示出错信息
debugPrint(e.toString());
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!