<script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js">
</script>
<script type="text/javascript">
wx.config({
debug: false,
appId: ‘$ {
appId !
}‘,
timestamp: $ {
timestamp !
},
nonceStr: ‘$ {
nonceStr !
}‘,
signature: ‘$ {
signature !
}‘,
jsApiList: [‘checkJsApi‘, ‘onMenuShareTimeline‘, ‘onMenuShareAppMessage‘, ‘onMenuShareQQ‘, ‘onMenuShareWeibo‘, ‘hideMenuItems‘, ‘getLocation‘]
});
var shareTitle = "更多优惠,尽在聚惠";
var shareDesc = "大回馈,花少钱享优质生活,更多优惠商品,就等你喊朋友一起来选!";
var currentLink = window.location.href;
var shareLink = currentLink < #
if u ? ?>+(currentLink.indexOf("?") > -1 ? ("&u=" + "${u!}" + "&t=" + "${t!}" + "&o=" + "${o!}" + "&s=" + "${s!}") : ("?u=" + "${u!}" + "&t=" + "${t!}" + "&o=" + "${o!}" + "&s=" + "${s!}")) < /#if>;
shareLink = shareLink <#if !city??> + (shareLink.indexOf("?") > -1 ? ("&city=" + "深圳") : ("?city=" + "深圳"))</#
if > ;
var shareImgUrl = "${IMGPATH!}/images/banner2.png";
var shareGid = "";
wx.ready(function() {
//分享给朋友
wx.onMenuShareAppMessage({
title: shareTitle,
desc: shareDesc,
link: shareLink,
imgUrl: shareImgUrl,
success: function(res) {
shared(shareLink, "friend", shareGid);
},
fail: function(res) {
alert(JSON.stringify(res));
}
});
//分享到朋友圈
wx.onMenuShareTimeline({
title: shareTitle,
desc: shareDesc,
link: shareLink,
imgUrl: shareImgUrl,
success: function(res) {
shared(shareLink, "Timeline", shareGid);
},
fail: function(res) {
alert(JSON.stringify(res));
}
});
//分享到QQ
wx.onMenuShareQQ({
title: shareTitle,
desc: shareDesc,
link: shareLink,
imgUrl: shareImgUrl,
success: function(res) {
shared(shareLink, "QQ", shareGid);
},
fail: function(res) {
alert(JSON.stringify(res));
}
});
//分享到腾讯QQ
wx.onMenuShareWeibo({
title: shareTitle,
desc: shareDesc,
link: shareLink,
imgUrl: shareImgUrl,
success: function(res) {
shared(shareLink, "Weibo", shareGid);
},
fail: function(res) {
alert(JSON.stringify(res));
}
});
//分享到QZone
wx.onMenuShareQZone({
title: shareTitle,
desc: shareDesc,
link: shareLink,
imgUrl: shareImgUrl,
success: function(res) {
shared(shareLink, "QZone", shareGid);
},
fail: function(res) {
alert(JSON.stringify(res));
}
});
});
function shared(url, type, gid) {
var rUrl = basePath + "/share/add?type=" + type + "&url=" + encodeURI(url);
if ( !! gid) {
rUrl += "&gid=" + gid;
}
$.ajax({
type: "GET",
url: rUrl,
dataType: "json",
success: function(rs) {
//alert("分享成功");
}
});
}
</script>
来源: http://www.bubuko.com/infodetail-2282037.html