鸿蒙ArkTs跳转微信小程序

1、导入依赖"@tencent/wechat_open_sdk": “1.0.3”,一定是要1.0.3版本以上,才支持
2、直接拿代码

import * as wxopensdk from '@tencent/wechat_open_sdk'; // 导入微信 SDK
import { LaunchMiniProgramModel } from '../../Models/LaunchMiniProgramModel';

export const WX_APP_ID = "这个是在微信开放平台申请到的appid"
export const WXApi = wxopensdk.WXAPIFactory.createWXAPI(WX_APP_ID)
//调用该方法可直接跳转
async function jumpLaunchMiniProgram(context: common.UIAbilityContext): Promise<void> {
  //获取小程序信息 以下是一个示例
  let getLaunchMiniProgramModel = new LaunchMiniProgramModel("小程序的原始id","小程序页面的可带参路径", 0)
  //跳转微信小程序
  let launchMiniProgramReq = new wxopensdk.LaunchMiniProgramReq;
  launchMiniProgramReq.userName = getLaunchMiniProgramModel.userName;  //拉起的小程序的原始id
  launchMiniProgramReq.path = getLaunchMiniProgramModel.applitePath;    //拉起小程序页面的可带参路径,不填默认拉起小程序首页,对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 "?foo=bar"。
  launchMiniProgramReq.miniprogramType = getLaunchMiniProgramModel.type; //拉起小程序的类型 0-正式版 1-开发版 2-体验版
  let success = await WXApi.sendReq(context, launchMiniProgramReq);
  console.info("是否跳转成功:"+success)
}

export class LaunchMiniProgramModel {
  userName: string;
  applitePath: string;
  type: number

  constructor(userName: string, applitePath: string, type: number) {
    this.userName = userName;
    this.applitePath = applitePath;
    this.type = type;
  }
}

3、如果还没有申请到小程序的appid,按照以下文档去申请

https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Launching_a_Mini_Program/OHOS_Development_example.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值