(pathname, { method = "GET", data, params, auth = true, headers = {} } = {})
| 155 | } |
| 156 | |
| 157 | async request(pathname, { method = "GET", data, params, auth = true, headers = {} } = {}) { |
| 158 | const options = { |
| 159 | method, |
| 160 | url: `${API_BASE}${pathname}`, |
| 161 | params, |
| 162 | data, |
| 163 | headers: auth ? this.headers(headers) : { |
| 164 | "content-Type": "application/json", |
| 165 | "User-Agent": defaultUserAgent, |
| 166 | Referer: `https://servicewechat.com/${MINI_APP_ID}/${PAGE_VERSION}/page-frame.html`, |
| 167 | ...headers, |
| 168 | }, |
| 169 | timeout: 20000, |
| 170 | validateStatus: () => true, |
| 171 | }; |
| 172 | const { data: result, status } = await axios.request(options); |
| 173 | if (status !== 200) throw new Error(`HTTP ${status}: ${JSON.stringify(result)}`); |
| 174 | if (Number(result?.code) !== 0) throw new Error(`${result?.code ?? ""} ${result?.message || JSON.stringify(result)}`.trim()); |
| 175 | return result; |
| 176 | } |
| 177 | |
| 178 | async getOperateData() { |
| 179 | if (!process.env.wx_auth) throw new Error("缺少 wx_auth,无法从 wx_server 获取登录数据"); |
no test coverage detected