jump.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <html>
  2. <head>
  3. <title>打开小程序</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
  6. <script>
  7. function docReady(fn) {
  8. if (document.readyState === 'complete' || document.readyState === 'interactive') {
  9. fn()
  10. } else {
  11. document.addEventListener('DOMContentLoaded', fn);
  12. }
  13. }
  14. docReady(async function () {
  15. var ua = navigator.userAgent.toLowerCase()
  16. var isWXWork = ua.match(/wxwork/i) == 'wxwork'
  17. var isWeixin = !isWXWork && ua.match(/micromessenger/i) == 'micromessenger'
  18. var isMobile = false
  19. var isDesktop = false
  20. if (navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|IEMobile)/i)) {
  21. isMobile = true
  22. } else {
  23. isDesktop = true
  24. }
  25. var container = document.getElementById('container')
  26. var wx = document.getElementById('container-wx')
  27. var tip = document.getElementById('container-tip')
  28. if (isWeixin) {
  29. container.innerHTML = '打开微信小程序'
  30. tip.innerHTML = '点击以下按钮打开 “盲票小程序”'
  31. wx.style.display = "none";
  32. } else {
  33. container.style.display = "none";
  34. wx.style.display = "inline";
  35. wx.innerHTML = '打开微信'
  36. tip.innerHTML = '请使用微信扫描当前二维码'
  37. }
  38. })
  39. //获取当前URL
  40. var url = document.location.href;
  41. //声明一个对象
  42. var getRequest = new Object();
  43. //获取?的位置
  44. var index = url.indexOf("?")
  45. if (index != -1) {
  46. //截取出?后面的字符串
  47. var str = url.substr(index + 1);
  48. //将截取出来的字符串按照&变成数组
  49. strs = str.split("&");
  50. //将get传参存入对象中
  51. for (var i = 0; i < strs.length; i++) {
  52. getRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
  53. }
  54. }
  55. console.log('getRequest', getRequest)
  56. function ajax(options) {
  57. return new Promise((resolve, reject) => {
  58. if (!options.url) {
  59. return;
  60. }
  61. let method = options.method || 'GET';
  62. let async = options.async || true;
  63. let xhr = new XMLHttpRequest();
  64. if (method === 'GET') {
  65. // url后面添加随机数防止请求缓存
  66. xhr.open(method, options.url + "?" + Math.random(), async);
  67. xhr.send(null);
  68. } else if (method === 'POST') {
  69. xhr.open(method, options.url, async);
  70. xhr.setRequestHeader('Content-type', 'application/json;charset=utf-8');
  71. xhr.send(JSON.stringify(options.data));
  72. }
  73. xhr.onreadystatechange = () => {
  74. if (xhr.responseText) {
  75. resolve(xhr.responseText);
  76. }
  77. };
  78. xhr.onerror = (e) => {
  79. reject(e);
  80. }
  81. }).catch(e => {
  82. });
  83. }
  84. function openWeapp() {
  85. let req = ajax({
  86. method: 'POST',
  87. url: 'https://test-mp-adm.quanshu123.com/test-api/api/v1/mp/wx/urlschema/generate',
  88. data: {
  89. path: '/pages/bills/detail',
  90. query: `id=${ getRequest.id }`
  91. }
  92. })
  93. req.then(data => {
  94. console.log('data', data)
  95. let resData = JSON.parse(data)
  96. console.log('resData', resData)
  97. if(resData.code == 0){
  98. window.location.href = `${ resData.data }?id=${ getRequest.id }`;
  99. }
  100. })
  101. }
  102. function openWx() {
  103. window.location.href = "weixin://";
  104. }
  105. </script>
  106. <style>
  107. .skip-wrap {
  108. width: 100%;
  109. height: 100%;
  110. position: relative;
  111. }
  112. .skip-theme {
  113. display: flex;
  114. align-items: center;
  115. flex-direction: column;
  116. padding: 200px 0 0;
  117. }
  118. .skip-theme-iamge {
  119. width: 60px;
  120. height: 60px;
  121. line-height: 60px;
  122. text-align: center;
  123. color: #fff;
  124. background-color: #e96737;
  125. border-radius: 50%;
  126. margin-bottom: 10px;
  127. }
  128. .skip-theme-txt {
  129. color: rgb(194, 184, 184);
  130. text-align: center;
  131. }
  132. .skip-btn {
  133. position: absolute;
  134. bottom: 50px;
  135. width: 100%;
  136. display: flex;
  137. align-items: center;
  138. justify-content: center;
  139. }
  140. .skip-btn p {
  141. height: 30px;
  142. width: 200px;
  143. background-color: rgb(7, 192, 88);
  144. border-radius: 8px;
  145. line-height: 30px;
  146. color: #fff;
  147. text-align: center;
  148. }
  149. </style>
  150. </head>
  151. <body>
  152. <div class="skip-wrap">
  153. <div class="skip-theme" id="container-tip"></div>
  154. <div class="skip-btn">
  155. <p onclick="openWeapp()" id="container"></p>
  156. <p onclick="openWeapp()" id="container-wx"></p>
  157. </div>
  158. </div>
  159. </body>
  160. </html>