zoukankan      html  css  js  c++  java
  • 微信小程序实例:分享给一个人还是分享到群的判断代码

    微信小程序的分享功能,在最新版库的ide上已经不能拿到分享回调了,官方api也删除了对应的回调函数,看样子是砍掉了,不过真机测试还是可以的,话不多说,上代码:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    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;
                    }
                },
            }
        }
  • 相关阅读:
    Lifegame第一阶段任务
    软件工程 第一次实验 Git代码版本管理
    个人作业——软件工程实践总结&个人技术博客
    个人技术总结-Android hellocharts折线图
    结对第二次作业——某次疫情统计可视化的实现
    软工实践寒假作业(2/2)
    软工实践寒假作业(1/2)
    第六次作业
    第五次作业
    第四次作业
  • 原文地址:https://www.cnblogs.com/cqlb/p/9494897.html
Copyright © 2011-2022 走看看