判断小程序分享到群聊还是用户

调用 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 {
                // 分享到个人
                }
            }
        }
    }
}

 

posted @ 2020-08-19 15:39  it大虫  阅读(566)  评论(2)    收藏  举报