请问有哪位大侠可以解答这个问题么?感谢感谢。看同类问题论坛上也有,但是没有合适答案
如何解决在云函数中调用subscribeMessage.send出错问题?在用云函数定时触发器开发消息订阅功能时,遇到一个问题。 环境:基础版本库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; } }
2022-03-16这个问题我昨天也遇到了,虽然消息发送成功了。但是云函数就退出了。所以效果就是我在云函数中准备给一批用户发送订阅消息,结果就是发送了第一个用户后,其它用户就收不到了。这个问题还是必须解决掉。我也还没有找到原因。不知道怎么回事?
subscribeMessage.send errCode: -504002报错?[图片]Error: cloud.callFunction:fail Error: errCode: -504002 functions execute fail | errMsg: TypeError: Do not know how to serialize a BigInt 调用订阅消息后测试消息可以发送成功,但是返回值报错Do not know how to serialize a BigInt,无法判断是否发送成功。 2022-05-01 解决方法:云函数的返回值不要返回result,直接返回result.errCode,就不会报错。原因是直接返回result被序列化导致报错(其实就是bug),所以返回result.errCode足以用于判断!
2022-03-16我也遇到同类问题,就是在一个带trigger的云函数中,调用另外一个云函数,该云函数主要就是调用cloud.openapi.subscribeMessage.send,然后出现-504002错误,有点莫名其妙 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)" }
send subscribeMessage.send 报errCode: -501007?订阅消息 /subscribeMessage.send ,采用 云调用方式。openapi.subscribeMessage.send j技术场景:在node环境里,调起云函数,去发送消息给已经订阅了的用户,报501007错误。 详见代码: node-test.js const tcb = require('@cloudbase/node-sdk'); const app = tcb.init({ secretId: "*****", secretKey: "*****", env: "*****" }); sendmessagenw() async function sendmessagenw() { const res = await app.callFunction({ name: 'send-message', }) console.log(res) } x下图云函数内容,就直接抄官方的demo [图片] 运行node文件后,报501007错误,是不是在node里调起 发订阅消息给用,只能采用 http方式?
2022-03-16