在用云函数定时触发器开发消息订阅功能时,遇到一个问题。
环境:基础版本库2.17.0
在定时器函数中,调用另外一个云函数,该云函数中调用了cloud.openapi.subscribeMessage.send。在云函数日志端显示函数调用失败,但是在微信里可以收到一条订阅消息。二其它的订阅消息就无法收到。日志显示异常信息如下:
exception occured {
"errCode": -504002,
"errMsg": "callFunction:fail -504002 functions execute fail. requestID t_1647352800638_12041-17f8de0ebd5_2, TypeError: Do not know how to serialize a BigInt\n at JSON.stringify (<anonymous>)\n at callback (/var/runtime/node12/CallbackContext.js:31:23)\n at /var/runtime/node12/CallbackContext.js:81:16\n at /var/runtime/node12/Runtime.engine.js:237:13\n at processTicksAndRejections (internal/process/task_queues.js:97:5)"
出现问题的云函数代码如下:
const cloud = require('wx-server-sdk')
cloud.init({
env:cloud.DYNAMIC_CURRENT_ENV
});
const GOOD_GIFTS = [
{
"type":"每周好物推荐",
"title":"适合送给亲人和朋友的德尔玛加湿器",
"notify":"每周五晚19:00准时更新",
"date":"2022-03-25",
// "abstract":"德尔玛加湿器"
"abstract":"比京东同款便宜约20%~30%"
}
];
/*
the procedure:
1.get all the subscriber's openid
2.send the notify message to every subscriber
*/
exports.main = async (event, context) => {
// get openid
const allOpenid = await cloud.callFunction({
name:"getAllOpenid",
});
if( allOpenid == null )
return;
// get all the subscribers's openid array
candidateSets = allOpenid.result.data;
console.log("candidateSets = ",candidateSets);
for( let i = 0; i < candidateSets.length; i++){
console.log("sending the subscribe messege to the user:",candidateSets[i]._openid);
for(let j = 0; j < GOOD_GIFTS.length; j++){
try{
// send the subsribe message
res = await cloud.callFunction({
// the cloud function name
name:"subscribeGift",
// the parameter:open id, then cloud function will use event.openid to get the parameter
data:{
openid : candidateSets[i]._openid,
type : GOOD_GIFTS[j].type,
title : GOOD_GIFTS[j].title,
notify : GOOD_GIFTS[j].notify,
date : GOOD_GIFTS[j].date,
abstract : GOOD_GIFTS[j].abstract
}
});
}catch(err){
console.log("exception occured",err);
}finally{
console.log("sended the subscribe messege to the user:",candidateSets[i]._openid);
console.log("subscribeGift call result is:",res);
}
} //end of inner for loop
}//end of outer for loop
if( res )
return true;
else
return false;
}
}
https://developers.weixin.qq.com/community/develop/doc/0002e2b137c8580a30ad1297b5bc00?highLine=%2520Do%2520not%2520know%2520how%2520to%2520serialize%2520a%2520BigInt是这个吗?
请问有哪位大侠可以解答这个问题么?感谢感谢。看同类问题论坛上也有,但是没有合适答案