jump_mp.html 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. window.onerror = e => {
  8. console.error(e)
  9. alert('发生错误' + e)
  10. }
  11. </script>
  12. <!-- weui 样式 -->
  13. <link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/2.4.1/weui.min.css"></link>
  14. <!-- 调试用的移动端 console -->
  15. <!-- <script src="https://cdn.jsdelivr.net/npm/eruda"></script> -->
  16. <!-- <script>eruda.init();</script> -->
  17. <!-- 公众号 JSSDK -->
  18. <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
  19. <!-- 云开发 Web SDK -->
  20. <script src="https://res.wx.qq.com/open/js/cloudbase/1.1.0/cloud.js"></script>
  21. <script>
  22. function docReady(fn) {
  23. if (document.readyState === 'complete' || document.readyState === 'interactive') {
  24. fn()
  25. } else {
  26. document.addEventListener('DOMContentLoaded', fn);
  27. }
  28. }
  29. docReady(async function() {
  30. var ua = navigator.userAgent.toLowerCase()
  31. var isWXWork = ua.match(/wxwork/i) == 'wxwork'
  32. var isWeixin = !isWXWork && ua.match(/micromessenger/i) == 'micromessenger'
  33. var isMobile = false
  34. var isDesktop = false
  35. if (navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|IEMobile)/i)) {
  36. isMobile = true
  37. } else {
  38. isDesktop = true
  39. }
  40. var token_id = getQueryString("token_id");
  41. var path = "/pages/zf/index?token_id=" + token_id +'&back=1'+'&funcCode=02010006';
  42. document.getElementById("launch-btn").setAttribute("path",path);
  43. if (isWeixin) {
  44. var containerEl = document.getElementById('wechat-web-container')
  45. containerEl.classList.remove('hidden')
  46. containerEl.classList.add('full', 'wechat-web-container')
  47. var launchBtn = document.getElementById('launch-btn')
  48. launchBtn.addEventListener('ready', function (e) {
  49. console.log('开放标签 ready')
  50. })
  51. launchBtn.addEventListener('launch', function (e) {
  52. console.log('开放标签 success')
  53. })
  54. launchBtn.addEventListener('error', function (e) {
  55. console.log('开放标签 fail', e.detail)
  56. })
  57. wx.config({
  58. // debug: true, // 调试时可开启
  59. appId: 'wxcdea3d211ab61546', // <!-- replace -->
  60. timestamp: 0, // 必填,填任意数字即可
  61. nonceStr: 'nonceStr', // 必填,填任意非空字符串即可
  62. signature: 'signature', // 必填,填任意非空字符串即可
  63. jsApiList: ['chooseImage'], // 必填,随意一个接口即可
  64. openTagList:['wx-open-launch-weapp'], // 填入打开小程序的开放标签名
  65. })
  66. } else if (isDesktop) {
  67. // 在 pc 上则给提示引导到手机端打开
  68. var containerEl = document.getElementById('desktop-web-container')
  69. containerEl.classList.remove('hidden')
  70. containerEl.classList.add('full', 'desktop-web-container')
  71. } else {
  72. var containerEl = document.getElementById('public-web-container')
  73. containerEl.classList.remove('hidden')
  74. containerEl.classList.add('full', 'public-web-container')
  75. var c = new cloud.Cloud({
  76. // 必填,表示是未登录模式
  77. identityless: true,
  78. // 资源方 AppID
  79. resourceAppid: 'wxcdea3d211ab61546', // <!-- replace -->
  80. // 资源方环境 ID
  81. resourceEnv: 'szjl-9g9sqgqwb4b6495e', // <!-- replace -->
  82. })
  83. await c.init()
  84. window.c = c
  85. var buttonEl = document.getElementById('public-web-jump-button')
  86. var buttonLoadingEl = document.getElementById('public-web-jump-button-loading')
  87. try {
  88. await openWeapp(() => {
  89. buttonEl.classList.remove('weui-btn_loading')
  90. buttonLoadingEl.classList.add('hidden')
  91. },token_id)
  92. } catch (e) {
  93. buttonEl.classList.remove('weui-btn_loading')
  94. buttonLoadingEl.classList.add('hidden')
  95. throw e
  96. }
  97. }
  98. })
  99. function getQueryString(name) {
  100. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  101. var reg_rewrite = new RegExp("(^|/)" + name + "/([^/]*)(/|$)", "i");
  102. var r = window.location.search.substr(1).match(reg);
  103. var q = window.location.pathname.substr(1).match(reg_rewrite);
  104. if(r != null){
  105. return unescape(r[2]);
  106. }else if(q != null){
  107. return unescape(q[2]);
  108. }else{
  109. return null;
  110. }
  111. }
  112. async function openWeapp(onBeforeJump,token_id) {
  113. var c = window.c
  114. const res = await c.callFunction({
  115. name: 'public',
  116. data: {
  117. action: 'getUrlScheme',
  118. token_id: token_id
  119. },
  120. })
  121. console.warn(res)
  122. if (onBeforeJump) {
  123. onBeforeJump()
  124. }
  125. location.href = res.result.openlink
  126. }
  127. </script>
  128. <style>
  129. .hidden {
  130. display: none;
  131. }
  132. .full {
  133. position: absolute;
  134. top: 0;
  135. bottom: 0;
  136. left: 0;
  137. right: 0;
  138. }
  139. .public-web-container {
  140. display: flex;
  141. flex-direction: column;
  142. align-items: center;
  143. }
  144. .public-web-container p {
  145. position: absolute;
  146. top: 40%;
  147. }
  148. .public-web-container a {
  149. position: absolute;
  150. bottom: 40%;
  151. }
  152. .wechat-web-container {
  153. display: flex;
  154. flex-direction: column;
  155. align-items: center;
  156. }
  157. .wechat-web-container p {
  158. position: absolute;
  159. top: 40%;
  160. }
  161. .wechat-web-container wx-open-launch-weapp {
  162. position: absolute;
  163. bottom: 40%;
  164. left: 0;
  165. right: 0;
  166. display: flex;
  167. flex-direction: column;
  168. align-items: center;
  169. }
  170. .desktop-web-container {
  171. display: flex;
  172. flex-direction: column;
  173. align-items: center;
  174. }
  175. .desktop-web-container p {
  176. position: absolute;
  177. top: 40%;
  178. }
  179. </style>
  180. </head>
  181. <body>
  182. <div class="page full">
  183. <div id="public-web-container" class="hidden">
  184. <p class="">正在打开 “河马付收银台”...</p> <!-- replace -->
  185. <a id="public-web-jump-button" href="javascript:" class="weui-btn weui-btn_primary weui-btn_loading" onclick="openWeapp()">
  186. <span id="public-web-jump-button-loading" class="weui-primary-loading weui-primary-loading_transparent"><i class="weui-primary-loading__dot"></i></span>
  187. 打开小程序
  188. </a>
  189. </div>
  190. <div id="wechat-web-container" class="hidden">
  191. <p class="">点击以下按钮打开 “河马付收银台”</p> <!-- replace -->
  192. <!-- 跳转小程序的开放标签。文档 https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_Open_Tag.html -->
  193. <wx-open-launch-weapp id="launch-btn" username="gh_47cd56883430" path="/pages/zf/index"> <!-- replace -->
  194. <template>
  195. <button style="width: 200px; height: 45px; text-align: center; font-size: 17px; display: block; margin: 0 auto; padding: 8px 24px; border: none; border-radius: 4px; background-color: #07c160; color:#fff;">打开小程序</button>
  196. </template>
  197. </wx-open-launch-weapp>
  198. </div>
  199. <div id="desktop-web-container" class="hidden">
  200. <p class="">请在手机打开网页链接</p>
  201. </div>
  202. </div>
  203. </body>
  204. </html>