前端需要获取当前页面的url传给后端。
varurll=encodeURIComponent(location.href.split('#')[0]);
需要后端在用url进行拼接签名时,将使用的url返回到前端,这样在
wx.onMenuShareTimeline({
link:data.url,
才会执行正确,因为微信分享页面ios端会自动拼接一些参数,导致url与签名的url不一致,无法正确打开微信接口。
而且,需要打开的微信接口需要写在 wx.ready里面;
缩略图:var imgUrl='图片完整路径.jpg';*必须要jpg格式,尺寸我写的300*300,可以用;
在wx.onMenuShareTimeline({
imgUrl:imgUrl,
引入就行了;还有一个方法,双重保险:
在body第一行写下
<div style="display:none"><img src="" /></div>,
微信jssdk会默认抓取body第一个大于200*200的jpg图片。
$.ajax({
type:"post",
url:"****",
dataType:"json",
data:{"url":urll},
success:function(data){
vardata=data.data;
//console.log(data);
wx.config({
debug:false,
appId:data.appId,
timestamp:data.timestamp,
nonceStr:data.nonceStr,
signature:data.signature,
jsApiList:['checkJsApi','onMenuShareTimeline','onMenuShareAppMessage']
});
wx.checkJsApi({
jsApiList:['onMenuShareTimeline','onMenuShareAppMessage'],
success:function(res){
// alert(res);
}
});
wx.ready(function(){
wx.onMenuShareTimeline({
title:'***?',
desc:'****!',
link:data.url,
imgUrl:imgUrl,
success:function(res){},
cancel:function(res){}
});
wx.onMenuShareAppMessage({
title:'****?',
desc:'****!',
link:data.url,
imgUrl:imgUrl,
success:function(){},
cancel:function(){}
});
});
}
});
网友评论