function isWeixin() { //判断是否是微信 var ua = navigator.userAgent.toLowerCase(); return ua.match(/MicroMessenger/i) == "micromessenger"; }; function getSystem() { var u = navigator.userAgent; var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); if (isAndroid) { return 'Android' } else if (isiOS) { return 'IOS' } } $(function () { $('.js-downUrl').on('click', function (e) { var goUrl = $(this).attr('goUrl') || 'javascript:void(0);' if (isWeixin()) { if ($('.wxDown').length) { $('.wxDown').show() return false; } var system = getSystem() var label = '' var html = '' if (system === 'Android') { label = '选择在游览器中打开' } else if (system === 'IOS') { label = '选择在safari中打开' } var html = '
\n' + '
\n' + ' \n' + '
\n' + ' 1\n' + '

点击右上角 按钮

\n' + '
\n' + '
\n' + ' 2\n' + '

'+label+'

\n' + '
\n' + '
\n' + '
' $('body').append(html) $('.wxDown').on('click', function () { $('.wxDown').hide() }) } else { if (! $('#js-created-a').length) { $('body').append('') } else { $('#js-created-a').attr('href', goUrl) } $('#js-created-a')[0].click() } return false; }) // 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: { wx_app_id: wxAppId, share_url: window.location.origin + window.location.pathname + window.location.search }, dataType: 'jsonp', success: function (res) { if (res.code === 200) { wx.config({ appId: res.data.wx_app_id, timestamp: res.data.timestamp, nonceStr: res.data.nonceStr, signature: res.data.signature, jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData', 'onMenuShareWeibo'] }) wx.ready(function () { // “分享给朋友”及“分享到QQ” wx.updateAppMessageShareData({ title: shareTitle, // 分享标题 desc: shareDesc, // 分享描述 link: window.location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致 imgUrl: shareImage // 分享图标 }, function(res) { //这里是回调函数 }) // “分享到朋友圈”及“分享到QQ空间” wx.updateTimelineShareData({ title: shareTitle, // 分享标题 link: window.location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致 imgUrl: shareImage // 分享图标 }, function(res) { //这里是回调函数 }) // “分享到腾讯微博” wx.onMenuShareWeibo({ title: shareTitle, // 分享标题 desc: shareDesc, // 分享描述 link: window.location.href, // 分享链接 imgUrl: shareImage, // 分享图标 success: function () { // 用户确认分享后执行的回调函数 }, cancel: function () { // 用户取消分享后执行的回调函数 } }) }) } } }) } })