(account)
| 150 | } |
| 151 | |
| 152 | async function loginByCode(account) { |
| 153 | $.log("🔐 正在获取code并登录..."); |
| 154 | const code = await getWxCode(account); |
| 155 | const res = await request("post", `${WXCLIENT_URL}/user/members:login`, "", { |
| 156 | data: { code }, |
| 157 | account, |
| 158 | }); |
| 159 | |
| 160 | const token = getResponseToken(res.headers); |
| 161 | if (res.status !== 200 || res.data?.code !== 200 || !token) { |
| 162 | throw new Error(`登录失败: HTTP ${res.status} ${JSON.stringify(res.data)}`); |
| 163 | } |
| 164 | |
| 165 | updateCachedToken(account, token); |
| 166 | $.log(`✅ 登录成功,已缓存token: ${maskToken(token)}`); |
| 167 | return token; |
| 168 | } |
| 169 | |
| 170 | async function validateToken(account, token) { |
| 171 | const res = await request("get", `${WXCLIENT_URL}/member/IndexInfo`, token, { |
no test coverage detected