往期鸿蒙5.0全套实战文章必看:(文中附带全栈鸿蒙5.0学习资料)
1. 拦截H5微信、支付宝支付
- 在entry模块的module.json5文件中添加配置具体标签路径如下:module-> querySchemes
"querySchemes": [
"alipays",
"weixin"
],
2. 自定义H5全局拦截
在 EntryAbility.ets 目录下,通过设置 urlIntercept 实现自定义拦截逻辑
InitUtils.getInstance(this.context)
.urlIntercept( (url: string) => {
if (!bundleManager.canOpenLink(url)) {
//new ToastManager(this.getUIContext()).showErrorMessage("未安装目标应用")
return HandleResult.CONSUMED
}
const openLinkOptions: OpenLinkOptions = {
appLinkingOnly: false,
};
(getContext(this) as common.UIAbilityContext).openLink(url, openLinkOptions).then(() => {
}).catch((err: Error) => {
})
return HandleResult.CONSUMED
},'alipays://platformapi',"weixin://wap/pay?")
urlIntercept 方法参数说明
参数 | 类型 | 描述 |
---|---|---|
handleUrl | (url: string) => HandleResult | 拦截 URL 关键词后执行的方法,默认返回 HandleResult.NOT_CONSUME 表示不处理。 |
searchSting | Array<string> | 拦截的 URL 关键字,例如 alipays://platformapi 或 weixin://wap/pay? 。 |