const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
// 云函数入口函数
exports.main = async (event, context) => {
try {
const result = await cloud.openapi.subscribeMessage.send({
touser: event.openid,
page: 'pages/setting/setting',
data: {
thing1: {
value: ''
},
thing3: {
value: '2021年12月10日 18:00~19:00'
},
thing4: {
value: ''
},
thing5: {
value: ''
},
thing7: {
value: ''
}
},
templateId: '',
})
console.log(result)
return result
} catch (err) {
console.log(err)
return err
}
}
前端代码:
getPermission:function(){
wx.requestSubscribeMessage({
tmplIds: ['mv1AiOjD9ljPoaiFToRtIdZeW4T7uU8CTZLNBWdPNCQ'],
})
},
sendMsg:function(){
wx.cloud.callFunction({
name:"sendMsg",
data:{
openid:"o6gY35eNuNk1p7k8Hc_VlOw8wKGI"
}
}).then(res=>{
console.log('发送成功',res)
})
},
调用的地方呢
env: cloud.DYNAMIC_CURRENT_ENV,
wx.requestSubscribeMessage({
tmplIds: [
"oAujDykWLvy8ci2leuDFyTInJRYpkJ08ufLykYlIHYM"
],
success(res) {
console.log(res)
wx.cloud.callFunction({
name: 'subscribeMsg',
success: res => {
console.log(res)
},
fail : err => {
console.log(err)
}
})
},
fail(res) {
console.log("订阅消息API调用失败:",res)
}
})
}
const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV,
})
exports.main = async (event, context) => {
const {
OPENID
} = cloud.getWXContext()
try {
const result = await cloud.openapi.subscribeMessage.send({
touser: OPENID,
page: 'pages/index/index',
templateId: "oAujDykWLvy8ci2leuDFyTInJRYpkJ08ufLykYlIHYM",
data: {
"thing1": {
"value": '青团社'
},
"thing3": {
"value": '2000/月'
},
"name4": {
"value": '腊鸡子默'
},
"thing12": {
"value": '青团社前端开发工程师'
},
"thing9": {
"value": '浙江省杭州市余杭区文一西路1380号'
}
}
})
return result
} catch (err) {
console.log(err)
return err
}
}
fail(res) {