Commit 01c75d92 by ethanlamzs

测试ios支付

1 parent 1428cf3a
......@@ -48,6 +48,9 @@ if [ ! -z "$_rebuild_" ]; then
pod install
fi
_ver_tmp=`date '+%y%m%d%H%M'`
echo 'build '
flutter build ios --build-number=$_ver_tmp
#16
if [ ! -z "$ot" ]; then
if [ "$ot" == '16' ]; then
......@@ -58,9 +61,7 @@ if [ ! -z "$ot" ]; then
flutter run --dart-define=env=$env --dart-define=version=$_main_ver$_ver -d 00008030-001C75810E42402E
fi
else
_ver_tmp=`date '+%y%m%d%H%M'`
echo 'build else '
flutter build ios --build-number=$_ver_tmp
fi
#11
#flutter run --dart-define=env=$env --dart-define=version=$_main_ver$_ver -d 00008030-001C75810E42402E
......
......@@ -59,6 +59,7 @@ class XeCreateOrderHandler extends MessageHandler {
// 1. 请求后端获取预支付订单信息
final deviceType = 'ios';
print("[debug]. handleMessage 1 ");
if (deviceType == 'andorid'){
await _wx_pay_proc_(userCode, tbxStuId, chargeCode, deviceType, phone, stuId, ext, duration, durationType, totalFee, renew, useCoin);
}else if (deviceType == 'ios'){
......@@ -204,11 +205,13 @@ class XeCreateOrderHandler extends MessageHandler {
var result = await _userAuthRepository.createOrder(userCode, tbxStuId, chargeCode, duration, durationType, totalFee,
renew, phone, stuId, ext, useCoin ? 1 : 0, deviceType);
print("[debug]. _ios_pay_proc_ 1 ");
var data = result['data'] as Map<String, dynamic>?;
if (data == null) {
throw Exception('支付参数获取失败');
}
print("[debug]. _ios_pay_proc_ 2 ");
// 3. 从后端响应中提取预支付ID
final prepayId = data['prepayId'] as String?;
if (prepayId == null || prepayId.isEmpty) {
......@@ -219,7 +222,7 @@ class XeCreateOrderHandler extends MessageHandler {
final timestamp = data['timeStamp'] as int;
final wxTradeNo = data['wxTradeNo'] as String;
print("[debug]. _ios_pay_proc_ 3 ");
debugPrint('_ios_pay_proc_ => prepayId: $prepayId');
debugPrint('_ios_pay_proc_ => timestamp: $timestamp');
debugPrint('_ios_pay_proc_ => wxTradeNo: $wxTradeNo');
......
......@@ -162,4 +162,22 @@ class UserAuthRepository {
}
}
// 检查ios的订单是否已经订阅
Future<dynamic> orderCheck(String userId,String receipt,String orderid, String platform) async {
try {
Response resp = await _appService.post(
'/api/v1/comm/user/ordercheck',
{
"userId": userId,
"receipt": receipt,
"orderid":orderid,
"platform": platform,
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
}
......@@ -6,6 +6,7 @@ import 'package:appframe/data/models/message/h5_message.dart';
import 'package:appframe/data/models/message/h5_resp.dart';
import 'package:appframe/data/repositories/message/upload_cancel_handler.dart';
import 'package:appframe/data/repositories/message/upload_start_handler.dart';
import 'package:flutter/widgets.dart';
// 消息处理器抽象类
abstract class MessageHandler {
......@@ -35,7 +36,7 @@ class MessageDispatcher {
Future<void> dispatch(String message, Function callback, {WebCubit? webCubit}) async {
final Map<String, dynamic> data = json.decode(message);
H5Message h5Message = H5Message.fromJson(data);
print(data);
var handler = _handlers[h5Message.cmd];
if (handler == null) {
try {
......
......@@ -3,6 +3,8 @@ import 'dart:async';
import 'package:in_app_purchase/in_app_purchase.dart';
import 'package:http/http.dart' as http;
import 'package:flutter/widgets.dart';
import 'package:appframe/data/repositories/user_auth_repository.dart';
import 'package:appframe/config/locator.dart';
class SubscriptionService {
......@@ -20,6 +22,7 @@ class SubscriptionService {
final InAppPurchase _iap = InAppPurchase.instance;
late StreamSubscription<List<PurchaseDetails>> _purchaseUpdatedSubscription;
final UserAuthRepository _userAuthRepository = getIt.get<UserAuthRepository>();
// 可用产品列表
List<ProductDetails> _products = [];
List<ProductDetails> get products => _products;
......@@ -32,6 +35,7 @@ class SubscriptionService {
Future<void> initialize() async {
// 1. 检查是否可用
final bool available = await _iap.isAvailable();
if (!available) {
throw Exception('In-App Purchase 不可用');
}
......@@ -72,7 +76,7 @@ class SubscriptionService {
//final orderId = await api.createPendingOrder(...);
final orderId = yWOrderId;
_pendingContexts[product.id] = {'userId': userId,'tbxStuId': tbxStuId,"orderId":orderId};
_orderIdMap[product.id] = orderId; // 按产品 ID 存储
......@@ -109,6 +113,8 @@ class SubscriptionService {
// 购买成功或续期成功
final orderId = _orderIdMap.remove(purchaseDetails.productID); // 取出并删除
final ctx = _pendingContexts[purchaseDetails.productID];
// 1. 验证收据(必须!)
_verifyReceipt(purchaseDetails,orderId??'');
// 2. 通知 App Store 交易完成
......@@ -145,7 +151,7 @@ class SubscriptionService {
// 将收据发送到你的后端进行验证
final String receipt = purchaseDetails.verificationData.serverVerificationData;
final bool isValid = await _sendReceiptToBackend(receipt);
final bool isValid = await _sendReceiptToBackend(receipt,orderid);
debugPrint("[info] _verifyReceipt is step 1 ");
if (isValid) {
// 更新本地订阅状态
......@@ -156,31 +162,15 @@ class SubscriptionService {
}
// 示例:发送收据到自己的服务器进行二次验证
Future<bool> _sendReceiptToBackend(String receipt) async {
/*
try {
final response = await http.post(
Uri.parse('https://your-server.com/api/verify_receipt'),
headers: {'Content-Type': 'application/json'},
body: {
'receipt': receipt,
'platform': 'ios',
},
);
if (response.statusCode == 200) {
// 解析你的服务器返回的订阅状态
return true;
}
return false;
} catch (e) {
debugPrint('验证收据失败: $e');
return false;
}
*/
Future<bool> _sendReceiptToBackend(String receipt,String orderid) async {
var result = _userAuthRepository.orderCheck("",receipt,orderid,"ios");
//var data = result['data'] as Map<String, dynamic>?;
//debugPrint(result);
debugPrint("[info] _sendReceiptToBackend is done receipt is "+receipt);
return true;
}
// ---------- 恢复购买 ----------
Future<void> restorePurchases() async {
await _iap.restorePurchases();
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!