()
| 227 | } |
| 228 | |
| 229 | async loginByOperateData() { |
| 230 | const op = await this.getOperateData(); |
| 231 | const session = await request("post", "/client/web/wechatSession", { |
| 232 | params: { code: op.code }, |
| 233 | data: {}, |
| 234 | }); |
| 235 | if (session.status === 200 && ok(session.data)) { |
| 236 | const data = session.data.data || {}; |
| 237 | this.wxInfo = data.wxInfo || {}; |
| 238 | this.userInfo = data.userInfo || {}; |
| 239 | } |
| 240 | const wxInfo = this.wxInfo || {}; |
| 241 | const login = await request("post", "/client/web/wechatLogin", { |
| 242 | data: { |
| 243 | openId: wxInfo.openid || wxInfo.openId || this.openid, |
| 244 | unionId: wxInfo.unionid || wxInfo.unionId || "", |
| 245 | sessionKey: wxInfo.sessionKey || wxInfo.session_key || "", |
| 246 | encryptedData: op.encryptedData, |
| 247 | iv: op.iv, |
| 248 | pcSn: "", |
| 249 | sourceType: 0, |
| 250 | shareId: null, |
| 251 | userUuid: null, |
| 252 | registerType: 1, |
| 253 | }, |
| 254 | }); |
| 255 | if (login.status !== 200 || !ok(login.data)) { |
| 256 | throw new Error(`wechatLogin失败[${login.status}]: ${login.text.slice(0, 800)}`); |
| 257 | } |
| 258 | this.userInfo = login.data.data || {}; |
| 259 | this.token = this.userInfo.token || ""; |
| 260 | if (!this.token) throw new Error(`wechatLogin未返回token: ${login.text.slice(0, 500)}`); |
| 261 | this.saveCache({ loginType: "wechatLogin" }); |
| 262 | $.log(`账号[${this.index}] 授权登录成功: ${mask(this.userInfo.userId || this.token)}`); |
| 263 | } |
| 264 | |
| 265 | async ensureLogin() { |
| 266 | const cached = this.getCached(); |
no test coverage detected