注意事项:
-
weixin-js-sdk版本一定要是1.6.0以上:"weixin-js-sdk": "^1.6.0"
-
H5的域名ip需要配置的微信公众平台后台系统的白名单中
-
wx.config的jsApiList必须有一个
-
wx.config的openTagList为["wx-open-launch-weapp"] 注意后边是weapp而非app
-
引入import wx from "weixin-js-sdk"
-
正式环境调试,微信开发者工具让它滚蛋~
-
代码如下,懒得排版了:
<div class="jump"> <div class="pos"> <div class="wxbtn"> <!-- ct为按钮显示的图片 wx-open-launch-weapp的button按钮为opacity:0 absolute --> <div class="ct"></div> <div> <wx-open-launch-weapp style=" position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: inline-block; border: none; " username="gh_xxxxxxxx" appid="wx111111111111" path="xxx/index" > <script type="text/wxtag-template"> <style> .btn { position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0; } </style> <button class="btn"></button> </script> </wx-open-launch-weapp> </div> </div> </div> </div> wx.config({ debug: false, // 开启调试模式, appId: res.data.jsigParam.appId, // 必填,企业号的唯一标识,此处填写企业号corpid timestamp: res.data.jsigParam.timestamp, // 必填,生成签名的时间戳 nonceStr: res.data.jsigParam.noncestr, // 必填,生成签名的随机串 signature: res.data.jsigParam.signature, // 必填,签名,见附录1 jsApiList: ["updateTimelineShareData"], // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 openTagList: ["wx-open-launch-weapp"], }); .jump { width: 100%; height: 100%; background: url("../../assets/bg.png") no-repeat; background-size: 100% 100%; position: relative; } .pos { width: 36.3125rem * 0.5; height: 8.5625rem * 0.5; position: absolute; left: 50%; transform: translate(-50%); bottom: 6.5rem; } .wxbtn { width: 36.3125rem * 0.5; height: 8.5625rem * 0.5; line-height: 8.5625rem * 0.5; text-align: center; color: #ffffff; font-weight: 500; position: relative; .ct { width: 100%; height: 100%; background: url("../../assets/btn.png") no-repeat; background-size: 100% 100%; } }