Skip to content

Commit 48fcd5b

Browse files
authored
Merge pull request #165 from WarmYunyang/master
ohos新增自动订阅支付
2 parents ae5ec84 + 76ef0f6 commit 48fcd5b

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

lib/src/tobias.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ class Tobias {
55
/// [evn] only supports Android due to native AliPaySDK
66
/// [universalLink] only supports iOS
77
Future<Map> pay(String order,
8-
{AliPayEvn evn = AliPayEvn.online, String? universalLink}) async {
8+
{AliPayEvn evn = AliPayEvn.online,
9+
String? universalLink,
10+
bool isOhosAutoSub = false}) async {
911
return await TobiasPlatform.instance
1012
.pay(order, evn: evn, universalLink: universalLink);
1113
}
1214

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

lib/src/tobias_method_channel.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,19 @@ class MethodChannelTobias extends TobiasPlatform {
1414
/// [universalLink] only supports iOS
1515
@override
1616
Future<Map> pay(String order,
17-
{AliPayEvn evn = AliPayEvn.online, String? universalLink}) async {
17+
{AliPayEvn evn = AliPayEvn.online,
18+
String? universalLink,
19+
bool isOhosAutoSub = false}) async {
1820
return await methodChannel.invokeMethod("pay",
1921
{"order": order, "payEnv": evn.index, "universalLink": universalLink});
2022
}
2123

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

lib/src/tobias_platform_interface.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,18 @@ abstract class TobiasPlatform extends PlatformInterface {
2929
}
3030

3131
/// [evn] only supports Android due to native AliPaySDK
32-
Future<Map> pay(String order, {AliPayEvn evn = AliPayEvn.online, String? universalLink}) async {
32+
Future<Map> pay(String order,
33+
{AliPayEvn evn = AliPayEvn.online,
34+
String? universalLink,
35+
bool isOhosAutoSub = false}) async {
3336
throw UnimplementedError('pay() has not been implemented.');
3437
}
3538

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

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import {
1111
import { bundleManager, common } from '@kit.AbilityKit';
1212
import * as alipay from "@cashier_alipay/cashiersdk"
1313
import { BusinessError } from '@kit.BasicServicesKit';
14+
import OpenLinkOptions from '@ohos.app.ability.OpenLinkOptions';
1415

1516
const MESSAGE_CHANNEL_NAME = "com.jarvanmo/tobias";
17+
const TAG: string = 'TobiasPlugin';
1618

1719
/** TobiasPlugin **/
1820
export default class TobiasPlugin implements FlutterPlugin, MethodCallHandler, AbilityAware {
@@ -49,6 +51,9 @@ export default class TobiasPlugin implements FlutterPlugin, MethodCallHandler, A
4951
case "pay":
5052
this.pay(call, result);
5153
break;
54+
case "payOhosAutoSub":
55+
this.payOhosAutoSub(call, result);
56+
break;
5257
case "auth":
5358
result.notImplemented();
5459
break;
@@ -84,6 +89,31 @@ export default class TobiasPlugin implements FlutterPlugin, MethodCallHandler, A
8489
});
8590
}
8691

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");
104+
result.success(resp)
105+
}).catch((err: BusinessError) => {
106+
console.log(TAG, `open link failed. Code is ${err.code}, message is ${err.message}`);
107+
resp.set("resultStatus", "erroe");
108+
result.success(resp)
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+
}
115+
}
116+
87117
isAliPayInstalled(result: MethodResult): void {
88118
result.success(bundleManager.canOpenLink("alipays://"))
89119
}

0 commit comments

Comments
 (0)