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 1d8c2b03
authored
2026-07-17 16:54:13 +0800
by
ethanlamzs
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
test
1 parent
cf893e75
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
19 deletions
lib/services/subscription_service_ios.dart
lib/services/subscription_service_ios.dart
View file @
1d8c2b0
...
@@ -86,8 +86,8 @@ class SubscriptionService {
...
@@ -86,8 +86,8 @@ class SubscriptionService {
}
}
// ---------- 购买订阅 ----------
// ---------- 购买订阅 ----------
Future
<
bool
>
buySubscription
(
ProductDetails
product
,
String
userId
,
String
tbxStuId
,
String
yWOrderId
)
async
{
Future
<
bool
>
buySubscription
(
ProductDetails
product
,
String
userId
,
String
tbxStuId
,
String
yWOrderId
)
async
{
_pendingContexts
[
product
.
id
]
=
{
'userId'
:
userId
,
'tbxStuId'
:
tbxStuId
,
"orderId"
:
yWOrderId
};
_pendingContexts
[
product
.
id
]
=
{
'userId'
:
userId
,
'tbxStuId'
:
tbxStuId
,
"orderId"
:
yWOrderId
};
_orderIdMap
[
product
.
id
]
=
yWOrderId
;
// 按产品 ID 存储
_orderIdMap
[
product
.
id
]
=
yWOrderId
;
// 按产品 ID 存储
...
@@ -201,7 +201,7 @@ class SubscriptionService {
...
@@ -201,7 +201,7 @@ class SubscriptionService {
}
}
// ---------- 服务端验证收据 ----------
// ---------- 服务端验证收据 ----------
Future
<
void
>
_verifyReceipt
(
PurchaseDetails
purchaseDetails
,
String
orderid
,
String
userid
,
String
scence
)
async
{
Future
<
bool
>
_verifyReceipt
(
PurchaseDetails
purchaseDetails
,
String
orderid
,
String
userid
,
String
scence
)
async
{
debugPrint
(
"[info] _verifyReceipt is checking 3 ["
+
scence
+
"] "
+
purchaseDetails
.
productID
+
" orderid:"
+
orderid
+
" userid:"
+
userid
);
debugPrint
(
"[info] _verifyReceipt is checking 3 ["
+
scence
+
"] "
+
purchaseDetails
.
productID
+
" orderid:"
+
orderid
+
" userid:"
+
userid
);
if
(
orderid
!=
null
&&
orderid
.
length
>
6
)
{
if
(
orderid
!=
null
&&
orderid
.
length
>
6
)
{
debugPrint
(
"[info] _verifyReceipt is start scence ["
+
scence
+
"] "
+
purchaseDetails
.
productID
+
" orderid:"
+
orderid
);
debugPrint
(
"[info] _verifyReceipt is start scence ["
+
scence
+
"] "
+
purchaseDetails
.
productID
+
" orderid:"
+
orderid
);
...
@@ -215,22 +215,20 @@ class SubscriptionService {
...
@@ -215,22 +215,20 @@ class SubscriptionService {
_hasActiveSubscription
=
true
;
_hasActiveSubscription
=
true
;
// 保存到期时间等信息
// 保存到期时间等信息
}
}
return
isValid
;
}
}
return
false
;
}
}
// 示例:发送收据到自己的服务器进行二次验证
// 示例:发送收据到自己的服务器进行二次验证
Future
<
bool
>
_sendReceiptToBackend
(
String
userid
,
String
receipt
,
String
orderid
)
async
{
Future
<
bool
>
_sendReceiptToBackend
(
String
userid
,
String
receipt
,
String
orderid
)
async
{
var
result
=
await
_userAuthRepository
.
orderCheck
(
userid
,
receipt
,
orderid
,
"ios"
,
1
);
var
result
=
_userAuthRepository
.
orderCheck
(
userid
,
receipt
,
orderid
,
"ios"
,
1
);
//var data = result['data'] as Map<String, dynamic>?;
//debugPrint(result);
debugPrint
(
"[info] _sendReceiptToBackend is done"
);
debugPrint
(
"[info] _sendReceiptToBackend is done"
);
return
true
;
return
result
!=
null
;
}
}
// ---------- 辅助方法 ----------
// ---------- 辅助方法 ----------
bool
_isSubscription
(
String
productId
)
{
bool
_isSubscription
(
String
productId
)
{
return
productId
==
monthlySubId_1
||
productId
==
monthlySubId_3
||
productId
==
monthlySubId_6
||
productId
==
monthlySubId_12
;
return
productId
==
monthlySubId_1
||
productId
==
monthlySubId_3
||
productId
==
monthlySubId_6
||
productId
==
monthlySubId_12
;
...
@@ -242,18 +240,19 @@ class SubscriptionService {
...
@@ -242,18 +240,19 @@ class SubscriptionService {
}
}
// ---------- 购买成功处理 ----------
// ---------- 购买成功处理 ----------
void
_handlePurchaseSuccess
(
PurchaseDetails
detail
,
String
orderId
,
String
userId
)
{
Future
<
void
>
_handlePurchaseSuccess
(
PurchaseDetails
detail
,
String
orderId
,
String
userId
)
async
{
// 发送收据到后端验证,携带 userId
// 发送收据到后端验证,携带 userId
_verifyReceipt
(
detail
,
orderId
??
''
,
userId
??
''
,
"purchased"
);
final
ok
=
await
_verifyReceipt
(
detail
,
orderId
??
''
,
userId
??
''
,
"purchased"
);
if
(
ok
){
// 完成交易
_iap
.
completePurchase
(
detail
);
// 乐观更新本地状态(等后端最终确认再真正解锁功能)
_hasActiveSubscription
=
true
;
_hasActiveSubscription
=
true
;
onSuccess
?.
call
(
'订阅成功'
);
if
(
detail
.
pendingCompletePurchase
){
onStateChanged
?.
call
();
await
_iap
.
completePurchase
(
detail
);
}
}
else
{
// 不complete
// 等待下次重新验证
}
}
}
// ---------- 恢复成功处理 ----------
// ---------- 恢复成功处理 ----------
...
...
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