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

Method login

wxapp/mimengshenghuo.js:168–192  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

166 }
167
168 async login() {
169 const cached = this.getCachedToken();
170 if (cached) {
171 this.token = cached;
172 $.log(`账号[${this.index}] 使用缓存token: ${maskToken(this.token)}`);
173 const ok = await this.checkToken();
174 if (ok) return;
175 $.log(`账号[${this.index}] 缓存token失效,重新登录`);
176 this.removeCachedToken();
177 }
178
179 const code = await getWxCode(this.openid);
180 const res = await this.gql(
181 `mutation codeLogin($client_id: String! $code: String!) {
182 login(client_id: $client_id, code: $code)
183 }`,
184 { client_id: APP.appid, code },
185 "",
186 true
187 );
188 const token = res?.data?.login || "";
189 if (!token) throw new Error(`登录未返回token: ${short(res)}`);
190 this.token = token;
191 $.log(`账号[${this.index}] 登录成功: ${maskToken(this.token)}`);
192 }
193
194 async checkToken() {
195 const res = await this.gql(

Callers 1

runMethod · 0.95

Calls 8

getCachedTokenMethod · 0.95
checkTokenMethod · 0.95
removeCachedTokenMethod · 0.95
gqlMethod · 0.95
maskTokenFunction · 0.70
getWxCodeFunction · 0.70
shortFunction · 0.70
logMethod · 0.45

Tested by

no test coverage detected