wx-auth-sdk 1.2.41 → 1.2.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -90,7 +90,7 @@ SDK 会自动:
90
90
 
91
91
  ## 登录态与 Cookie 域
92
92
 
93
- 认证成功后,SDK 将签名 Token 写入 Cookie(**按根域存储,会话 Cookie——不设 `expires`,浏览器进程关闭即失效,重新打开浏览器需重新扫码**;同一浏览器会话内刷新/开新标签页不丢登录态)。Cookie 的 `domain` 由**当前页面域名**推导,而不是后端地址(apiBase):
93
+ 认证成功后,SDK 将签名 Token 写入 Cookie(**按根域存储,7 天持久 Cookie + 滑动续期——每次校验成功自动续期,活跃用户不掉登录态,连续 7 天不访问才需重新扫码**;同一浏览器内刷新/重开/开新标签页都不丢登录态)。Cookie 的 `domain` 由**当前页面域名**推导,而不是后端地址(apiBase):
94
94
 
95
95
  | 页面域名 | Cookie 落点 | 登录态共享范围 |
96
96
  |---------|------------|---------------|
@@ -103,7 +103,7 @@ SDK 会自动:
103
103
  - **同一注册域内一个认证,全域自动登录**:`sub1.mysite.com` 认证后,`sub2.mysite.com`、根域 `mysite.com` 都能静默通过(凭根域 Cookie)。
104
104
  - **跨注册域不共享**:`mysite.com` 与 `other.com` 是相互独立的登录态,需各自认证一次(浏览器安全机制,无法绕过)。
105
105
  - **主站已登录 → 子站有登录态**:`panhub.shenzjd.com` 认证后,访问 `parse.shenzjd.com` 等其他子站同样静默通过。
106
- - **登录态统一会话级(2026-09-05)**:Cookie 不设 `expires`,浏览器进程关闭即失效、重新打开需重新扫码(2026-09-04 曾临时改为 3 天持久,随激励解锁下线回退);同一浏览器会话内刷新/开新标签不丢(策略沿革见主仓库 AGENTS.md「登录态有效期」)。
106
+ - **登录态 7 天持久 + 滑动续期(2026-09-19)**:Cookie 带 7 天 `expires`,每次校验成功自动回写续期,活跃用户永不重登;连续 7 天不访问才需重新扫码(2026-09-05~09-18 曾为会话级,更早沿革见主仓库 AGENTS.md「登录态有效期」)。
107
107
  - **⚠️ 多级公共后缀**:若页面域名属于 `.com.cn` / `.co.uk` 等多级后缀(如 `site.mysite.com.cn`),"取最后两段"会推导出 `.com.cn`,浏览器会拒绝写入。此类接入需确认域名后再接入。
108
108
 
109
109
  > **为什么 cookie 不跟 apiBase 走?** 早期版本 SDK 曾按 apiBase 域名写 Cookie,导致部署在第三方域名(`apiBase` 指向微信认证后端、页面域名不同)时 Cookie 落错域、后端起总不到凭证、前端反复弹窗(死循环)。SDK 已改为始终按「页面所在域」写 Cookie,与后端地址无关。
@@ -165,7 +165,7 @@ await WxAuth.requireAuth({ required: true }); // 本次弹窗强制不可关闭
165
165
  初始化 WxAuth.init()
166
166
  │
167
167
  ▼
168
- 读取 Cookie(会话级,浏览器进程内有效)
168
+ 读取 Cookie(7 天持久 + 滑动续期,浏览器内长期有效)
169
169
  │
170
170
  ├── 有效 ──────────── onVerified() ✅ 静默通过
171
171
  │
@@ -264,14 +264,14 @@ interface AuthUser {
264
264
  | 出码失败可在面板内「刷新二维码」重试 | ✅ |
265
265
  | 有 Cookie 静默认证 | ✅ |
266
266
  | Cookie 按页面根域写入(跨子域共享) | ✅ |
267
- | 会话 Cookie 登录态(浏览器进程内共享,关闭即失效) | ✅ |
267
+ | 7 天持久 Cookie 登录态 + 滑动续期(浏览器内共享,活跃用户不掉登录) | ✅ |
268
268
  | 服务抖动/限流重试,不误清凭证、不误弹码框 | ✅ |
269
269
  | F12 删弹窗自动恢复 | ✅ |
270
270
  | ~~双 Tab 登录方式(小程序扫码 / 公众号验证码)~~ | ⛔ 2026-09-16 临时停用 |
271
271
  | ~~出码失败自动回落公众号验证码 Tab~~ | ⛔ 改为面板内重试 |
272
272
  | ~~验证码输入框(自动跳格 / 粘贴识别 / 键盘导航 / 自动提交)~~ | ⛔ 随公众号登录临时停用 |
273
273
 
274
- > **登录态有效期(2026-09-05)**:web 登录态为**会话级**——Cookie 不设 `expires`,浏览器进程关闭即失效,重新打开浏览器需重新扫码。同一浏览器会话内刷新/开新标签页不丢登录态;不写 localStorage 备份。2026-09-04 曾短暂改为 3 天持久,随激励解锁下线回退(详见主仓库 AGENTS.md)。
274
+ > **登录态有效期(2026-09-19)**:web 登录态为 **7 天持久 Cookie + 滑动续期**——每次校验成功自动回写续期,活跃用户永不重登,连续 7 天不访问才需重新扫码;同一浏览器内刷新/重开/开新标签页都不丢登录态;不写 localStorage 备份。2026-09-05~09-18 曾为会话级,更早沿革见主仓库 AGENTS.md。
275
275
 
276
276
  ---
277
277
 
package/dist/wx-auth.css CHANGED
@@ -1 +1 @@
1
- .wx-auth-modal{position:fixed;inset:0;z-index:9999;display:none;align-items:center;justify-content:center;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,PingFang SC,Hiragino Sans GB,Microsoft YaHei,sans-serif}.wx-auth-overlay{position:absolute;width:100%;height:100%;background:#00000080;animation:wxAuthFadeIn .2s ease}.wx-auth-content{position:relative;width:350px;max-width:90vw;background:#fff;border-radius:12px;overflow:hidden;box-shadow:0 10px 40px #0003;animation:wxAuthSlideUp .3s ease}.wx-auth-modal .wx-auth-header{position:relative;background:#07c160;color:#fff;padding:10px 16px;display:flex;align-items:center;justify-content:space-between}.wx-auth-modal .wx-auth-title{font-size:16px;font-weight:600;flex:1;text-align:center}.wx-auth-modal .wx-auth-close{position:absolute;right:8px;top:6px;background:none;border:none;color:#fff;font-size:24px;cursor:pointer;width:30px;height:30px;line-height:30px;padding:0;opacity:.85;flex-shrink:0}.wx-auth-close:hover{opacity:1}.wx-auth-body{padding:20px;text-align:center}.wx-auth-desc{font-size:15px;color:#333;margin-bottom:16px;font-weight:500}.wx-auth-hint{font-size:15px;color:#333;margin-top:12px;margin-bottom:4px;font-weight:500}.wx-auth-note{font-size:12px;color:#888;margin-bottom:14px;line-height:1.4;white-space:nowrap}.wx-auth-qrcode-container{width:180px;height:180px;margin:0 auto 8px;border:2px solid #07C160;border-radius:8px;overflow:hidden;background:#f5f5f5}.wx-auth-qrcode{width:100%;height:100%;display:none;object-fit:contain}.wx-auth-tabs{display:flex;gap:8px;margin-bottom:16px}.wx-auth-tab{flex:1;padding:8px 0;font-size:13px;border:1px solid #DCDCDC;background:#f7f7f7;color:#666;border-radius:6px;cursor:pointer;transition:all .2s}.wx-auth-tab:active{transform:scale(.98)}.wx-auth-tab-active{background:#07c160;border-color:#07c160;color:#fff;font-weight:600}.wx-auth-mp-loading{height:100%;display:flex;align-items:center;justify-content:center}.wx-auth-spinner{width:28px;height:28px;border:3px solid #e5e5e5;border-top-color:#07c160;border-radius:50%;animation:wxAuthSpin 1s linear infinite}@keyframes wxAuthSpin{to{transform:rotate(360deg)}}.wx-auth-mp-qrcode{width:100%;height:100%;display:none;object-fit:contain}.wx-auth-mp-container{position:relative}.wx-auth-mp-expired{position:absolute;inset:0;z-index:1;display:none;flex-direction:column;align-items:center;justify-content:center;gap:10px;background:#ffffffeb}.wx-auth-mp-expired-text{font-size:13px;color:#666}.wx-auth-mp-expired .wx-auth-mp-refresh{flex:none;width:auto;margin:0;padding:8px 18px;font-size:13px}.wx-auth-mp-status{font-size:13px;color:#666;margin:4px 0 12px;min-height:18px;line-height:1.4}.wx-auth-mp-hint{margin:12px 0 4px}.wx-auth-inputs{display:flex;gap:8px;justify-content:center;margin:20px 0}.wx-auth-input{width:42px;height:50px;font-size:20px;font-weight:600;text-align:center;border:2px solid #DCDCDC;border-radius:8px;outline:none;transition:all .2s;color:#333}.wx-auth-input:focus{border-color:#07c160;box-shadow:0 0 0 2px #07c16033}.wx-auth-input:disabled{background:#f5f5f5;color:#999}.wx-auth-success-icon{font-size:48px;margin-bottom:8px}.wx-auth-success-text{font-size:16px;color:#07c160;font-weight:600}.wx-auth-message{font-size:13px;padding:8px 12px;border-radius:6px;margin:8px 0;line-height:1.4}.wx-auth-message-info{background:#e8f4ff;color:#06c;border:1px solid #B3D9FF}.wx-auth-message-success{background:#f0fdf4;color:#07c160;border:1px solid #07C160}.wx-auth-message-error{background:#fef2f2;color:#dc2626;border:1px solid #DC2626}.wx-auth-actions{display:flex;gap:10px;margin-top:16px}.wx-auth-btn{flex:1;padding:12px 16px;border:none;border-radius:8px;font-size:14px;font-weight:600;cursor:pointer;transition:all .2s;outline:none}.wx-auth-btn:active{transform:scale(.98)}.wx-auth-btn:disabled{opacity:.5;cursor:not-allowed}.wx-auth-btn-primary{background:#07c160;color:#fff}.wx-auth-btn-primary:hover:not(:disabled){background:#06ad56}.wx-auth-btn-secondary{background:#f2f2f2;color:#333}.wx-auth-btn-secondary:hover:not(:disabled){background:#e5e5e5}@keyframes wxAuthFadeIn{0%{opacity:0}to{opacity:1}}@keyframes wxAuthSlideUp{0%{opacity:0;transform:translateY(20px)}to{opacity:1;transform:translateY(0)}}@media(max-width:480px){.wx-auth-content{width:95vw;margin:20px}.wx-auth-qrcode-container{width:160px;height:160px}.wx-auth-inputs{gap:6px}.wx-auth-input{width:38px;height:46px;font-size:18px}}@media(prefers-color-scheme:dark){.wx-auth-content{background:#1a1a1a}.wx-auth-desc,.wx-auth-hint{color:#e5e5e5}.wx-auth-note{color:#aaa}.wx-auth-input{background:#2a2a2a;border-color:#444;color:#e5e5e5}.wx-auth-input:focus{border-color:#07c160;box-shadow:0 0 0 2px #07c16040}.wx-auth-input:disabled{background:#333;color:#888}.wx-auth-qrcode-container{background:#2a2a2a}.wx-auth-tab{background:#2a2a2a;border-color:#444;color:#aaa}.wx-auth-tab-active{background:#07c160;border-color:#07c160;color:#fff}.wx-auth-spinner{border-color:#444;border-top-color:#07c160}.wx-auth-mp-status{color:#aaa}.wx-auth-mp-expired{background:#1a1a1aeb}.wx-auth-mp-expired-text{color:#aaa}.wx-auth-btn-secondary{background:#2a2a2a;color:#e5e5e5}.wx-auth-btn-secondary:hover:not(:disabled){background:#333}.wx-auth-message-info{background:#0d2a1f;color:#7cc4ff;border-color:#1f4a6b}.wx-auth-message-success{background:#0d2a1a;color:#4ade80;border-color:#1f6b3a}.wx-auth-message-error{background:#2a0d0d;color:#f87171;border-color:#6b1f1f}}.wx-auth-required .wx-auth-close{display:none!important}.wx-auth-optional .wx-auth-overlay{cursor:pointer}
1
+ .wx-auth-modal{position:fixed;inset:0;z-index:9999;display:none;align-items:center;justify-content:center;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,PingFang SC,Hiragino Sans GB,Microsoft YaHei,sans-serif}.wx-auth-overlay{position:absolute;width:100%;height:100%;background:#00000080;animation:wxAuthFadeIn .2s ease}.wx-auth-content{position:relative;width:350px;max-width:90vw;background:#fff;border-radius:12px;overflow:hidden;box-shadow:0 10px 40px #0003;animation:wxAuthSlideUp .3s ease}.wx-auth-modal .wx-auth-header{position:relative;background:#07c160;color:#fff;box-sizing:border-box;min-height:56px;padding:0 16px;display:flex;align-items:center;justify-content:space-between}.wx-auth-modal .wx-auth-title{font-size:16px;font-weight:600;flex:1;text-align:center}.wx-auth-modal .wx-auth-close{position:absolute;right:10px;top:50%;transform:translateY(-50%);background:none;border:none;color:#fff;font-size:24px;cursor:pointer;width:30px;height:30px;line-height:30px;padding:0;opacity:.85;flex-shrink:0}.wx-auth-close:hover{opacity:1}.wx-auth-body{padding:20px;text-align:center}.wx-auth-desc{font-size:15px;color:#333;margin-bottom:16px;font-weight:500}.wx-auth-hint{font-size:15px;color:#333;margin-top:12px;margin-bottom:4px;font-weight:500}.wx-auth-note{font-size:12px;color:#888;margin-bottom:14px;line-height:1.4;white-space:nowrap}.wx-auth-qrcode-container{width:180px;height:180px;margin:0 auto 8px;border:2px solid #07C160;border-radius:8px;overflow:hidden;background:#f5f5f5}.wx-auth-qrcode{width:100%;height:100%;display:none;object-fit:contain}.wx-auth-tabs{display:flex;gap:8px;margin-bottom:16px}.wx-auth-tab{flex:1;padding:8px 0;font-size:13px;border:1px solid #DCDCDC;background:#f7f7f7;color:#666;border-radius:6px;cursor:pointer;transition:all .2s}.wx-auth-tab:active{transform:scale(.98)}.wx-auth-tab-active{background:#07c160;border-color:#07c160;color:#fff;font-weight:600}.wx-auth-mp-loading{height:100%;display:flex;align-items:center;justify-content:center}.wx-auth-spinner{width:28px;height:28px;border:3px solid #e5e5e5;border-top-color:#07c160;border-radius:50%;animation:wxAuthSpin 1s linear infinite}@keyframes wxAuthSpin{to{transform:rotate(360deg)}}.wx-auth-mp-qrcode{width:100%;height:100%;display:none;object-fit:contain}.wx-auth-mp-container{position:relative}.wx-auth-mp-expired{position:absolute;inset:0;z-index:1;display:none;flex-direction:column;align-items:center;justify-content:center;gap:10px;background:#ffffffeb}.wx-auth-mp-expired-text{font-size:13px;color:#666}.wx-auth-mp-expired .wx-auth-mp-refresh{flex:none;width:auto;margin:0;padding:8px 18px;font-size:13px}.wx-auth-mp-status{font-size:13px;color:#666;margin:4px 0 12px;min-height:18px;line-height:1.4}.wx-auth-mp-hint{margin:12px 0 4px}.wx-auth-inputs{display:flex;gap:8px;justify-content:center;margin:20px 0}.wx-auth-input{width:42px;height:50px;font-size:20px;font-weight:600;text-align:center;border:2px solid #DCDCDC;border-radius:8px;outline:none;transition:all .2s;color:#333}.wx-auth-input:focus{border-color:#07c160;box-shadow:0 0 0 2px #07c16033}.wx-auth-input:disabled{background:#f5f5f5;color:#999}.wx-auth-success-icon{font-size:48px;margin-bottom:8px}.wx-auth-success-text{font-size:16px;color:#07c160;font-weight:600}.wx-auth-message{font-size:13px;padding:8px 12px;border-radius:6px;margin:8px 0;line-height:1.4}.wx-auth-message-info{background:#e8f4ff;color:#06c;border:1px solid #B3D9FF}.wx-auth-message-success{background:#f0fdf4;color:#07c160;border:1px solid #07C160}.wx-auth-message-error{background:#fef2f2;color:#dc2626;border:1px solid #DC2626}.wx-auth-actions{display:flex;gap:10px;margin-top:16px}.wx-auth-btn{flex:1;padding:12px 16px;border:none;border-radius:8px;font-size:14px;font-weight:600;cursor:pointer;transition:all .2s;outline:none}.wx-auth-btn:active{transform:scale(.98)}.wx-auth-btn:disabled{opacity:.5;cursor:not-allowed}.wx-auth-btn-primary{background:#07c160;color:#fff}.wx-auth-btn-primary:hover:not(:disabled){background:#06ad56}.wx-auth-btn-secondary{background:#f2f2f2;color:#333}.wx-auth-btn-secondary:hover:not(:disabled){background:#e5e5e5}@keyframes wxAuthFadeIn{0%{opacity:0}to{opacity:1}}@keyframes wxAuthSlideUp{0%{opacity:0;transform:translateY(20px)}to{opacity:1;transform:translateY(0)}}@media(max-width:480px){.wx-auth-content{width:95vw;margin:20px}.wx-auth-qrcode-container{width:160px;height:160px}.wx-auth-inputs{gap:6px}.wx-auth-input{width:38px;height:46px;font-size:18px}}@media(prefers-color-scheme:dark){.wx-auth-content{background:#1a1a1a}.wx-auth-desc,.wx-auth-hint{color:#e5e5e5}.wx-auth-note{color:#aaa}.wx-auth-input{background:#2a2a2a;border-color:#444;color:#e5e5e5}.wx-auth-input:focus{border-color:#07c160;box-shadow:0 0 0 2px #07c16040}.wx-auth-input:disabled{background:#333;color:#888}.wx-auth-qrcode-container{background:#2a2a2a}.wx-auth-tab{background:#2a2a2a;border-color:#444;color:#aaa}.wx-auth-tab-active{background:#07c160;border-color:#07c160;color:#fff}.wx-auth-spinner{border-color:#444;border-top-color:#07c160}.wx-auth-mp-status{color:#aaa}.wx-auth-mp-expired{background:#1a1a1aeb}.wx-auth-mp-expired-text{color:#aaa}.wx-auth-btn-secondary{background:#2a2a2a;color:#e5e5e5}.wx-auth-btn-secondary:hover:not(:disabled){background:#333}.wx-auth-message-info{background:#0d2a1f;color:#7cc4ff;border-color:#1f4a6b}.wx-auth-message-success{background:#0d2a1a;color:#4ade80;border-color:#1f6b3a}.wx-auth-message-error{background:#2a0d0d;color:#f87171;border-color:#6b1f1f}}.wx-auth-required .wx-auth-close{display:none!important}.wx-auth-optional .wx-auth-overlay{cursor:pointer}
package/dist/wx-auth.js CHANGED
@@ -113,7 +113,8 @@ let a = { ...C }, d = "", x = "", i = {
113
113
  required: !!a.required,
114
114
  mpSession: null
115
115
  }, f = "mp", h = 0;
116
- function I(e) {
116
+ const I = 10080 * 60 * 1e3;
117
+ function E(e) {
117
118
  try {
118
119
  if (e === "localhost" || /^\d+\.\d+\.\d+\.\d+$/.test(e))
119
120
  return "";
@@ -125,7 +126,7 @@ function I(e) {
125
126
  }
126
127
  const c = {
127
128
  getRootDomain() {
128
- return I(window.location.hostname);
129
+ return E(window.location.hostname);
129
130
  },
130
131
  // 获取Cookie
131
132
  getCookie(e) {
@@ -153,23 +154,24 @@ const c = {
153
154
  const t = this.getRootDomain();
154
155
  this.writeCookieRaw(e, "", void 0, t, !0), t && this.writeCookieRaw(e, "", void 0, "", !0);
155
156
  },
156
- // ===== 签名 Token 存储(会话 Cookie,2026-09-05 恢复)=====
157
- // 登录态策略:web 登录态为会话级——不设 expires,浏览器进程关闭即失效,
158
- // 每次新会话重新走一遍登录链路(2026-09-04 曾放宽为 3 天持久化,现回退)。
159
- // 背景(2026-09-05):搜索侧激励解锁(floating-unlock 看广告解锁)已下线,
160
- // 变现收敛到「确认登录 → 激励广告」必经链路,登录态的定期失效是这条链路的
161
- // 流量来源;3 天持久化会让回访用户绕过该链路,故恢复会话级。
162
- // 不引入 localStorage 备份:会话语义下备份直接破坏策略,clearToken 保留对
163
- // 旧版本备份 key 的防御性清理。
157
+ // ===== 签名 Token 存储(7 天持久 Cookie + 滑动续期,2026-09-19)=====
158
+ // 登录态策略:setToken 写 7 天持久 Cookie;silentCheck / autoCheck 每次校验
159
+ // 成功都回写 token(= 滑动续期),活跃用户永不重登,连续 7 天不访问才需重新扫码。
160
+ // 沿革:2026-08-30 首次会话级 → 2026-09-04 放宽 3 天 → 2026-09-05 回退会话级
161
+ // (当时动机是「确认登录 → 激励广告」链路的曝光量)→ 2026-09-19 恢复持久:
162
+ // 积分系统上线后广告变现已收敛到 spend/unlock 按使用动作收费,不再依赖重登
163
+ // 次数,而「关浏览器就掉登录」是用户反馈最集中的体验问题。
164
+ // 不引入 localStorage 备份(7 天已够长,备份反而在隐私模式/换设备场景产生
165
+ // 幽灵登录态);clearToken 保留对旧版本备份 key 的防御性清理。
164
166
  // 存储的是签名 Token(HMAC,不可伪造),而非明文 openid(永久凭证)。
165
167
  // 注意:Cookie 是根域共享;localStorage 按站点隔离,且不再读取。
166
168
  // 读取:wxauth-token Cookie(旧版本 localStorage 备份不再兜底)
167
169
  getToken() {
168
170
  return this.getCookie("wxauth-token");
169
171
  },
170
- // 写入:会话 Cookie(浏览器关闭即失效,见上方登录态策略)
172
+ // 写入:持久 Cookie(7 天;silentCheck/autoCheck 成功路径每次调用即滑动续期)
171
173
  setToken(e) {
172
- this.setCookie("wxauth-token", e);
174
+ this.setCookie("wxauth-token", e, I);
173
175
  },
174
176
  // 删除:清 Cookie + 防御性清理旧版本 localStorage 备份残留
175
177
  // (同时清掉明文 openid Cookie —— 防御性清理,服务端已下线 openid 通道 2026-08-26)
@@ -247,12 +249,12 @@ function k(e) {
247
249
  function y(e) {
248
250
  return new Promise((t) => setTimeout(t, e));
249
251
  }
250
- const E = 3e3, M = 2e3, T = 3e3;
252
+ const M = 3e3, T = 2e3, P = 3e3;
251
253
  function g() {
252
254
  h++;
253
255
  }
254
256
  async function b(e) {
255
- if (await y(E), !(e !== h || !i.isOpen)) {
257
+ if (await y(M), !(e !== h || !i.isOpen)) {
256
258
  for (; e === h && i.isOpen; ) {
257
259
  const t = i.mpSession;
258
260
  if (!t || Date.now() >= t.expiresAt) break;
@@ -272,10 +274,10 @@ async function b(e) {
272
274
  } catch (o) {
273
275
  if (e !== h) return;
274
276
  if (!k(o)) break;
275
- await y(T);
277
+ await y(P);
276
278
  continue;
277
279
  }
278
- await y(M);
280
+ await y(T);
279
281
  }
280
282
  e === h && i.isOpen && f === "mp" && u.showMpExpired();
281
283
  }
@@ -550,7 +552,7 @@ const u = {
550
552
  }
551
553
  },
552
554
  // 主入口:需要验证时调用
553
- // 凭证仅签名 Token(登录 Cookie,会话级,2026-09-05),不再兼容明文 openid
555
+ // 凭证仅签名 Token(登录 Cookie,7 天持久 + 滑动续期,2026-09-19),不再兼容明文 openid
554
556
  // (2026-08-26 服务端已下线 openid 通道)
555
557
  async requireAuth(e) {
556
558
  const t = c.getToken();
@@ -1,5 +1,5 @@
1
- (function(w,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(w=typeof globalThis<"u"?globalThis:w||self,m(w.WxAuthSDK={}))})(this,(function(w){"use strict";var m=document.createElement("style");m.textContent=`.wx-auth-modal{position:fixed;inset:0;z-index:9999;display:none;align-items:center;justify-content:center;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,PingFang SC,Hiragino Sans GB,Microsoft YaHei,sans-serif}.wx-auth-overlay{position:absolute;width:100%;height:100%;background:#00000080;animation:wxAuthFadeIn .2s ease}.wx-auth-content{position:relative;width:350px;max-width:90vw;background:#fff;border-radius:12px;overflow:hidden;box-shadow:0 10px 40px #0003;animation:wxAuthSlideUp .3s ease}.wx-auth-modal .wx-auth-header{position:relative;background:#07c160;color:#fff;padding:10px 16px;display:flex;align-items:center;justify-content:space-between}.wx-auth-modal .wx-auth-title{font-size:16px;font-weight:600;flex:1;text-align:center}.wx-auth-modal .wx-auth-close{position:absolute;right:8px;top:6px;background:none;border:none;color:#fff;font-size:24px;cursor:pointer;width:30px;height:30px;line-height:30px;padding:0;opacity:.85;flex-shrink:0}.wx-auth-close:hover{opacity:1}.wx-auth-body{padding:20px;text-align:center}.wx-auth-desc{font-size:15px;color:#333;margin-bottom:16px;font-weight:500}.wx-auth-hint{font-size:15px;color:#333;margin-top:12px;margin-bottom:4px;font-weight:500}.wx-auth-note{font-size:12px;color:#888;margin-bottom:14px;line-height:1.4;white-space:nowrap}.wx-auth-qrcode-container{width:180px;height:180px;margin:0 auto 8px;border:2px solid #07C160;border-radius:8px;overflow:hidden;background:#f5f5f5}.wx-auth-qrcode{width:100%;height:100%;display:none;object-fit:contain}.wx-auth-tabs{display:flex;gap:8px;margin-bottom:16px}.wx-auth-tab{flex:1;padding:8px 0;font-size:13px;border:1px solid #DCDCDC;background:#f7f7f7;color:#666;border-radius:6px;cursor:pointer;transition:all .2s}.wx-auth-tab:active{transform:scale(.98)}.wx-auth-tab-active{background:#07c160;border-color:#07c160;color:#fff;font-weight:600}.wx-auth-mp-loading{height:100%;display:flex;align-items:center;justify-content:center}.wx-auth-spinner{width:28px;height:28px;border:3px solid #e5e5e5;border-top-color:#07c160;border-radius:50%;animation:wxAuthSpin 1s linear infinite}@keyframes wxAuthSpin{to{transform:rotate(360deg)}}.wx-auth-mp-qrcode{width:100%;height:100%;display:none;object-fit:contain}.wx-auth-mp-container{position:relative}.wx-auth-mp-expired{position:absolute;inset:0;z-index:1;display:none;flex-direction:column;align-items:center;justify-content:center;gap:10px;background:#ffffffeb}.wx-auth-mp-expired-text{font-size:13px;color:#666}.wx-auth-mp-expired .wx-auth-mp-refresh{flex:none;width:auto;margin:0;padding:8px 18px;font-size:13px}.wx-auth-mp-status{font-size:13px;color:#666;margin:4px 0 12px;min-height:18px;line-height:1.4}.wx-auth-mp-hint{margin:12px 0 4px}.wx-auth-inputs{display:flex;gap:8px;justify-content:center;margin:20px 0}.wx-auth-input{width:42px;height:50px;font-size:20px;font-weight:600;text-align:center;border:2px solid #DCDCDC;border-radius:8px;outline:none;transition:all .2s;color:#333}.wx-auth-input:focus{border-color:#07c160;box-shadow:0 0 0 2px #07c16033}.wx-auth-input:disabled{background:#f5f5f5;color:#999}.wx-auth-success-icon{font-size:48px;margin-bottom:8px}.wx-auth-success-text{font-size:16px;color:#07c160;font-weight:600}.wx-auth-message{font-size:13px;padding:8px 12px;border-radius:6px;margin:8px 0;line-height:1.4}.wx-auth-message-info{background:#e8f4ff;color:#06c;border:1px solid #B3D9FF}.wx-auth-message-success{background:#f0fdf4;color:#07c160;border:1px solid #07C160}.wx-auth-message-error{background:#fef2f2;color:#dc2626;border:1px solid #DC2626}.wx-auth-actions{display:flex;gap:10px;margin-top:16px}.wx-auth-btn{flex:1;padding:12px 16px;border:none;border-radius:8px;font-size:14px;font-weight:600;cursor:pointer;transition:all .2s;outline:none}.wx-auth-btn:active{transform:scale(.98)}.wx-auth-btn:disabled{opacity:.5;cursor:not-allowed}.wx-auth-btn-primary{background:#07c160;color:#fff}.wx-auth-btn-primary:hover:not(:disabled){background:#06ad56}.wx-auth-btn-secondary{background:#f2f2f2;color:#333}.wx-auth-btn-secondary:hover:not(:disabled){background:#e5e5e5}@keyframes wxAuthFadeIn{0%{opacity:0}to{opacity:1}}@keyframes wxAuthSlideUp{0%{opacity:0;transform:translateY(20px)}to{opacity:1;transform:translateY(0)}}@media(max-width:480px){.wx-auth-content{width:95vw;margin:20px}.wx-auth-qrcode-container{width:160px;height:160px}.wx-auth-inputs{gap:6px}.wx-auth-input{width:38px;height:46px;font-size:18px}}@media(prefers-color-scheme:dark){.wx-auth-content{background:#1a1a1a}.wx-auth-desc,.wx-auth-hint{color:#e5e5e5}.wx-auth-note{color:#aaa}.wx-auth-input{background:#2a2a2a;border-color:#444;color:#e5e5e5}.wx-auth-input:focus{border-color:#07c160;box-shadow:0 0 0 2px #07c16040}.wx-auth-input:disabled{background:#333;color:#888}.wx-auth-qrcode-container{background:#2a2a2a}.wx-auth-tab{background:#2a2a2a;border-color:#444;color:#aaa}.wx-auth-tab-active{background:#07c160;border-color:#07c160;color:#fff}.wx-auth-spinner{border-color:#444;border-top-color:#07c160}.wx-auth-mp-status{color:#aaa}.wx-auth-mp-expired{background:#1a1a1aeb}.wx-auth-mp-expired-text{color:#aaa}.wx-auth-btn-secondary{background:#2a2a2a;color:#e5e5e5}.wx-auth-btn-secondary:hover:not(:disabled){background:#333}.wx-auth-message-info{background:#0d2a1f;color:#7cc4ff;border-color:#1f4a6b}.wx-auth-message-success{background:#0d2a1a;color:#4ade80;border-color:#1f6b3a}.wx-auth-message-error{background:#2a0d0d;color:#f87171;border-color:#6b1f1f}}.wx-auth-required .wx-auth-close{display:none!important}.wx-auth-optional .wx-auth-overlay{cursor:pointer}
2
- /*$vite$:1*/`,document.head.appendChild(m);const a={observer:null,rafId:null,isProtected:!1,restorePending:!1},f={enable(e){if(a.isProtected||typeof window>"u")return;a.observer&&(a.observer.disconnect(),a.observer=null),a.rafId!==null&&(cancelAnimationFrame(a.rafId),a.rafId=null),a.isProtected=!0,a.restorePending=!1,a.observer=new MutationObserver(o=>{for(const n of o)if(n.type==="childList")for(const r of n.removedNodes){if(r.nodeType!==Node.ELEMENT_NODE)continue;const l=r;if(l.id===e.modalId||l.querySelector?.(`#${e.modalId}`)){console.warn("[WxAuth] 检测到弹窗被删除,正在恢复..."),f.safeRestore(e);return}}}),a.observer.observe(document.body,{childList:!0,subtree:!0});const t=()=>{if(!a.isProtected)return;const{getState:o}=e;if(!o().isOpen){a.rafId=null;return}const n=document.getElementById(e.modalId);(!n||!n.isConnected||f.isHidden(n))&&(console.warn("[WxAuth] 轮询检测到弹窗丢失/隐藏,正在恢复...",{has:!!n,connected:n?.isConnected,hidden:n?f.isHidden(n):null}),f.safeRestore(e)),a.isProtected&&(a.rafId=requestAnimationFrame(t))};a.rafId=requestAnimationFrame(t),console.log("[WxAuth] 弹窗保护已启用 (MutationObserver + rAF)")},disable(){a.observer&&(a.observer.disconnect(),a.observer=null),a.rafId!==null&&(cancelAnimationFrame(a.rafId),a.rafId=null),a.isProtected=!1,a.restorePending=!1,console.log("[WxAuth] 弹窗保护已禁用")},safeRestore(e){if(!a.restorePending){a.restorePending=!0;try{f.restoreFn(e)}finally{requestAnimationFrame(()=>{a.restorePending=!1})}}},isHidden(e){if(e.style.display==="none"||e.style.visibility==="hidden"||e.style.opacity==="0")return!0;try{const t=window.getComputedStyle(e);if(t.display==="none"||t.visibility==="hidden"||parseFloat(t.opacity)===0)return!0}catch{}return!1},restoreFn(e){const{modalId:t,getState:o,onRestore:n}=e;if(!o().isOpen)return;const r=document.getElementById(t);if(r){r.style.display="flex",r.style.visibility="visible",r.style.opacity="1";return}n()}},C={apiBase:"https://wx-auth.shenzjd.com",onVerified:null,onError:null,onClose:null,required:!1,wechatName:"神族九帝",qrcodeUrl:"",silent:!1};let s={...C},d="",b="",i={isOpen:!1,resolveAuth:null,currentStep:"qr",required:!!s.required,mpSession:null},p="mp",h=0;function I(e){try{if(e==="localhost"||/^\d+\.\d+\.\d+\.\d+$/.test(e))return"";const t=e.split(".");return t.length>=2?"."+t.slice(-2).join("."):""}catch{return""}}const u={getRootDomain(){return I(window.location.hostname)},getCookie(e){const o=`; ${document.cookie}`.split(`; ${e}=`);return o.length===2&&o.pop()?.split(";").shift()||null},writeCookieRaw(e,t,o,n,r=!1){const l=n?`;domain=${n}`:"",D=window.location.protocol==="https:"?";Secure":"",P=r?";expires=Thu, 01 Jan 1970 00:00:00 GMT":o!==void 0?`;expires=${new Date(Date.now()+o).toUTCString()}`:"";document.cookie=`${e}=${r?"":t};path=/${l}${P}${D};SameSite=Strict`},setCookie(e,t,o){const n=this.getRootDomain();this.writeCookieRaw(e,t,o,n),n&&!this.getCookie(e)&&this.writeCookieRaw(e,t,o,"")},deleteCookie(e){const t=this.getRootDomain();this.writeCookieRaw(e,"",void 0,t,!0),t&&this.writeCookieRaw(e,"",void 0,"",!0)},getToken(){return this.getCookie("wxauth-token")},setToken(e){this.setCookie("wxauth-token",e)},clearToken(){this.deleteCookie("wxauth-token"),this.deleteCookie("wxauth-openid");try{window.localStorage.removeItem("wxauth-token")}catch{}},getOrCreateDeviceId(){if(b)return b;let e=this.getCookie("wxauth-device");if(!e)try{e=window.localStorage.getItem("wxauth-device")}catch{}if(!e||!/^[A-Za-z0-9_-]{1,64}$/.test(e)){const t=new Uint8Array(16);if(typeof crypto<"u"&&crypto.getRandomValues)crypto.getRandomValues(t);else for(let o=0;o<16;o++)t[o]=Math.floor(Math.random()*256);e=Array.from(t).map(o=>o.toString(16).padStart(2,"0")).join("")}this.setCookie("wxauth-device",e,365*86400*1e3);try{window.localStorage.setItem("wxauth-device",e)}catch{}return b=e,e},async request(e,t={}){try{const o=await fetch(e,{method:t.method||"GET",headers:{"Content-Type":"application/json",...t.headers},body:t.body?JSON.stringify(t.body):null,credentials:"include"});if(!o.ok){const n=new Error(`HTTP ${o.status}`);throw n.status=o.status,n}return await o.json()}catch(o){const n=o;throw n.status===void 0&&(n.isNetworkError=!0),console.error("[WxAuth] Request error:",o),n}},generateCodeInputs(){let e='<div class="wx-auth-inputs">';for(let t=0;t<6;t++)e+=`<input type="text" inputmode="numeric" pattern="[0-9]*" maxlength="1" class="wx-auth-input" data-index="${t}" autocomplete="off" />`;return e+="</div>",e}},A=[1e3,3e3];function k(e){const t=e;return t?t.isNetworkError?!0:typeof t.status=="number"?t.status>=500||t.status===429:!1:!1}function g(e){return new Promise(t=>setTimeout(t,e))}const E=3e3,M=2e3,T=3e3;function v(){h++}async function q(e){if(await g(E),!(e!==h||!i.isOpen)){for(;e===h&&i.isOpen;){const t=i.mpSession;if(!t||Date.now()>=t.expiresAt)break;try{const o=await u.request(`${s.apiBase}/api/auth/mp-scan/status?ticket=${encodeURIComponent(t.ticket)}`);if(e!==h)return;if(o.status==="confirmed"&&o.token){x.completeLogin(o);return}if(o.status==="expired"){i.mpSession=null;break}}catch(o){if(e!==h)return;if(!k(o))break;await g(T);continue}await g(M)}e===h&&i.isOpen&&p==="mp"&&c.showMpExpired()}}async function S(e){const t=d?`&siteId=${encodeURIComponent(d)}`:"",o=`${s.apiBase}/api/auth/check?token=${encodeURIComponent(e)}${t}`;for(let n=0;;n++)try{const r=await u.request(o);return r.authenticated?{kind:"ok",result:r}:r.error==="rate_limited"||r.error==="server_error"?{kind:"transient"}:{kind:"invalid",result:r}}catch(r){if(!k(r)||n>=A.length)return{kind:"transient"};await g(A[n])}}const c={createModal(e){const t=document.createElement("div");t.id="wx-auth-modal",t.className="wx-auth-modal",t.classList.add(e?"wx-auth-required":"wx-auth-optional");const o="",n="",r=`<div class="wx-auth-panel wx-auth-panel-mp">
1
+ (function(w,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(w=typeof globalThis<"u"?globalThis:w||self,m(w.WxAuthSDK={}))})(this,(function(w){"use strict";var m=document.createElement("style");m.textContent=`.wx-auth-modal{position:fixed;inset:0;z-index:9999;display:none;align-items:center;justify-content:center;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,PingFang SC,Hiragino Sans GB,Microsoft YaHei,sans-serif}.wx-auth-overlay{position:absolute;width:100%;height:100%;background:#00000080;animation:wxAuthFadeIn .2s ease}.wx-auth-content{position:relative;width:350px;max-width:90vw;background:#fff;border-radius:12px;overflow:hidden;box-shadow:0 10px 40px #0003;animation:wxAuthSlideUp .3s ease}.wx-auth-modal .wx-auth-header{position:relative;background:#07c160;color:#fff;box-sizing:border-box;min-height:56px;padding:0 16px;display:flex;align-items:center;justify-content:space-between}.wx-auth-modal .wx-auth-title{font-size:16px;font-weight:600;flex:1;text-align:center}.wx-auth-modal .wx-auth-close{position:absolute;right:10px;top:50%;transform:translateY(-50%);background:none;border:none;color:#fff;font-size:24px;cursor:pointer;width:30px;height:30px;line-height:30px;padding:0;opacity:.85;flex-shrink:0}.wx-auth-close:hover{opacity:1}.wx-auth-body{padding:20px;text-align:center}.wx-auth-desc{font-size:15px;color:#333;margin-bottom:16px;font-weight:500}.wx-auth-hint{font-size:15px;color:#333;margin-top:12px;margin-bottom:4px;font-weight:500}.wx-auth-note{font-size:12px;color:#888;margin-bottom:14px;line-height:1.4;white-space:nowrap}.wx-auth-qrcode-container{width:180px;height:180px;margin:0 auto 8px;border:2px solid #07C160;border-radius:8px;overflow:hidden;background:#f5f5f5}.wx-auth-qrcode{width:100%;height:100%;display:none;object-fit:contain}.wx-auth-tabs{display:flex;gap:8px;margin-bottom:16px}.wx-auth-tab{flex:1;padding:8px 0;font-size:13px;border:1px solid #DCDCDC;background:#f7f7f7;color:#666;border-radius:6px;cursor:pointer;transition:all .2s}.wx-auth-tab:active{transform:scale(.98)}.wx-auth-tab-active{background:#07c160;border-color:#07c160;color:#fff;font-weight:600}.wx-auth-mp-loading{height:100%;display:flex;align-items:center;justify-content:center}.wx-auth-spinner{width:28px;height:28px;border:3px solid #e5e5e5;border-top-color:#07c160;border-radius:50%;animation:wxAuthSpin 1s linear infinite}@keyframes wxAuthSpin{to{transform:rotate(360deg)}}.wx-auth-mp-qrcode{width:100%;height:100%;display:none;object-fit:contain}.wx-auth-mp-container{position:relative}.wx-auth-mp-expired{position:absolute;inset:0;z-index:1;display:none;flex-direction:column;align-items:center;justify-content:center;gap:10px;background:#ffffffeb}.wx-auth-mp-expired-text{font-size:13px;color:#666}.wx-auth-mp-expired .wx-auth-mp-refresh{flex:none;width:auto;margin:0;padding:8px 18px;font-size:13px}.wx-auth-mp-status{font-size:13px;color:#666;margin:4px 0 12px;min-height:18px;line-height:1.4}.wx-auth-mp-hint{margin:12px 0 4px}.wx-auth-inputs{display:flex;gap:8px;justify-content:center;margin:20px 0}.wx-auth-input{width:42px;height:50px;font-size:20px;font-weight:600;text-align:center;border:2px solid #DCDCDC;border-radius:8px;outline:none;transition:all .2s;color:#333}.wx-auth-input:focus{border-color:#07c160;box-shadow:0 0 0 2px #07c16033}.wx-auth-input:disabled{background:#f5f5f5;color:#999}.wx-auth-success-icon{font-size:48px;margin-bottom:8px}.wx-auth-success-text{font-size:16px;color:#07c160;font-weight:600}.wx-auth-message{font-size:13px;padding:8px 12px;border-radius:6px;margin:8px 0;line-height:1.4}.wx-auth-message-info{background:#e8f4ff;color:#06c;border:1px solid #B3D9FF}.wx-auth-message-success{background:#f0fdf4;color:#07c160;border:1px solid #07C160}.wx-auth-message-error{background:#fef2f2;color:#dc2626;border:1px solid #DC2626}.wx-auth-actions{display:flex;gap:10px;margin-top:16px}.wx-auth-btn{flex:1;padding:12px 16px;border:none;border-radius:8px;font-size:14px;font-weight:600;cursor:pointer;transition:all .2s;outline:none}.wx-auth-btn:active{transform:scale(.98)}.wx-auth-btn:disabled{opacity:.5;cursor:not-allowed}.wx-auth-btn-primary{background:#07c160;color:#fff}.wx-auth-btn-primary:hover:not(:disabled){background:#06ad56}.wx-auth-btn-secondary{background:#f2f2f2;color:#333}.wx-auth-btn-secondary:hover:not(:disabled){background:#e5e5e5}@keyframes wxAuthFadeIn{0%{opacity:0}to{opacity:1}}@keyframes wxAuthSlideUp{0%{opacity:0;transform:translateY(20px)}to{opacity:1;transform:translateY(0)}}@media(max-width:480px){.wx-auth-content{width:95vw;margin:20px}.wx-auth-qrcode-container{width:160px;height:160px}.wx-auth-inputs{gap:6px}.wx-auth-input{width:38px;height:46px;font-size:18px}}@media(prefers-color-scheme:dark){.wx-auth-content{background:#1a1a1a}.wx-auth-desc,.wx-auth-hint{color:#e5e5e5}.wx-auth-note{color:#aaa}.wx-auth-input{background:#2a2a2a;border-color:#444;color:#e5e5e5}.wx-auth-input:focus{border-color:#07c160;box-shadow:0 0 0 2px #07c16040}.wx-auth-input:disabled{background:#333;color:#888}.wx-auth-qrcode-container{background:#2a2a2a}.wx-auth-tab{background:#2a2a2a;border-color:#444;color:#aaa}.wx-auth-tab-active{background:#07c160;border-color:#07c160;color:#fff}.wx-auth-spinner{border-color:#444;border-top-color:#07c160}.wx-auth-mp-status{color:#aaa}.wx-auth-mp-expired{background:#1a1a1aeb}.wx-auth-mp-expired-text{color:#aaa}.wx-auth-btn-secondary{background:#2a2a2a;color:#e5e5e5}.wx-auth-btn-secondary:hover:not(:disabled){background:#333}.wx-auth-message-info{background:#0d2a1f;color:#7cc4ff;border-color:#1f4a6b}.wx-auth-message-success{background:#0d2a1a;color:#4ade80;border-color:#1f6b3a}.wx-auth-message-error{background:#2a0d0d;color:#f87171;border-color:#6b1f1f}}.wx-auth-required .wx-auth-close{display:none!important}.wx-auth-optional .wx-auth-overlay{cursor:pointer}
2
+ /*$vite$:1*/`,document.head.appendChild(m);const a={observer:null,rafId:null,isProtected:!1,restorePending:!1},f={enable(e){if(a.isProtected||typeof window>"u")return;a.observer&&(a.observer.disconnect(),a.observer=null),a.rafId!==null&&(cancelAnimationFrame(a.rafId),a.rafId=null),a.isProtected=!0,a.restorePending=!1,a.observer=new MutationObserver(o=>{for(const n of o)if(n.type==="childList")for(const r of n.removedNodes){if(r.nodeType!==Node.ELEMENT_NODE)continue;const l=r;if(l.id===e.modalId||l.querySelector?.(`#${e.modalId}`)){console.warn("[WxAuth] 检测到弹窗被删除,正在恢复..."),f.safeRestore(e);return}}}),a.observer.observe(document.body,{childList:!0,subtree:!0});const t=()=>{if(!a.isProtected)return;const{getState:o}=e;if(!o().isOpen){a.rafId=null;return}const n=document.getElementById(e.modalId);(!n||!n.isConnected||f.isHidden(n))&&(console.warn("[WxAuth] 轮询检测到弹窗丢失/隐藏,正在恢复...",{has:!!n,connected:n?.isConnected,hidden:n?f.isHidden(n):null}),f.safeRestore(e)),a.isProtected&&(a.rafId=requestAnimationFrame(t))};a.rafId=requestAnimationFrame(t),console.log("[WxAuth] 弹窗保护已启用 (MutationObserver + rAF)")},disable(){a.observer&&(a.observer.disconnect(),a.observer=null),a.rafId!==null&&(cancelAnimationFrame(a.rafId),a.rafId=null),a.isProtected=!1,a.restorePending=!1,console.log("[WxAuth] 弹窗保护已禁用")},safeRestore(e){if(!a.restorePending){a.restorePending=!0;try{f.restoreFn(e)}finally{requestAnimationFrame(()=>{a.restorePending=!1})}}},isHidden(e){if(e.style.display==="none"||e.style.visibility==="hidden"||e.style.opacity==="0")return!0;try{const t=window.getComputedStyle(e);if(t.display==="none"||t.visibility==="hidden"||parseFloat(t.opacity)===0)return!0}catch{}return!1},restoreFn(e){const{modalId:t,getState:o,onRestore:n}=e;if(!o().isOpen)return;const r=document.getElementById(t);if(r){r.style.display="flex",r.style.visibility="visible",r.style.opacity="1";return}n()}},C={apiBase:"https://wx-auth.shenzjd.com",onVerified:null,onError:null,onClose:null,required:!1,wechatName:"神族九帝",qrcodeUrl:"",silent:!1};let s={...C},d="",b="",i={isOpen:!1,resolveAuth:null,currentStep:"qr",required:!!s.required,mpSession:null},p="mp",h=0;const I=10080*60*1e3;function E(e){try{if(e==="localhost"||/^\d+\.\d+\.\d+\.\d+$/.test(e))return"";const t=e.split(".");return t.length>=2?"."+t.slice(-2).join("."):""}catch{return""}}const u={getRootDomain(){return E(window.location.hostname)},getCookie(e){const o=`; ${document.cookie}`.split(`; ${e}=`);return o.length===2&&o.pop()?.split(";").shift()||null},writeCookieRaw(e,t,o,n,r=!1){const l=n?`;domain=${n}`:"",P=window.location.protocol==="https:"?";Secure":"",$=r?";expires=Thu, 01 Jan 1970 00:00:00 GMT":o!==void 0?`;expires=${new Date(Date.now()+o).toUTCString()}`:"";document.cookie=`${e}=${r?"":t};path=/${l}${$}${P};SameSite=Strict`},setCookie(e,t,o){const n=this.getRootDomain();this.writeCookieRaw(e,t,o,n),n&&!this.getCookie(e)&&this.writeCookieRaw(e,t,o,"")},deleteCookie(e){const t=this.getRootDomain();this.writeCookieRaw(e,"",void 0,t,!0),t&&this.writeCookieRaw(e,"",void 0,"",!0)},getToken(){return this.getCookie("wxauth-token")},setToken(e){this.setCookie("wxauth-token",e,I)},clearToken(){this.deleteCookie("wxauth-token"),this.deleteCookie("wxauth-openid");try{window.localStorage.removeItem("wxauth-token")}catch{}},getOrCreateDeviceId(){if(b)return b;let e=this.getCookie("wxauth-device");if(!e)try{e=window.localStorage.getItem("wxauth-device")}catch{}if(!e||!/^[A-Za-z0-9_-]{1,64}$/.test(e)){const t=new Uint8Array(16);if(typeof crypto<"u"&&crypto.getRandomValues)crypto.getRandomValues(t);else for(let o=0;o<16;o++)t[o]=Math.floor(Math.random()*256);e=Array.from(t).map(o=>o.toString(16).padStart(2,"0")).join("")}this.setCookie("wxauth-device",e,365*86400*1e3);try{window.localStorage.setItem("wxauth-device",e)}catch{}return b=e,e},async request(e,t={}){try{const o=await fetch(e,{method:t.method||"GET",headers:{"Content-Type":"application/json",...t.headers},body:t.body?JSON.stringify(t.body):null,credentials:"include"});if(!o.ok){const n=new Error(`HTTP ${o.status}`);throw n.status=o.status,n}return await o.json()}catch(o){const n=o;throw n.status===void 0&&(n.isNetworkError=!0),console.error("[WxAuth] Request error:",o),n}},generateCodeInputs(){let e='<div class="wx-auth-inputs">';for(let t=0;t<6;t++)e+=`<input type="text" inputmode="numeric" pattern="[0-9]*" maxlength="1" class="wx-auth-input" data-index="${t}" autocomplete="off" />`;return e+="</div>",e}},A=[1e3,3e3];function k(e){const t=e;return t?t.isNetworkError?!0:typeof t.status=="number"?t.status>=500||t.status===429:!1:!1}function y(e){return new Promise(t=>setTimeout(t,e))}const M=3e3,T=2e3,D=3e3;function v(){h++}async function q(e){if(await y(M),!(e!==h||!i.isOpen)){for(;e===h&&i.isOpen;){const t=i.mpSession;if(!t||Date.now()>=t.expiresAt)break;try{const o=await u.request(`${s.apiBase}/api/auth/mp-scan/status?ticket=${encodeURIComponent(t.ticket)}`);if(e!==h)return;if(o.status==="confirmed"&&o.token){x.completeLogin(o);return}if(o.status==="expired"){i.mpSession=null;break}}catch(o){if(e!==h)return;if(!k(o))break;await y(D);continue}await y(T)}e===h&&i.isOpen&&p==="mp"&&c.showMpExpired()}}async function S(e){const t=d?`&siteId=${encodeURIComponent(d)}`:"",o=`${s.apiBase}/api/auth/check?token=${encodeURIComponent(e)}${t}`;for(let n=0;;n++)try{const r=await u.request(o);return r.authenticated?{kind:"ok",result:r}:r.error==="rate_limited"||r.error==="server_error"?{kind:"transient"}:{kind:"invalid",result:r}}catch(r){if(!k(r)||n>=A.length)return{kind:"transient"};await y(A[n])}}const c={createModal(e){const t=document.createElement("div");t.id="wx-auth-modal",t.className="wx-auth-modal",t.classList.add(e?"wx-auth-required":"wx-auth-optional");const o="",n="",r=`<div class="wx-auth-panel wx-auth-panel-mp">
3
3
  <div class="wx-auth-qrcode-container wx-auth-mp-container">
4
4
  <div class="wx-auth-mp-loading"><span class="wx-auth-spinner"></span></div>
5
5
  <img class="wx-auth-mp-qrcode" src="" alt="小程序码" style="display:none" />
@@ -29,4 +29,4 @@
29
29
  <div class="wx-auth-message" style="display:none"></div>
30
30
  </div>
31
31
  </div>
32
- `,document.body.appendChild(t),this.syncModalShape(t,e),this.bindInputEvents(),t},syncModalShape(e,t){e.classList.remove("wx-auth-required","wx-auth-optional"),e.classList.add(t?"wx-auth-required":"wx-auth-optional");const o=e.querySelector(".wx-auth-overlay");o&&(o.onclick=t?y=>y.preventDefault():null);const n=e.querySelector(".wx-auth-close");if(t){n?.remove();return}if(n)return;const r=e.querySelector(".wx-auth-header");if(!r)return;const l=document.createElement("button");l.type="button",l.className="wx-auth-close",l.setAttribute("aria-label","关闭"),l.textContent="×",l.addEventListener("click",()=>x.close()),r.appendChild(l)},bindInputEvents(){setTimeout(()=>{const e=document.querySelectorAll(".wx-auth-input");e.length&&e.forEach((t,o)=>{t.addEventListener("input",n=>{const r=n.target.value.replace(/\D/g,"");n.target.value=r,r&&o<5&&e[o+1].focus(),o===5&&r&&setTimeout(()=>x.verifyCode(),300)}),t.addEventListener("keydown",n=>{const r=n.target;n.key==="Backspace"&&!r.value&&o>0?e[o-1].focus():n.key==="ArrowLeft"&&o>0?(n.preventDefault(),e[o-1].focus()):n.key==="ArrowRight"&&o<5&&(n.preventDefault(),e[o+1].focus())}),t.addEventListener("paste",n=>{n.preventDefault();const r=n.clipboardData?.getData("text").replace(/\D/g,"").slice(0,6);r&&(r.split("").forEach((l,y)=>{e[y]&&(e[y].value=l)}),r.length===6&&setTimeout(()=>x.verifyCode(),300))})})},100)},show(e){const t=e??!!s.required;i.required=t;let o=document.getElementById("wx-auth-modal");o?this.syncModalShape(o,t):o=this.createModal(t);const n=o.querySelector(".wx-auth-message");n&&(n.textContent="",n.className="wx-auth-message",n.style.display="none"),v(),i.mpSession=null,o.style.display="flex",i.isOpen=!0,f.enable({modalId:"wx-auth-modal",getState:()=>i,onRestore:()=>{this.createModal(i.required),s.qrcodeUrl&&this.setQrCode(s.qrcodeUrl);const r=document.querySelector(".wx-auth-wechat-name");r&&s.wechatName&&(r.textContent=`"${s.wechatName}"`),this.bindInputEvents(),p==="mp"&&x.switchMode("mp"),setTimeout(()=>{const l=document.querySelector(".wx-auth-input");l&&l.focus()},100)}})},hide(){const e=document.getElementById("wx-auth-modal");e&&(e.style.display="none",i.isOpen=!1,v(),i.mpSession=null,f.disable())},setQrCode(e){if(!e)return;const t=document.querySelector(".wx-auth-qrcode");t&&(t.src=e,t.style.display="block")},setMpQr(e){const t=document.getElementById("wx-auth-modal"),o=t?.querySelector(".wx-auth-mp-qrcode"),n=t?.querySelector(".wx-auth-mp-loading");o&&(o.src=e,o.style.display="block",n&&(n.style.display="none"),this.setMpExpiredVisible(!1),this.setMpStatus("",!1))},setMpExpiredVisible(e){const o=document.getElementById("wx-auth-modal")?.querySelector(".wx-auth-mp-expired");o&&(o.style.display=e?"flex":"none")},setMpStatus(e,t){const o=document.getElementById("wx-auth-modal"),n=o?.querySelector(".wx-auth-mp-status");n&&(n.textContent=e,n.style.display=e?"block":"none");const r=o?.querySelector(".wx-auth-mp-loading");if(r&&(r.style.display=t?"flex":"none"),t){const l=o?.querySelector(".wx-auth-mp-qrcode");l&&(l.style.display="none")}},showMpExpired(e="二维码已过期"){const o=document.getElementById("wx-auth-modal")?.querySelector(".wx-auth-mp-expired-text");o&&(o.textContent=e),this.setMpExpiredVisible(!0)},showMessage(e,t="info"){const o=document.querySelector(".wx-auth-message");o&&(o.textContent=e,o.className=`wx-auth-message wx-auth-message-${t}`,o.style.display="block",setTimeout(()=>{o.textContent===e&&(o.style.display="none")},3e3))},getVerifyCode(){const e=document.querySelectorAll(".wx-auth-input");return e.length?Array.from(e).map(t=>t.value).join(""):""},clearCodeInputs(){const e=document.querySelectorAll(".wx-auth-input");e.forEach(t=>t.value=""),e[0]&&e[0].focus()}},x={init(e={}){if(s={...C,...e},!s.apiBase&&typeof window<"u"&&(s.apiBase=window.location.origin),!s.apiBase){console.error("[WxAuth] apiBase is required");return}if(typeof window<"u"){const t=document.referrer;if(t)try{d=new URL(t).hostname}catch{}!d&&window.location.hostname&&(d=window.location.hostname),d||(d="default"),console.log("[WxAuth] 自动获取 siteId:",d);const o=u.getOrCreateDeviceId();console.log("[WxAuth] deviceId:",o)}console.log("[WxAuth] SDK initialized",s),typeof window<"u"&&(s.silent?this.silentCheck():this.autoCheck())},async silentCheck(){const e=u.getToken();if(!e)return!1;const t=await S(e);return t.kind==="ok"?(t.result.token&&u.setToken(t.result.token),this.onVerified(t.result.user),!0):(t.kind==="transient"&&console.warn("[WxAuth] silentCheck 服务暂时不可用,跳过(凭证保留)"),!1)},async autoCheck(){const e=u.getToken();if(!e)return this.showAuthModal(),!1;const t=await S(e);return t.kind==="ok"?(console.log("[WxAuth] 自动认证成功(凭证)"),t.result.token&&u.setToken(t.result.token),this.onVerified(t.result.user),!0):t.kind==="transient"?(console.warn("[WxAuth] 服务暂时不可用,跳过自动认证(凭证保留)"),this.onError({code:"server_error",retryable:!0,message:"登录服务暂时不可用,请稍后重试"}),!1):(this.showAuthModal(),!1)},async showAuthModal(e){c.show(e?.required),this.switchMode("mp")},switchMode(e){p=e;const t=document.getElementById("wx-auth-modal");if(!t)return;t.querySelectorAll(".wx-auth-tab").forEach(r=>{r.classList.toggle("wx-auth-tab-active",r.dataset.mode===p)});const o=t.querySelector(".wx-auth-panel-code"),n=t.querySelector(".wx-auth-panel-mp");o&&(o.style.display=p==="code"?"":"none"),n&&(n.style.display=p==="mp"?"":"none"),p==="mp"?this.startMpLogin():v()},async startMpLogin(){if(!i.isOpen)return;const e=++h;if(c.setMpExpiredVisible(!1),c.setMpStatus("",!0),i.mpSession&&Date.now()<i.mpSession.expiresAt){c.setMpQr(i.mpSession.qrDataUrl),q(e);return}try{const t=await u.request(`${s.apiBase}/api/auth/mp-scan/create`,{method:"POST",body:{siteId:d}});if(e!==h||!i.isOpen)return;if(!t.ticket||!t.qrDataUrl)throw new Error("create 响应缺少 ticket/qrDataUrl");i.mpSession={ticket:String(t.ticket),qrDataUrl:String(t.qrDataUrl),expiresAt:Date.now()+(Number(t.expiresIn)||300)*1e3},c.setMpQr(i.mpSession.qrDataUrl),q(e)}catch(t){if(e!==h||!i.isOpen)return;console.warn("[WxAuth] 小程序码生成失败",t),c.setMpStatus("",!1),c.showMpExpired("二维码生成失败,请点下方按钮重试"),c.showMessage("小程序扫码暂不可用,请稍后重试","error")}},async requireAuth(e){const t=u.getToken();if(t){const o=await S(t);if(o.kind==="ok")return console.log("[WxAuth] 已认证(凭证)"),o.result.token&&u.setToken(o.result.token),this.onVerified(o.result.user),!0;if(o.kind==="transient")return console.warn("[WxAuth] 认证状态检查暂时不可用(凭证保留)"),this.onError({code:"server_error",retryable:!0,message:"登录服务暂时不可用,请稍后重试"}),!1}return await this.showAuthModal(e),new Promise(o=>{i.resolveAuth=o})},completeLogin(e){if(e?.token&&u.setToken(e.token),p==="mp")c.setMpStatus("✅ 登录成功",!1);else{const t=document.querySelector(".wx-auth-btn-primary");t&&(t.textContent="✅ 已登录",t.style.background="#07C160")}setTimeout(()=>{this.onVerified(e?.user),this.close(!0)},500)},async verifyCode(){const e=c.getVerifyCode();if(!e||e.length!==6){c.showMessage("请输入6位验证码","error");return}const t=document.querySelector(".wx-auth-btn-primary");t&&(t.disabled=!0,t.textContent="登录中...");try{const o=d?`&siteId=${encodeURIComponent(d)}`:"",n=`&deviceId=${encodeURIComponent(u.getOrCreateDeviceId())}`,r=await u.request(`${s.apiBase}/api/auth/check?authToken=${e}${o}${n}`);r.authenticated?this.completeLogin(r):(c.showMessage(r.error==="rate_limited"?"尝试过于频繁,请稍后再试":"验证码错误或已过期","error"),c.clearCodeInputs(),t&&(t.disabled=!1,t.textContent="登录"))}catch(o){c.showMessage(k(o)?"服务暂时不可用,请稍后重试":"登录失败,请重试","error"),t&&(t.disabled=!1,t.textContent="登录")}},close(e=!1){c.hide(),i.resolveAuth&&(i.resolveAuth(!1),i.resolveAuth=null),!e&&typeof s.onClose=="function"&&s.onClose()},clearToken(){u.clearToken()},async revoke(){const e=u.getToken();if(e)try{const t=s.apiBase&&!/\/$/.test(s.apiBase)?s.apiBase:"https://wx-auth.shenzjd.com",o=await fetch(`${t}/api/auth/logout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:e,deviceId:u.getOrCreateDeviceId()}),credentials:"include"});o.ok||console.warn("[WxAuth] revoke 请求失败,降级本地清理",o.status)}catch(t){console.warn("[WxAuth] revoke 网络异常,降级本地清理",t)}return this.clearToken(),!0},onVerified(e){console.log("[WxAuth] 验证成功",e),typeof s.onVerified=="function"&&s.onVerified(e),i.resolveAuth&&(i.resolveAuth(!0),i.resolveAuth=null)},onError(e){console.error("[WxAuth] 错误",e),typeof s.onError=="function"&&s.onError(e)}};typeof window<"u"&&(window.WxAuth=Object.freeze(x)),w.WxAuth=x,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})}));
32
+ `,document.body.appendChild(t),this.syncModalShape(t,e),this.bindInputEvents(),t},syncModalShape(e,t){e.classList.remove("wx-auth-required","wx-auth-optional"),e.classList.add(t?"wx-auth-required":"wx-auth-optional");const o=e.querySelector(".wx-auth-overlay");o&&(o.onclick=t?g=>g.preventDefault():null);const n=e.querySelector(".wx-auth-close");if(t){n?.remove();return}if(n)return;const r=e.querySelector(".wx-auth-header");if(!r)return;const l=document.createElement("button");l.type="button",l.className="wx-auth-close",l.setAttribute("aria-label","关闭"),l.textContent="×",l.addEventListener("click",()=>x.close()),r.appendChild(l)},bindInputEvents(){setTimeout(()=>{const e=document.querySelectorAll(".wx-auth-input");e.length&&e.forEach((t,o)=>{t.addEventListener("input",n=>{const r=n.target.value.replace(/\D/g,"");n.target.value=r,r&&o<5&&e[o+1].focus(),o===5&&r&&setTimeout(()=>x.verifyCode(),300)}),t.addEventListener("keydown",n=>{const r=n.target;n.key==="Backspace"&&!r.value&&o>0?e[o-1].focus():n.key==="ArrowLeft"&&o>0?(n.preventDefault(),e[o-1].focus()):n.key==="ArrowRight"&&o<5&&(n.preventDefault(),e[o+1].focus())}),t.addEventListener("paste",n=>{n.preventDefault();const r=n.clipboardData?.getData("text").replace(/\D/g,"").slice(0,6);r&&(r.split("").forEach((l,g)=>{e[g]&&(e[g].value=l)}),r.length===6&&setTimeout(()=>x.verifyCode(),300))})})},100)},show(e){const t=e??!!s.required;i.required=t;let o=document.getElementById("wx-auth-modal");o?this.syncModalShape(o,t):o=this.createModal(t);const n=o.querySelector(".wx-auth-message");n&&(n.textContent="",n.className="wx-auth-message",n.style.display="none"),v(),i.mpSession=null,o.style.display="flex",i.isOpen=!0,f.enable({modalId:"wx-auth-modal",getState:()=>i,onRestore:()=>{this.createModal(i.required),s.qrcodeUrl&&this.setQrCode(s.qrcodeUrl);const r=document.querySelector(".wx-auth-wechat-name");r&&s.wechatName&&(r.textContent=`"${s.wechatName}"`),this.bindInputEvents(),p==="mp"&&x.switchMode("mp"),setTimeout(()=>{const l=document.querySelector(".wx-auth-input");l&&l.focus()},100)}})},hide(){const e=document.getElementById("wx-auth-modal");e&&(e.style.display="none",i.isOpen=!1,v(),i.mpSession=null,f.disable())},setQrCode(e){if(!e)return;const t=document.querySelector(".wx-auth-qrcode");t&&(t.src=e,t.style.display="block")},setMpQr(e){const t=document.getElementById("wx-auth-modal"),o=t?.querySelector(".wx-auth-mp-qrcode"),n=t?.querySelector(".wx-auth-mp-loading");o&&(o.src=e,o.style.display="block",n&&(n.style.display="none"),this.setMpExpiredVisible(!1),this.setMpStatus("",!1))},setMpExpiredVisible(e){const o=document.getElementById("wx-auth-modal")?.querySelector(".wx-auth-mp-expired");o&&(o.style.display=e?"flex":"none")},setMpStatus(e,t){const o=document.getElementById("wx-auth-modal"),n=o?.querySelector(".wx-auth-mp-status");n&&(n.textContent=e,n.style.display=e?"block":"none");const r=o?.querySelector(".wx-auth-mp-loading");if(r&&(r.style.display=t?"flex":"none"),t){const l=o?.querySelector(".wx-auth-mp-qrcode");l&&(l.style.display="none")}},showMpExpired(e="二维码已过期"){const o=document.getElementById("wx-auth-modal")?.querySelector(".wx-auth-mp-expired-text");o&&(o.textContent=e),this.setMpExpiredVisible(!0)},showMessage(e,t="info"){const o=document.querySelector(".wx-auth-message");o&&(o.textContent=e,o.className=`wx-auth-message wx-auth-message-${t}`,o.style.display="block",setTimeout(()=>{o.textContent===e&&(o.style.display="none")},3e3))},getVerifyCode(){const e=document.querySelectorAll(".wx-auth-input");return e.length?Array.from(e).map(t=>t.value).join(""):""},clearCodeInputs(){const e=document.querySelectorAll(".wx-auth-input");e.forEach(t=>t.value=""),e[0]&&e[0].focus()}},x={init(e={}){if(s={...C,...e},!s.apiBase&&typeof window<"u"&&(s.apiBase=window.location.origin),!s.apiBase){console.error("[WxAuth] apiBase is required");return}if(typeof window<"u"){const t=document.referrer;if(t)try{d=new URL(t).hostname}catch{}!d&&window.location.hostname&&(d=window.location.hostname),d||(d="default"),console.log("[WxAuth] 自动获取 siteId:",d);const o=u.getOrCreateDeviceId();console.log("[WxAuth] deviceId:",o)}console.log("[WxAuth] SDK initialized",s),typeof window<"u"&&(s.silent?this.silentCheck():this.autoCheck())},async silentCheck(){const e=u.getToken();if(!e)return!1;const t=await S(e);return t.kind==="ok"?(t.result.token&&u.setToken(t.result.token),this.onVerified(t.result.user),!0):(t.kind==="transient"&&console.warn("[WxAuth] silentCheck 服务暂时不可用,跳过(凭证保留)"),!1)},async autoCheck(){const e=u.getToken();if(!e)return this.showAuthModal(),!1;const t=await S(e);return t.kind==="ok"?(console.log("[WxAuth] 自动认证成功(凭证)"),t.result.token&&u.setToken(t.result.token),this.onVerified(t.result.user),!0):t.kind==="transient"?(console.warn("[WxAuth] 服务暂时不可用,跳过自动认证(凭证保留)"),this.onError({code:"server_error",retryable:!0,message:"登录服务暂时不可用,请稍后重试"}),!1):(this.showAuthModal(),!1)},async showAuthModal(e){c.show(e?.required),this.switchMode("mp")},switchMode(e){p=e;const t=document.getElementById("wx-auth-modal");if(!t)return;t.querySelectorAll(".wx-auth-tab").forEach(r=>{r.classList.toggle("wx-auth-tab-active",r.dataset.mode===p)});const o=t.querySelector(".wx-auth-panel-code"),n=t.querySelector(".wx-auth-panel-mp");o&&(o.style.display=p==="code"?"":"none"),n&&(n.style.display=p==="mp"?"":"none"),p==="mp"?this.startMpLogin():v()},async startMpLogin(){if(!i.isOpen)return;const e=++h;if(c.setMpExpiredVisible(!1),c.setMpStatus("",!0),i.mpSession&&Date.now()<i.mpSession.expiresAt){c.setMpQr(i.mpSession.qrDataUrl),q(e);return}try{const t=await u.request(`${s.apiBase}/api/auth/mp-scan/create`,{method:"POST",body:{siteId:d}});if(e!==h||!i.isOpen)return;if(!t.ticket||!t.qrDataUrl)throw new Error("create 响应缺少 ticket/qrDataUrl");i.mpSession={ticket:String(t.ticket),qrDataUrl:String(t.qrDataUrl),expiresAt:Date.now()+(Number(t.expiresIn)||300)*1e3},c.setMpQr(i.mpSession.qrDataUrl),q(e)}catch(t){if(e!==h||!i.isOpen)return;console.warn("[WxAuth] 小程序码生成失败",t),c.setMpStatus("",!1),c.showMpExpired("二维码生成失败,请点下方按钮重试"),c.showMessage("小程序扫码暂不可用,请稍后重试","error")}},async requireAuth(e){const t=u.getToken();if(t){const o=await S(t);if(o.kind==="ok")return console.log("[WxAuth] 已认证(凭证)"),o.result.token&&u.setToken(o.result.token),this.onVerified(o.result.user),!0;if(o.kind==="transient")return console.warn("[WxAuth] 认证状态检查暂时不可用(凭证保留)"),this.onError({code:"server_error",retryable:!0,message:"登录服务暂时不可用,请稍后重试"}),!1}return await this.showAuthModal(e),new Promise(o=>{i.resolveAuth=o})},completeLogin(e){if(e?.token&&u.setToken(e.token),p==="mp")c.setMpStatus("✅ 登录成功",!1);else{const t=document.querySelector(".wx-auth-btn-primary");t&&(t.textContent="✅ 已登录",t.style.background="#07C160")}setTimeout(()=>{this.onVerified(e?.user),this.close(!0)},500)},async verifyCode(){const e=c.getVerifyCode();if(!e||e.length!==6){c.showMessage("请输入6位验证码","error");return}const t=document.querySelector(".wx-auth-btn-primary");t&&(t.disabled=!0,t.textContent="登录中...");try{const o=d?`&siteId=${encodeURIComponent(d)}`:"",n=`&deviceId=${encodeURIComponent(u.getOrCreateDeviceId())}`,r=await u.request(`${s.apiBase}/api/auth/check?authToken=${e}${o}${n}`);r.authenticated?this.completeLogin(r):(c.showMessage(r.error==="rate_limited"?"尝试过于频繁,请稍后再试":"验证码错误或已过期","error"),c.clearCodeInputs(),t&&(t.disabled=!1,t.textContent="登录"))}catch(o){c.showMessage(k(o)?"服务暂时不可用,请稍后重试":"登录失败,请重试","error"),t&&(t.disabled=!1,t.textContent="登录")}},close(e=!1){c.hide(),i.resolveAuth&&(i.resolveAuth(!1),i.resolveAuth=null),!e&&typeof s.onClose=="function"&&s.onClose()},clearToken(){u.clearToken()},async revoke(){const e=u.getToken();if(e)try{const t=s.apiBase&&!/\/$/.test(s.apiBase)?s.apiBase:"https://wx-auth.shenzjd.com",o=await fetch(`${t}/api/auth/logout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:e,deviceId:u.getOrCreateDeviceId()}),credentials:"include"});o.ok||console.warn("[WxAuth] revoke 请求失败,降级本地清理",o.status)}catch(t){console.warn("[WxAuth] revoke 网络异常,降级本地清理",t)}return this.clearToken(),!0},onVerified(e){console.log("[WxAuth] 验证成功",e),typeof s.onVerified=="function"&&s.onVerified(e),i.resolveAuth&&(i.resolveAuth(!0),i.resolveAuth=null)},onError(e){console.error("[WxAuth] 错误",e),typeof s.onError=="function"&&s.onError(e)}};typeof window<"u"&&(window.WxAuth=Object.freeze(x)),w.WxAuth=x,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wx-auth-sdk",
3
- "version": "1.2.41",
3
+ "version": "1.2.43",
4
4
  "description": "微信登录 SDK - 小程序扫码 / 公众号验证码双方式,零依赖",
5
5
  "type": "module",
6
6
  "main": "./dist/wx-auth.umd.js",