云函数代码:
// 云函数入口文件
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.userInfo.openId,
"templateId": '5s76E-SmUzThGyUzt9kwZHyM8bS2a9kp8n-eddGHI3Q',
"page": 'pages/note/note',
"miniprogramState": 'developer',
"lang": 'zh_CN',
"data": {
"thing3": {
"value": '做毕业设计'
},
"time1": {
"value": '2023年06月05日'
}
}
})
return result
} catch (err) {
return err
}
}
调用云函数
cloud.callFunction({
name: 'sendNotification',
data: {
openid: 'oZ2FT5frfjqxcx-hO7FOZ8G4g1B0'
// openid: 'oZ2FT5V65xu-S0TThSfeG15HooUY'
},
success: res => {
// console.log("okokokokoko")
console.log(res)
},
fail: err => {
console.error(err)
}
})