huawei-auth.html 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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, maximum-scale=1.0, user-scalable=no">
  6. <title>连接华为运动健康</title>
  7. <style>
  8. * { margin: 0; padding: 0; box-sizing: border-box; }
  9. 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; }
  10. .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); }
  11. .icon { font-size: 44px; margin-bottom: 12px; }
  12. h1 { font-size: 18px; font-weight: 700; color: #333; margin-bottom: 8px; }
  13. .desc { font-size: 14px; color: #999; margin-bottom: 20px; line-height: 1.6; }
  14. .btn { display: inline-block; background: #F97316; color: #fff; border: none; border-radius: 24px; padding: 10px 32px; font-size: 14px; cursor: pointer; text-decoration: none; }
  15. .btn:hover { opacity: 0.9; }
  16. .error { color: #E53E3E; font-size: 13px; margin-top: 12px; display: none; }
  17. </style>
  18. </head>
  19. <body>
  20. <div class="card">
  21. <div class="icon">⌚</div>
  22. <h1>连接华为运动健康</h1>
  23. <p class="desc" id="desc">正在跳转华为账号授权…</p>
  24. <a class="btn" id="fallback" style="display:none" href="javascript:void(0)">若未自动跳转请点此</a>
  25. <p class="error" id="error">授权页加载失败,请返回重试</p>
  26. </div>
  27. <script>
  28. // §5.1:入口 /huawei-auth.html?memberId=<id>&authUrl=<encodeURIComponent(authUrl)>
  29. // 读 query 后 location.replace(authUrl) 跳华为授权(authUrl 由前端调接口1获取后拼在本页 query)。
  30. // 本页不出现任何华为账号/密码输入框(防钓鱼观感与合规风险)。
  31. (function() {
  32. function getParam(name) {
  33. var m = location.search.match(new RegExp('[?&]' + name + '=([^&]*)'))
  34. return m ? decodeURIComponent(m[1].replace(/\+/g, '%20')) : ''
  35. }
  36. var authUrl = getParam('authUrl')
  37. var fallback = document.getElementById('fallback')
  38. var error = document.getElementById('error')
  39. var desc = document.getElementById('desc')
  40. function jump(url) {
  41. // 小屏 web-view 内 location.replace 跳转 OAuth
  42. location.replace(url)
  43. }
  44. fallback.addEventListener('click', function() {
  45. if (authUrl) { desc.textContent = '正在跳转华为账号授权…'; jump(authUrl) }
  46. })
  47. if (authUrl) {
  48. desc.textContent = '正在跳转华为账号授权…'
  49. jump(authUrl)
  50. } else {
  51. desc.textContent = '缺少授权参数'
  52. error.style.display = 'block'
  53. fallback.style.display = 'none'
  54. }
  55. })();
  56. </script>
  57. </body>
  58. </html>