1. 程式人生 > >微信網頁分享

微信網頁分享

微信內網頁分享時,圖片url不宜過長,否則會導致,分享到QQ的圖片無法顯示

$(function () {
        var config;


        var url = "[[@{/share/getJsShareConfig}]]"
        $.post(url, function (res) {
            res.data.debug = false;
            res.data.jsApiList = ['onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareTimeline', 'updateAppMessageShareData', 'updateTimelineShareData', 'translateVoice', 'checkJsApi'];
            $("#out").html("驗證成功")
            config = res.data;
            wx.config(res.data);
        });

        wx.ready(function () {
            console.log("驗證成功");
        });

        wx.error(function (res) {
            console.log("驗證失敗");
        });

        layui.use(['form'], function () {
            var form = layui.form;

            form.on('submit(submit)', function (data) {
                var shareData = {
                    title: data.field.title,
                    desc: data.field.desc,
                    link: 'http://xiaodingduang.com/share/redirect?url=' + data.field.url,
                    imgUrl: data.field.imgUrl,
                    success: function () {
                        layer.alert("生成成功", {
                            title: '提示'
                        })
                    }
                }
                wx.updateAppMessageShareData(shareData);
                wx.updateTimelineShareData(shareData);
                return false;
            });
        })

    })