| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
- <title>华为运动健康授权结果</title>
- <style>
- * { margin: 0; padding: 0; box-sizing: border-box; }
- body { font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; background: #F8F8F8; display: flex; align-items: center; justify-content: center; min-height: 100vh; }
- .card { background: #fff; border-radius: 16px; padding: 32px 24px; width: 88%; max-width: 380px; text-align: center; box-shadow: 0 2px 12px rgba(0,0,0,0.06); }
- .icon { font-size: 44px; margin-bottom: 12px; }
- h1 { font-size: 18px; font-weight: 700; color: #333; margin-bottom: 8px; }
- .desc { font-size: 14px; color: #999; margin-bottom: 20px; line-height: 1.6; }
- .btn { display: inline-block; background: #F97316; color: #fff; border: none; border-radius: 24px; padding: 10px 32px; font-size: 14px; cursor: pointer; text-decoration: none; }
- .btn:hover { opacity: 0.9; }
- </style>
- </head>
- <body>
- <div class="card">
- <div class="icon" id="icon">⏳</div>
- <h1 id="title">处理中…</h1>
- <p class="desc" id="desc">正在完成华为账号授权…</p>
- <a class="btn" id="btn" style="display:none" href="javascript:void(0)">返回重试</a>
- </div>
- <script>
- // §5.2 入口:/huawei-cb.html?code=<code>&state=<memberId>
- // 解析 code/state → POST /api/huawei-health/callback → 三态渲染:
- // 成功「已授权,请返回小程序」/ 失败错误文案+重试 / 无 code 兜底「授权未完成,请返回重试」。
- // 服务端 memberId 与 JWT 归属的最终校验在后端接口2完成,本页只做类型/长度基本校验。
- (function() {
- function getParam(name) {
- var m = location.search.match(new RegExp('[?&]' + name + '=([^&]*)'))
- return m ? decodeURIComponent(m[1].replace(/\+/g, '%20')) : ''
- }
- var API_BASE = '/api'
- var code = getParam('code')
- var state = getParam('state')
- var icon = document.getElementById('icon')
- var title = document.getElementById('title')
- var desc = document.getElementById('desc')
- var btn = document.getElementById('btn')
- function showError(text) {
- icon.textContent = '⚠️'
- title.textContent = '授权失败'
- desc.textContent = text
- btn.style.display = 'inline-block'
- btn.textContent = '返回重试'
- btn.addEventListener('click', function() { location.href = '/huawei-auth.html' })
- }
- if (!code) {
- // 参数缺失(无 code):兜底文案
- icon.textContent = 'ℹ️'
- title.textContent = '授权未完成'
- desc.textContent = '授权未完成,请返回重试'
- btn.style.display = 'inline-block'
- btn.textContent = '返回重试'
- btn.addEventListener('click', function() { location.href = '/huawei-auth.html' })
- return
- }
- var memberId = null
- var n = parseInt(state, 10)
- if (!isNaN(n) && n > 0) { memberId = n }
- var payload = { code: code }
- if (memberId) { payload.memberId = memberId }
- fetch(API_BASE + '/huawei-health/callback', {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify(payload)
- }).then(function(res) { return res.json() })
- .then(function(result) {
- if (result && result.code === 200) {
- icon.textContent = '✅'
- title.textContent = '已授权,请返回小程序'
- desc.textContent = '绑定成功,数据仅用于家庭健康档案展示'
- // ≥3s 自动尝试关闭引导(小程序 web-view 用户手动返回亦可)
- setTimeout(function() {
- if (location.href.indexOf('weixin') >= 0) { try { window.close() } catch (e) {} }
- }, 3000)
- } else {
- showError((result && result.message) || '绑定失败,请重新授权')
- }
- })
- .catch(function() { showError('网络异常,请重新授权') })
- })();
- </script>
- </body>
- </html>
|