【入门到实战】OpenHarmony开发:拦截H5微信、支付宝支付

往期鸿蒙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 表示不处理。
searchStingArray<string>拦截的 URL 关键字,例如 alipays://platformapi 或 weixin://wap/pay?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值