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