(apiPath, data = {})
| 208 | } |
| 209 | |
| 210 | async mobilePost(apiPath, data = {}) { |
| 211 | if (!this.session.sessionId) throw new Error("缺少SESSION"); |
| 212 | const res = await axios.post(`${MOBILE_BASE}${apiPath}`, formBody({ |
| 213 | ...(data || {}), |
| 214 | userId: USER_ID, |
| 215 | }), { |
| 216 | headers: this.commonHeaders({ |
| 217 | Cookie: `SESSION=${this.session.sessionId}`, |
| 218 | Authorization: this.session.token || "", |
| 219 | }), |
| 220 | timeout: 20000, |
| 221 | validateStatus: () => true, |
| 222 | }); |
| 223 | |
| 224 | const newSession = getSessionId(res.headers); |
| 225 | if (newSession) this.session.sessionId = newSession; |
| 226 | |
| 227 | if (res.status !== 200) throw new Error(`HTTP ${res.status}`); |
| 228 | if (String(res.data?.status) === "-2") throw new Error("登录态失效(-2)"); |
| 229 | if (String(res.data?.status) !== "0") { |
| 230 | throw new Error(res.data?.msg || `接口异常: ${res.data?.status || "unknown"}`); |
| 231 | } |
| 232 | return res.data; |
| 233 | } |
| 234 | |
| 235 | async checkSession() { |
| 236 | try { |
no test coverage detected