• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

HarmonyOS 5 - Three Ways to Launch Alipay - Tutorial

Lomanu4 Оффлайн

Lomanu4

Команда форума
Администратор
Регистрация
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.


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу