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 01c75d92
authored
2026-07-07 17:35:00 +0800
by
ethanlamzs
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
测试ios支付
1 parent
1428cf3a
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
26 deletions
build_ios.sh
lib/data/repositories/message/xe_create_order_handler.dart
lib/data/repositories/user_auth_repository.dart
lib/services/dispatcher.dart
lib/services/subscription_service_ios.dart
build_ios.sh
View file @
01c75d9
...
@@ -48,6 +48,9 @@ if [ ! -z "$_rebuild_" ]; then
...
@@ -48,6 +48,9 @@ if [ ! -z "$_rebuild_" ]; then
pod install
pod install
fi
fi
_ver_tmp
=
`
date
'+%y%m%d%H%M'
`
echo
'build '
flutter build ios --build-number
=
$_ver_tmp
#16
#16
if
[
! -z
"
$ot
"
]
;
then
if
[
! -z
"
$ot
"
]
;
then
if
[
"
$ot
"
==
'16'
]
;
then
if
[
"
$ot
"
==
'16'
]
;
then
...
@@ -58,9 +61,7 @@ if [ ! -z "$ot" ]; then
...
@@ -58,9 +61,7 @@ if [ ! -z "$ot" ]; then
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
fi
fi
else
else
_ver_tmp
=
`
date
'+%y%m%d%H%M'
`
echo
'build else '
echo
'build else '
flutter build ios --build-number
=
$_ver_tmp
fi
fi
#11
#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/data/repositories/message/xe_create_order_handler.dart
View file @
01c75d9
...
@@ -59,6 +59,7 @@ class XeCreateOrderHandler extends MessageHandler {
...
@@ -59,6 +59,7 @@ class XeCreateOrderHandler extends MessageHandler {
// 1. 请求后端获取预支付订单信息
// 1. 请求后端获取预支付订单信息
final
deviceType
=
'ios'
;
final
deviceType
=
'ios'
;
print
(
"[debug]. handleMessage 1 "
);
if
(
deviceType
==
'andorid'
){
if
(
deviceType
==
'andorid'
){
await
_wx_pay_proc_
(
userCode
,
tbxStuId
,
chargeCode
,
deviceType
,
phone
,
stuId
,
ext
,
duration
,
durationType
,
totalFee
,
renew
,
useCoin
);
await
_wx_pay_proc_
(
userCode
,
tbxStuId
,
chargeCode
,
deviceType
,
phone
,
stuId
,
ext
,
duration
,
durationType
,
totalFee
,
renew
,
useCoin
);
}
else
if
(
deviceType
==
'ios'
){
}
else
if
(
deviceType
==
'ios'
){
...
@@ -204,11 +205,13 @@ class XeCreateOrderHandler extends MessageHandler {
...
@@ -204,11 +205,13 @@ class XeCreateOrderHandler extends MessageHandler {
var
result
=
await
_userAuthRepository
.
createOrder
(
userCode
,
tbxStuId
,
chargeCode
,
duration
,
durationType
,
totalFee
,
var
result
=
await
_userAuthRepository
.
createOrder
(
userCode
,
tbxStuId
,
chargeCode
,
duration
,
durationType
,
totalFee
,
renew
,
phone
,
stuId
,
ext
,
useCoin
?
1
:
0
,
deviceType
);
renew
,
phone
,
stuId
,
ext
,
useCoin
?
1
:
0
,
deviceType
);
print
(
"[debug]. _ios_pay_proc_ 1 "
);
var
data
=
result
[
'data'
]
as
Map
<
String
,
dynamic
>?;
var
data
=
result
[
'data'
]
as
Map
<
String
,
dynamic
>?;
if
(
data
==
null
)
{
if
(
data
==
null
)
{
throw
Exception
(
'支付参数获取失败'
);
throw
Exception
(
'支付参数获取失败'
);
}
}
print
(
"[debug]. _ios_pay_proc_ 2 "
);
// 3. 从后端响应中提取预支付ID
// 3. 从后端响应中提取预支付ID
final
prepayId
=
data
[
'prepayId'
]
as
String
?;
final
prepayId
=
data
[
'prepayId'
]
as
String
?;
if
(
prepayId
==
null
||
prepayId
.
isEmpty
)
{
if
(
prepayId
==
null
||
prepayId
.
isEmpty
)
{
...
@@ -219,7 +222,7 @@ class XeCreateOrderHandler extends MessageHandler {
...
@@ -219,7 +222,7 @@ class XeCreateOrderHandler extends MessageHandler {
final
timestamp
=
data
[
'timeStamp'
]
as
int
;
final
timestamp
=
data
[
'timeStamp'
]
as
int
;
final
wxTradeNo
=
data
[
'wxTradeNo'
]
as
String
;
final
wxTradeNo
=
data
[
'wxTradeNo'
]
as
String
;
print
(
"[debug]. _ios_pay_proc_ 3 "
);
debugPrint
(
'_ios_pay_proc_ => prepayId:
$prepayId
'
);
debugPrint
(
'_ios_pay_proc_ => prepayId:
$prepayId
'
);
debugPrint
(
'_ios_pay_proc_ => timestamp:
$timestamp
'
);
debugPrint
(
'_ios_pay_proc_ => timestamp:
$timestamp
'
);
debugPrint
(
'_ios_pay_proc_ => wxTradeNo:
$wxTradeNo
'
);
debugPrint
(
'_ios_pay_proc_ => wxTradeNo:
$wxTradeNo
'
);
...
...
lib/data/repositories/user_auth_repository.dart
View file @
01c75d9
...
@@ -162,4 +162,22 @@ class UserAuthRepository {
...
@@ -162,4 +162,22 @@ class UserAuthRepository {
}
}
}
}
// 检查ios的订单是否已经订阅
Future
<
dynamic
>
orderCheck
(
String
userId
,
String
receipt
,
String
orderid
,
String
platform
)
async
{
try
{
Response
resp
=
await
_appService
.
post
(
'/api/v1/comm/user/ordercheck'
,
{
"userId"
:
userId
,
"receipt"
:
receipt
,
"orderid"
:
orderid
,
"platform"
:
platform
,
},
);
return
resp
.
statusCode
==
HttpStatus
.
ok
?
resp
.
data
:
null
;
}
on
DioException
{
return
null
;
}
}
}
}
lib/services/dispatcher.dart
View file @
01c75d9
...
@@ -6,6 +6,7 @@ import 'package:appframe/data/models/message/h5_message.dart';
...
@@ -6,6 +6,7 @@ import 'package:appframe/data/models/message/h5_message.dart';
import
'package:appframe/data/models/message/h5_resp.dart'
;
import
'package:appframe/data/models/message/h5_resp.dart'
;
import
'package:appframe/data/repositories/message/upload_cancel_handler.dart'
;
import
'package:appframe/data/repositories/message/upload_cancel_handler.dart'
;
import
'package:appframe/data/repositories/message/upload_start_handler.dart'
;
import
'package:appframe/data/repositories/message/upload_start_handler.dart'
;
import
'package:flutter/widgets.dart'
;
// 消息处理器抽象类
// 消息处理器抽象类
abstract
class
MessageHandler
{
abstract
class
MessageHandler
{
...
@@ -35,7 +36,7 @@ class MessageDispatcher {
...
@@ -35,7 +36,7 @@ class MessageDispatcher {
Future
<
void
>
dispatch
(
String
message
,
Function
callback
,
{
WebCubit
?
webCubit
})
async
{
Future
<
void
>
dispatch
(
String
message
,
Function
callback
,
{
WebCubit
?
webCubit
})
async
{
final
Map
<
String
,
dynamic
>
data
=
json
.
decode
(
message
);
final
Map
<
String
,
dynamic
>
data
=
json
.
decode
(
message
);
H5Message
h5Message
=
H5Message
.
fromJson
(
data
);
H5Message
h5Message
=
H5Message
.
fromJson
(
data
);
print
(
data
);
var
handler
=
_handlers
[
h5Message
.
cmd
];
var
handler
=
_handlers
[
h5Message
.
cmd
];
if
(
handler
==
null
)
{
if
(
handler
==
null
)
{
try
{
try
{
...
...
lib/services/subscription_service_ios.dart
View file @
01c75d9
...
@@ -3,6 +3,8 @@ import 'dart:async';
...
@@ -3,6 +3,8 @@ import 'dart:async';
import
'package:in_app_purchase/in_app_purchase.dart'
;
import
'package:in_app_purchase/in_app_purchase.dart'
;
import
'package:http/http.dart'
as
http
;
import
'package:http/http.dart'
as
http
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:appframe/data/repositories/user_auth_repository.dart'
;
import
'package:appframe/config/locator.dart'
;
class
SubscriptionService
{
class
SubscriptionService
{
...
@@ -20,6 +22,7 @@ class SubscriptionService {
...
@@ -20,6 +22,7 @@ class SubscriptionService {
final
InAppPurchase
_iap
=
InAppPurchase
.
instance
;
final
InAppPurchase
_iap
=
InAppPurchase
.
instance
;
late
StreamSubscription
<
List
<
PurchaseDetails
>>
_purchaseUpdatedSubscription
;
late
StreamSubscription
<
List
<
PurchaseDetails
>>
_purchaseUpdatedSubscription
;
final
UserAuthRepository
_userAuthRepository
=
getIt
.
get
<
UserAuthRepository
>();
// 可用产品列表
// 可用产品列表
List
<
ProductDetails
>
_products
=
[];
List
<
ProductDetails
>
_products
=
[];
List
<
ProductDetails
>
get
products
=>
_products
;
List
<
ProductDetails
>
get
products
=>
_products
;
...
@@ -32,6 +35,7 @@ class SubscriptionService {
...
@@ -32,6 +35,7 @@ class SubscriptionService {
Future
<
void
>
initialize
()
async
{
Future
<
void
>
initialize
()
async
{
// 1. 检查是否可用
// 1. 检查是否可用
final
bool
available
=
await
_iap
.
isAvailable
();
final
bool
available
=
await
_iap
.
isAvailable
();
if
(!
available
)
{
if
(!
available
)
{
throw
Exception
(
'In-App Purchase 不可用'
);
throw
Exception
(
'In-App Purchase 不可用'
);
}
}
...
@@ -109,6 +113,8 @@ class SubscriptionService {
...
@@ -109,6 +113,8 @@ class SubscriptionService {
// 购买成功或续期成功
// 购买成功或续期成功
final
orderId
=
_orderIdMap
.
remove
(
purchaseDetails
.
productID
);
// 取出并删除
final
orderId
=
_orderIdMap
.
remove
(
purchaseDetails
.
productID
);
// 取出并删除
final
ctx
=
_pendingContexts
[
purchaseDetails
.
productID
];
// 1. 验证收据(必须!)
// 1. 验证收据(必须!)
_verifyReceipt
(
purchaseDetails
,
orderId
??
''
);
_verifyReceipt
(
purchaseDetails
,
orderId
??
''
);
// 2. 通知 App Store 交易完成
// 2. 通知 App Store 交易完成
...
@@ -145,7 +151,7 @@ class SubscriptionService {
...
@@ -145,7 +151,7 @@ class SubscriptionService {
// 将收据发送到你的后端进行验证
// 将收据发送到你的后端进行验证
final
String
receipt
=
purchaseDetails
.
verificationData
.
serverVerificationData
;
final
String
receipt
=
purchaseDetails
.
verificationData
.
serverVerificationData
;
final
bool
isValid
=
await
_sendReceiptToBackend
(
receipt
);
final
bool
isValid
=
await
_sendReceiptToBackend
(
receipt
,
orderid
);
debugPrint
(
"[info] _verifyReceipt is step 1 "
);
debugPrint
(
"[info] _verifyReceipt is step 1 "
);
if
(
isValid
)
{
if
(
isValid
)
{
// 更新本地订阅状态
// 更新本地订阅状态
...
@@ -156,27 +162,11 @@ class SubscriptionService {
...
@@ -156,27 +162,11 @@ class SubscriptionService {
}
}
// 示例:发送收据到自己的服务器进行二次验证
// 示例:发送收据到自己的服务器进行二次验证
Future
<
bool
>
_sendReceiptToBackend
(
String
receipt
)
async
{
Future
<
bool
>
_sendReceiptToBackend
(
String
receipt
,
String
orderid
)
async
{
/*
try {
var
result
=
_userAuthRepository
.
orderCheck
(
""
,
receipt
,
orderid
,
"ios"
);
final response = await http.post(
//var data = result['data'] as Map<String, dynamic>?;
Uri.parse('https://your-server.com/api/verify_receipt'),
//debugPrint(result);
headers: {'Content-Type': 'application/json'},
body: {
'receipt': receipt,
'platform': 'ios',
},
);
if (response.statusCode == 200) {
// 解析你的服务器返回的订阅状态
return true;
}
return false;
} catch (e) {
debugPrint('验证收据失败: $e');
return false;
}
*/
debugPrint
(
"[info] _sendReceiptToBackend is done receipt is "
+
receipt
);
debugPrint
(
"[info] _sendReceiptToBackend is done receipt is "
+
receipt
);
return
true
;
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