search
HomeWeChat AppletMini Program DevelopmentWeChat Mini Program Example: Judgment Code for Sharing to One Person or to a Group

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;
                }
            },
        }
    }

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
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

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.