MCPcopy Create free account
hub / github.com/smallfawn/QLScriptPublic / login

Method login

wxapp/wps.js:319–340  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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();

Callers 3

ensureLoginMethod · 0.95
requestMethod · 0.95
smtpFunction · 0.45

Calls 10

saveCacheMethod · 0.95
wxServerCodeFunction · 0.85
genEcKeyPairFunction · 0.85
base64urlFunction · 0.85
signEcFunction · 0.85
accountRequestFunction · 0.85
deriveSecretFunction · 0.85
assertOkFunction · 0.70
maskFunction · 0.70
logMethod · 0.45

Tested by

no test coverage detected