platform_api.dart
3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import 'package:pigeon/pigeon.dart';
class AppleSignInModel {
final String userId;
final String? email;
final String? nickname;
final String? identityToken;
AppleSignInModel({
required this.userId,
this.email,
this.nickname,
this.identityToken,
});
}
class AppleProductInfo {
/// 苹果商品id
final String productId;
/// 原价描述
final String originPriceDescription;
/// 真实价格描述
final String priceDescription;
/// 原价格
final double originPrice;
/// 真实价格, = 0 代表试用商品
final double price;
/// price/unit = 单位价格
final String unitPrice;
/// 当前货币符号
final String currencyCode;
/// 当前用户是否可以试用
final bool isTrialPeriod;
AppleProductInfo({
required this.productId,
required this.originPriceDescription,
required this.priceDescription,
required this.originPrice,
required this.price,
required this.unitPrice,
required this.currencyCode,
required this.isTrialPeriod,
});
}
enum AppleProductPaymentErrorMsg {
missingUUID,
productNotFound,
userCancelled,
failedVerification,
unknown,
}
class AppleProductPaymentResult {
final String productId;
final String? appAccountToken;
final String? originalTransactionId;
final String? transactionId;
final bool? success;
/// 错误描述:
/// 和AppleProductPaymentErrorMsg匹配的flutter处理,
/// 不匹配的则是StoreKit 直接给的错误描述,直接展示即可
final String? errorMessage;
AppleProductPaymentResult({
required this.productId,
this.appAccountToken,
this.originalTransactionId,
this.transactionId,
this.success,
this.errorMessage,
});
}
@ConfigurePigeon(
PigeonOptions(
dartOut: 'lib/pigeon/platform_api.g.dart',
dartPackageName: 'doublefeel_flutter',
dartOptions: DartOptions(),
kotlinOut:
'android/app/src/main/kotlin/com/doublefeel/app/pigeon/PlatformApi.kt',
kotlinOptions: KotlinOptions(
package: 'com.doublefeel.app.pigeon.platform',
),
swiftOut: 'ios/Runner/Pigeon/PlatformApi.swift',
swiftOptions: SwiftOptions(),
arkTSOut: 'ohos/entry/src/main/ets/pigeon/PlatformApi.ets',
copyrightHeader: 'pigeon/copyright.txt',
),
)
@HostApi()
abstract class PlatformHostApi {
/// 返回完整的 User-Agent 字符串,由 native 侧组装:
/// `{systemWebViewUA} {appName}/{versionCode}({versionName})({manufacturer}##{brand}##{model}; {OS}{osVersion}; {height}x{width})(huawei)`
String getFullUserAgent();
/// 更新用户信息, 有登录态后调用
/// jsonString: UserPreferences的序列化string
/// baseUrl: 请求地址, https://api.doublefeel.cn
void updateLoginInfo(String jsonString, String baseUrl);
/// 请求苹果登录
@async
AppleSignInModel? requestAppleSignIn();
/// 查询指定id的苹果商品
/// productId: 苹果商品id
/// baseUnit: 除数基础单位(多少个天、周、月) ->
@async
AppleProductInfo? requestAppleProductInfo(String productId, int baseUnit);
/// 从服务器下单后请求苹果支付
@async
AppleProductPaymentResult? performApplePayment(String productId, String uuid);
}