huawei-auth.html 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>连接华为运动健康</title>
  7. <style>
  8. * { margin: 0; padding: 0; box-sizing: border-box; }
  9. body { font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif; background: #f7f8fa; display: flex; align-items: center; justify-content: center; min-height: 100vh; }
  10. .wrap { background: #fff; border-radius: 16px; padding: 40px 32px; width: 88%; max-width: 420px; text-align: center; box-shadow: 0 2px 12px rgba(0,0,0,.06); }
  11. h1 { font-size: 20px; color: #1f2329; margin-bottom: 12px; }
  12. .sub { font-size: 14px; color: #8a919f; margin-bottom: 28px; line-height: 1.6; }
  13. .loading { color: #5f6b7a; font-size: 15px; margin-bottom: 16px; }
  14. .btn { display: inline-block; background: #4259ff; color: #fff; border: none; border-radius: 8px; padding: 12px 28px; font-size: 15px; cursor: pointer; }
  15. .btn:hover { opacity: .9; }
  16. .err { color: #e5484d; font-size: 14px; margin-top: 12px; line-height: 1.6; }
  17. .hide { display: none; }
  18. </style>
  19. </head>
  20. <body>
  21. <div class="wrap">
  22. <h1>连接华为运动健康</h1>
  23. <p class="sub">正在跳转华为账号授权页,请在弹出的页面中完成授权。</p>
  24. <p id="loading" class="loading">加载中…</p>
  25. <button id="fallback" class="btn hide" onclick="jump()">若未自动跳转请点此</button>
  26. <p id="err" class="err hide"></p>
  27. </div>
  28. <script>
  29. // H5 中转授权页(huawei-auth.html):读 query 后 location.replace(authUrl) 跳华为授权。
  30. // authUrl 由小程序调 POST /api/huawei-health/auth-url 获取后拼在本页 query(real 分支)。
  31. // 页面内不含任何密码输入框(合规/防钓鱼观感)。
  32. function parseQuery() {
  33. var qs = window.location.search.replace(/^\?/, '')
  34. var out = {}
  35. if (!qs) return out
  36. var parts = qs.split('&')
  37. for (var i = 0; i < parts.length; i++) {
  38. var kv = parts[i].split('=')
  39. if (kv[0]) out[decodeURIComponent(kv[0])] = decodeURIComponent(kv[1] || '')
  40. }
  41. return out
  42. }
  43. var q = parseQuery()
  44. var authUrl = q.authUrl || ''
  45. function jump() {
  46. if (!authUrl) {
  47. document.getElementById('loading').classList.add('hide')
  48. document.getElementById('err').classList.remove('hide')
  49. document.getElementById('err').textContent = '缺少授权链接(authUrl),请返回小程序重新发起绑定'
  50. return
  51. }
  52. window.location.replace(authUrl)
  53. }
  54. document.getElementById('fallback').classList.remove('hide')
  55. jump()
  56. </script>
  57. </body>
  58. </html>