微信小程序實現分享至朋友圈的功能來啦


參考: https://www.jianshu.com/p/64f73586e63a 

https://developers.weixin.qq.com/miniprogram/dev/reference/api/Page.html#onShareTimeline

 

 

https://www.jianshu.com/p/41990bc2167c

 

 

 

https://www.jb51.net/article/187128.htm

 

 onLoad: function(options) {
        wx.showShareMenu({
            withShareTicket: true,
            menus: ['shareAppMessage', 'shareTimeline'],
            success(res) {
                console.log(res)
            },
            fail(e) {
                console.log(e)
            }
        })
    },


   onShareAppMessage: function() {
        return {
            title: "名巢未來酒店",
            desc: 'Minnest',
            path: '/pages/order/index/index'
        }
    },
    onShareTimeline: function() {
        return {
            title: '測試小程序分享至朋友圈',
            path: '../test/test',
            imageUrl: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1594374964481&di=3ceba827e91e126012c43de3887a58c7&imgtype=0&src=http%3A%2F%2Fdmimg.5054399.com%2Fallimg%2Fpkm%2Fpk%2F13.jpg'
        }
    },

  

  /**
     * 分享
     */
    onShareAppMessage: function() {
        var openId = wx.getStorageSync('openId');
        var queryPath = '/pages/home/index/index' + (openId ? '?shareOpenId=' + openId : '');
        console.log(queryPath);
        return {
            title: "名巢未來酒店",
            desc: 'Minnest',
            path: queryPath
        }
    },

    /**
     * 分享到朋友圈
     */
    onShareTimeline: function() {
        var openId = wx.getStorageSync('openId');
        var queryPath = '/pages/home/index/index' + (openId ? '?shareOpenId=' + openId : '');
        return {
            title: '名巢未來酒店',
            query: queryPath
        }
    },

  

  onLoad: function(options) {
        this.getLocation();
        this.getAds();
        this.initTimeList();
        this.getCouponCards(() => {
            this.setData({
                showCouponsModal: true
            })
        });
        // 進入首頁進行加載判斷
        this.getnologinpic();
        wx.showShareMenu({
            withShareTicket:true,
            menus:['shareAppMessage', 'shareTimeline']
        })
        // 獲取分享人
        if (options && options.shareOpenId) {
            var params = {
                url: '/api/system/users',
                body: {
                    openid: options.shareOpenId,
                }
            }
            request.doRequest(
                params,
                function(data) {
                    if (data.data.length != 0) {
                        wx.setStorage({
                          data: data.data[0].id,
                          key: 'shareUser',
                        })
                    } else {
                        wx.setStorage({
                            data: 0,
                            key: 'shareUser',
                        })
                    }
                },
            )
        } else {
            wx.setStorage({
                data: 0,
                key: 'shareUser',
            })
        }
    },

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM