1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| export default function weixinShare() { return axios .get(`${base.BASE_URL}/share`, { params: { url: location.href.split("#")[0] }, }) .then((res) => { const { data: { code, data }, } = res; if (code === 200) { wx.config({ appId: appId, timestamp: data.timestamp, nonceStr: data.nonceStr, signature: data.signature, jsApiList: [ "updateAppMessageShareData", "onMenuShareTimeline", "onMenuShareAppMessage", ], });
let imgUrl = "imgUrl"; let title = "title"; let desc = ""; axios.get(`${base.BASE_URL}/random_link`).then((res) => { const { data: { data, code }, } = res; if (code === 200) { if (data.linkImage) { imgUrl = data.linkImage; } if (data.linkTittle) { title = data.linkTittle; } if (data.linkContent) { desc = data.linkContent } } wx.ready(function() { wx.updateAppMessageShareData({ title: title, desc: desc, link: link, imgUrl: imgUrl, success: function() { console.log("success"); }, fail: function(err) { console.log(JSON.stringify(err)); }, }); wx.onMenuShareTimeline({ title: data.linkTittle, link: link, imgUrl: imgUrl, success: function() { console.log("success"); }, fail: function(err) { console.log(JSON.stringify(err)); }, }); }); }); } }); }
|