| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <!doctype html>
- <html lang="zh-CN">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>山峡化工服务号绑定</title>
- <style nonce="__NONCE__">
- body { margin: 0; padding: 48px 24px; background: #f5f8f7; color: #1f2a26; font-family: sans-serif; line-height: 1.7; }
- main { max-width: 480px; margin: auto; padding: 28px; border-radius: 16px; background: #fff; }
- h1 { font-size: 22px; }
- button { width: 100%; min-height: 44px; border: 0; border-radius: 10px; background: #0a9f6d; color: #fff; font-size: 16px; }
- #return-hint { color: #6b7b74; font-size: 14px; }
- </style>
- </head>
- <body>
- <main>
- <h1>微信通知绑定</h1>
- <p>__MESSAGE__</p>
- <button id="return-button" type="button">返回小程序</button>
- <p id="return-hint">如未自动返回,请点击上方按钮或左上角返回小程序。</p>
- </main>
- <script id="wechat-sdk" nonce="__NONCE__" async src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
- <script nonce="__NONCE__">
- (function () {
- var busy = false, autoAttempted = false;
- var hint = document.getElementById('return-hint');
- function fallback() {
- busy = false;
- hint.textContent = '如未返回,请点左上角返回小程序;原页面将自动完成绑定,也可点击“刷新绑定状态”。';
- }
- function goBack() {
- if (busy) return;
- var mp = window.wx && window.wx.miniProgram;
- // SDK 在桥接未就绪时会排队;不要在这里排队后再因 Ready 事件重复返回。
- if (!window.WeixinJSBridge || !mp || typeof mp.navigateBack !== 'function') { fallback(); return; }
- autoAttempted = true;
- busy = true;
- var timer = setTimeout(fallback, 2500);
- try {
- mp.navigateBack({ delta: 1, fail: function () { clearTimeout(timer); fallback(); } });
- } catch (_) { clearTimeout(timer); fallback(); }
- }
- function autoBack() {
- if (autoAttempted || !window.WeixinJSBridge || !window.wx || !window.wx.miniProgram) return;
- goBack();
- }
- document.getElementById('return-button').addEventListener('click', goBack);
- document.getElementById('wechat-sdk').addEventListener('load', autoBack);
- document.getElementById('wechat-sdk').addEventListener('error', fallback);
- document.addEventListener('WeixinJSBridgeReady', autoBack);
- autoBack();
- // SDK 加载失败或桥接无响应时仍保留用户可操作的返回入口。
- setTimeout(function () { if (!busy) fallback(); }, 4000);
- })();
- </script>
- </body>
- </html>
|