Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ethan
/
appframe
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit 24c81ee0
authored
2026-07-06 17:37:22 +0800
by
ethanlamzs
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
处理微信支付问题
1 parent
dfb1fcfe
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
8 deletions
build_ios.sh
lib/bloc/setting/account_cubit.dart
lib/services/subscription_service_ios.dart
build_ios.sh
View file @
24c81ee
...
...
@@ -48,9 +48,9 @@ if [ ! -z "$_rebuild_" ]; then
fi
#16
#
flutter run --dart-define=env=$env --dart-define=version=$_main_ver$_ver -d 00008140-001068C93AB8801C
flutter run --dart-define
=
env
=
$env
--dart-define
=
version
=
$_main_ver$_ver
-d 00008140-001068C93AB8801C
#11
flutter run --dart-define
=
env
=
$env
--dart-define
=
version
=
$_main_ver$_ver
-d 00008030-001C75810E42402E
#
flutter run --dart-define=env=$env --dart-define=version=$_main_ver$_ver -d 00008030-001C75810E42402E
lib/bloc/setting/account_cubit.dart
View file @
24c81ee
...
...
@@ -161,7 +161,8 @@ class AccountCubit extends Cubit<AccountState> {
Future
<
void
>
goLogoff
()
async
{
await
router
.
push
(
'/account/logoff'
,
//'/account/logoff',
'/iosbuytest'
,
extra:
{
'phone'
:
state
.
phone
,
},
...
...
lib/services/subscription_service_ios.dart
View file @
24c81ee
...
...
@@ -13,6 +13,10 @@ class SubscriptionService {
static
const
String
monthlySubId_2
=
'cn.banxe.appframe.membership.2m'
;
static
const
String
monthlySubId_3
=
'cn.banxe.appframe.membership.3m'
;
// 纯粹的数据容器,不继承任何类
final
Map
<
String
,
Map
<
String
,
dynamic
>>
_pendingContexts
=
{};
final
Map
<
String
,
String
>
_orderIdMap
=
{};
// key: productID, value: orderId
final
InAppPurchase
_iap
=
InAppPurchase
.
instance
;
late
StreamSubscription
<
List
<
PurchaseDetails
>>
_purchaseUpdatedSubscription
;
...
...
@@ -64,7 +68,14 @@ class SubscriptionService {
}
// ---------- 购买订阅 ----------
Future
<
bool
>
buySubscription
(
ProductDetails
product
)
async
{
Future
<
bool
>
buySubscription
(
ProductDetails
product
,
String
userId
,
String
tbxStuId
)
async
{
//final orderId = await api.createPendingOrder(...);
final
orderId
=
""
;
_pendingContexts
[
product
.
id
]
=
{
'userId'
:
userId
,
'tbxStuId'
:
tbxStuId
,
"orderId"
:
orderId
};
_orderIdMap
[
product
.
id
]
=
orderId
;
// 按产品 ID 存储
// 订阅必须使用 PurchaseParam 并设置购买类型为订阅
final
PurchaseParam
purchaseParam
=
PurchaseParam
(
productDetails:
product
,
...
...
@@ -88,6 +99,7 @@ class SubscriptionService {
if
(!
_isSubscription
(
purchaseDetails
.
productID
))
continue
;
// 根据交易状态处理
debugPrint
(
"[info] _onPurchaseUpdate status is "
+
purchaseDetails
.
status
.
toString
());
switch
(
purchaseDetails
.
status
)
{
case
PurchaseStatus
.
pending
:
// 等待支付确认(例如需要家长批准),不做处理
...
...
@@ -95,8 +107,10 @@ class SubscriptionService {
case
PurchaseStatus
.
purchased
:
// 购买成功或续期成功
final
orderId
=
_orderIdMap
.
remove
(
purchaseDetails
.
productID
);
// 取出并删除
// 1. 验证收据(必须!)
_verifyReceipt
(
purchaseDetails
);
_verifyReceipt
(
purchaseDetails
,
orderId
??
''
);
// 2. 通知 App Store 交易完成
_iap
.
completePurchase
(
purchaseDetails
);
break
;
...
...
@@ -109,7 +123,7 @@ class SubscriptionService {
case
PurchaseStatus
.
restored
:
// 恢复购买成功
_verifyReceipt
(
purchaseDetails
);
_verifyReceipt
(
purchaseDetails
,
""
);
_iap
.
completePurchase
(
purchaseDetails
);
break
;
...
...
@@ -122,25 +136,28 @@ class SubscriptionService {
}
// ---------- 服务端验证收据 ----------
Future
<
void
>
_verifyReceipt
(
PurchaseDetails
purchaseDetails
)
async
{
Future
<
void
>
_verifyReceipt
(
PurchaseDetails
purchaseDetails
,
String
orderid
)
async
{
if
(
purchaseDetails
.
verificationData
.
serverVerificationData
.
isEmpty
)
{
debugPrint
(
'无收据数据'
);
return
;
}
debugPrint
(
"[info] _verifyReceipt is start "
+
purchaseDetails
.
productID
+
" : "
+
purchaseDetails
.
toString
());
// 将收据发送到你的后端进行验证
final
String
receipt
=
purchaseDetails
.
verificationData
.
serverVerificationData
;
final
bool
isValid
=
await
_sendReceiptToBackend
(
receipt
);
debugPrint
(
"[info] _verifyReceipt is step 1 "
);
if
(
isValid
)
{
// 更新本地订阅状态
_hasActiveSubscription
=
true
;
// 保存到期时间等信息
}
debugPrint
(
"[info] _verifyReceipt is done "
);
}
// 示例:发送收据到自己的服务器进行二次验证
Future
<
bool
>
_sendReceiptToBackend
(
String
receipt
)
async
{
/*
try {
final response = await http.post(
Uri.parse('https://your-server.com/api/verify_receipt'),
...
...
@@ -159,6 +176,9 @@ class SubscriptionService {
debugPrint('验证收据失败: $e');
return false;
}
*/
debugPrint
(
"[info] _sendReceiptToBackend is done receipt is "
+
receipt
);
return
true
;
}
// ---------- 恢复购买 ----------
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment