微信、微博、facebook等分享

var wx = {
    appId:'',
    imgUrl:'http://guangdong.sinaimg.cn/ily/haier/111183280.jpg',
    link:'http://gd.sina.com.cn/zt2014/haiersmart09/index.html',
    title:'海尔智慧城市行',
    desc:'好智慧耀健康,海尔智能城市行。珠海,9月26日-9月28日(为期3天),丰富礼品,劲爆优惠等你来!',
    fakeid:'',
    weiboContent:'微博内容',
    scene:0,
    init:function(){
        var _this = this;
        _this.desc= _this.desc || _this.link;
        if (typeof WeixinJSBridge == "undefined"){
            document.addEventListener('WeixinJSBridgeReady',function(){_this.onBridgeReady(_this)}, false);
        }else{
            _this.onBridgeReady(_this);
        }
    },
    onBridgeReady:function(_this){
        if(true){
            WeixinJSBridge.call("showOptionMenu"); 
        }else{
            WeixinJSBridge.call("hideOptionMenu"); 
        }
        // 发送给好友; 
        WeixinJSBridge.on('menu:share:appmessage', function(argv){
            WeixinJSBridge.invoke('sendAppMessage',{
                "appid": _this.appId,
                "img_url": _this.imgUrl,
                "img_width": "640",
                "img_height" : "640",
                "link" : _this.link,
                "desc" : _this.desc,
                "title": _this.title
            }, function(res) {
                _this.callback();
            });
        });
        // 分享到朋友圈;
        WeixinJSBridge.on('menu:share:timeline', function(argv){
            //report(link, fakeid, 2);
            WeixinJSBridge.invoke('shareTimeline',{
                "img_url": _this.imgUrl,
                "img_width": "640",
                "img_height" : "640",
                "link" : _this.link,
                "desc" : _this.desc,
                "title": _this.title
            }, function(res) {
                _this.callback();
            });
        });

        // 分享到微博;   
        WeixinJSBridge.on('menu:share:weibo', function(argv){
            WeixinJSBridge.invoke('shareWeibo',{
                "content" : _this.title + _this.link,
                "url" : _this.link 
            }, function(res) {
                _this.callback();
            });
        });

        // 分享到Facebook
        WeixinJSBridge.on('menu:share:facebook', function(argv){
            //report(link, fakeid, 4);
            WeixinJSBridge.invoke('shareFB',{
                "img_url": _this.imgUrl,
                "img_width": "640",
                "img_height" : "640",
                "link" : _this.link,
                "desc" : _this.desc,
                "title": _this.title
            }, function(res) {
                _this.callback();
            });
        });

        // 新的接口
        WeixinJSBridge.on('menu:general:share', function(argv){
            switch(argv.shareTo){
                case 'friend': _this.scene = 1; break;
                case 'timeline': _this.scene = 2; break;
                case 'weibo' : _this.scene = 3; break;
            }
            argv.generalShare({
                "appid": _this.appId,
                "img_url": _this.imgUrl,
                "img_width": "640",
                "img_height" : "640",
                "link" : _this.link,
                "desc" : _this.desc,
                "title": _this.title
            }, function(res){
                _this.callback();
            });
        });
    },
    callback:function(){
        //alert('微信分享返回调用啦。');
    }
}
wx.init();


你可能感兴趣的:(微信、微博、facebook等分享)