微信开发,JS,通过微信浏览器-----分享好友、朋友

页面导航:首页 > 网络编程 > JavaScript > 微信开发,JS,通过微信浏览器-----分享好友、朋友

微信开发,JS,通过微信浏览器-----分享好友、朋友

来源: 作者: 时间:2016-02-21 09:50 【

微信分享,全局对象var basUrl = location protocol + 39; 39; + window location host;var dataForWeixin = { appId: , MsgImg: basUrl+ 39; assets img logo-2 pn
// 分享,全局对象
var basUrl = location.protocol + '//' + window.location.host;
var dataForWeixin = {
    appId: "",
    MsgImg: basUrl+'/assets/img/logo-2.png',
    TLImg: "",
    url: "",
    title: "XXXXXXXXX",
    desc: "微信名片XXXXXXXXX!",
    fakeid: "",
    weibodesc: "微信名片XXXXXXXXX!",
    callback: function () { }
};
(function () {
    var onBridgeReady = function () {//分享给好友
        WeixinJSBridge.on('menu:share:appmessage', function (argv) {
            WeixinJSBridge.invoke('sendAppMessage', {
                "appid": dataForWeixin.appId,
                "img_url": dataForWeixin.MsgImg,
                "img_width": "120",
                "img_height": "120",
                "link": dataForWeixin.url,
                "desc": dataForWeixin.desc,
                "title": dataForWeixin.title
            }, function (res) { 
                (dataForWeixin.callback)();
            });
        });//分享朋友圈
        WeixinJSBridge.on('menu:share:timeline', function (argv) {
            //(dataForWeixin.callback)();
            WeixinJSBridge.invoke('shareTimeline', {
                "img_url": dataForWeixin.MsgImg,
                "img_width": "120",
                "img_height": "120",
                "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.weibodesc + ' ' + dataForWeixin.url,
                "url": dataForWeixin.url
            }, function (res) { 
                (dataForWeixin.callback)();
            });
        });//分享到“非死不可”
        WeixinJSBridge.on('menu:share:facebook', function (argv) {
            WeixinJSBridge.invoke('shareFB', {
                "img_url": dataForWeixin.MsgImg,
                "img_width": "120",
                "img_height": "120",
                "link": dataForWeixin.url,
                "desc": dataForWeixin.desc,
                "title": dataForWeixin.title
            }, function (res) { });
        });
    };
    if (document.addEventListener) {
        document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
    } else if (document.attachEvent) {
        document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
        document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
    }
})();

Tags:

文章评论

最 近 更 新
热 点 排 行
Js与CSS工具
代码转换工具

<