()
| 317 | } |
| 318 | |
| 319 | async login() { |
| 320 | if (!this.openid) throw new Error("缺少 openid,无法自动登录。可设置 wps=openid 或 wps=openid#Cookie"); |
| 321 | const authCode = await wxServerCode(this.openid, ACCOUNT_PLUGIN_APPID); |
| 322 | const keyPair = genEcKeyPair(); |
| 323 | const body = { |
| 324 | type: "wxapp", |
| 325 | appid: ACCOUNT_PLUGIN_APPID, |
| 326 | auth_code: authCode, |
| 327 | public_key: base64url(JSON.stringify(keyPair.publicKey.export({ format: "jwk" }))), |
| 328 | auth_code_sign: signEc(keyPair.privateKey, authCode), |
| 329 | slv: "none", |
| 330 | }; |
| 331 | const res = await accountRequest("POST", "/passport/secure/api/easy_login", { data: body }); |
| 332 | const data = assertOk(res.data, "WPS自动登录"); |
| 333 | if (data.further_action) throw new Error(`WPS登录需要额外操作: ${data.further_action}`); |
| 334 | if (!data.jwk) throw new Error(`WPS登录未返回 jwk: ${JSON.stringify(res.data)}`); |
| 335 | this.cookies = res.cookies; |
| 336 | this.secret = deriveSecret(keyPair.privateKey, data.jwk); |
| 337 | this.uid = data.user_id || this.cookies.uid || ""; |
| 338 | this.saveCache(); |
| 339 | $.log(`账号[${this.index}] WPS登录成功: ${mask(this.uid || this.cookies.wps_sid)}`); |
| 340 | } |
| 341 | |
| 342 | async ensureLogin() { |
| 343 | this.loadCache(); |
no test coverage detected