微信二次分享的JSSDK的调用

网页端微信的二次分享如果不调用分享的SDK,分享之后就不会带有标题、描述 、缩略图

微信分享SDK调用

引入

<script src="//res.wx.qq.com/open/js/jweixin-1.4.0.js" charset="utf-8" async="async"></script>

参数配置

    function getWXqianmin(a,b,c,d){
        var href=window.location.href
        console.log(href)
        var shareTitle=a //分享标题
        var lineLink=b //分享 链接
        var imgUrl=c //分享图标
        var descContent=d //分享描述
        $.ajax({
            type:'get',
            dataType:'json',
            url:'${path}/weixin/signature',  //获取微信签名的后台接口
            data:{
                url:href  //接口数据请求参数
            },
            success:function(data){
                console.log(data)
                var appId = data.info.appId;
                var timestamp = data.info.timestamp;
                var nonceStr = data.info.nonceStr;
                var signature = data.info.signature;
                wx.config({
                    debug:false,
                    appId:appId,
                    timestamp:timestamp,
                    nonceStr:nonceStr,
                    signature:signature,
                    jsApiList: [
                        'checkJsApi',
                        'onMenuShareTimeline',//分享到朋友圈
                        'onMenuShareAppMessage'//分享给微信好友
                    ]
                });
                wx.ready(function() {
                     wx.onMenuShareTimeline({ //分享到朋友圈
                           title: shareTitle, // 分享标题
                           link: lineLink, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                           imgUrl: imgUrl, // 分享图标
                           success: function () {
                                // 用户确认分享后执行的回调函数

                           },
                           cancel: function () {
                               // 用户取消分享后执行的回调函数
                               alert('你还没分享哦')
                           }
                       });
                       wx.onMenuShareAppMessage({  // 分享给朋友
                           title: shareTitle, // 分享标题
                           desc: descContent, // 分享描述
                           link: lineLink, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                           imgUrl: imgUrl, // 分享图标
                           type: '', // 分享类型,music、video或link,不填默认为link
                           dataUrl:'' , // 如果type是music或video,则要提供数据链接,默认为空
                           success: function () {
                               // 用户确认分享后执行的回调函数    

                           },
                           cancel: function () {
                               // 用户取消分享后执行的回调函数
                               alert('你还没分享哦')
                           }
                       });
               });
            }
        })
    }

调用成功之后

原文地址:https://www.cnblogs.com/xxflz/p/10141429.html