/** * Created by huosdk on 2018/10/9. */ $(function () { // var reg = new RegExp('wx_app_id=([^&]*)[&|$]', 'g') // var exp = reg.exec(window.location.search) var wxAppId = $('#wxAppId').val() var shareTitle = $('#shareTitle').val() var shareDesc = $('#shareDesc').val() var shareImage = $('#shareImage').val() if (wxAppId) { $.ajax({ url: 'https://miniapi.beibaoyx.com/share/index', data: { format: 'json', wx_app_id: wxAppId, share_url: location.href.split('#')[0] }, dataType: 'jsonp', success: function (res) { if (res.code === 200) { wx.config({ // debug: true, appId: res.data.wx_app_id, timestamp: res.data.timestamp, nonceStr: res.data.noncestr, signature: res.data.signature, // jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData', 'onMenuShareAppMessage'] jsApiList: ['onMenuShareAppMessage', 'onMenuShareTimeline', 'onMenuShareQQ', 'onMenuShareQZone'] }) wx.ready(function () { wx.onMenuShareAppMessage({ title: shareTitle, // 分享标题 desc: shareDesc, // 分享描述 link: window.location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致 imgUrl: shareImage, // 分享图标 success: function () { // window.alert(1111) // 用户点击了分享后执行的回调函数 } }) wx.onMenuShareTimeline({ title : shareTitle, // 分享标题 link : window.location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致 imgUrl : shareImage, // 分享图标 success: function () { // 用户点击了分享后执行的回调函数 } }) wx.onMenuShareQQ({ title: shareTitle, // 分享标题 desc: shareDesc, // 分享描述 link: window.location.href, // 分享链接 imgUrl: shareImage, // 分享图标 success: function () { // 用户确认分享后执行的回调函数 }, cancel: function () { // 用户取消分享后执行的回调函数 } }) wx.onMenuShareQZone({ title: shareTitle, // 分享标题 desc: shareDesc, // 分享描述 link: window.location.href, // 分享链接 imgUrl: shareImage, // 分享图标 success: function () { // 用户确认分享后执行的回调函数 }, cancel: function () { // 用户取消分享后执行的回调函数 } }) // // “分享给朋友”及“分享到QQ” // wx.updateAppMessageShareData({ // title: 'test', // 分享标题 // desc: 'testtest', // 分享描述 // link: window.location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致 // imgUrl: 'https://ministatic.beibaoyx.com/upload/admin/20180929/63080d45597d524911a1ad484fc7ae39.png' // 分享图标 // }, function(res) { // window.alert(JSON.stringify(res)) // //这里是回调函数 // }) // // // “分享到朋友圈”及“分享到QQ空间” // wx.updateTimelineShareData({ // title: shareTitle, // 分享标题 // link: window.location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致 // imgUrl: shareImage // 分享图标 // }, function(res) { // window.alert(JSON.stringify(res)) // //这里是回调函数 // }) }) } } }) } })