()
| 243 | } |
| 244 | |
| 245 | async loginByWxCode() { |
| 246 | try { |
| 247 | const wxData = await this.getOperateData(); |
| 248 | const articleIds = await this.getArticleIds(); |
| 249 | const params = { |
| 250 | edata: wxData.encryptedData, |
| 251 | iv: wxData.iv, |
| 252 | code: wxData.code, |
| 253 | uuid: this.uuid, |
| 254 | article_ids: articleIds, |
| 255 | app_versions: "1.0.0", |
| 256 | }; |
| 257 | const result = await this.request("/wechat/mini/phoneNew/login", { |
| 258 | method: "POST", |
| 259 | params, |
| 260 | auth: false, |
| 261 | }); |
| 262 | const token = result?.access_token || result?.accessToken || ""; |
| 263 | if (!result?.success || !token) throw new Error(`登录响应未返回token: ${JSON.stringify(result)}`); |
| 264 | this.token = token; |
| 265 | this.refreshToken = result.refresh_token || result.refreshToken || ""; |
| 266 | await this.loginCommunityToken().catch(() => {}); |
| 267 | this.saveCachedToken(); |
| 268 | $.log(`账号[${this.index}] CODE登录成功: ${shortToken(this.token)}`); |
| 269 | } catch (e) { |
| 270 | $.log(`账号[${this.index}] CODE登录失败: ${e.message || e}`); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | async loginCommunityToken() { |
| 275 | if (!this.token) return; |
no test coverage detected