浅谈前端H5自定义分享实现方法
引入jweinxin相关js文件,然后才可以做H5的分享
<script src="js/jweixin-1.2.0.js"></script>
let wxData = ''; $.ajax({ url: baseUrl + '/api/Invitation/inviteFriendsShare', type: "GET", data: { url: encodeURIComponent(window.location.href.split('#')[0]) }, success: function (res) { signPackage = res.data; var title = document.title; wxData = { "imgUrl": "https://img.boltshopvip.com/api/mtshare.png", //分享图标 "title": "麻团小课堂 | 给孩子最好的通识启蒙课,足不出户看世界!", //分享标题 "desc": '让知识陪孩子去远航!', //分享描述 "link": "https://mtdd.jsxcloud.com/h5/index.html" }; wx.config({ debug: false, appId: signPackage.appId, timestamp: parseInt(signPackage.timestamp), nonceStr: signPackage.nonceStr, signature: signPackage.signature, jsApiList: [ 'onMenuShareTimeline', 'onMenuShareAppMessage' ] }); }, fail: function (res) { console.log(res); } }) wx.ready(function () { wx.onMenuShareTimeline({ title: wxData.title, link: wxData.link, imgUrl: wxData.imgUrl, success: function () {
//分享成功后的回调
} }); wx.onMenuShareAppMessage({ title: wxData.title, desc: wxData.desc, link: wxData.link, imgUrl: wxData.imgUrl, type: 'link', dataUrl: '', success: function () {
//分享成功后的回调
}
});
});