IT门户, 中国互联网人工智能物联网行业资讯平台--公众IT
新闻来源:互联网资料整理       发布时间:2023/4/5 14:21:21       共计:4614 浏览

前言:

16小时前小编发现微信小程序用户:【见龙在田】提出了一个关于“如何解决在云函数中调用subscribeMessage.send出错问题?”的问题,在问题中开发者见龙在田对该问题做了如下阐述:

问题类型:


  • API和组件:

问题描述:

在用云函数定时触发器开发消息订阅功能时,遇到一个问题。

环境:基础版本库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
at JSON.stringify (<anonymous>)
at callback (/var/runtime/node12/CallbackContext.js:31:23)
at /var/runtime/node12/CallbackContext.js:81:16
at /var/runtime/node12/Runtime.engine.js:237:13
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;

}

}

注:以上是微信小程序开发者:”见龙在田”对于本问题的一些阐述,这里做一个引用,我们将实时关注微信小程序助手对该问题提出的解决方案。

解决方案:

【1小时前】微信小程序技术运营专员对用户见龙在田提出的如何解决在云函数中调用subscribeMessage.send出错问题?给予如下回复

https://developers.weixin.qq.com/community/develop/doc/0002e2b137c8580a30ad1297b5bc00?highLine=%2520Do%2520not%2520know%2520how%2520to%2520serialize%2520a%2520BigInt是这个吗?

结语:

微信官方智能微信小程序适用搜索触达微信小程序,适用包括微信官方系产品及全部浏览器上访问,将来以至于还适用在智能家居系统上运行,这能够让开发人员真实实现开口吸纳流量、收口留存客户的目的。微信官方的智能技术很高,因而微信小程序的技术也强大到别的服务平台不能比拟。

如果您也在使用微信小程序,请关注我们,如果您有关于微信小程序的使用问题请关注我们,如果您要找百度小程序模板、微信小程序模板请关注小程序模板网或者去微信开放社区找官方人员给予解决,相信微信官方在小程序上的发力会是一个里程碑!

版权说明:
本网站凡注明“公众IT 原创”的皆为本站原创文章,如需转载请注明出处!
本网转载皆注明出处,遵循行业规范,如发现作品内容版权或其它问题的,请与我们联系处理!
您可以扫描右侧微信二维码联系我们。
网站首页 关于我们 联系我们 合作联系 会员说明 新闻投稿 隐私协议 网站地图