优化:支付走内购的逻辑改为当pay URL为空的时候才走内购
This commit is contained in:
parent
4ef714453e
commit
a83c76edab
@ -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*
|
||||
|
||||
@ -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 一致)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user