微信分享到朋友圈的内容和图片的定制

// 微信分享到朋友圈的内容和图片的定制
(function () {

    // data for weixin
    var dataForWeixin = {
        appId: "wx4654ffed0376f250",  // ttfund app id
        imgUrl: "http://j5.dfcfw.com/image/201407/20140725182526.jpg",
        imgWidth: "200",
        imgHeight: "200",
        url: location.href,
        title: "",
        desc: "",
        callback: function () {}
    };

    var onBridgeReady = function () {

        // 禁止分享
        // WeixinJSBridge.call('hideOptionMenu');

        // 发送给朋友
        WeixinJSBridge.on("menu:share:appmessage", function (argv) {
            WeixinJSBridge.invoke("sendAppMessage", {
                "appid": dataForWeixin.appId,
                "img_url": dataForWeixin.imgUrl,
                "img_width": dataForWeixin.imgWidth,
                "img_height": dataForWeixin.imgHeight,
                "link": dataForWeixin.url,
                "desc": dataForWeixin.desc,
                "title": dataForWeixin.title
            }, function (res) { dataForWeixin.callback(); });
        });

        // 发送到朋友圈
        WeixinJSBridge.on("menu:share:timeline", function (argv) {
            WeixinJSBridge.invoke("shareTimeline", {
                "appid": dataForWeixin.appId,
                "img_url": dataForWeixin.imgUrl,
                "img_width": dataForWeixin.imgWidth,
                "img_height": dataForWeixin.imgHeight,
                "link": dataForWeixin.url,
                "desc": dataForWeixin.desc,
                "title": dataForWeixin.title
            }, function (res) { dataForWeixin.callback(); });
        });

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

        // 分享到facebook
        WeixinJSBridge.on("menu:share:facebook", function (argv) {
            WeixinJSBridge.invoke("shareFB", {
                "img_url": dataForWeixin.imgUrl,
                "img_width": dataForWeixin.imgWidth,
                "img_height": dataForWeixin.imgHeight,
                "link": dataForWeixin.url,
                "desc": dataForWeixin.desc,
                "title": dataForWeixin.title
            }, function (res) { dataForWeixin.callback(); });
        });
    };

    if (document.addEventListener) {
        document.addEventListener("WeixinJSBridgeReady", onBridgeReady, false);
    } else if (document.attachEvent) {
        document.attachEvent("onWeixinJSBridgeReady", onBridgeReady);
    }
})();

 

posted @ 2014-06-05 19:11  farawayfromhome  阅读(664)  评论(0编辑  收藏  举报