调用JS如下:
tuisong() {
console.log(this.data.rec)
var item = {
"time1": {
"value": this.dateFormat(this.data.rec[1].cdate)
},
"thing2": {
"value": this.data.rec[1].line
},
"thing3": {
"value": this.data.rec[1].postion
},
"thing4": {
"value": this.data.rec[1].status
}
}
wx.requestSubscribeMessage({
tmplIds: ['R88OQ7kzfTRYe0yFXbdtz_gtPQtlPGc-bt9V-TzQAZE'], //这里填入我们生成的模板id
success: res => {
if (res.errMsg === 'requestSubscribeMessage:ok') {
console.log('授权成功', res)
wx.cloud.callFunction({
name: 'getopenid',
}).then(res=>{
console.log('当前OPENID是',res.result.openid)
this.setData({
openid:res.result.openid
})
wx.cloud.callFunction({
name: 'send',
data: {
data: item,
openid: this.data.openid,
templateId: 'R88OQ7kzfTRYe0yFXbdtz_gtPQtlPGc-bt9V-TzQAZE',
}}).then(res=>{
console.log('订阅成功', res)
})
.catch(res=>{
console.log('订阅失败', res)
})
})
}
},
fail: res => {
console.log('授权失败', res)
}
})
},
云函数如下:
const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
exports.main = async (event, context) => {
return cloud.openapi.subscribeMessage.send({
touser: event.openid,
page: 'pages/query/index/index',
data: event.data,
templateId: event.templateId,
})
};
错误提示:
订阅失败 Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID 063184d2-56ce-474d-83f2-2349b16d26f2, cloud function service error code -504002, error message TypeError: Do not know how to serialize a BigInt
at JSON.stringify (<anonymous>)
at callback (:19586/var/runtime/node12/CallbackContext.js:31)
at :19586/var/runtime/node12/CallbackContext.js:81
at :19586/var/runtime/node12/Runtime.engine.js:237
at processTicksAndRejections (:19586/appservice/internal/process/task_queues.js:97); at cloud.callFunction api;
at new t (WASubContext.js?t=wechat&s=1666316963773&v=2.14.1:17)
at u (WASubContext.js?t=wechat&s=1666316963773&v=2.14.1:17)
at l (WASubContext.js?t=wechat&s=1666316963773&v=2.14.1:17)
at Function.success (WASubContext.js?t=wechat&s=1666316963773&v=2.14.1:17)
at f (WASubContext.js?t=wechat&s=1666316963773&v=2.14.1:2)
at WASubContext.js?t=wechat&s=1666316963773&v=2.14.1:2
at f (WASubContext.js?t=wechat&s=1666316963773&v=2.14.1:26)
at Function.<anonymous> (WASubContext.js?t=wechat&s=1666316963773&v=2.14.1:26)
at f (WASubContext.js?t=wechat&s=1666316963773&v=2.14.1:2)
at WASubContext.js?t=wechat&s=1666316963773&v=2.14.1:2
各位大神请帮忙看看,为啥老是订阅失败,但小程序又可以接收到订阅消息哦