MCPcopy Create free account
hub / github.com/smallfawn/QLScriptPublic / request

Method request

wxapp/dasenlin.js:154–179  ·  view source on GitHub ↗
({ base = SIGN_BASE, method = "GET", apiPath, params = {}, data = {}, raw = false, stringifyPost = false, urlToken = false })

Source from the content-addressed store, hash-verified

152 }
153
154 async request({ base = SIGN_BASE, method = "GET", apiPath, params = {}, data = {}, raw = false, stringifyPost = false, urlToken = false }) {
155 const upperMethod = method.toUpperCase();
156 const token = this.token;
157 const options = {
158 method: upperMethod,
159 url: `${base}${apiPath.startsWith("/") ? apiPath : `/${apiPath}`}`,
160 headers: this.getHeaders(),
161 timeout: 20000,
162 validateStatus: () => true,
163 };
164
165 if (token && urlToken) {
166 if (options.url.includes("?")) options.url += `&mini_token=${encodeURIComponent(token)}`;
167 else options.url += `?mini_token=${encodeURIComponent(token)}`;
168 }
169
170 const payload = token ? { ...data, mini_token: token, type: data.type ?? 1 } : { ...data };
171 if (upperMethod === "GET") options.params = token ? { ...params, mini_token: token, type: params.type ?? 1 } : params;
172 else options.data = stringifyPost ? JSON.stringify(payload) : payload;
173
174 const { data: result, status } = await axios.request(options);
175 if (status !== 200) throw new Error(`HTTP ${status}: ${JSON.stringify(result)}`);
176 if (raw) return result;
177 if (!isSuccess(result)) throw new Error(getMessage(result));
178 return result.data ?? result.datas ?? result;
179 }
180
181 async getLoginCode() {
182 const { data } = await wechat.getCode(this.account);

Callers 3

getSignInfoMethod · 0.95
signInMethod · 0.95
loginByWxCodeMethod · 0.45

Calls 3

getHeadersMethod · 0.95
getMessageFunction · 0.85
isSuccessFunction · 0.70

Tested by

no test coverage detected