()
| 196 | } |
| 197 | |
| 198 | async loginByWxCode() { |
| 199 | try { |
| 200 | const wxData = await this.getOperateData(); |
| 201 | const user = wxData.userInfo || {}; |
| 202 | const payload = { |
| 203 | avatarUrl: user.avatarUrl || "", |
| 204 | city: user.city || "", |
| 205 | country: user.country || "", |
| 206 | gender: user.gender || 0, |
| 207 | nickName: user.nickName || user.nickname || "微信用户", |
| 208 | province: user.province || "", |
| 209 | code: wxData.code, |
| 210 | source: 2, |
| 211 | }; |
| 212 | const result = await this.request("/user/wxLogin", { |
| 213 | method: "POST", |
| 214 | data: payload, |
| 215 | auth: false, |
| 216 | }); |
| 217 | const data = result?.data || {}; |
| 218 | if (!data.authorization) throw new Error(`登录响应未返回authorization: ${JSON.stringify(result)}`); |
| 219 | this.token = data.authorization; |
| 220 | this.sessionKey = data.sessionKey || ""; |
| 221 | this.userId = data.userId || ""; |
| 222 | this.saveCachedToken(); |
| 223 | $.log(`账号[${this.index}] CODE登录成功: ${shortToken(this.token)}`); |
| 224 | } catch (e) { |
| 225 | $.log(`账号[${this.index}] CODE登录失败: ${e.message || e}`); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | async checkToken() { |
| 230 | try { |
no test coverage detected