前端需要傳頁面的url給后端,其中不包含#之后的內容,后端會返回timestamp、nonceStr、signature
that.$http.post(that.$api.getH5Sign, { url: window.location.href.split('#')[0] }).then(res => { wxj.config({ debug: true, // 開啟調試模式 appId: that.$config.weixinAppId, // 必填,公眾號的唯一標識 timestamp: res.data.timestamp, // 必填,生成簽名的時間戳 nonceStr: res.data.noncestr, // 必填,生成簽名的隨機串 signature: res.data.sgture, // 必填,簽名 jsApiList: ["updateAppMessageShareData", "updateTimelineShareData"] // 必填,需要使用的JS接口列表 }); wxj.ready(function () { //需在用戶可能點擊分享按鈕前就先調用 wxj.updateAppMessageShareData({ title:that.detail.routeName, // 分享標題 desc: that.detail.routeFeatures, // 分享描述 link: window.location.href, // 分享鏈接,即要進入的頁面的鏈接(其中的域名)必須與當前頁面對應的公眾號JS安全域名一致 imgUrl: imgUrl, // 分享圖標 }); wxj.updateTimelineShareData({ title: that.detail.routeName, // 分享標題 desc: that.detail.routeFeatures, // 分享描述 link: window.location.href, //分享鏈接,即要進入的頁面的鏈接(其中的域名)必須與當前頁面對應的公眾號JS安全域名一致
imgUrl: imgUrl, // 分享圖標
})
});
})