收藏
回答

订阅消息实际已发送,但是云函数显示调用失败,是什么原因呢?

云函数日志截图

手机收到消息截图


云函数代码代码如下

if (action === 'SEND-POINTS-MESSAGE') {
  return sendPointMessage(payload)
}


async function sendPointMessage() {
    console.log('开始发送积分变动通知 --------- ');
    try {
        const result = await cloud.openapi.subscribeMessage.send({
            touser: 'oSkWu4lD_R-3fj0Hed1P3KhBcmbk',
            page: 'pages/home/home',
            lang: 'zh_CN',
            data: {
                // 变动原因
                thing5: {
                    value: '测试积分变动通知'
                },
                // 变动积分
                thing4: {
                    value: '+100积分'
                },
                // 剩余积分
                number8: {
                    value: 2700
                },
                // 操作人
                thing9: {
                    value: '27'
                },
                // 备注
                thing3: {
                    value: '积分可兑换礼品哟'
                }
            },
            templateId: 'KE4nhxVKrMRWnTPnTKWORzrYYa7bREb_P-Tnqc47Wrc',
            miniprogramState: 'formal'
        })
        console.log('发送积分变动通知结果 ---------- ', result)
        return result
    } catch (err) {
        console.error('发送积分变动通知失败 ---------- ', err)
        return err
    }
}




回答关注问题邀请回答
收藏

2 个回答

  • 27
    27
    2022-08-13

    用文档的数据测试,手机能收到消息,但云函数依然报异常。

    云函数日志截图

    手机收到消息截图:

    云函数代码如下:

    async function sendPointMessage() {
        console.log('开始发送积分变动通知 --------- ');
        try {
            const result = await cloud.openapi.subscribeMessage.send({
                touser: 'oSkWu4lD_R-3fj0Hed1P3KhBcmbk',
                page: 'pages/home/home',
                lang: 'zh_CN',
                data: {
                    // 变动原因
                    thing5: {
                        value: '参加周会'
                    },
                    // 变动积分
                    thing4: {
                        value: '+2积分'
                    },
                    // 剩余积分
                    number8: {
                        value: 20
                    },
                    // 操作人
                    thing9: {
                        value: '张三'
                    },
                    // 备注
                    thing3: {
                        value: '积分兑换消费'
                    }
                },
                templateId: 'KE4nhxVKrMRWnTPnTKWORzrYYa7bREb_P-Tnqc47Wrc',
                miniprogramState: 'formal'
            })
            console.log('发送积分变动通知结果 ---------- ', result)
            return result
        } catch (err) {
            console.error('发送积分变动通知失败 ---------- ', err)
            return err
        }
    }
    
    2022-08-13
    有用
    回复 1
  • 🌞
    🌞
    2022-08-13

    数据类型报错

    2022-08-13
    有用
    回复 1
    • 27
      27
      2022-08-13
      是吗?那我再试试,谢谢。
      2022-08-13
      回复
登录 后发表内容