UNPKG

@scu-xiaochuan/scu-pecourse-utils

Version:

69 lines 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.apiService = exports.ApiService = void 0; const utils_1 = require("../utils"); class ApiService { url = 'http://211.83.159.5:8086'; headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0 WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36', Origin: 'http://211.83.159.5:81', Referer: 'http://211.83.159.5:81/', }; constructor(token) { if (token) { this.initAuth(token); } } initAuth(token) { this.headers.Authorization = `bearer ${token}`; } async get({ path, params }) { const url = `${this.url}${path}`; const timestamp = (0, utils_1.getTimestamp)(); const query = { app_key: utils_1.app_key, timestamp, sign: (0, utils_1.getSign)({ path, appsecret: utils_1.app_secret, timestamp, }), ...params, }; const qs = new URLSearchParams(query).toString(); const req = await fetch(`${url}?${qs}`, { method: 'GET', headers: { ...this.headers, }, }); return req.json(); } async post({ path, data }) { const url = `${this.url}${path}`; const timestamp = (0, utils_1.getTimestamp)(); const query = { app_key: utils_1.app_key, timestamp, sign: (0, utils_1.getSign)({ path, appsecret: utils_1.app_secret, timestamp, data, }), ...data, }; const req = await fetch(`${url}`, { headers: { ...this.headers, 'Content-Type': 'application/x-www-form-urlencoded', }, method: 'POST', body: new URLSearchParams(query).toString(), }); return req.json(); } } exports.ApiService = ApiService; exports.apiService = new ApiService(); //# sourceMappingURL=apiService.js.map