platform_api.dart
4.84 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
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 WatchAppOtherInfo {
final int? userId;
final String? nickname;
final String? markName;
WatchAppOtherInfo({
this.userId,
this.nickname,
this.markName,
});
}
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,
});
}
class AppleProductPaymentResult {
final String productId;
final String? appAccountToken;
final String? originalTransactionId;
final String? transactionId;
/// success 为空时是支付pending状态,不需要处理
/// 只有 true/false时才是支付结果出来的时候
final bool? success;
/// 错误描述, success = false时取用:
/// 优先取 errorCode: -1: UUID格式错误, -2: productID查询商品失败,-3:用户取消支付, -4:支付校验失败,-5:未知错误(Apple未知错误)
/// errorCode 为空时,取用 errorMessage
final String? errorMessage;
final int? errorCode;
AppleProductPaymentResult({
required this.productId,
this.appAccountToken,
this.originalTransactionId,
this.transactionId,
this.success,
this.errorMessage,
this.errorCode,
});
}
enum HResourceType {
image,
video,
}
@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();
/// 申请通知权限
@async
bool requestNotificationAuth();
/// 是否是测试环境
bool isDebugEnvoriment();
@async
bool shareText(String text);
@async
bool shareFileData(Uint8List databytes);
/// 更新用户信息, 有登录态后调用
/// jsonString: UserPreferences的序列化string
/// baseUrl: 请求地址, https://api.doublefeel.cn
void updateLoginInfo(String jsonString, String baseUrl);
/// 退出登录
void logout();
/// 刷新会员信息
void refreshVip();
/// 刷新watch app 和 表盘的所有数据:
/// 任何可能导致展示watch内容变化时调用(好友变化、某些设置导致变化等)
void refreshWatchAppAndWidgets();
/// 请求评分弹窗
@async
bool requestAppReview();
/// 跳app应用设置:通知、定位等权限
bool jumpAppSetting();
/// 原生处理跳转url
bool nativeHandleUrl(String urlString);
/// 从原生拿需要处理的url, 主要场景是点击通知跳转
String? requestUnhandedUrl();
/// 请求苹果登录
@async
AppleSignInModel? requestAppleSignIn();
/// 查询指定id的苹果商品
/// productId: 苹果商品id
/// baseUnit: 除数基础单位(多少个天、周、月) ->
@async
AppleProductInfo? requestAppleProductInfo(String productId, int baseUnit);
/// 从服务器下单后请求苹果支付
@async
AppleProductPaymentResult? performApplePayment(String productId, String uuid);
/// 恢复购买
@async
bool performRestore();
/// 上传文件到云端
/// 注意catch flutter error
@async
String? uploadFile(String filePath, HResourceType resourceType);
/// 原生切图片,
/// imageUrl: 图片本地地址
/// maxKB: 压缩大小
/// width.height 切图后输出的大小
@async
String? performCropImage(
String imageUrl, int? maxKB, int? width, int? height);
/// 发起本地推送
@async
bool sendLocalNotification(String title, String content, String link);
}