微信公众号H5网页跳转小程序方法

要在微信公众号H5网页跳转到小程序,需要使用微信JS-SDK,引入JS文件:http://res.wx.qq.com/open/js/jweixin-1.6.0.js ,在服务端验签获取配置信息,获取成功以后,引入开放标签openTagList: [‘wx-open-launch-weapp’],就可以使用了。

JS-SDK使用方法请参照官方文档:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html

<wx-open-launch-weapp
  id="launch-btn"
  username="gh_xxxxxxxx"
  path="pages/home/index.html?user=123&action=abc"
>
  <template>
    <button class="btn">打开小程序</button>
  </template>
</wx-open-launch-weapp>
<script>
var se={};
axios({
   method: 'post',
   url: '/api/wechatJsSdk',
   data: {
     'url':  window.location.href,
   }
 }).then(function (res) {
   // vant.Toast({message:res.data.msg,closeOnClick:true});
   // console.log(res);
   if (res.data.code == 1) {
     se.wx = res.data.data;
     wxconfig();
   }
 });

function wxconfig(){
  wx.config({
    debug: false,
    appId: se.wx.appId,
    timestamp: se.wx.timestamp,
    nonceStr: se.wx.nonceStr,
    signature: se.wx.signature,
    jsApiList: [],
    openTagList: ['wx-open-launch-weapp']
  });

  wx.ready(function () {
    //自动执行的
  });

  wx.error(function (res) {
    alert(res.errMsg);
  });
}
</script>

同样的方法,还可以实现公众号H5跳转APP。

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值