HarmonyOS鸿蒙Next中uniapp开发的APP如何跳转到微信小程序?

HarmonyOS鸿蒙Next中uniapp开发的APP如何跳转到微信小程序? 如题,求简单的方案,用webview scheme的形试了下,报错了,webview禁用了 weixin://协议。还有其他方案吗?

6 回复

【背景知识】

uni.navigateToMiniProgram在App平台打开微信小程序,使用plus.share的launchMiniProgram,而uni-app官方基于技术演进方向(UTS插件)考虑,暂未规划对HarmonyOS平台的plus接口适配支持,所以该方法未支持HarmonyOS。

【解决方案】

HarmonyOS拉起微信小程序:HarmonyOS应用拉起小程序开发示例
UTS桥接调用HarmonyOS API:UTS调用HarmonyOS三方库API

示例代码:

// UTS插件目录/utssdk/app-harmony/index.uts
import * as wxopensdk from '@tencent/wechat_open_sdk'; // 导入微信SDK
import { common } from '@kit.AbilityKit';

let APP_ID = "";

export const WXApi = wxopensdk.WXAPIFactory.createWXAPI(APP_ID);

export const launchMiniProgram = async (
  userName : string,
  path : string,
  miniprogramType : number
) => {
  const context = UTSHarmony.getUIAbilityContext(); // 假定我们在组件环境内调用
  const launchMiniProgramReq = new wxopensdk.LaunchMiniProgramReq;
  launchMiniProgramReq.userName = userName;  // 拉起的小程序的原始id
  launchMiniProgramReq.path = path;    // 拉起小程序页面的可带参路径,不填默认拉起小程序首页,对于小游戏,可以只传入query部分,来实现传参效果,如:传入"?foo=bar"。
  launchMiniProgramReq.miniprogramType = miniprogramType; // 拉起小程序的类型:0-正式版、1-开发版、2-体验版
  const promise = await WXApi.sendReq(context, launchMiniProgramReq)
  return promise
}
// UTS插件目录/utssdk/app-harmony/config.json
{
  "dependencies": {
    "@tencent/wechat_open_sdk": "1.0.6"
  }
}
<template>
  <view class="content">
    <button type="default" @click="launchMiniProgram">打开微信小程序</button>
  </view>
</template>

<script>
  import {
    launchMiniProgram
  } from "@/uni_modules/UTS插件目录";
  export default {
    data() {
      return {}
    },
    onLoad() {

    },
    methods: {
      launchMiniProgram() {
        launchMiniProgram('拉起的小程序的id', '拉起小程序页面的可带参路径', 1)
      }
    }
  }
</script>

<style>
  .content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  .content button {
    margin-bottom: 32rpx;
    width: 100%;
  }
</style>

更多关于HarmonyOS鸿蒙Next中uniapp开发的APP如何跳转到微信小程序?的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


文档标题

章节一

这是文档的主要内容段落,包含各种文本信息。

子章节

  • 列表项一
  • 列表项二
  • 列表项三

章节二

代码示例:

def hello_world():
    print("Hello, World!")

表格示例:

列1 列2 列3
数据1 数据2 数据3
数据4 数据5 数据6

重要说明段落。

有要学HarmonyOS AI的同学吗,联系我:https://www.itying.com/goods-1206.html

我没有查到呢,可以贴个链接吗,

在HarmonyOS Next中,UniApp开发的APP可通过微信官方提供的OpenSDK实现跳转小程序。需集成微信OpenSDK for HarmonyOS版本,调用wx.launchMiniProgram接口并传入目标小程序的原始ID(gh_开头)或用户名。跳转前需确保用户已安装微信客户端,且目标小程序处于可访问状态。具体实现依赖微信官方对HarmonyOS的SDK适配进度。

在HarmonyOS Next中,由于系统安全限制,WebView默认禁用weixin://等自定义协议,因此无法通过scheme方式直接跳转微信小程序。目前可行的替代方案是:

  1. 使用HarmonyOS的Intent跳转能力
    通过want配置指定微信小程序的跳转参数(需微信提供HarmonyOS适配的Intent协议)。示例代码:

    let want = {
      bundleName: "com.tencent.mm",
      abilityName: "特定ability", // 需微信公开HarmonyOS端跳转能力
      parameters: { miniProgramId: "小程序原始ID" }
    };
    await context.startAbility(want);
    
  2. 通过URL跳转中转页
    在WebView中加载微信官方H5中转页面(需微信支持),利用页面重定向触发小程序:

    <webview src="https://wx.qq.com/miniprogram?appid=XXXXX"></webview>
    
  3. 调用系统分享接口
    将小程序路径封装成分享数据,通过系统分享面板选择微信打开:

    let shareData = {
      type: "text/html",
      data: "小程序卡片数据" // 需符合微信分享规范
    };
    systemShare.share(shareData);
    

注意事项:

  • 方案1依赖微信对HarmonyOS的适配进度
  • 方案2需确保微信H5页面对HarmonyOS浏览器兼容
  • 可结合uni-app的条件编译针对HarmonyOS平台单独处理跳转逻辑

建议关注微信官方后续对HarmonyOS跳转协议的官方支持公告。

回到顶部