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

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

Aug 11, 2018 pm 05:23 PM
WeChat share

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)