<wx-open-launch-weapp id="launch-btn" username="gh_b55a4e10aaf6" path="pages/index/index">
<script type="text/wxtag-template">
<style>
.custom-btn { width: 100%; padding: 12px; background-color: #07c160; color: white; border: none; border-radius: 4px; font-size: 16px; }
</style>
<div class="custom-btn">打开小程序</div>
</script>
</wx-open-launch-weapp>
async initWxConfig() {
http.post('/frontend/login/getSign', { url: window.location.href, ad_id: 0 }).then(res => {
const signPackage = res.data;
var ua = navigator.userAgent.toLowerCase()
var isWXWork = ua.match(/wxwork/i) == 'wxwork'
var isWeixin = !isWXWork && ua.match(/micromessenger/i) == 'micromessenger'
if (isWeixin) {
wx.config({
debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: 'wx13145f521e3a7f19', // 必填,公众号的唯一标识
timestamp: signPackage.timestamp, // 必填,生成签名的时间戳
nonceStr: signPackage.nonceStr, // 必填,生成签名的随机串
signature: signPackage.signature,// 必填,签名
jsApiList: ["chooseImage"], // 必填,需要使用的JS接口列表
openTagList: [
"wx-open-launch-weapp"
]
});
wx.ready(function () {
console.log('ready')
})
wx.error(function (res) {
console.log(res, '微信错误信息')
})
document.addEventListener('WeixinOpenTagsError', function (e) {
console.error(e.detail.errMsg); // 无法使用开放标签的错误原因,需回退兼容。仅无法使用开放标签,JS-SDK其他功能不受影响
});
}
})
.catch(error => {
console.error('There was an error!', error);
});
},
接口返回的数据
{
'code":200,
'data":{
"appld":"wx65da39a899e7f019",
"timestamp":1773306408
"nonceStr":"5dfZcCGmUZzhUKqz”
"signature": "d15c8def3ec1113d5171bcdd531582dfad8e6e7f",
"url":"https://h5.dev.yyqmed.com/feedback”
}
结果 debug 出来的错误是: {realAuthUrl":"[https://h5.dev.yyqmed.com/feedback, https://h5.dev.yyqmed.com/feedback]""errMsg":"config:invalid
signature"}
