Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.9k views
in Technique[技术] by (71.8m points)

小程序订阅消息subscribeMessage.send报错43101,没有底部授权弹窗没有消息通知,可能是什么原因?

希望通过小程序demo实现,用户评论的结果通知到用户自己。提交评价,评价成功则调用云函数。

调试基础库:2.14.1

云函数代码如下:

exports.main = async (event, context) => {
  console.log("event", event)
  const { OPENID } = cloud.getWXContext()
  console.log("OPENID", OPENID)
  const result = await cloud.openapi.subscribeMessage.send({
    touser: OPENID,
    page: `/pages/blog-comment/blog-comment?blogId=${event.blogId}`,
    data: {
      thing1: {
        value: '评价完成'
      },
      thing2: {
        value: event.content
      }
    },
    template_id: '7zt83hMczrBmoptjry5n50sZ6JdkVcS4p3A706O9i_g',
  })
  console.log("结果", result)
  return result
}

云函数可以被调用,event和OPENID都可以正常打印,报错返回结果:

{"errorCode":1,"errorMessage":"user code exception caught","stackTrace":"Error: errCode: 43101  | errMsg: openapi.subscribeMessage.send:fail user refuse to accept the msg rid: 5ff57464-05346540-27a2bba9
    at callWXOpenAPI (/var/user/node_modules/wx-server-sdk/index.js:2378:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)","statusCode":430}

我很困惑的是43101这个报错看起来十分宽泛,我定位不到错误的地方。但无论是模拟器还是真机我都没有看到底部的授权通知。我不太明白为什么就“用户拒绝”了。路过的各位大佬麻烦指点一下,我可能哪里写错了,谢谢!

补充:小程序的设置里只有用户信息一栏:
image


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

设置 -> 通知管理,看看是不是开启了接收通知,没开启的话开起来
--------------->
更新一版吧
首先你需要在c端用户主动点击情况下去调用wx.requestSubscribeMessage

wx.requestSubscribeMessage({
          tmplIds: xxxx,
          success(res) {
            if (res.errMsg === 'requestSubscribeMessage:ok') {
              let flag = subscribeData.data.every(id => res[id] === 'reject')
              // 点击取消按钮有cancel事件时
              if (flag && cancel) {
                cancel()
                return
              }
              // 点击取消 return
              if(flag) return 
              success && success(res, subscribeData.data)
            }
          }
        })

这时用户点击了允许你才可以在服务端发送订阅消息

具体流程建议你再仔细看看小程序文档


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...