实现代码
<script>
$(function(){
var Api = "";
var title = "六一免费送";
var desc3E = "简介";
var curUrl = location.href.split('#')[0];
var linkUrl = curUrl;
//就是这个位置
var imageUrl ="https://****/img/launcher.png"
var _this = this;
$.ajax({
url:'https://****/wechat/getShareInfo',
data:{
url : curUrl
},
success:function(res){
_this.configPlist(res);
}
})
this.configPlist = function(res){
var _this = this;
var appId = res["data"].appId;
var nonceStr = res["data"].nonceStr;
var jsapi_ticket = res["data"].jsapi_ticket;
var timestamp = res["data"].timestamp;
var signature = res["data"].signature;
wx.config({
debug:false,
appId:res["data"].appId,
timestamp:res["data"].timestamp,
signature:res["data"].signature,
nonceStr:res["data"].nonceStr,
jsApiList:[
"onMenuShareAppMessage",
"onMenuShareTimeline",
"hideMenuItems"
]
})
wx.ready(function(){
_this.doHideMenuItems();
_this.doOnMenuShareAppMessage();
_this.doOnMenuShareTimeline();
})
wx.error(function(res) {
alert('error');
});
}
this.doHideMenuItems = function(){
wx.hideMenuItems({
menuList: [
'menuItem:openWithSafari',
'menuItem:share:email',
'menuItem:openWithQQBrowser',
'menuItem:favorite',
'menuItem:share:weiboApp',
'menuItem:share:qq',
'menuItem:share:QZone',
],
});
}
this.doOnMenuShareAppMessage = function(){
wx.onMenuShareAppMessage({
// 分享给朋友
title : title,
desc : desc3E,
link : linkUrl,
imgUrl :imageUrl,
})
}
this.doOnMenuShareTimeline = function(){
wx.onMenuShareTimeline({
title : title,
link : linkUrl,
imgUrl : imageUrl,
})
}
this.doOnMenuShareQQ = function(){
wx.onMenuShareQQ({
title: title,
desc: desc3E,
link: linkUrl,
imgUrl:imageUrl
});
}
this.doOnMenuShareQZone = function(){
wx.onMenuShareQZone({
title: title,
desc: desc3E,
link: linkUrl,
imgUrl:imageUrl
})
}
})
</script>