(method, urlPath, { token = "", params = null } = {})
| 94 | } |
| 95 | |
| 96 | async function apiRequest(method, urlPath, { token = "", params = null } = {}) { |
| 97 | const timestamp = String(Date.now()); |
| 98 | const sign = makeSign(urlPath, method, params, timestamp, token); |
| 99 | const res = await axios({ |
| 100 | method, |
| 101 | url: `${API_BASE}${urlPath}`, |
| 102 | data: method === "POST" ? params : undefined, |
| 103 | params: method === "GET" ? params : undefined, |
| 104 | timeout: 15000, |
| 105 | validateStatus: () => true, |
| 106 | headers: { |
| 107 | token, |
| 108 | sign, |
| 109 | timestamp, |
| 110 | "Content-Type": "application/json", |
| 111 | "User-Agent": "Mozilla/5.0 MicroMessenger MiniProgramEnv/Windows", |
| 112 | Referer: `https://servicewechat.com/${MINI_APP_ID}/127/page-frame.html`, |
| 113 | }, |
| 114 | }); |
| 115 | return res.data; |
| 116 | } |
| 117 | |
| 118 | function assertOk(res, action) { |
| 119 | if (!res || Number(res.code) !== 1) { |
no test coverage detected