Skip to content

Commit 76ef0f6

Browse files
committed
ohos新增自动订阅支付-方法
1 parent 6221b6a commit 76ef0f6

File tree

4 files changed

+52
-35
lines changed

4 files changed

+52
-35
lines changed

lib/src/tobias.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ class Tobias {
1212
.pay(order, evn: evn, universalLink: universalLink);
1313
}
1414

15+
/// 鸿蒙 - 自动订阅支付
16+
Future<Map> payOhosAutoSub(String order) async {
17+
return await TobiasPlatform.instance.payOhosAutoSub(order);
18+
}
19+
1520
/// Auth by AliPay
1621
Future<Map> auth(String auth) async {
1722
return await TobiasPlatform.instance.auth(auth);

lib/src/tobias_method_channel.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ class MethodChannelTobias extends TobiasPlatform {
2121
{"order": order, "payEnv": evn.index, "universalLink": universalLink});
2222
}
2323

24+
/// 鸿蒙 - 自动订阅支付
25+
@override
26+
Future<Map> payOhosAutoSub(String order) async {
27+
return await methodChannel.invokeMethod("payOhosAutoSub", {"order": order});
28+
}
29+
2430
/// Auth by AliPay
2531
@override
2632
Future<Map> auth(String auth) async {

lib/src/tobias_platform_interface.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ abstract class TobiasPlatform extends PlatformInterface {
3636
throw UnimplementedError('pay() has not been implemented.');
3737
}
3838

39+
/// 鸿蒙 - 自动订阅支付
40+
Future<Map> payOhosAutoSub(String order) async {
41+
throw UnimplementedError('payOhosAutoSub() has not been implemented.');
42+
}
43+
3944
Future<Map> auth(String auth) async {
4045
throw UnimplementedError('auth() has not been implemented.');
4146
}

ohos/src/main/ets/components/plugin/TobiasPlugin.ets

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ export default class TobiasPlugin implements FlutterPlugin, MethodCallHandler, A
5151
case "pay":
5252
this.pay(call, result);
5353
break;
54+
case "payOhosAutoSub":
55+
this.payOhosAutoSub(call, result);
56+
break;
5457
case "auth":
5558
result.notImplemented();
5659
break;
@@ -73,44 +76,42 @@ export default class TobiasPlugin implements FlutterPlugin, MethodCallHandler, A
7376

7477
pay(call: MethodCall, result: MethodResult): void {
7578
const order: string = call.argument("order");
76-
const isOhosAutoSub: boolean = call.argument("isOhosAutoSub");
77-
if(isOhosAutoSub){
78-
console.log(TAG, '当前为自动订阅');
79-
let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
80-
let openLinkOptions: OpenLinkOptions = {
81-
appLinkingOnly: false
82-
};
83-
const resp: Map<string, string> = new Map();
84-
try {
85-
context.openLink(order, openLinkOptions)
86-
.then(() => {
87-
console.log(TAG, 'open link success.');
88-
resp.set("resultStatus", "success");
89-
result.success(resp)
90-
}).catch((err: BusinessError) => {
91-
console.log(TAG, `open link failed. Code is ${err.code}, message is ${err.message}`);
92-
resp.set("resultStatus", "erroe");
79+
const isShowLoading: boolean = true;
80+
const payment = new alipay.Pay();
81+
payment.pay(order, isShowLoading)
82+
.then((res: Map<string, string>) => {
83+
result.success(res);
84+
})
85+
.catch((_: BusinessError) => {
86+
const resp: Map<string, string> = new Map();
87+
resp.set("resultStatus", "-1");
88+
result.success(resp);
89+
});
90+
}
91+
92+
payOhosAutoSub(call: MethodCall, result: MethodResult): void {
93+
const order: string = call.argument("order");
94+
let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
95+
let openLinkOptions: OpenLinkOptions = {
96+
appLinkingOnly: false
97+
};
98+
const resp: Map<string, string> = new Map();
99+
try {
100+
context.openLink(order, openLinkOptions)
101+
.then(() => {
102+
console.log(TAG, 'open link success.');
103+
resp.set("resultStatus", "success");
93104
result.success(resp)
94-
})
95-
} catch (paramError) {
96-
console.log(TAG, `Failed to start link. Code is ${paramError.code}, message is ${paramError.message}`);
105+
}).catch((err: BusinessError) => {
106+
console.log(TAG, `open link failed. Code is ${err.code}, message is ${err.message}`);
97107
resp.set("resultStatus", "erroe");
98108
result.success(resp)
99-
}
100-
} else {
101-
console.log(TAG, '当前为非自动订阅');
102-
const isShowLoading: boolean = true;
103-
const payment = new alipay.Pay();
104-
payment.pay(order, isShowLoading)
105-
.then((res: Map<string, string>) => {
106-
result.success(res);
107-
})
108-
.catch((_: BusinessError) => {
109-
const resp: Map<string, string> = new Map();
110-
resp.set("resultStatus", "-1");
111-
result.success(resp);
112-
});
113-
}
109+
})
110+
} catch (paramError) {
111+
console.log(TAG, `Failed to start link. Code is ${paramError.code}, message is ${paramError.message}`);
112+
resp.set("resultStatus", "erroe");
113+
result.success(resp)
114+
}
114115
}
115116

116117
isAliPayInstalled(result: MethodResult): void {

0 commit comments

Comments
 (0)