
export function noticeuntil(data) {
let code = uni.getStorageSync('code');
let access_token = uni.getStorageSync('token');
let openid = uni.getStorageSync('openid')
let appid = '' // 小程序id
let secret = '' //小程序密钥
if (access_token == '') {
wx.request({
method: 'GET',
url: `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${appid}&secret=${secret}`,
success: function(res) {
uni.setStorageSync('token', res.data.access_token);
},
fail: function(res) {
console.log("订阅失败");
},
})
} else if (openid == '') {
wx.request({
url: `https://api.weixin.qq.com/sns/jscode2session?appid=${this.appid}&secret=${this.secret}&js_code=${code}&grant_type=authorization_code`,
success: (res) => {
uni.setStorageSync('openid', res.data.openid);
}
})
} else {
wx.request({
method: 'POST',
url: `https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=${access_token}`,
data: {
"touser": this.userInfo.openid,
"template_id": "_KGhOaZJvMB4b7b0w696fYSaAc61fS3yFjb3b0aaNDk",
"page": "pages/index/index",
"miniprogram_state": "developer", //
"lang": "zh_CN",
"data": {
"character_string1": {
"value": "T208006372074467328"
},
"thing2": {
"value": "余额"
},
"amount3": {
"value": "100.00"
},
"phrase4": {
"value": "已确认"
}
}
},
success: function(res) {
console.log(res)
},
fail: function(res) {
console.log("订阅失败");
},
})
}
wx.requestSubscribeMessage({
tmplIds: ['_KGhOaZJvMB4b7b0w696fYSaAc61fS3yFjb3b0aaNDk'],
success(res) {
/*
[TEMPLATE_ID]是动态的键,即模板id,值包括'accept'、'reject'、'ban'、'filter'。
'accept'表示用户同意订阅该条id对应的模板消息,
'reject'表示用户拒绝订阅该条id对应的模板消息,
'ban'表示已被后台封禁,'filter'表示该模板因为模板标题同名被后台过滤。
例如 { errMsg: "requestSubscribeMessage:ok", zun-LzcQyW- edafCVvzPkK4de2Rllr1fFpw2A_x0oXE: "accept"}
表示用户同意订阅zun-LzcQyW-edafCVvzPkK4de2Rllr1fFpw2A_x0oXE这条消息
*/
console.log(res)
}
})
}
(1条消息) 【实战】微信小程序订阅消息,后台SpringBoot实现_蔚蓝不远的博客-优快云博客
微信小程序订阅功能实现 前后端_Posden的博客-优快云博客