share.js 2.99 KB
function share(obj, obj2) {
    // obj 微信朋友, obj2 微信朋友圈
    if (/QQ/i.test(navigator.userAgent)) {
        $.ajax({
            url: '//qzonestyle.gtimg.cn/qzone/qzact/common/share/share.js',
            dataType: 'script',
            cache: true,
            success: function() {
                window.setShareInfo && window.setShareInfo({
                    title: obj.shareTitle,
                    summary: obj.shareDesc,
                    pic: obj.shareImg,
                    url: obj.shareLink
                });
            }
        });
    }
    
    if (typeof(wx) == "undefined") {
        return;
    }

    var _weChatInterface = 'https://m.yohobuy.com/activity/wechat/share';

    $.getJSON(_weChatInterface + '?url=' + encodeURIComponent(location.href.split('#')[0]) + '&callback=?', function(json) {
        var _appId, _timestamp, _nonceStr, _signature;
        if (json !== undefined && json !== '') {
            _appId = json.appId.toString();
            _timestamp = json.timestamp;
            _nonceStr = json.nonceStr.toString();
            _signature = json.signature.toString();

            wx.config({
                debug: false,
                appId: _appId,
                timestamp: _timestamp,
                nonceStr: _nonceStr,
                signature: _signature,
                jsApiList: [
                    'checkJsApi',
                    'onMenuShareTimeline',
                    'onMenuShareAppMessage',
                    'onMenuShareQQ',
                    'onMenuShareWeibo',
                    'hideMenuItems',
                    'showMenuItems',
                    'hideAllNonBaseMenuItem',
                    'showAllNonBaseMenuItem',
                    'translateVoice',
                    'startRecord',
                    'stopRecord',
                    'onRecordEnd',
                    'playVoice',
                    'pauseVoice',
                    'stopVoice',
                    'uploadVoice',
                    'downloadVoice',
                    'chooseImage',
                    'previewImage',
                    'uploadImage',
                    'downloadImage',
                    'getNetworkType',
                    'openLocation',
                    'getLocation',
                    'hideOptionMenu',
                    'showOptionMenu',
                    'closeWindow',
                    'scanQRCode',
                    'chooseWXPay',
                    'openProductSpecificView',
                    'addCard',
                    'chooseCard',
                    'openCard'
                ]
            });
        }
    });
    wx.ready(function() {
        var shareData = {
            title: obj.shareTitle,
            desc: obj.shareDesc,
            imgUrl: obj.shareImg,
            link: obj.shareLink
        };

        wx.onMenuShareAppMessage(shareData);
        wx.onMenuShareTimeline(obj2 ? obj2 : shareData);
        wx.onMenuShareQQ(shareData);
        wx.onMenuShareWeibo(shareData);
    });
}