feat: 购买下单透传终端类型,手机端收银台拉起支付宝 App(契约 v1.1.0)

根因:pay 判手机/PC 用下单请求 UA,而下单由 jiu 后端 Go client 发出,
恒被判 PC 扫码页——手机用户拿不到 wap 拉起页。

- backend:/license/purchase 请求体加可选 client_type(oneof=pc mobile),
  缺省按本请求 UA 兜底(官网浏览器购买自动受益);CreatePurchase 透传给 pay;
  单测断言透传 + 既有用例补参
- client:createPurchase 支持 clientType;PurchaseCard 按平台声明
  (iOS/Android=mobile,桌面=pc,Web 不传走 UA),kIsWeb 先于 dart:io;
  launchUrl 外部浏览器不变,wap 收银台自动拉起支付宝
- 配套:pay-contract v1.1.0(744725b)+ pay 侧 resolveIsMobile(dbdadd1)已各自提交

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JJ1g8XV1YhhmHRzhwWEW7o
This commit is contained in:
wangjia
2026-07-04 10:31:49 +08:00
parent aa3aad417c
commit f3cfdcadca
5 changed files with 64 additions and 15 deletions
@@ -41,10 +41,16 @@ class LicenseRepository {
}
/// 在线购买/续费下单(仅管理员),返回 pay 收银台跳转信息。
Future<PurchaseOrder> createPurchase(String bizCode) async {
/// [clientType] 终端类型("pc"/"mobile",可选):显式声明收银台形态——
/// mobile 走支付宝手机网站支付(H5 拉起 App),pc 走电脑扫码页;
/// 不传时后端按请求 UA 判断(浏览器场景 UA 真实,App 场景须显式传)。
Future<PurchaseOrder> createPurchase(String bizCode,
{String? clientType}) async {
try {
final resp =
await _client.post('/license/purchase', data: {'biz_code': bizCode});
final resp = await _client.post('/license/purchase', data: {
'biz_code': bizCode,
if (clientType != null) 'client_type': clientType,
});
return PurchaseOrder.fromJson(resp.data['data'] as Map<String, dynamic>);
} on DioException catch (e) {
throw AppException(
+13 -2
View File
@@ -4,7 +4,9 @@
// GET /license/purchase/:otnwebhook 续期到账后自动刷新授权并展示新到期日。
// 价格仅展示,实付以 pay 侧套餐表为准(下单响应回传 amount)。
import 'dart:async';
import 'dart:io' show Platform;
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:intl/intl.dart';
@@ -73,13 +75,22 @@ class _PurchaseCardState extends ConsumerState<PurchaseCard> {
super.dispose();
}
/// 终端类型(契约 v1.1.0):手机 App 显式声明 mobile 让 pay 出「手机网站支付」
/// 收银台(H5 拉起支付宝 App);桌面 App 声明 pc(扫码页);Web 端不传,
/// 后端按浏览器真实 UA 判断。kIsWeb 判断先于 dart:io(项目规则)。
String? get _clientType {
if (kIsWeb) return null;
return (Platform.isIOS || Platform.isAndroid) ? 'mobile' : 'pc';
}
Future<void> _submit() async {
setState(() => _submitting = true);
try {
final order = await ref
.read(licenseRepositoryProvider)
.createPurchase(_plan.bizCode);
// 外部浏览器打开收银台:桌面端进网页支付,移动端由系统浏览器拉起支付宝
.createPurchase(_plan.bizCode, clientType: _clientType);
// 外部浏览器打开收银台:桌面端进网页支付,移动端由系统浏览器打开
// wap 收银台自动拉起支付宝 App
await launchUrl(Uri.parse(order.payUrl),
mode: LaunchMode.externalApplication);
if (!mounted) return;