微信更改分享图片和分享链接的方法

1.将以下代码加到head头里

<script>
        window.imgUrl = "http://app55.vliang.com/img/share1.jpg";
        (function(){
            //外挂接口
            var c = window.P_WX_C =  window.P_WX_C || {};
            //外挂接口事件
            var d = window.P_WX_D = window.P_WX_D  || {};
            var onBridgeReady =  function (){
                WeixinJSBridge.call('hideToolbar');
                var
                    appId  = '',
                    link   = "http://app55.vliang.com/home?wxid=<?=$_SESSION['wxid']?>&isshare=1",
                    title  = htmlDecode("玩极限科考,找回高中背诵古文的被虐感!还有更丧心病狂的隐藏诗词关。来答题涨涨知识吧"),
                    desc   = htmlDecode("玩极限科考,找回高中背诵古文的被虐感!还有更丧心病狂的隐藏诗词关。来答题涨涨知识吧。"),
                    fakeid = "",
                    desc = desc || link;
                c.shareAppMessage = function(){


                    WeixinJSBridge.invoke('sendAppMessage',{
                        "appid"      : appId,
                        "img_url"    : window.imgUrl,
                        "img_width"  : "640",
                        "img_height" : "640",
                        "link"       : link,
                        "desc"       : desc,
                        "title"      : title
                    }, function(res){



                    });
                };
                c.shareWeibo = function(){

                    WeixinJSBridge.invoke('shareWeibo',{
                        "content" : title +link,
                        "url"     : link
                    }, function(res){


                    });
                };
                c.shareTimeline = function(){

                    WeixinJSBridge.invoke('shareTimeline',{
                        "img_url"    : window.imgUrl,
                        "img_width"  : "640",
                        "img_height" : "640",
                        "link"       : link,
                        "desc"       : desc,
                        "title"      : title
                    }, function(res){

                    });
                };
                WeixinJSBridge.on('menu:share:appmessage', function(argv){
                    title=htmlDecode("搜狗输入法");
                    c.shareAppMessage();
                });
                WeixinJSBridge.on('menu:share:timeline', function(argv){
                    title  = htmlDecode("玩极限科考,找回高中背诵古文的被虐感!还有更丧心病狂的隐藏诗词关。来答题涨涨知识吧"),
                    c.shareTimeline();
                });
                var weiboContent = '';
                WeixinJSBridge.on('menu:share:weibo', function(argv){
                    c.shareWeibo();
                });
            };
            if(document.addEventListener){
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            } else if(document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady'   , onBridgeReady);
                document.attachEvent('onWeixinJSBridgeReady' , onBridgeReady);
            }



            var imgs = $('.page img'),
                imgsSrc = [],
                minWidth = 0;
            imgs.each(function(){
                var jqthis = $(this),
                    src = jqthis.attr('data-src') || jqthis.attr('src');
                if(jqthis.width() >= minWidth && src){
                    imgsSrc.push(src);
                    jqthis.on('click', function() {
                        reviewImage(src);
                    });
                }
            });
            function reviewImage(src) {
                if (typeof window.WeixinJSBridge != 'undefined') {
                    WeixinJSBridge.invoke('imagePreview', {
                        'current' : src,
                        'urls' : imgsSrc
                    });
                }
            }
        }
            )();
    </script>

2.更改window.imgUrl的值(图片地址)

3.更改link,title,desc这些参数

原文地址:https://www.cnblogs.com/myphper/p/3760667.html