优化:支付走内购的逻辑改为当pay URL为空的时候才走内购

This commit is contained in:
ivan 2026-03-29 15:31:51 +08:00
parent 4ef714453e
commit a83c76edab
2 changed files with 386 additions and 343 deletions

View File

@ -3,7 +3,7 @@
## 通用信息 ## 通用信息
| 项目 | 值 | | 项目 | 值 |
|------|----| | ------- | ------------------------------------------ |
| 加密方式 | AES-128-ECB, PKCS5Padding, Base64 | | 加密方式 | AES-128-ECB, PKCS5Padding, Base64 |
| AES Key | `liyP4LkMfP68XvCt` | | AES Key | `liyP4LkMfP68XvCt` |
| 预发域名 | `pre-ai.petsheroai.xyz` | | 预发域名 | `pre-ai.petsheroai.xyz` |
@ -7088,7 +7088,7 @@ V2 完整响应体 (解密后):
## 错误码 ## 错误码
| code | 说明 | | code | 说明 |
|------|------| | ---- | ----------- |
| 0 | 成功 | | 0 | 成功 |
| -1 | 失败 | | -1 | 失败 |
| -2 | 系统错误 | | -2 | 系统错误 |
@ -7101,8 +7101,8 @@ V2 完整响应体 (解密后):
## 字段映射全表 ## 字段映射全表
| 原始字段 | V2字段 | | 原始字段 | V2字段 |
|----------|--------| | ---------------------- | ------------- |
| User_token | knight | | User\_token | knight |
| accountId | wizard | | accountId | wizard |
| accountName | captain | | accountName | captain |
| activityId | warrior | | activityId | warrior |
@ -7184,7 +7184,7 @@ V2 完整响应体 (解密后):
| face | dash | | face | dash |
| faceIndex | leap | | faceIndex | leap |
| faceInfos | strike | | faceInfos | strike |
| face_index | parry | | face\_index | parry |
| feature | dodge | | feature | dodge |
| features | scout | | features | scout |
| feedbackId | track | | feedbackId | track |
@ -7207,7 +7207,7 @@ V2 完整响应体 (解密后):
| forcePayCenter | upgrade | | forcePayCenter | upgrade |
| fps | notification | | fps | notification |
| frameIndex | unite | | frameIndex | unite |
| frame_index | pledge | | frame\_index | pledge |
| freeBlurTimes | vow | | freeBlurTimes | vow |
| freeTimes | decree | | freeTimes | decree |
| gender | venture | | gender | venture |
@ -7404,5 +7404,6 @@ V2 完整响应体 (解密后):
| y1 | configure | | y1 | configure |
| y2 | manufacture | | y2 | manufacture |
--- ***
*本文档由 ProtocolEncTool 自动生成API 变更后请重新执行生成命令。*
*本文档由 ProtocolEncTool 自动生成API 变更后请重新执行生成命令。transplant*

View File

@ -1,6 +1,7 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_lucide/flutter_lucide.dart'; import 'package:flutter_lucide/flutter_lucide.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../core/adjust/adjust_events.dart'; import '../../core/adjust/adjust_events.dart';
import '../../core/api/api_config.dart'; import '../../core/api/api_config.dart';
@ -38,6 +39,11 @@ class _RechargeScreenState extends State<RechargeScreen>
/// code item Buy loading /// code item Buy loading
String? _loadingProductId; String? _loadingProductId;
///
String? _pendingOrderId;
String? _pendingUserId;
double? _pendingPurchaseAmount;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -61,6 +67,23 @@ class _RechargeScreenState extends State<RechargeScreen>
mounted) { mounted) {
setState(() => _loadingProductId = null); setState(() => _loadingProductId = null);
} }
//
if (state == AppLifecycleState.resumed &&
_pendingOrderId != null &&
_pendingUserId != null &&
_pendingPurchaseAmount != null &&
mounted) {
_startOrderPolling(
orderId: _pendingOrderId!,
userId: _pendingUserId!,
purchaseAmount: _pendingPurchaseAmount!,
);
//
_pendingOrderId = null;
_pendingUserId = null;
_pendingPurchaseAmount = null;
}
} }
Future<void> _fetchActivities() async { Future<void> _fetchActivities() async {
@ -260,23 +283,38 @@ class _RechargeScreenState extends State<RechargeScreen>
: null; : null;
final orderId = data?['federation']?.toString(); final orderId = data?['federation']?.toString();
if (_isGooglePay(paymentMethod, subPaymentMethod)) { final purchaseAmount =
(AdjustEvents.parsePrice(item.actualAmount) ?? 0).toDouble();
final payUrl = data?['convert']?.toString();
final openType = data?['transplant'] as int?;
if (_shouldUseGooglePay(payUrl)) {
await _launchGooglePlayPurchase(item, await _launchGooglePlayPurchase(item,
serverOrderId: orderId, userId: userId); serverOrderId: orderId, userId: userId);
return; return;
} }
final purchaseAmount =
(AdjustEvents.parsePrice(item.actualAmount) ?? 0).toDouble();
final payUrl = data?['convert']?.toString();
if (payUrl != null && payUrl.isNotEmpty) { if (payUrl != null && payUrl.isNotEmpty) {
if (mounted) { if (mounted) {
setState(() => _loadingProductId = null); setState(() => _loadingProductId = null);
if (_shouldUseSystemBrowser(openType)) {
//
await launchUrl(Uri.parse(payUrl), mode: LaunchMode.externalApplication);
// didChangeAppLifecycleState
_pendingOrderId = orderId;
_pendingUserId = userId;
_pendingPurchaseAmount = purchaseAmount;
_showSnackBar(
context, 'Order created. Complete payment in the browser.');
} else {
//
await Navigator.of(context).push( await Navigator.of(context).push(
MaterialPageRoute<void>( MaterialPageRoute<void>(
builder: (_) => PaymentWebViewScreen(paymentUrl: payUrl), builder: (_) => PaymentWebViewScreen(paymentUrl: payUrl),
), ),
); );
//
if (mounted && orderId != null && orderId.isNotEmpty) { if (mounted && orderId != null && orderId.isNotEmpty) {
_startOrderPolling( _startOrderPolling(
orderId: orderId, orderId: orderId,
@ -287,6 +325,7 @@ class _RechargeScreenState extends State<RechargeScreen>
_showSnackBar( _showSnackBar(
context, 'Order created. Complete payment in the page.'); context, 'Order created. Complete payment in the page.');
} }
}
} else { } else {
if (mounted) { if (mounted) {
setState(() => _loadingProductId = null); setState(() => _loadingProductId = null);
@ -354,11 +393,14 @@ class _RechargeScreenState extends State<RechargeScreen>
poll(0); poll(0);
} }
/// ceremony==GooglePay resource==GOOGLEPAY /// payUrl
static bool _isGooglePay(String paymentMethod, String? subPaymentMethod) { static bool _shouldUseGooglePay(String? payUrl) {
final r = paymentMethod.trim().toLowerCase(); return payUrl == null || payUrl.isEmpty;
final c = (subPaymentMethod ?? '').trim().toLowerCase(); }
return r == 'googlepay' || c == 'googlepay';
/// openType 0=1==
static bool _shouldUseSystemBrowser(int? openType) {
return openType == 1;
} }
/// false Google Pay /// false Google Pay