我也遇到这个问题了,没报错但是就是发不出
订阅消息webhook发送失败?云函数发送订阅消息,本地调试可以正常发送。 [图片] webhook调用云函数发送订阅消息老是失败,求各位大佬帮忙找找原因 [图片] 下面是云函数代码 const cloud = require('wx-server-sdk') cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV, }) const db=cloud.database(); const _ = db.command; exports.main = async (event, context) => { try { //审核结束的商品ID,来自CMS的Webhook var goodsId = event.actionFilter._id; //webhook调用时的ID // var goodsId = event._id; //本地调试时的ID //获取商品信息 var goodsData = await db.collection("XianZhi").doc(goodsId).get() //枚举框架,true=通过,false=不通过 var SizeEnum = { properties: { true: {value: true, code: "通过"}, false: {value: false, code: "不通过"}, } } //获取审核结果布朗值 var Encode = goodsData.data.passshow //审核结果布朗值转换成中文字符串 var CHcode = SizeEnum.properties[Encode].code; //获取审核时间 var passtime = goodsData.data.passtime //时间戳转日期 // var dateTime = new Date(parseInt(passtime)).toLocaleString() var time = new Date(passtime); var year = time.getFullYear(); var month = time.getMonth() + 1; var date = time.getDate(); var hour = time.getHours(); var minute = time.getMinutes(); var second = time.getSeconds(); month = month < 10 ? "0" + month : month; date = date < 10 ? "0" + date : date; hour = hour < 10 ? "0" + hour : hour; minute = minute < 10 ? "0" + minute : minute; second = second < 10 ? "0" + second : second; var dateTime = year + "年" + month + "月" + date + "日" + " " + hour + ":" + minute + ":" + second; //获取审核不通过原因 var because = goodsData.data.because //获取提示信息 var toast = goodsData.data.toast //获取发送对象 var touser = goodsData.data.openid const result = await cloud.openapi.subscribeMessage.send({ "touser": touser, "page": '/pages/seller/seller', "lang": 'zh_CN', "data": { //审核类型 thing1:{ value:"闲置商品发布审核" }, //审核结果 thing4:{ value:CHcode }, //审核时间 date7:{ value:dateTime }, //不通过的原因 thing5:{ value:because }, //温馨提示 thing12:{ value:toast } }, "templateId": '7WkR7ofDDQuZ6NPIz3_RkRmUoBsaDr1b35KZKA1H2zM' }) //发送之后,减去一个订阅数量 var userData = await db.collection("DinYue_Message").where({ openid:touser, type:"Shenhen" }).update({ data:{ num:_.inc(-1) } }) return result,userData } catch (err) { return err } }
2022-11-17