function WeiXinShare(title, link, imgurl, sharedesc) {
var _data = {
url: location.href,
t: Math.random()
};
var _getWechatSignUrl = ‘/home/JsSdk’;
$.ajax({
url: _getWechatSignUrl,
data: {
tempurl: location.href,
t: Math.random()
},
success: function (res) {
res = JSON.parse(res);
console.log(res.code);
if (res.code == 1) {
wxConfig(res.data.data.appid, res.data.data.timestamp, res.data.data.nonceStr, res.data.data.signature);
}
}
});
// var tt=location.href;
console.log(location.href);
//debugger;
function wxConfig(_appId, _timestamp, _nonceStr, _signature) {
wx.config({
debug: false,
appId: _appId,
timestamp: _timestamp,
nonceStr: _nonceStr,
signature: _signature,
jsApiList: [
'checkJsApi',
'onMenuShareTimeline',
'onMenuShareAppMessage'
]
});
}
wx.ready(function () { //需在用户可能点击分享按钮前就先调用
wx.onMenuShareTimeline({
title: title, // 分享标题
link: location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: 'http://school.fg1413.com/' + imgurl, // 分享图标
success: function () {
// 用户点击了分享后执行的回调函数
}
});
wx.onMenuShareAppMessage({
title: title, // 分享标题
desc: sharedesc, // 分享描述
link: location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: 'http://school.fg1413.com/' + imgurl, // 分享图标
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
// 用户点击了分享后执行的回调函数
}
});
});
}