<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": "

"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": "

"nonceStr": "eff876fc-f300-426d-99b5-20c7d15694b7",
"timestamp": "1446539973"
},
"resultList": null
/wechat/share
參數url
你把json里面的數據作為微信分享配置的參數進行配置
簽名使用的url是用來追蹤你頁面的