| 206 | } |
| 207 | |
| 208 | async loginByCode() { |
| 209 | const code = await this.getWxCode(); |
| 210 | const session = await request("post", "/client/web/wechatSession", { |
| 211 | params: { code }, |
| 212 | data: {}, |
| 213 | }); |
| 214 | if (session.status !== 200 || !ok(session.data)) { |
| 215 | throw new Error(`wechatSession失败[${session.status}]: ${session.text.slice(0, 500)}`); |
| 216 | } |
| 217 | const data = session.data.data || {}; |
| 218 | this.wxInfo = data.wxInfo || {}; |
| 219 | this.userInfo = data.userInfo || {}; |
| 220 | if (this.wxInfo.openid && !this.openid) this.openid = this.wxInfo.openid; |
| 221 | const token = this.userInfo.token || data.token || ""; |
| 222 | if (!token) return false; |
| 223 | this.token = token; |
| 224 | this.saveCache({ loginType: "wechatSession" }); |
| 225 | $.log(`账号[${this.index}] code登录成功: ${mask(this.userInfo.userId || this.token)}`); |
| 226 | return true; |
| 227 | } |
| 228 | |
| 229 | async loginByOperateData() { |
| 230 | const op = await this.getOperateData(); |