wx-h5-demo: 授权改 navigateTo 独立授权页(pages/annex/auth/index) 替代非实时 postMessage

This commit is contained in:
2026-09-07 20:59:38 +08:00
parent 3f47899643
commit 935fee400e
2 changed files with 11 additions and 9 deletions

View File

@@ -63,9 +63,9 @@
<p class="hint">
本页演示<b>共享授权规范</b>:<code>wx-auth.js</code>(<code>wxAuth.init/requestProfile/goMall/readAuth/isAuthorized</code>)。
授权流程:点「授权登录」→ <code>wx.miniProgram.postMessage({action:'requestProfile'})</code> →
通用宿主页 <code>pages/annex/web_view</code> 弹原生授权面板(头像/昵称/手机号)→ <code>POST /api/mp/public/auth/profile</code> 落库共享 UserAuth →
宿主页更新 <code>web-view src</code>(hash 带结果)→ 本页重载 → <code>wxAuth.readAuth()</code> 显示。
授权流程:点「授权登录」→ <code>wx.miniProgram.navigateTo('/pages/annex/auth/index')</code> →
小程序端独立授权页(头像/昵称/手机号,非 web-view 原生组件页)→ <code>POST /api/mp/public/auth/profile</code> 落库共享 UserAuth →
授权返回后宿主页更新 <code>web-view src</code>(hash 带结果)→ 本页重载 → <code>wxAuth.readAuth()</code> 显示。
「进商城」→ <code>wx.miniProgram.switchTab('/pages/goods_cate/goods_cate')</code>。
</p>
@@ -97,7 +97,7 @@
/* ============================================================
① 页面版本号(YYMMDD + 两位序号)—— 用于排查 webview 是否缓存了旧页面
============================================================ */
var VER = '26090702';
var VER = '26090703';
var verNoEl = el('verNo');
if (verNoEl) verNoEl.textContent = VER;
@@ -217,7 +217,7 @@
if (!(window.wx && window.wx.miniProgram)) {
dbgErr('requestProfile 被拒绝:window.wx.miniProgram 不存在(不在微信 web-view 或 jweixin 未加载)');
} else {
dbg('requestProfile 前置检查通过(wx.miniProgram 存在),开始发送 postMessage', 'ok');
dbg('requestProfile 前置检查通过(wx.miniProgram 存在),开始 navigateTo 授权页', 'ok');
}
wxAuth.requestProfile();
});