MCPcopy Index your code
hub / github.com/smallfawn/QLScriptPublic / request

Method request

wxapp/tmj.js:196–220  ·  view source on GitHub ↗
(apiPath, data = {}, method = "GET")

Source from the content-addressed store, hash-verified

194 }
195
196 async request(apiPath, data = {}, method = "GET") {
197 const payload = data || {};
198 const ts = Date.now();
199 const signData = method === "POST"
200 ? { body: JSON.stringify(payload), secretKey: SECRET_KEY, ts }
201 : { ...payload, secretKey: SECRET_KEY, ts };
202 const options = {
203 method,
204 url: `${API_BASE}${apiPath}`,
205 headers: this.getHeaders(signPayload(signData), ts),
206 timeout: 20000,
207 validateStatus: () => true,
208 };
209 if (method === "GET") options.params = payload;
210 else options.data = payload;
211
212 const { status, data: result } = await axios.request(options);
213 if (status !== 200) throw new Error(`HTTP ${status}: ${JSON.stringify(result)}`);
214 if (!result || result.success !== true) {
215 const err = new Error(result?.msg || result?.message || JSON.stringify(result));
216 err.code = result?.code;
217 throw err;
218 }
219 return result.result;
220 }
221
222 async getLoginCode() {
223 const { data } = await wechat.getCode(this.openid);

Callers 6

loginByWxCodeMethod · 0.95
ensureIntegralAccountMethod · 0.95
findSignActivityMethod · 0.95
loadSignInfoMethod · 0.95
queryMonthSignMethod · 0.95
doSignMethod · 0.95

Calls 2

getHeadersMethod · 0.95
signPayloadFunction · 0.85

Tested by

no test coverage detected