鸿蒙5.0webview跳转微信支付
·
鸿蒙5.0自研应用内嵌入H5,H5内支付跳转支付
第一步:在【module.json5】设置weixin的schemes
如:
"querySchemes": [ "weixin" ],
第二步:在web监听中添加微信mweb_url链接,并加载
if (url.startsWith('https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=')) {
if (this.isSetReferer) {
this.isSetReferer = false;
return false;
}
const headers = data.getRequestHeader();
headers.push({headerKey:'Referer',headerValue:'https://mall.xxxx.com/'})
headers.push({headerKey:'Origin',headerValue:'https://mall.xxxx.com'})
this.controller.loadUrl(url,headers);
this.isSetReferer = true;
return true;
}
第三步:监听微信跳转地址
if (url.includes('weixin://wap/pay?')){
if (Wx.WXApi.isWXAppInstalled()){
ToastUtil.showToast('未安装微信,请先安装')
return false;
}
this.abilityContext.openLink(url).then(() => {
Logger.p(`open link success.`);
}).catch((err: BusinessError) => {
Logger.p(`open link failed, errCode: ${JSON.stringify(err.code)}`);
});;
return true;
}更多推荐
所有评论(0)