收藏
回答

纯血鸿蒙跳转微工卡小程序报错navigateToMiniProgram:fail can only

问题类型 API/组件名称 微信版本 基础库版本
Bug wx.navigateToMiniProgram 8.0.14 3.14.1

安卓和iOS手机同样的代码该流程没有任何问题,只有鸿蒙手机在点击跳转后报错:navigateToMiniProgram:fail can only be invoked by user TAP gesture.

如上图的流程演示:用户点击实名认证后,会拉起用户的授权手机号弹窗,完成授权手机号后会跟后台换取跳转微工卡小程序的地址。安卓/iOS完全正常,只有鸿蒙设备不支持。

小程序代码片段如下:

  /**
   * 获取手机号码
   */
  getPhoneNumber: function (e) {
    if (e.detail.errMsg === 'getPhoneNumber:ok') {
      this.setData({
        phoneCode: e.detail.code,
        checkResult: true,
      });
      if (e.detail.code === undefined || e.detail.code === null) {
        wx.showModal({
          title: '温馨提示',
          content: '未获取到手机号码相关信息,请您更新微信客户端版本到8.0.16以上,若无法更新,请到应用市场下载最新版本微信',
          showCancel: false,
          confirmText: '好的',
          success(res) {}
        });
      } else {
        this.getCardUrl(e.detail.code);
      }
    } else {
      this.setData({
        checkResult: false,
      });
    }
  },
 /**
   * 跳转微工卡
   */
  getCardUrl: async function (code) {
    const {
      corporationId,
      openId,
      idNo,
      name,
      userId,
      source
    } = this.data;
    const params = {
      idNo,
      name,
      userId,
      source,
      openid: openId,
    }
    const res = await getPayRollCardUrl(corporationId, code, params);
    try {
      wx.navigateToMiniProgram({
        appId: res.data.payrollCardAppid,
        path: res.data.url,
        success: (res) => {
          // 打开成功
          wx.showToast({
            title: "正在跳转...",
            icon: 'none',
            duration: 2000,
          });
        },
        fail(e) {
          wx.showToast({
            title: `跳转失败,${e.errMsg}`,
            icon: 'none',
            duration: 2000,
          });
        }
      });
    } catch (e) {
      wx.showToast({
        title: `跳转微工卡失败,${e.errMsg}`,
        icon: 'none',
        duration: 2000,
      });
    }
  },

设备型号(纯血鸿蒙都跳转不了):

设备品牌:HUAWEI
设备型号:HBN-AL00
系统类型:OpenHarmonyOS 6.0.0
客户端版本:8.0.14
基础库版本:3.14.1

设备日志:

2026-2-2 10:41:10 [log] page pages/wechatAuth/wechatAuth onHide have been invoked
2026-2-2 10:41:10 [log] App onHide have been invoked
2026-2-2 10:41:12 [log] App onShow have been invoked
2026-2-2 10:41:12 [log] wx.hideHomeButton api invoke
2026-2-2 10:41:12 [log] page pages/wechatAuth/wechatAuth onShow have been invoked
2026-2-2 10:41:12 [log] wx.hideHomeButton success callback with msg hideHomeButton:ok
2026-2-2 10:41:12 [log] wx.showLoading api invoke
2026-2-2 10:41:12 [log] wx.getStorageSync api invoke
2026-2-2 10:41:12 [log] wx.getStorageSync return
2026-2-2 10:41:12 [log] wx.getStorageSync api invoke
2026-2-2 10:41:12 [log] wx.getStorageSync return
2026-2-2 10:41:12 [log] wx.request api invoke
2026-2-2 10:41:12 [log] wx.showLoading success callback with msg showLoading:ok
2026-2-2 10:41:13 [log] wx.hideLoading api invoke
2026-2-2 10:41:13 [log] wx.request success callback with msg request:ok with seq 0
2026-2-2 10:41:13 [log] wx.navigateToMiniProgram api invoke
2026-2-2 10:41:13 [log] wx.showToast api invoke
2026-2-2 10:41:13 [log] wx.navigateToMiniProgram fail callback with msg navigateToMiniProgram:fail can only be invoked by user TAP gesture.
2026-2-2 10:41:13 [log] wx.hideLoading success callback with msg hideLoading:ok
2026-2-2 10:41:13 [log] wx.showToast success callback with msg showToast:ok
2026-2-2 10:41:18 [log] page pages/wechatAuth/wechatAuth onHide have been invoked
2026-2-2 10:41:18 [log] App onHide have been invoked
2026-2-2 10:41:53 [log] App onShow have been invoked
2026-2-2 10:41:53 [log] wx.showLoading api invoke
2026-2-2 10:41:53 [log] wx.getStorageSync api invoke
2026-2-2 10:41:53 [log] wx.getStorageSync return
2026-2-2 10:41:53 [log] wx.getStorageSync api invoke
2026-2-2 10:41:53 [log] wx.getStorageSync return
2026-2-2 10:41:53 [log] wx.request api invoke
2026-2-2 10:41:53 [log] wx.hideHomeButton api invoke
2026-2-2 10:41:53 [log] page pages/wechatAuth/wechatAuth onShow have been invoked
2026-2-2 10:41:53 [log] wx.showLoading success callback with msg showLoading:ok
2026-2-2 10:41:53 [log] wx.hideHomeButton success callback with msg hideHomeButton:ok
2026-2-2 10:41:54 [log] wx.hideLoading api invoke
2026-2-2 10:41:54 [log] wx.request success callback with msg request:ok with seq 0
2026-2-2 10:41:54 [log] wx.showModal api invoke
2026-2-2 10:41:54 [log] wx.hideLoading success callback with msg hideLoading:ok
2026-2-2 10:41:59 [log] page pages/wechatAuth/wechatAuth onHide have been invoked
2026-2-2 10:41:59 [log] App onHide have been invoked
2026-2-2 10:42:11 [log] App onShow have been invoked
2026-2-2 10:42:11 [log] wx.showLoading api invoke
2026-2-2 10:42:11 [log] wx.getStorageSync api invoke
2026-2-2 10:42:11 [log] wx.getStorageSync return
2026-2-2 10:42:11 [log] wx.getStorageSync api invoke
2026-2-2 10:42:11 [log] wx.getStorageSync return
2026-2-2 10:42:11 [log] wx.request api invoke
2026-2-2 10:42:11 [log] wx.hideHomeButton api invoke
2026-2-2 10:42:11 [log] page pages/wechatAuth/wechatAuth onShow have been invoked
2026-2-2 10:42:11 [log] wx.showLoading success callback with msg showLoading:ok
2026-2-2 10:42:11 [log] wx.hideHomeButton success callback with msg hideHomeButton:ok
2026-2-2 10:42:11 [log] wx.hideLoading api invoke
2026-2-2 10:42:11 [log] wx.request success callback with msg request:ok with seq 0
2026-2-2 10:42:11 [log] wx.showModal api invoke
2026-2-2 10:42:11 [log] wx.hideLoading success callback with msg hideLoading:ok
2026-2-2 10:42:19 [log] page pages/wechatAuth/wechatAuth onHide have been invoked
2026-2-2 10:42:19 [log] App onHide have been invo
回答关注问题邀请回答
收藏

2 个回答

  • 社区技术运营专员--阳光
    社区技术运营专员--阳光
    02-03

    鸿蒙验证也没问题 先根据报错排查下吧 确认中途是不是有异步操作

    02-03
    有用
    回复
  • 智能回答 智能回答 本次回答由AI生成
    02-02
    有用
    回复 1
    • sor
      sor
      02-02
      1、录屏文件不支持上传
      2、详细环境信息是指?
      3、/pages/card/auth?mchid=1680556551&sub_mchid=1696226911&appid=wxa97903a700e9a56c&token=4d0cd96b-8a1e-4066-a86e-ac197993e82f&openid=oyZch7dczq8i-loch9OLc8yCC8ek
      02-02
      回复
登录 后发表内容