123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <html>
- <head>
- <title>打开小程序</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
- <script>
- function docReady(fn) {
- if (document.readyState === 'complete' || document.readyState === 'interactive') {
- fn()
- } else {
- document.addEventListener('DOMContentLoaded', fn);
- }
- }
- docReady(async function () {
- var ua = navigator.userAgent.toLowerCase()
- var isWXWork = ua.match(/wxwork/i) == 'wxwork'
- var isWeixin = !isWXWork && ua.match(/micromessenger/i) == 'micromessenger'
- var isMobile = false
- var isDesktop = false
- if (navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|IEMobile)/i)) {
- isMobile = true
- } else {
- isDesktop = true
- }
- var container = document.getElementById('container')
- var wx = document.getElementById('container-wx')
- var tip = document.getElementById('container-tip')
- if (isWeixin) {
- container.innerHTML = '打开微信小程序'
- tip.innerHTML = '点击以下按钮打开 “盲票小程序”'
- wx.style.display = "none";
- } else {
- container.style.display = "none";
- wx.style.display = "inline";
- wx.innerHTML = '打开微信'
- tip.innerHTML = '请使用微信扫描当前二维码'
- }
- })
- //获取当前URL
- var url = document.location.href;
- //声明一个对象
- var getRequest = new Object();
- //获取?的位置
- var index = url.indexOf("?")
- if (index != -1) {
- //截取出?后面的字符串
- var str = url.substr(index + 1);
- //将截取出来的字符串按照&变成数组
- strs = str.split("&");
- //将get传参存入对象中
- for (var i = 0; i < strs.length; i++) {
- getRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
- }
- }
- console.log('getRequest', getRequest)
- function ajax(options) {
- return new Promise((resolve, reject) => {
- if (!options.url) {
- return;
- }
- let method = options.method || 'GET';
- let async = options.async || true;
- let xhr = new XMLHttpRequest();
- if (method === 'GET') {
- // url后面添加随机数防止请求缓存
- xhr.open(method, options.url + "?" + Math.random(), async);
- xhr.send(null);
- } else if (method === 'POST') {
- xhr.open(method, options.url, async);
- xhr.setRequestHeader('Content-type', 'application/json;charset=utf-8');
- xhr.send(JSON.stringify(options.data));
- }
- xhr.onreadystatechange = () => {
- if (xhr.responseText) {
- resolve(xhr.responseText);
- }
- };
- xhr.onerror = (e) => {
- reject(e);
- }
- }).catch(e => {
- });
- }
- function openWeapp() {
- let req = ajax({
- method: 'POST',
- url: 'https://test-mp-adm.quanshu123.com/test-api/api/v1/mp/wx/urlschema/generate',
- data: {
- path: '/pages/bills/detail',
- query: `id=${ getRequest.id }`
- }
- })
- req.then(data => {
- let resData = JSON.parse(data)
- if(resData.code == 0){
- window.location.href = resData.data;
- }
- })
- }
- function openWx() {
- window.location.href = "weixin://";
- }
- </script>
- <style>
- .skip-wrap {
- width: 100%;
- height: 100%;
- position: relative;
- }
- .skip-theme {
- display: flex;
- align-items: center;
- flex-direction: column;
- padding: 200px 0 0;
- }
- .skip-theme-iamge {
- width: 60px;
- height: 60px;
- line-height: 60px;
- text-align: center;
- color: #fff;
- background-color: #e96737;
- border-radius: 50%;
- margin-bottom: 10px;
- }
- .skip-theme-txt {
- color: rgb(194, 184, 184);
- text-align: center;
- }
- .skip-btn {
- position: absolute;
- bottom: 50px;
- width: 100%;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .skip-btn p {
- height: 30px;
- width: 200px;
- background-color: rgb(7, 192, 88);
- border-radius: 8px;
- line-height: 30px;
- color: #fff;
- text-align: center;
- }
- </style>
- </head>
- <body>
- <div class="skip-wrap">
- <div class="skip-theme" id="container-tip"></div>
- <div class="skip-btn">
- <p onclick="openWeapp()" id="container"></p>
- <p onclick="openWeapp()" id="container-wx"></p>
- </div>
- </div>
- </body>
- </html>
|