微信、微博、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();


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值