From 9782273038efde82cbd78820a70b7e57fd82077c Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Wed, 19 Nov 2025 17:55:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=94=AF=E4=BB=98=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 18 ++++++++++++++++++ lib/data/services/pay_service.dart | 6 +----- pubspec.yaml | 3 ++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4d98d097a..e08b80ab5 100644 --- a/README.md +++ b/README.md @@ -40,3 +40,21 @@ lib/ │ └─ main.dart # 程序入口 ``` +### 本地调试内购(IAP)流程 + +不需要真实购买即可在本地跑通前端内购流程: + +- 在项目根目录的环境变量文件(如 `.env`)里添加: + +``` +APP_IAP_MOCK=1 +``` + +- 作用:在 `PayService` 中启用“本地内购模拟”,调用 `processGooglePayment` 或 `processApplePayment` 会: + - 立即触发“已发起内购(本地模拟)”; + - 短暂延时后触发“支付处理中…(本地模拟)”; + - 再触发“支付成功(本地模拟)”。 + +- 注意:该模式不依赖 Google Play / App Store 安装来源,也不会进行服务器收据校验,仅用于前端 UI 与状态机验证。 + +- 关闭模拟:将 `APP_IAP_MOCK` 移除或设为 `0/false`,恢复真实内购流程。 diff --git a/lib/data/services/pay_service.dart b/lib/data/services/pay_service.dart index 1f8fe1882..abda1ca0a 100644 --- a/lib/data/services/pay_service.dart +++ b/lib/data/services/pay_service.dart @@ -287,7 +287,7 @@ class PayService extends GetxService { } /// 构建 Apple/Google 主动查询(pay_askorder)所需的验证参数 - /// 返回与后端 PayAskOrCancelReq 对应的 Map + /// 返回与后端 PayAskOrCancelReq 对应的 Map(不再携带 apple_sandbox) Future> buildIapAskParams() async { final params = {}; if (_lastOrderId != null && _lastOrderId!.isNotEmpty) { @@ -301,12 +301,8 @@ class PayService extends GetxService { final txId = _lastIapPurchase?.purchaseID ?? ''; // 是否按交易ID校验,默认 false,可通过环境变量开启 final useTxIdEnv = _getEnvBool('APP_IAP_USE_TXID', defaultValue: false); - // 沙箱标识,默认在非发布模式下认为是沙箱;支持环境变量覆盖 - final sandbox = - _getEnvBool('APP_IAP_SANDBOX', defaultValue: !kReleaseMode); params['apple_receipt_data'] = useTxIdEnv ? txId : receiptOrData; params['apple_use_transaction_id'] = useTxIdEnv; - params['apple_sandbox'] = sandbox; } else if (platform == 'android') { final packageInfo = await PackageInfo.fromPlatform(); final pkg = packageInfo.packageName; diff --git a/pubspec.yaml b/pubspec.yaml index 52bdd5bc4..5943a452f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: voitrans description: "Voitrans - AI Voice Assistant." publish_to: "none" -version: 1.0.18+54 +version: 1.0.18+57 environment: sdk: ">=3.3.0 <4.0.0" @@ -66,6 +66,7 @@ dependencies: tobias: ^5.2.0 # 支付宝SDK url_launcher: ^6.3.1 in_app_purchase: ^3.1.11 + in_app_purchase_android: ^0.4.0+5 firebase_core: ^4.0.0 firebase_auth: ^6.0.1 google_sign_in: ^6.2.2