HarmonyOS NEXT H5通过url scheme拉起支付宝应用进行支付
·
有二种方法可以实现:
1.使用直接支付功能
(未安装支付宝 APP 是跳转 H5 支付,已安装支付宝 APP 会直接跳转 APP 支付 通过 router 跳转或者通过 navigation 跳转,只针对未安装支付宝 APP 时跳转 H5 的方式有差异)。这里只展示router方式,navigation方式看官网
/**
* h5支付宝支付
* @param url 由服务端生成
* new Pay().pay的第二个参数 showPayLoading 控制是否展示支付宝loading
*/
new Pay().pay(url,true).then((result)=>{
const message =
`resultStatus: ${result.get('resultStatus')} memo: ${result.get('memo')} result: ${result.get('result')}`
console.log('messagePay',message)
})
2.使用H5转native支付
// 在你的H5容器中拦截url加载
Web({
src: 'https://xxx/xx',
controller: this.webviewController,
})
.onLoadIntercept((event) => {
let url = event.data.getRequestUrl();//拿到服务端生成的url
if (!(url.startsWith("http") || url.startsWith("https"))) {
return false;
}
console.log(`alipay: url: ${url}`);
//拉起支付宝进行支付
let result = new Pay().payInterceptorWithUrl(url, true, (result) => {
let resultCode = result.get("resultCode");
let returnUrl = result.get("returnUrl");
console.log(`resultCode: ${resultCode}, returnUrl: ${returnUrl}`);
// 如果url不为空,建议商户跳转到对应url,当然也可自行处理this.webviewController.loadUrl(returnUrl);
});
return result;
})更多推荐


所有评论(0)