报错:{errMsg: "requestSubscribeMessage:fail No template data return, verify the template id exist", errCode: 20001}

上面的意思是,template id 不存在,但是在小程序后台看了,订阅消息中确实是存在的。

  //主动询问订阅消息
  onNotifyAsk(callback) {
    let tempId = this.data.tempIds;
    wx.requestSubscribeMessage({
      tmplIds: tempId,
      success: res => {
        console.log('调起成功');
        if (res[tempId[0]] === 'accept') {
          console.log('允许');
          callback('accept')
        }
        if (res[tempId[0]] === 'reject') {
          console.log('拒绝')
          callback('reject')
        }
      },
      fail: err => {
        callback('error');
        console.log(err)
        if (err.errCode == 20004) {
          console.log('关闭小程序主开关')
        } else {
          console.log('订阅失败')
        }
      }
    });
  },
​
tempIds: ['dlcx-N6lY-kDe_7uOO5lI6qcoxFs2Cdc62t6GIxPD0I'],

​

以上是之间的代码,现在无法正常工作。

修改以后的代码可以正常工作:

//主动询问订阅消息
  onNotifyAsk(callback) {
    let tempId = this.data.tempIds;
    wx.requestSubscribeMessage({
      tmplIds: ['dlcx-N6lY-kDe_7uOO5lI6qcoxFs2Cdc62t6GIxPD0I'],
      success: res => {
        console.log('调起成功');
        if (res['dlcx-N6lY-kDe_7uOO5lI6qcoxFs2Cdc62t6GIxPD0I'] === 'accept') {
          console.log('允许');
          callback('accept')
        }
        if (res['dlcx-N6lY-kDe_7uOO5lI6qcoxFs2Cdc62t6GIxPD0I'] === 'reject') {
          console.log('拒绝')
          callback('reject')
        }
      },
      fail: err => {
        callback('error');
        console.log(err)
        if (err.errCode == 20004) {
          console.log('关闭小程序主开关')
        } else {
          console.log('订阅失败')
        }
      }
    });
  },

以上把信息写死,竟然可以了。

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐