| 190 | } |
| 191 | |
| 192 | async loginByWxCode() { |
| 193 | try { |
| 194 | const code = await this.getWxCode(); |
| 195 | const { status, data } = await axios.post( |
| 196 | `${UIC_BASE}/passport/general/auth.json`, |
| 197 | { |
| 198 | appId: MINI_APP_ID, |
| 199 | code, |
| 200 | platformName: "weapp", |
| 201 | signature: "Windows", |
| 202 | }, |
| 203 | { |
| 204 | headers: { |
| 205 | "Content-Type": "application/json", |
| 206 | "User-Agent": USER_AGENT, |
| 207 | "Referer": `https://servicewechat.com/${MINI_APP_ID}/54/page-frame.html`, |
| 208 | "X-Requested-With": "XMLHttpRequest", |
| 209 | }, |
| 210 | timeout: 15000, |
| 211 | validateStatus: () => true, |
| 212 | } |
| 213 | ); |
| 214 | if (status !== 200 || data?.code !== 0 || !data?.data?.sessionId) { |
| 215 | throw new Error(`UIC登录失败: HTTP ${status} ${typeof data === "string" ? data.slice(0, 200) : JSON.stringify(data)}`); |
| 216 | } |
| 217 | this.token = data.data || {}; |
| 218 | this.saveCachedToken(); |
| 219 | $.log(`账号[${this.index}] 登录成功: ${data.data?.nickName || data.data?.nickname || ""} ${maskPhone(data.data?.mobile)}`); |
| 220 | } catch (e) { |
| 221 | $.log(`账号[${this.index}] 登录失败: ${e.message || e}`); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | async checkToken() { |
| 226 | try { |