文章目录
在uniapp中,写了一个单独的页面,来写组件,如下:
1:注意微信SDK的引入,使用了
"jweixin-module": "^1.6.0"
2:template部分:
<template>
<view style="position: relative;">
<wx-open-subscribe style="width: 100vw; z-index: 2; position: absolute; top: 0;" :template="templateIds" id="subscribe-btn" ref="subscribeBtn" @success="success">
<script type="text/wxtag-template">
<style>
.btn2 {
width: 100%;
border: none;
padding: 15px 0;
background: #ff4444;
color: #fff;
}
</style>
<button class="btn2">立即参与</button>
</script>
</wx-open-subscribe>
</view>
3:后台获取参数,配置wx.config
jweixin.config({
debug: true,
appId: res.data.appId,
timestamp: res.data.timestamp,
nonceStr: res.data.nonceStr,
signature: res.data.signature,
jsApiList: ['wx-open-subscribe', 'wx-open-launch-app', 'launchAppLication'],
openTagList: ['wx-open-subscribe', 'wx-open-launch-app', 'wx-open-subscribe-dialog']
})
后来遇到的问题,在测试页面,按钮显示,点击有弹窗,后移动到需要的页面的时候:按钮一直不显示,后来发现是传参错误。
我们的传参是要绑定的页面,从测试页面复制到正式页面,参数没有做修改,就一直报错:
真机上显示,invalid signature
微信工具显示,openTagList为空
后将页面参数传正确后,问题解决。猜想,根据要绑定的页面生成的签名和所需的参数