1.登录公众号的微信开放平台
2.下载.txt文件放到项目域名根目录
3.将项目网址域名添加到平台白名单
(function() {
function shareInit(titleData, shareDescData, shareImgUrl) {
var shareUrl = window.location.href;
var shareTitleGroup, shareTitle, shareDesc, shareImg;
shareTitleGroup = titleData;
shareTitle = titleData;
shareDesc = shareDescData;
shareImg = shareImgUrl;
$.ajax({
type: 'GET',
url: 'https://logo.baidu.com/share', //换成自己的,由后台提供
data: { pageurl: encodeURIComponent(shareUrl) },
dataType: 'json',
success: function (e) {
wx.config({
debug: false,
appId: e.appId,
timestamp: e.timestamp,
nonceStr: e.nonceStr,
signature: e.signature,
jsApiList: [
'updateAppMessageShareData',
'updateTimelineShareData',
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareWeibo',
'onMenuShareQZone'
]
});
wx.ready(function () {
wx.updateAppMessageShareData({
title: shareTitle,
desc: shareDesc,
link: shareUrl,
imgUrl: shareImg,
success: function () {
_hmt.push(['_trackEvent', "wxshare", "friend"]);
}
});
wx.updateTimelineShareData({
title: shareTitle,
link: shareUrl,
imgUrl: shareImg,
success: function () {
_hmt.push(['_trackEvent', "wxshare", "friendGroup"]);
}
});
wx.onMenuShareTimeline({
title: shareTitleGroup,
link: shareUrl,
imgUrl: shareImg,
success: function () {
}
});
wx.onMenuShareAppMessage({
title: shareTitle,
desc: shareDesc,
link: shareUrl,
imgUrl: shareImg,
type: '',
dataUrl: '',
success: function () {
}
});
wx.onMenuShareQQ({
title: shareTitle,
desc: shareDesc,
link: shareUrl,
imgUrl: shareImg,
success: function () {
}
});
wx.onMenuShareWeibo({
title: shareTitle,
desc: shareDesc,
link: shareUrl,
imgUrl: shareImg,
success: function () {
}
});
wx.onMenuShareQZone({
title: shareTitle,
desc: shareDesc,
link: shareUrl,
imgUrl: shareImg,
success: function () {
}
});
});
}
});
}
shareInit('假如70年代有搜索', '致敬李小龙诞辰80周年', 'https://baidulogo.bj.bcebos.com/bd_lixiaolong/img/share.jpg')