码迷,mamicode.com
首页 > 微信 > 详细

自定义微信发送给好友,分享到朋友圈的缩略图,链接,标题和摘要

时间:2015-02-04 18:23:16      阅读:329      评论:0      收藏:0      [点我收藏+]

标签:

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

<script type="text/javascript">
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);
    }
})();
</script>

自定义微信发送给好友,分享到朋友圈的缩略图,链接,标题和摘要

标签:

原文地址:http://www.cnblogs.com/love-is/p/4272769.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!