问题找到了,原来这个小程序的appid和云函数调用时的appid不一样。 而且文档给的方法返回值也会有问题。应该改成这样 'use strict'; const cloud = require('wx-server-sdk') cloud.init( { env: cloud.DYNAMIC_CURRENT_ENV, } ) exports.main = async (event, context) => { console.log("dddd:", cloud.DYNAMIC_CURRENT_ENV) let { OPENID, APPID } = cloud.getWXContext() // 这里获取到的 openId 和 appId 是可信的 console.log(`openid:${OPENID},APPID:${APPID}`) try { console.log(`入参:templateId:${event.templateId}, openid:${event.openid}, time1:${event.time1}, thing2:${event.thing2}, thing3:${event.thing3}`) let result = await cloud.openapi.subscribeMessage.send({ "touser": event.openid, "page": 'index', "lang": 'zh_CN', "data": { "thing1": { "value": event.thing1 }, "thing3": { "value": event.thing3 }, "time2": { "value": event.time2 } }, "templateId": event.templateId, "miniprogramState": 'developer' }) console.log("================") Object.keys(result).forEach(function (key) { console.log(key, result[key]); }) console.log(typeof result.errCode); console.log(typeof result.errMsg); console.log(JSON.stringify(result.errCode)); console.log(JSON.stringify(result.errMsg)); console.log("================") return {errMsg:result.errMsg,errCode:result.errCode} } catch (err) { console.log("22222:") console.log(err) return err } };
微搭调用云函数cloud.openapi.subscribeMessage.send发消息失败https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html [图片] [图片] [图片]
2022-07-27