修复SiteServer CMS(SSCMS)分享插件在微信下分享时appid不合法的问题

- AppID appId CMS SiteServer SS CMS 微信公众号

1、微信分享时提示AppID不合法的原因,是因为/plugins/sscms.share/wwwroot/assets/share/js/wxShare.js文件里面的appId: res.apiId这里写错了,应该是appId:appId;

2、如果分享的图片是不含域名的话,分享时图片为加载错误,所以直接在这个脚本里面增加了给图片加域名前缀的代码

image.png

附完整代码

if (window.navigator.userAgent.toLowerCase().indexOf('micromessenger') > 0) {
    axios.get(wxShare.apiUrl, {
        headers: {
            'Content-Type': 'application/json;charset=UTF-8',
        },
        params: {
            siteId: wxShare.siteId,
            url: location.href
        }
    }).then(function (resOrigin) {
        var res = resOrigin.data
        if (res.success) {
            wx.config({
                debug: false,
                appId: res.appId,
                timestamp: res.timestamp,
                nonceStr: res.nonceStr,
                signature: res.signature,
                jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData']
            });
            wx.ready(function () {
                if (/^\//.test(wxShare.imgUrl)) {
                    wxShare.imgUrl = location.origin + wxShare.imgUrl;
                }
                var wxShareData = {
                    title: wxShare.title,
                    desc: wxShare.desc,
                    link: window.location.href,
                    imgUrl: wxShare.imgUrl
                };
                wx.updateAppMessageShareData(wxShareData);
                wx.updateTimelineShareData(wxShareData);
            });
            wx.error(function (resData) {
                console.error(resData);
            });
        }
    }).catch(function (err) {
        console.error(err);
    });
}


阅读次数:

本文作者:海涛

相关文章!