123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- 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 = '选择<img class="img2" src="./image/icon_safari.png" alt="">在safari中打开'
- }
- var html = '<div class="wxDown">\n' +
- ' <div class="wxDown_cnt">\n' +
- ' <img class="topicon" src="./image/sanjiaox.png" alt="">\n' +
- ' <div class="item">\n' +
- ' <i class="ids">1</i>\n' +
- ' <p class="text">点击右上角 <img class="img1" src="./image/dian.png" alt=""> 按钮</p>\n' +
- ' </div>\n' +
- ' <div class="item">\n' +
- ' <i class="ids">2</i>\n' +
- ' <p class="text">'+label+'</p>\n' +
- ' </div>\n' +
- ' </div>\n' +
- '</div>'
- $('body').append(html)
- $('.wxDown').on('click', function () {
- $('.wxDown').hide()
- })
- } else {
- if (! $('#js-created-a').length) {
- $('body').append('<a href="' + goUrl + '" id="js-created-a"></a>')
- } 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 () {
- // 用户取消分享后执行的回调函数
- }
- })
- })
- }
- }
- })
- }
- })
|