<script type="text/javascript">
$(function(){
getUrl();
});
function getUrl(){
$.ajax({
url:'/wechat/share',
type:'get',
data:{
"url": encodeURIComponent(location.href.split('#')[0])
},
success:function(json){
json = JSON.parse(json);
if(json.success == 1){
if(json.data){
wx.config({
debug: true,
appId: "wx043d1b90c7bd4cfa",
timestamp: json.data.timestamp,
nonceStr: json.data.nonceStr,
signature: json.data.signature,
jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage']
});
wx.error(function(res){
alert(res.errMsg);
})
wx.ready(function(){
var encodeurl=location.href.split('#')[0];
wx.onMenuShareTimeline({
title: '闺蜜分享1000万现金红包,豪礼大放送!',
desc: "您的闺蜜为您送来20元现金红包,机会难得,快来领取......",
link: encodeurl, //分享的url以http或https开头 。具体分享的地址应该不需要编码,至少百度分享里面就是直接的url
imgUrl: "https://m.guimilicai.com/images/cent_cbg.png"
});
wx.onMenuShareAppMessage({
title: '闺蜜分享1000万现金红包,豪礼大放送!',
desc: "您的闺蜜为您送来20元现金红包,机会难得,快来领取......",
link: encodeurl,
imgUrl: "https://m.guimilicai.com/images/cent_cbg.png",
});
});
}
}
},
error:function(){
alert(false);
}
})
}
</script>
</body>
</html>
后台返回的数据
"code": null,
"comment": null,
"data": {
"signature": "c556057efe17da230832abc07d1b287df9991278",
"jsapi_ticket": "bxLdikRXVbTPdHSM05e5u5KK_6aepzSJbcorNNqO52PqNBTx1sGMuo_-iTq75JYvvkuyTsKmTOOyxSVv9NTq-g",
"url": "www.baidu.com",
"nonceStr": "eff876fc-f300-426d-99b5-20c7d15694b7",
"timestamp": "1446539973"
},
"resultList": null
/wechat/share
参数url
)
所以你要分享的url也会有好多个
所以后台不可能写死
后台或者微信那边会对这个url进行解码
就得到了动态的签名
后台返回的数据
"code": null,
"comment": null,
"data": {
"signature": "c556057efe17da230832abc07d1b287df9991278",
"jsapi_ticket": "bxLdikRXVbTPdHSM05e5u5KK_6aepzSJbcorNNqO52PqNBTx1sGMuo_-iTq75JYvvkuyTsKmTOOyxSVv9NTq-g",
"url": "www.baidu.com",
"nonceStr": "eff876fc-f300-426d-99b5-20c7d15694b7",
"timestamp": "1446539973"
},
"resultList": null
/wechat/share
参数url
你把json里面的数据作为微信分享配置的参数进行配置
签名使用的url是用来追踪你页面的