rn 跳转到微信小程序

本文介绍了如何在微信开发平台上通过`@shm-open/react-native-wechat`库实现移动应用与微信小程序的跳转,包括获取AppID和小程序原始ID,以及在JS代码中的具体步骤和注意事项。
摘要由CSDN通过智能技术生成

废话少说直接上方法:

1.在微信开发平台上绑定你的移动App应用获取移动应用的AppID,同时获取你的小程序原始ID

2.安装 @shm-open/react-native-wechat 

我这里使用的版本是:"@shm-open/react-native-wechat": "^1.3.0",

安装方法:

$ npm install @shm-open/react-native-wechat

3.在你的程序中引用(JS代码如下)

import * as WeChat from "@shm-open/react-native-wechat"

  // 跳转小程序
  async function JumpToMiniProgram() {

    // 注意AppID不是小程序的AppID !!!
    WeChat.registerApp( 移动应用AppID wxe....., "");  //注册wechat  

    const flag = await WeChat.isWXAppInstalled()  //判断是否安装微信

    if (!flag) {
      return Alert.alert('提示', '您还未安装微信客户端');
    }
  
    let MiniProgram = {
      userName: '小程序原始ID gh_xxxxxx',  //不是小程序的AppID 是原始ID
      path: 'pages/pagehome/pagehome',  //要跳转到小程序的那一页
      miniprogramType: 0,  //小程序类型   RELEASE = 0,TEST = 1,PREVIEW = 2
    }

    await WeChat.openMiniprogram(MiniProgram)  //开始跳转至微信小程序

  }



然后就能够从移动App跳转到微信小程序了。(注意:一定要先注册WeChat,在调用WeChat的方法不然会报错:Error: registerApp required.)

  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值