直接上代码(多个消息模板时,每个模板id直接用逗号分隔)
<!-- 订阅浮窗 -->
<div id="wxsub" style="position: fixed;bottom: 300rpx;right: 35rpx;width: 152rpx;height: 152rpx;"></div>
let href = encodeURIComponent(window.location.href.split('#')[0])
this.$u.get(`${getUrl}?url=${href}`).then(res => {
if (res.code === 0) {
wx.config({
debug: false,
appId: res.data.appId,
timestamp: res.data.timestamp,
nonceStr: res.data.nonceStr,
signature: res.data.signature,
jsApiList: ['checkJsApi'],
openTagList: ['wx-open-subscribe']
});
wx.ready(function(res) {
var dom1 = document.getElementById('wxsub')
dom1.innerHTML =
`<wx-open-subscribe id="subscribet" template="消息模板id" >
<template>
<img src="imgUrl" width="110px" height="110px"/>
</template>
</wx-open-subscribe>`
var subscribet = document.getElementById('subscribet')
subscribet.addEventListener('success', function(e) {
console.log('s-success', e);
})
subscribet.addEventListener('error', function(e) {
console.log('s-error', e);
})
});
wx.error(function(res) {
console.log('res', res);
});
}
})
实现效果(该订阅为一次性订阅,点击一次只能接收一次通知,再想接收,得提前订阅,微信这个功能真鸡肋~~~)