微信取消了微信公众平台前端网页上添加分享到朋友圈,关注微信等按钮,目前我们所能做的唯一定制化就是自定义微信发送给好友,分享到朋友圈的缩略图,链接,标题和摘要。今天刚好遇到分享下代码:


lfbg2r4h.png


var dataForWeixin={
    appId:"",
    MsgImg:"$dataForWeixin[‘MsgImg‘]",
    TLImg:"$dataForWeixin[‘MsgImg‘]",
    url: ‘{$share_url}‘,
    title:"$dataForWeixin[‘title‘]",
    desc:"$dataForWeixin[‘desc‘]",
    fakeid:"",
};
(function(){
    var onBridgeReady=function(){
        // 发送给好友;
        WeixinJSBridge.on(‘menu:share:appmessage‘, function(argv){
            WeixinJSBridge.invoke(‘sendAppMessage‘,{
                "appid":        dataForWeixin.appId,
                "img_url":      dataForWeixin.img,
                "img_width":    "120",
                "img_height":   "120",
                "link":             dataForWeixin.url,
                "desc":             dataForWeixin.desc,
                "title":            dataForWeixin.title
            }, function(res){(dataForWeixin.callback)(res);});
        // 分享到朋友圈;
        WeixinJSBridge.on(‘menu:share:timeline‘, function(argv){
            WeixinJSBridge.invoke(‘shareTimeline‘,{
            "img_url":dataForWeixin.img,
            "img_width":"120",
            "img_height":"120",
            "link":dataForWeixin.url,
            "desc":dataForWeixin.desc,
            "title":dataForWeixin.title
            }, function(res)(res){(dataForWeixin.callback)(res);});
        });
        // 分享到微博;
        WeixinJSBridge.on(‘menu:share:weibo‘, function(argv){
            WeixinJSBridge.invoke(‘shareWeibo‘,{
            "content":dataForWeixin.title+‘ ‘+dataForWeixin.url,
            "url":dataForWeixin.url
            }, function(res){(dataForWeixin.callback)(res);});
        });
        // 分享到Facebook
        WeixinJSBridge.on(‘menu:share:facebook‘, function(argv){
            WeixinJSBridge.invoke(‘shareFB‘,{
            "img_url":dataForWeixin.img,
            "img_width":"120",
            "img_height":"120",
            "link":dataForWeixin.url,
            "desc":dataForWeixin.desc,
            "title":dataForWeixin.title
            }, function(res){(dataForWeixin.callback)(res);});
        });
    };
    if(document.addEventListener){
        document.addEventListener(‘WeixinJSBridgeReady‘, onBridgeReady, false);
    }else if(document.attachEvent){
        document.attachEvent(‘WeixinJSBridgeReady‘   , onBridgeReady);
        document.attachEvent(‘onWeixinJSBridgeReady‘ , onBridgeReady);
    }
})();

GetwxLink