公众号,h5,html 跳转到小程序

公众号h5打开小程序
微信提供了开放标签
地址https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_Open_Tag.html
1,引入微信的JSSDK
2,配置wx.config

wx.config({
    
    
  debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  appId: '', // 必填,公众号的唯一标识
  timestamp: , // 必填,生成签名的时间戳
  nonceStr: '', // 必填,生成签名的随机串
  signature: '',// 必填,签名
  jsApiList: [] // 必填,需要使用的JS接口列表
});

3,在页面使用wx-open-launch-weapp

<wx-open-launch-weapp
  id="launch-btn"
  username="gh_xxxxxxxx"
  path="pages/home/index?user=123&action=abc"
>
  <template>
    <style>.btn {
    
     padding: 12px }</style>
    <button class="btn">打开小程序</button>
  </template>
</wx-open-launch-weapp>
<script>
  var btn = document.getElementById('launch-btn');
  btn.addEventListener('launch', function (e) {
    
    
    console.log('success');
  });
  btn.addEventListener('error', function (e) {
    
    
    console.log('fail', e.detail);
  });
</script>

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44467587/article/details/115691537