优化:支付走内购的逻辑改为当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 Key | `liyP4LkMfP68XvCt` |
| 预发域名 | `pre-ai.petsheroai.xyz` |
@ -7088,7 +7088,7 @@ V2 完整响应体 (解密后):
## 错误码
| code | 说明 |
|------|------|
| ---- | ----------- |
| 0 | 成功 |
| -1 | 失败 |
| -2 | 系统错误 |
@ -7101,8 +7101,8 @@ V2 完整响应体 (解密后):
## 字段映射全表
| 原始字段 | V2字段 |
|----------|--------|
| User_token | knight |
| ---------------------- | ------------- |
| User\_token | knight |
| accountId | wizard |
| accountName | captain |
| activityId | warrior |
@ -7184,7 +7184,7 @@ V2 完整响应体 (解密后):
| face | dash |
| faceIndex | leap |
| faceInfos | strike |
| face_index | parry |
| face\_index | parry |
| feature | dodge |
| features | scout |
| feedbackId | track |
@ -7207,7 +7207,7 @@ V2 完整响应体 (解密后):
| forcePayCenter | upgrade |
| fps | notification |
| frameIndex | unite |
| frame_index | pledge |
| frame\_index | pledge |
| freeBlurTimes | vow |
| freeTimes | decree |
| gender | venture |
@ -7404,5 +7404,6 @@ V2 完整响应体 (解密后):
| y1 | configure |
| y2 | manufacture |
---
*本文档由 ProtocolEncTool 自动生成API 变更后请重新执行生成命令。*
***
*本文档由 ProtocolEncTool 自动生成API 变更后请重新执行生成命令。transplant*

View File

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