收藏
回答

订阅消息问题?

调用JS如下:

tuisong() {
    console.log(this.data.rec)
    var item = {
      "time1": {
        "value"this.dateFormat(this.data.rec[1].cdate)
      },
      "thing2": {
        "value":  this.data.rec[1].line
      },
      "thing3": {
        "value"this.data.rec[1].postion
      },
      "thing4": {
        "value"this.data.rec[1].status
      }
    }
    wx.requestSubscribeMessage({
      tmplIds: ['R88OQ7kzfTRYe0yFXbdtz_gtPQtlPGc-bt9V-TzQAZE'], //这里填入我们生成的模板id
      success: res => {
        if (res.errMsg === 'requestSubscribeMessage:ok') {
          console.log('授权成功', res)
          wx.cloud.callFunction({
            name: 'getopenid',
          }).then(res=>{
            console.log('当前OPENID是',res.result.openid)
            this.setData({
              openid:res.result.openid
            })
            wx.cloud.callFunction({
              name: 'send',
              data: {
                data: item,
                openid: this.data.openid,
                templateId: 'R88OQ7kzfTRYe0yFXbdtz_gtPQtlPGc-bt9V-TzQAZE',
              }}).then(res=>{
                console.log('订阅成功', res)
              })
              .catch(res=>{
                  console.log('订阅失败', res)
              })
          })
        }
      },
      fail: res => {
        console.log('授权失败', res)
      }
    })
  },

云函数如下:

const cloud = require('wx-server-sdk')


cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
}) 


exports.main = async (event, context) => {
  return cloud.openapi.subscribeMessage.send({
    touser: event.openid,
    page: 'pages/query/index/index',
    data: event.data,
    templateId: event.templateId,
  })
};



错误提示:

订阅失败 Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID 063184d2-56ce-474d-83f2-2349b16d26f2, cloud function service error code -504002, error message TypeError: Do not know how to serialize a BigInt

    at JSON.stringify (<anonymous>)

    at callback (:19586/var/runtime/node12/CallbackContext.js:31)

    at :19586/var/runtime/node12/CallbackContext.js:81

    at :19586/var/runtime/node12/Runtime.engine.js:237

    at processTicksAndRejections (:19586/appservice/internal/process/task_queues.js:97); at cloud.callFunction api; 

    at new t (WASubContext.js?t=wechat&s=1666316963773&v=2.14.1:17)

    at u (WASubContext.js?t=wechat&s=1666316963773&v=2.14.1:17)

    at l (WASubContext.js?t=wechat&s=1666316963773&v=2.14.1:17)

    at Function.success (WASubContext.js?t=wechat&s=1666316963773&v=2.14.1:17)

    at f (WASubContext.js?t=wechat&s=1666316963773&v=2.14.1:2)

    at WASubContext.js?t=wechat&s=1666316963773&v=2.14.1:2

    at f (WASubContext.js?t=wechat&s=1666316963773&v=2.14.1:26)

    at Function.<anonymous> (WASubContext.js?t=wechat&s=1666316963773&v=2.14.1:26)

    at f (WASubContext.js?t=wechat&s=1666316963773&v=2.14.1:2)

    at WASubContext.js?t=wechat&s=1666316963773&v=2.14.1:2



最后一次编辑于  2022-10-21
回答关注问题邀请回答
收藏

2 个回答

  • 葫芦爷救娃娃
    葫芦爷救娃娃
    2022-10-21

    wx.requestSubscribeMessage({

                                  tmplIds: ['LQh_C30ykrNusZ1grLMzVakWiNn6BX_yStMquKCkXa8','HvGlhNaNy3r4Qpp-GtXNQUasb-6EcrH-cQHVcl2La7w'],

                                  //在数组中填入刚刚复制的模版id

                                  success(res) {

                                    console.log(res)//我们可以输出res来看看是怎么样的(大家可以试试)

                                    //然后我们判断用户是否点击了同意授权

                                    if(res[   'LQh_C30ykrNusZ1grLMzVakWiNn6BX_yStMquKCkXa8','HvGlhNaNy3r4Qpp-GtXNQUasb-6EcrH-cQHVcl2La7w']=='accept'){

                                        wx.hideLoading(),

                                        wx.showToast({

                                          title: '您已订阅下次消息通知,记得及时查看哦!',

                                          icon:"none"

                                        })

                                    }else{

                                      //用户没有点击同意订阅

                                      wx.showToast({

                                        title: '为了更好的服务,请订阅一下哦',

                                        icon:"none"

                                      })

                                      return;

                                    }

                                  }

                                });

    这样试一下,每一步都把判断的参数打印试一下,确保能成功调起订阅,然后再调用其他方法或者函数

    2022-10-21
    有用
    回复 11
    • 8040
      8040
      2022-10-21
      2022-10-21
      回复
    • 8040
      8040
      2022-10-21回复8040
      我都有的,但就是走订阅失败
      2022-10-21
      回复
    • 葫芦爷救娃娃
      葫芦爷救娃娃
      2022-10-21回复8040
      检查一下你后台对应的appid是否一致
      2022-10-21
      回复
    • 8040
      8040
      2022-10-21
      应该不跟appid有关吧
      2022-10-21
      回复
    • 葫芦爷救娃娃
      葫芦爷救娃娃
      2022-10-21回复8040
      你再艾特其他大佬试试
      2022-10-21
      回复
    查看更多(6)
  • 8040
    8040
    2022-10-21

    各位大神请帮忙看看,为啥老是订阅失败,但小程序又可以接收到订阅消息哦

    2022-10-21
    有用
    回复
登录 后发表内容