| 89 | } |
| 90 | |
| 91 | async api({ method = "GET", path, data, allowFail = false }) { |
| 92 | const opts = { |
| 93 | method, |
| 94 | url: `${this.base}${path}`, |
| 95 | headers: { |
| 96 | Authorization: this.token, |
| 97 | locale: "zh_CN", |
| 98 | "content-type": "application/json", |
| 99 | }, |
| 100 | }; |
| 101 | if (method === "GET") opts.params = data || {}; |
| 102 | else opts.data = data === undefined ? {} : data; |
| 103 | const res = await request(opts); |
| 104 | const ok = res.status === 200 && ["00000", "000000", "A00002"].includes(String(res.data?.code)); |
| 105 | if (!ok && !allowFail) throw new Error(`HTTP ${res.status}: ${short(res.data)}`); |
| 106 | return res.data; |
| 107 | } |
| 108 | |
| 109 | async login() { |
| 110 | const code = await getWxCode(APP.appid, this.openid); |