需要通过调用 wx.showShareMenu 并且设置 withShareTicket 为 true。这一项必须设置,这样当用户将小程序分享到任一群聊之后,才可以获取到此次分享的 shareTicket。

onLoad: function (options) {
    wx.showShareMenu({
    // shareTicket 是获取转发目标群信息的票据,只有拥有 shareTicket 才能拿到群信息,用户每次转发都会生成对应唯一的shareTicket 。
    withShareTicket: true
    });
}

在onShareAppMessage中判断

onShareAppMessage: function (res) {
    var that = this;
    return {
        title: '自定义转发标题',
        path: 'pages/index/index',
        complete: function (res) {
            console.log(res);
            if (res.errMsg == 'shareAppMessage:ok') {
                //判断是否分享到群
                if (res.hasOwnProperty('shareTickets')) {
                   console.log(res.shareTickets[0]);
                   //分享到群
                } else {
                // 分享到个人
                }
            }
        }
    }
}    
                        

 

相关文章:

  • 2022-03-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-18
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2021-05-02
  • 2021-04-30
相关资源
相似解决方案