- Регистрация
- 1 Мар 2015
- Сообщения
- 1,481
- Баллы
- 155
HarmonyOS 5 , and the app market is gradually enriching. Many apps are preparing to integrate Alipay for payment functions. Currently, there are three ways to launch Alipay: through the Alipay SDK, using OpenLink, or passing the Alipay package name with startAbility. The above three launching methods all refer to Next apps and do not include Abilities, which have their own ecological restrictions and temporarily do not support launching third-party apps.
I. Launching via Alipay SDK
The OpenHarmony third-party repository includes Alipay’s SDK:
Repository Address:
Official Demo Address:
The official demo requires logging in to DingTalk to request authorization, which is generally accessible.
Code Implementation:
onAlipay() {
// All values in this payment information object should be returned by the server
let obj = new PayInfo();
obj.appId = "1111111111111";
obj.orderId = "1111111111";
obj.productName = "1年VIP";
obj.amount = 10;
obj.notifyUrl = '';
obj.rsaPrivate = "MIICXQIBAAKBgQC...";
OrderInfoUtil.getOrderInfo(obj).then(orderInfo => {
// orderInfo generated by the server
new Pay().pay(orderInfo, true).then(result => {
let message =
resultStatus: ${result.get('resultStatus')} memo: ${result.get('memo')} result: ${result.get('result')};
console.log("Payment result: " + message);
if (result.get('resultStatus') === '9000') {
console.log("Payment successful");
} else {
console.log("Payment failed");
}
}).catch((error: BusinessError) => {
LogUtil.e("aLiParSdk:", error);
});
});
}
For the complete code, refer to the Git repository below. Detailed explanations can also be found in another blogger’s article:
博客链接: HarmonyOS Next — Alipay SDK Integration Tutorial
Complete Code Repository:
Effect Diagram:
II. Launching Alipay via OpenLink
OpenLink can be used to achieve inter-app navigation. Specifically for Alipay, you can refer to the browser-launch example.
API Used: UIAbilityContext.openLink
Reference:
Code Example:
let context = getContext(this) as common.UIAbilityContext;
let link = 'alipays://platformapi/startapp';
let openLinkOptions: OpenLinkOptions = {
appLinkingOnly: false,
parameters: { demo_key: 'demo_value' }
};
context.openLink(link, openLinkOptions, (err, result) => {
LogUtil.e(TAG, openLink error: ${JSON.stringify(err)});
LogUtil.i(TAG, openLink result: ${JSON.stringify(result.resultCode)});
LogUtil.i(TAG, openLink data: ${JSON.stringify(result.want)});
}).then(() => {
LogUtil.i(TAG, openLink success.);
}).catch((err: BusinessError) => {
LogUtil.e(TAG, openLink failed, errCode ${err.code});
});
Complete Code Repository:
Effect Reference:
III. Launching Alipay with startAbility
In HarmonyOS 5, if you know an app’s bundle name, you can launch it using startAbility by passing a Want with that bundle name.
API Used: UIAbilityContext.startAbility
Reference:
How to Obtain Alipay’s Bundle Name
Via hdc Command:
hdc shell aa dump -l
hdc Tool Usage
Via Device File Browser: Path: /data/app/el2/100/database/com.alipay.mobile.client
Code Example:
const context = getContext(this) as common.UIAbilityContext;
let want: Want = {
deviceId: '',
bundleName: 'com.alipay.mobile.client',
abilityName: 'EntryAbility',
flags: wantConstant.Flags.FLAG_INSTALL_ON_DEMAND,
parameters: { /* custom parameters */ }
};
context.startAbility(want);
Complete Code Repository:
Effect Implementation:
These are three common ways to launch Alipay in HarmonyOS 5. We hope this helps other developers. If there are any shortcomings in the article, please forgive us and point them out.
I. Launching via Alipay SDK
The OpenHarmony third-party repository includes Alipay’s SDK:
Repository Address:
Official Demo Address:
The official demo requires logging in to DingTalk to request authorization, which is generally accessible.
Code Implementation:
onAlipay() {
// All values in this payment information object should be returned by the server
let obj = new PayInfo();
obj.appId = "1111111111111";
obj.orderId = "1111111111";
obj.productName = "1年VIP";
obj.amount = 10;
obj.notifyUrl = '';
obj.rsaPrivate = "MIICXQIBAAKBgQC...";
OrderInfoUtil.getOrderInfo(obj).then(orderInfo => {
// orderInfo generated by the server
new Pay().pay(orderInfo, true).then(result => {
let message =
resultStatus: ${result.get('resultStatus')} memo: ${result.get('memo')} result: ${result.get('result')};
console.log("Payment result: " + message);
if (result.get('resultStatus') === '9000') {
console.log("Payment successful");
} else {
console.log("Payment failed");
}
}).catch((error: BusinessError) => {
LogUtil.e("aLiParSdk:", error);
});
});
}
For the complete code, refer to the Git repository below. Detailed explanations can also be found in another blogger’s article:
博客链接: HarmonyOS Next — Alipay SDK Integration Tutorial
Complete Code Repository:
Effect Diagram:
II. Launching Alipay via OpenLink
OpenLink can be used to achieve inter-app navigation. Specifically for Alipay, you can refer to the browser-launch example.
API Used: UIAbilityContext.openLink
Reference:
Code Example:
let context = getContext(this) as common.UIAbilityContext;
let link = 'alipays://platformapi/startapp';
let openLinkOptions: OpenLinkOptions = {
appLinkingOnly: false,
parameters: { demo_key: 'demo_value' }
};
context.openLink(link, openLinkOptions, (err, result) => {
LogUtil.e(TAG, openLink error: ${JSON.stringify(err)});
LogUtil.i(TAG, openLink result: ${JSON.stringify(result.resultCode)});
LogUtil.i(TAG, openLink data: ${JSON.stringify(result.want)});
}).then(() => {
LogUtil.i(TAG, openLink success.);
}).catch((err: BusinessError) => {
LogUtil.e(TAG, openLink failed, errCode ${err.code});
});
Complete Code Repository:
Effect Reference:
III. Launching Alipay with startAbility
In HarmonyOS 5, if you know an app’s bundle name, you can launch it using startAbility by passing a Want with that bundle name.
API Used: UIAbilityContext.startAbility
Reference:
How to Obtain Alipay’s Bundle Name
Via hdc Command:
hdc shell aa dump -l
hdc Tool Usage
Via Device File Browser: Path: /data/app/el2/100/database/com.alipay.mobile.client
Code Example:
const context = getContext(this) as common.UIAbilityContext;
let want: Want = {
deviceId: '',
bundleName: 'com.alipay.mobile.client',
abilityName: 'EntryAbility',
flags: wantConstant.Flags.FLAG_INSTALL_ON_DEMAND,
parameters: { /* custom parameters */ }
};
context.startAbility(want);
Complete Code Repository:
Effect Implementation:
These are three common ways to launch Alipay in HarmonyOS 5. We hope this helps other developers. If there are any shortcomings in the article, please forgive us and point them out.