1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
var errorPage = `<div class="page"><div class="weui-msg"><div class="weui-msg__icon-area"><i class="weui-icon-warn weui-icon_msg"></i></div><div class="weui-msg__text-area"><h2 class="weui-msg__title">操作失败</h2><p class="weui-msg__desc">请用微信内置浏览器打开</p></div></div></div>`; var errorPageCss = "<style>.weui-msg{padding-top:48px;padding:calc(48px + constant(safe-area-inset-top)) constant(safe-area-inset-right) constant(safe-area-inset-bottom) constant(safe-area-inset-left);padding:calc(48px + env(safe-area-inset-top)) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);text-align:center;line-height:1.4;min-height:100%;box-sizing:border-box;display:-webkit-box;display:-webkit-flex;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-webkit-flex-direction:column;flex-direction:column;background-color:#fff;}.weui-msg__icon-area{margin-bottom:32px;}.weui-msg__text-area{margin-bottom:32px;padding:0 32px;-webkit-box-flex:1;-webkit-flex:1;flex:1;line-height:1.6;}.weui-msg__text-area:first-child{padding-top:96px;}.weui-msg__title{font-weight:700;font-size:22px;}.weui-msg__desc,.weui-msg__title{margin-bottom:16px;word-wrap:break-word;word-break:break-all;}.weui-msg__desc{font-size:17px;color:rgba(0,0,0,0.9);}.weui-icon-warn:before{content:'';margin:0;width:64px;height:64px;display:block;background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAEXRFWHRTb2Z0d2FyZQBTbmlwYXN0ZV0Xzt0AAASKSURBVGiB7ZpN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WSDdSE2PCxUtdYk2ixdXfzmTTY9DQDi9Wv90SOHWyGoqmx4WE43Gsj6+nBszEkwAGAjI2xqChgDxtjUFBsZcVghjo1BX59BIOPwExNw5IijgN3dvxsP59Dd7aQy7O9nk5OGWcYG8NQpFgo5CUmbm/D1a+U6nSaj+bh5cGICT5wwzqq1P0DZrD4762RxDk+eZFeugBDixQsnyxx4/DifncVjx4xz62xwiDdv9IcP2zxBQ+S3btlZ3AUAFgqx8XH3NVmBjY/Xb8x1P6c9HjYzgz6fu5rMgz4fm5mpv5vfYD6AqsrDYXDrE9USisLDYfnboYrGExoMBvnt2/a20e1T3uQLBhsW/De2Wct09kZ3Gcrl9Pl5+vjRljYTapp61KBCZx/2+EUHH7f5kw4+8PQnmkbxuHj1Snz6ZGplW1HYmTNsehqDwXYfOZPpyEN/beX/t7TYaRwYaDc/AcyLEvgVsZj4AAAAAElFTkSuQmCC');}.weui-icon_msg.weui-icon-warn{color:#fa5151;font-size:64px;display:inline-block;vertical-align:middle;font:normal normal normal 14px/1 weui;font-size:inherit;text-rendering:auto;-webkit-font-smoothing:antialiased;}</style>";
function api_initWxjssdk(params) { $.ajax({ url: '//初始化jssdk的接口地址', dataType: 'jsonp', timeout: 2000, jsonpCallback: 'jscfg', data: { url: window.location.href, source: 'test2' }, success: function (result) { wx.config($.parseJSON(result.jsCfg)); } }); }
const getUrlParameter = name => { let array, result = {}; if (window.location.search) { array = window.location.search.replace(/^\?/, '').split('&'); } else if (window.location.hash) { array = window.location.hash.replace(/^\#/, '').split('&'); } else { array = []; } if (array.length === 0) return null; for (let i = 0; i < array.length; i++) { let keyValue = array[i].split('='); result[keyValue[0]] = keyValue.length == 2 ? keyValue[1] : ''; } return name ? result[name] : result; };
var browser = (function () { var u = navigator.userAgent; var ua = u.toLowerCase(); var browser = { runOnlyWx: true, isWeChat: null, isWechatdevtools: null, isIos: /iPhone/i.test(ua), isAndroid: /Android/i.test(ua), ua: ua, mobile: !!u.match(/AppleWebKit.*Mobile.*/) };
browser.isWeChat = browser.ua.match(/MicroMessenger/i) == 'micromessenger'; browser.isWechatdevtools = browser.ua.match(/wechatdevtools/i) == 'wechatdevtools'; console.info('Browser:', browser); if (browser.mobile) { if (browser.runOnlyWx && !browser.isWeChat) { $('#app').before(errorPageCss).html(errorPage); } } else { $('#app').html('请用手机浏览器打开'); } window.globalData = Object.assign({}, window.globalData, { browser: browser }); return browser; })();
if (browser.mobile) { var ua = navigator.userAgent.toLowerCase(); if (browser.isWeChat) { var openid = window.localStorage.getItem('SDGAME_openid'); if (openid == null) { openid = getUrlParameter('openid'); } if (openid == null) { window.location.href = 'https://服务器授权微信api接口地址?redirect=' + encodeURI(location.href) + '&source=test2&auth_type=snsapi_base'; } if (openid != null) { window.localStorage.setItem('SDGAME_openid', openid); api_initWxjssdk(); } } }
wx.ready(function () { wx.hideAllNonBaseMenuItem(); wx.showMenuItems({ menuList: ['menuItem:share:appMessage', 'menuItem:share:timeline', 'menuItem:refresh', 'menuItem:profile', 'menuItem:addContact', 'menuItem:copyUrl', 'menuItem:favorite'] }); var imgsUrl = window.location.href; var imgFxUrl = imgsUrl.substring(0, imgsUrl.lastIndexOf('/') + 1); var shareData = { title: '', desc: '', link: location.href.split('?')[0] + '?share=1', imgUrl: imgFxUrl + '/img/share.jpg' }; wx.onMenuShareAppMessage(shareData); wx.onMenuShareTimeline(shareData); var u = navigator.userAgent; var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); if (isAndroid) { wx.updateAppMessageShareData(shareData); wx.updateTimelineShareData(shareData); } });
|