123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- /**
- * 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))
- // //这里是回调函数
- // })
- })
- }
- }
- })
- }
- })
|