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 8c9ea6ca
authored
2026-07-06 21:22:17 +0800
by
ethanlamzs
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
调试ios的支付
1 parent
02ea609e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
16 deletions
build_ios.sh
lib/data/repositories/message/xe_create_order_handler.dart
lib/services/subscription_service_ios.dart
lib/ui/pages/subscription_page.dart
build_ios.sh
View file @
8c9ea6c
...
@@ -54,6 +54,6 @@ flutter run --dart-define=env=$env --dart-define=version=$_main_ver$_ver -d 0000
...
@@ -54,6 +54,6 @@ flutter run --dart-define=env=$env --dart-define=version=$_main_ver$_ver -d 0000
#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
flutter build ios --build-number
=
$_ver
#
flutter build ios --build-number=$_ver
lib/data/repositories/message/xe_create_order_handler.dart
View file @
8c9ea6c
...
@@ -6,6 +6,8 @@ import 'package:appframe/config/locator.dart';
...
@@ -6,6 +6,8 @@ import 'package:appframe/config/locator.dart';
import
'package:appframe/data/repositories/user_auth_repository.dart'
;
import
'package:appframe/data/repositories/user_auth_repository.dart'
;
import
'package:appframe/services/dispatcher.dart'
;
import
'package:appframe/services/dispatcher.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter_localization/flutter_localization.dart'
;
import
'package:appframe/services/subscription_service_ios.dart'
;
import
'package:fluwx/fluwx.dart'
;
import
'package:fluwx/fluwx.dart'
;
class
XeCreateOrderHandler
extends
MessageHandler
{
class
XeCreateOrderHandler
extends
MessageHandler
{
...
@@ -19,6 +21,8 @@ class XeCreateOrderHandler extends MessageHandler {
...
@@ -19,6 +21,8 @@ class XeCreateOrderHandler extends MessageHandler {
// 超时定时器
// 超时定时器
Timer
?
_timeoutTimer
;
Timer
?
_timeoutTimer
;
final
SubscriptionService
_subService
=
SubscriptionService
();
XeCreateOrderHandler
()
{
XeCreateOrderHandler
()
{
_fluwx
=
getIt
.
get
<
Fluwx
>();
_fluwx
=
getIt
.
get
<
Fluwx
>();
_userAuthRepository
=
getIt
.
get
<
UserAuthRepository
>();
_userAuthRepository
=
getIt
.
get
<
UserAuthRepository
>();
...
@@ -26,6 +30,8 @@ class XeCreateOrderHandler extends MessageHandler {
...
@@ -26,6 +30,8 @@ class XeCreateOrderHandler extends MessageHandler {
@override
@override
Future
<
dynamic
>
handleMessage
(
params
)
async
{
Future
<
dynamic
>
handleMessage
(
params
)
async
{
print
(
"handleMessage "
+
params
);
// 从 params 中提取支付参数
// 从 params 中提取支付参数
final
String
chargeCode
=
params
[
'chargeCode'
]
as
String
?
??
''
;
final
String
chargeCode
=
params
[
'chargeCode'
]
as
String
?
??
''
;
final
int
durationType
=
params
[
'durationType'
]
as
int
?
??
0
;
final
int
durationType
=
params
[
'durationType'
]
as
int
?
??
0
;
...
@@ -50,13 +56,27 @@ class XeCreateOrderHandler extends MessageHandler {
...
@@ -50,13 +56,27 @@ class XeCreateOrderHandler extends MessageHandler {
'phone=
$phone
, userCode=
$userCode
, tbxStuId=
$tbxStuId
, stuId=
$stuId
, '
'phone=
$phone
, userCode=
$userCode
, tbxStuId=
$tbxStuId
, stuId=
$stuId
, '
'ext=
$ext
'
);
'ext=
$ext
'
);
// 1. 检查微信是否安装
// 1. 请求后端获取预支付订单信息
final
deviceType
=
'ios'
;
if
(
deviceType
==
'andorid'
){
await
_wx_pay_proc_
(
userCode
,
tbxStuId
,
chargeCode
,
deviceType
,
phone
,
stuId
,
ext
,
duration
,
durationType
,
totalFee
,
renew
,
useCoin
);
}
else
if
(
deviceType
==
'ios'
){
// 暂时不支持使用学币扣减
await
_ios_pay_proc_
(
userCode
,
tbxStuId
,
chargeCode
,
deviceType
,
phone
,
stuId
,
ext
,
duration
,
durationType
,
totalFee
,
renew
,
0
);
}
}
// 执行微信支付
Future
<
dynamic
>
_wx_pay_proc_
(
String
userCode
,
tbxStuId
,
chargeCode
,
deviceType
,
phone
,
stuId
,
ext
,
int
duration
,
durationType
,
totalFee
,
bool
renew
,
useCoin
)
async
{
// 2. 检查微信是否安装
if
(!
await
_fluwx
.
isWeChatInstalled
)
{
if
(!
await
_fluwx
.
isWeChatInstalled
)
{
throw
Exception
(
'设备上未安装微信App,不支持微信支付'
);
throw
Exception
(
'设备上未安装微信App,不支持微信支付'
);
}
}
// 2. 请求后端获取预支付订单信息
final
deviceType
=
'android'
;
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
);
if
(
result
==
null
)
{
if
(
result
==
null
)
{
...
@@ -83,14 +103,14 @@ class XeCreateOrderHandler extends MessageHandler {
...
@@ -83,14 +103,14 @@ class XeCreateOrderHandler extends MessageHandler {
final
paySign
=
data
[
'paySign'
]
as
String
;
final
paySign
=
data
[
'paySign'
]
as
String
;
final
wxTradeNo
=
data
[
'wxTradeNo'
]
as
String
;
final
wxTradeNo
=
data
[
'wxTradeNo'
]
as
String
;
debugPrint
(
'prepayId:
$prepayId
'
);
debugPrint
(
'
_wx_pay_proc_ =>
prepayId:
$prepayId
'
);
debugPrint
(
'nonceStr:
$nonceStr
'
);
debugPrint
(
'
_wx_pay_proc_ =>
nonceStr:
$nonceStr
'
);
debugPrint
(
'timestamp:
$timestamp
'
);
debugPrint
(
'
_wx_pay_proc_ =>
timestamp:
$timestamp
'
);
debugPrint
(
'paySign:
$paySign
'
);
debugPrint
(
'
_wx_pay_proc_ =>
paySign:
$paySign
'
);
debugPrint
(
'appId:
$appId
'
);
debugPrint
(
'
_wx_pay_proc_ =>
appId:
$appId
'
);
debugPrint
(
'partnerId:
$partnerId
'
);
debugPrint
(
'
_wx_pay_proc_ =>
partnerId:
$partnerId
'
);
debugPrint
(
'packageValue:
$packageValue
'
);
debugPrint
(
'
_wx_pay_proc_ =>
packageValue:
$packageValue
'
);
debugPrint
(
'wxTradeNo:
$wxTradeNo
'
);
debugPrint
(
'
_wx_pay_proc_ =>
wxTradeNo:
$wxTradeNo
'
);
if
(
nonceStr
.
isEmpty
||
paySign
.
isEmpty
||
wxTradeNo
.
isEmpty
)
{
if
(
nonceStr
.
isEmpty
||
paySign
.
isEmpty
||
wxTradeNo
.
isEmpty
)
{
throw
Exception
(
'支付参数获取失败'
);
throw
Exception
(
'支付参数获取失败'
);
...
@@ -155,6 +175,8 @@ class XeCreateOrderHandler extends MessageHandler {
...
@@ -155,6 +175,8 @@ class XeCreateOrderHandler extends MessageHandler {
}
finally
{
}
finally
{
_cleanup
();
_cleanup
();
}
}
}
}
/// Fluwx 响应监听器
/// Fluwx 响应监听器
...
@@ -174,4 +196,50 @@ class XeCreateOrderHandler extends MessageHandler {
...
@@ -174,4 +196,50 @@ class XeCreateOrderHandler extends MessageHandler {
_timeoutTimer
=
null
;
_timeoutTimer
=
null
;
_payCompleter
=
null
;
_payCompleter
=
null
;
}
}
// 执行ios的微信支付
Future
<
dynamic
>
_ios_pay_proc_
(
String
userCode
,
tbxStuId
,
chargeCode
,
deviceType
,
phone
,
stuId
,
ext
,
int
duration
,
durationType
,
totalFee
,
bool
renew
,
useCoin
)
async
{
var
result
=
await
_userAuthRepository
.
createOrder
(
userCode
,
tbxStuId
,
chargeCode
,
duration
,
durationType
,
totalFee
,
renew
,
phone
,
stuId
,
ext
,
useCoin
?
1
:
0
,
deviceType
);
var
data
=
result
[
'data'
]
as
Map
<
String
,
dynamic
>?;
if
(
data
==
null
)
{
throw
Exception
(
'支付参数获取失败'
);
}
// 3. 从后端响应中提取预支付ID
final
prepayId
=
data
[
'prepayId'
]
as
String
?;
if
(
prepayId
==
null
||
prepayId
.
isEmpty
)
{
throw
Exception
(
'预支付订单ID获取失败'
);
}
// 4. 从后端响应中提取支付参数(nonceStr、timestamp、paySign 由后端生成)
final
timestamp
=
data
[
'timeStamp'
]
as
int
;
final
wxTradeNo
=
data
[
'wxTradeNo'
]
as
String
;
debugPrint
(
'_ios_pay_proc_ => prepayId:
$prepayId
'
);
debugPrint
(
'_ios_pay_proc_ => timestamp:
$timestamp
'
);
debugPrint
(
'_ios_pay_proc_ => wxTradeNo:
$wxTradeNo
'
);
if
(
wxTradeNo
.
isEmpty
)
{
throw
Exception
(
'支付参数获取失败'
);
}
// 执行ios支付
await
_subService
.
initialize
();
// 为了调试,先模拟
final
product
=
_subService
.
products
[
0
];
_subService
.
buySubscription
(
product
,
userCode
,
tbxStuId
,
wxTradeNo
);
}
}
}
lib/services/subscription_service_ios.dart
View file @
8c9ea6c
...
@@ -68,11 +68,11 @@ class SubscriptionService {
...
@@ -68,11 +68,11 @@ class SubscriptionService {
}
}
// ---------- 购买订阅 ----------
// ---------- 购买订阅 ----------
Future
<
bool
>
buySubscription
(
ProductDetails
product
,
String
userId
,
String
tbxStuId
)
async
{
Future
<
bool
>
buySubscription
(
ProductDetails
product
,
String
userId
,
String
tbxStuId
,
String
yWOrderId
)
async
{
//final orderId = await api.createPendingOrder(...);
//final orderId = await api.createPendingOrder(...);
final
orderId
=
""
;
final
orderId
=
yWOrderId
;
_pendingContexts
[
product
.
id
]
=
{
'userId'
:
userId
,
'tbxStuId'
:
tbxStuId
,
"orderId"
:
orderId
};
_pendingContexts
[
product
.
id
]
=
{
'userId'
:
userId
,
'tbxStuId'
:
tbxStuId
,
"orderId"
:
orderId
};
_orderIdMap
[
product
.
id
]
=
orderId
;
// 按产品 ID 存储
_orderIdMap
[
product
.
id
]
=
orderId
;
// 按产品 ID 存储
...
...
lib/ui/pages/subscription_page.dart
View file @
8c9ea6c
...
@@ -31,7 +31,7 @@ class _SubscriptionPageState extends State<SubscriptionPage> {
...
@@ -31,7 +31,7 @@ class _SubscriptionPageState extends State<SubscriptionPage> {
Future
<
void
>
_buy
(
ProductDetails
product
)
async
{
Future
<
void
>
_buy
(
ProductDetails
product
)
async
{
if
(!
_isInitialized
)
return
;
if
(!
_isInitialized
)
return
;
try
{
try
{
await
_subService
.
buySubscription
(
product
);
await
_subService
.
buySubscription
(
product
,
""
,
""
,
""
);
}
catch
(
e
)
{
}
catch
(
e
)
{
// 显示出错信息
// 显示出错信息
debugPrint
(
e
.
toString
());
debugPrint
(
e
.
toString
());
...
...
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