WeChat Mini Program Example: Judgment Code for Sharing to One Person or to a Group

不言
Release: 2018-08-11 17:23:47
Original
4509 people have browsed it

The content of this article is about WeChat applet examples: the code for judging whether to share with one person or with a group. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. help.

The sharing function of the WeChat applet can no longer get the sharing callback on the latest version of the IDE. The official API has also deleted the corresponding callback function. It seems to have been cut off, but the real machine test still works Okay, without further ado, here’s the code:

onLoad: function(options) {
    wx.showShareMenu({
            //只有拥有 shareTicket 才能拿到群信息,用户每次转发都会生成对应唯一的shareTicket 。
            withShareTicket: true
        });
},
onShareAppMessage: function(res) {
        var _this = this;
        console.log(res);
        if (res.from === 'button') {
            // 来自页面内转发按钮
            _this.data.shareBtn = true;
        } else {
            //来自右上角转发
            _this.data.shareBtn = false;
        }
        return {
            title: '自定义转发标题',
            path: 'pages/index/index',
            complete: function(res) {
                console.log(res);
                if (res.errMsg == 'shareAppMessage:ok') {
                    //分享为按钮转发
                    if (_this.data.shareBtn) {
                        //判断是否分享到群
                        if (res.hasOwnProperty('shareTickets')) {
                            console.log(res.shareTickets[0]);
                            //分享到群
                            _this.data.isshare = 1;
                        } else {
                            // 分享到个人
                            _this.data.isshare = 0;
                        }
                    }
                } else {
                    wx.showToast({
                        title: '分享失败',
                    })
                    _this.data.isshare = 0;
                }
            },
        }
    }
Copy after login

Related recommendations:

How to limit the size of WeChat applet when uploading pictures (with code)

Mini Program: How to dynamically add and delete JSON object arrays (with code)

The above is the detailed content of WeChat Mini Program Example: Judgment Code for Sharing to One Person or to a Group. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template