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

Method loginByWxCode

wxapp/nissin.js:172–204  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

170 }
171
172 async loginByWxCode() {
173 try {
174 const code = await this.getLoginCode();
175 const openData = await this.request({
176 method: "POST",
177 apiPath: "/auth/getOpenId",
178 skipToken: true,
179 data: {
180 code,
181 invitorMemberId: 0,
182 },
183 });
184 this.redOpenId = openData.openId || "";
185 if (!this.redOpenId) throw new Error(`auth/getOpenId 未返回 openId: ${JSON.stringify(openData)}`);
186
187 const loginData = await this.request({
188 method: "POST",
189 apiPath: "/auth/login",
190 skipToken: true,
191 data: {
192 openId: this.redOpenId,
193 },
194 });
195 this.applyToken({
196 ...loginData,
197 redOpenId: this.redOpenId,
198 });
199 this.saveCachedToken();
200 $.log(`账号[${this.index}] 登录成功: userId=${this.userId || "未知"}`);
201 } catch (e) {
202 $.log(`账号[${this.index}] 登录失败: ${e.message || e}`);
203 }
204 }
205
206 async checkToken() {
207 try {

Callers 1

runMethod · 0.95

Calls 5

getLoginCodeMethod · 0.95
requestMethod · 0.95
applyTokenMethod · 0.95
saveCachedTokenMethod · 0.95
logMethod · 0.45

Tested by

no test coverage detected