data:{
weixinVersion:'',//微信版本号
templateId:[]
}
onLoad: function (options){
let that = this
wx.getSystemInfo({
success: function (res) {
let version = res.version;
version = version.replace(/\./g, "")
that.setData({
weixinVersion: version,
})
}
})
let tempId= "HLqRVGo4uOEc-8dO1woj1K4_Gd0IiBZ-zNvzpWWaoBE,g9NA51_veMd5mydAwPsPSKnnEKBSRW4F8qtA9r53s6s",//后台返回的tempId
let tempPiniD = tempId.split(',')
that.setData({
templateId: tempPiniD,
})
}
// 订阅消息
requestMsg() {
let that = this
//微信版本大于7.0.4才可以发送订阅消息
if (that.data.weixinVersion > 704) {
wx.requestSubscribeMessage({
tmplIds: that.data.templateId,
success: (res) => {
let params = []//传给后端已选择的订阅消息
for (let i in that.data.templateId) {
if (res[that.data.templateId[i]] === 'accept') {
params.push(that.data.templateId[i])
}
}
if (params == '') {
console.log('用户取消订阅')
} else {
api.wxRequest({
method: 'POST',
url: "app/template/subscribe",
data: {
templateIds: params
},
}).then(res => {
console.log("template/subscribe", res)
})
}
console.log('成功后执行提交订单')
that.jump()
},
fail(err) {
console.log("失败", err);
that.jump()
}
})
} else {
console.log('用户微信版本小于7.0.4')
that.jump()
}
},
// 支付成功跳转
jump() {
let that = this
wx.redirectTo({
url: '../orderDetails/orderDetails',
})
},
The front end of the applet implements the subscription message
Guess you like
Origin blog.csdn.net/hql1024/article/details/108843252
Recommended
Ranking