关于调用云函数发送模板消息总是失败
发布于 5 年前 作者 yang90 11937 次浏览 来自 问答

openid和form_id都是同一用户的,但调用官方提供的例子,总是返回

“errCode”:41028,“errMsg”:“openapi.templateMessage.send:fail invalid form id hint: [DUJcrA09814126]”

折腾了大半天,都不知道原因在哪里,到这里寻求一下帮助。

这是云函数

const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
  try {
    const result = await cloud.openapi.templateMessage.send({
        touser: event.openid,
        template_id: event.msgid,
        page: event.page,
        form_id: event.formid,
        data: event.msgData,
        emphasisKeyword: 'keyword2.DATA'
    })
    console.log(result)
    return result
  } catch (err) {
    console.log(err)
    return err
  }
}

这是调用代码:

console.log('openid:' + that.data.messages[that.data.index2]._openid)
    console.log('form_id:' + that.data.messages[that.data.index2].form_id) 
      wx.cloud.callFunction({
        name: 'send',
        data: {         
          openid: that.data.messages[that.data.index2]._openid,        
          msgid: 'eBnlQKSCORuwkctGXnrPLBoX2MxhGLI8aCZFz4S65e8',//模板id
          page: 'index?no=' + that.data.messages[that.data.index2].no,
          form_id: that.data.messages[that.data.index2].form_id,
          msgData: {
            "keyword1": { "value": db.serverDate(), "color": "#173177" },
            "keyword2": { "value": that.data.inputContent, "color": "#173177" }
          }
        },
        success: res => {
          wx: wx.showToast({
            title: '推送消息成功',
            icon: 'none'
          })
          console.log(res)
        },
 
        fail: e => {
          console.error('[失败:', e)         
        }
      })
1 回复
回到顶部