diff --git a/lib/routes/bilibili/cache.js b/lib/routes/bilibili/cache.js index 51dd0485d5..d2fe80200a 100644 --- a/lib/routes/bilibili/cache.js +++ b/lib/routes/bilibili/cache.js @@ -1,5 +1,4 @@ const got = require('@/utils/got'); -const qs = require('querystring'); const iconv = require('iconv-lite'); const cheerio = require('cheerio'); @@ -13,11 +12,11 @@ module.exports = { url: 'https://space.bilibili.com/ajax/member/GetInfo', headers: { Referer: `https://space.bilibili.com/${uid}/`, - 'Content-Type': 'application/x-www-form-urlencoded', }, - data: qs.stringify({ + form: true, + data: { mid: uid, - }), + }, }); name = nameResponse.data.data.name; ctx.cache.set(key, name); diff --git a/lib/routes/earthquake/index.js b/lib/routes/earthquake/index.js index 4b58af840c..5c5a6ce992 100644 --- a/lib/routes/earthquake/index.js +++ b/lib/routes/earthquake/index.js @@ -1,5 +1,4 @@ const got = require('@/utils/got'); -const qs = require('querystring'); module.exports = async (ctx) => { const region = ctx.params.region || 1; @@ -8,14 +7,12 @@ module.exports = async (ctx) => { const response = await got({ method: 'post', url: api, - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - }, - data: qs.stringify({ + form: true, + data: { region: region, dateType: 2, magnitude: 0, - }), + }, }); const data = response.data; diff --git a/lib/routes/geektime/column.js b/lib/routes/geektime/column.js index 3edd055160..d81961dbbc 100644 --- a/lib/routes/geektime/column.js +++ b/lib/routes/geektime/column.js @@ -9,8 +9,8 @@ module.exports = async (ctx) => { url: 'https://time.geekbang.org/serv/v1/column/intro', headers: { Referer: 'https://time.geekbang.org/', - 'Content-Type': 'application/json', }, + json: true, data: { cid: column_id, }, @@ -24,8 +24,8 @@ module.exports = async (ctx) => { url: 'https://time.geekbang.org/serv/v1/column/articles/latest', headers: { Referer: 'https://time.geekbang.org/', - 'Content-Type': 'application/json', }, + json: true, data: { cid: column_id, }, diff --git a/lib/routes/geektime/news.js b/lib/routes/geektime/news.js index 3278c6697d..62cb9c7a53 100644 --- a/lib/routes/geektime/news.js +++ b/lib/routes/geektime/news.js @@ -9,8 +9,8 @@ module.exports = async (ctx) => { url: 'https://time.geekbang.org/serv/v1/column/intro', headers: { Referer: 'https://time.geekbang.org/', - 'Content-Type': 'application/json', }, + json: true, data: { cid: column_id, }, @@ -24,8 +24,8 @@ module.exports = async (ctx) => { url: 'https://time.geekbang.org/serv/v1/column/audios', headers: { Referer: 'https://time.geekbang.org/', - 'Content-Type': 'application/json', }, + json: true, data: { cid: column_id, }, diff --git a/lib/routes/github/follower.js b/lib/routes/github/follower.js index 16ce23e6f5..7dc389cefd 100644 --- a/lib/routes/github/follower.js +++ b/lib/routes/github/follower.js @@ -13,6 +13,7 @@ module.exports = async (ctx) => { headers: { Authorization: `bearer ${config.github.access_token}`, }, + json: true, data: { query: ` { diff --git a/lib/routes/github/star.js b/lib/routes/github/star.js index c5a9919164..5f80848cfd 100644 --- a/lib/routes/github/star.js +++ b/lib/routes/github/star.js @@ -14,6 +14,7 @@ module.exports = async (ctx) => { headers: { Authorization: `bearer ${config.github.access_token}`, }, + json: true, data: { query: ` { diff --git a/lib/routes/icourse163/newest.js b/lib/routes/icourse163/newest.js index 32e06a3bbb..7bc21b5dee 100644 --- a/lib/routes/icourse163/newest.js +++ b/lib/routes/icourse163/newest.js @@ -1,5 +1,4 @@ const got = require('@/utils/got'); -const qs = require('querystring'); module.exports = async (ctx) => { const link = 'https://www.icourse163.org/category/all'; @@ -13,16 +12,16 @@ module.exports = async (ctx) => { method: 'post', url: `https://www.icourse163.org/web/j/courseBean.getCoursePanelListByFrontCategory.rpc?csrfKey=${csrfKey}`, headers: { - 'Content-Type': 'application/x-www-form-urlencoded', Cookie: `NTESSTUDYSI=${csrfKey};`, }, - data: qs.stringify({ + form: true, + data: { categoryId: -1, type: 30, orderBy: 10, pageIndex: 1, pageSize: 20, - }), + }, }); const items = response.data.result.result.map((item) => { diff --git a/lib/routes/imaijia/category.js b/lib/routes/imaijia/category.js index e1552b1df9..7c810b14e8 100644 --- a/lib/routes/imaijia/category.js +++ b/lib/routes/imaijia/category.js @@ -1,5 +1,4 @@ const got = require('@/utils/got'); -const qs = require('querystring'); module.exports = async (ctx) => { const category = ctx.params.category; @@ -12,11 +11,12 @@ module.exports = async (ctx) => { headers: { Referer: url, }, + form: true, url: api_url, - data: qs.stringify({ + data: { pageNo: 1, catid: `${category}`, - }), + }, }); const data = response.data; diff --git a/lib/routes/infoq/recommend.js b/lib/routes/infoq/recommend.js index 48d1a699f0..0a546a6157 100644 --- a/lib/routes/infoq/recommend.js +++ b/lib/routes/infoq/recommend.js @@ -10,8 +10,8 @@ module.exports = async (ctx) => { url: apiUrl, headers: { Referer: pageUrl, - 'Content-Type': 'application/json', }, + json: true, data: { size: 5, }, diff --git a/lib/routes/infoq/topic.js b/lib/routes/infoq/topic.js index 2bd69e6300..8c70bafa87 100644 --- a/lib/routes/infoq/topic.js +++ b/lib/routes/infoq/topic.js @@ -12,8 +12,8 @@ module.exports = async (ctx) => { url: infoUrl, headers: { Referer: pageUrl, - 'Content-Type': 'application/json', }, + json: true, data: { id: paramId, }, @@ -26,8 +26,8 @@ module.exports = async (ctx) => { url: apiUrl, headers: { Referer: pageUrl, - 'Content-Type': 'application/json', }, + json: true, data: { size: 5, type: type, diff --git a/lib/routes/infoq/utils.js b/lib/routes/infoq/utils.js index 3a0f7259bf..02c98ca83d 100644 --- a/lib/routes/infoq/utils.js +++ b/lib/routes/infoq/utils.js @@ -13,8 +13,8 @@ const ProcessFeed = async (list, cache) => { url: detailUrl, headers: { Referer: link, - 'Content-Type': 'application/json', }, + json: true, data: { uuid: uuid, }, diff --git a/lib/routes/jike/topic.js b/lib/routes/jike/topic.js index bbdc2757cd..3fd8ef0560 100644 --- a/lib/routes/jike/topic.js +++ b/lib/routes/jike/topic.js @@ -13,6 +13,7 @@ module.exports = async (ctx) => { Referer: `https://m.okjike.com/topics/${id}`, 'App-Version': '4.12.0', }, + json: true, data: { loadMoreKey: null, topic: id, diff --git a/lib/routes/jike/topicSquare.js b/lib/routes/jike/topicSquare.js index d1a0164048..b4c8c16e2f 100644 --- a/lib/routes/jike/topicSquare.js +++ b/lib/routes/jike/topicSquare.js @@ -11,6 +11,7 @@ module.exports = async (ctx) => { Referer: `https://m.okjike.com/topics/${id}`, 'App-Version': '4.12.0', }, + json: true, data: { loadMoreKey: null, topicId: id, diff --git a/lib/routes/jike/topicText.js b/lib/routes/jike/topicText.js index f6e04312b4..df03db1332 100644 --- a/lib/routes/jike/topicText.js +++ b/lib/routes/jike/topicText.js @@ -12,6 +12,7 @@ module.exports = async (ctx) => { Referer: `https://m.okjike.com/topics/${id}`, 'App-Version': '4.12.0', }, + json: true, data: { loadMoreKey: null, topic: id, diff --git a/lib/routes/jike/user.js b/lib/routes/jike/user.js index 7ca57d5a61..5d3724715e 100644 --- a/lib/routes/jike/user.js +++ b/lib/routes/jike/user.js @@ -11,6 +11,7 @@ module.exports = async (ctx) => { 'App-Version': '4.12.0', platform: 'web', }, + json: true, data: { limit: 20, loadMoreKey: null, diff --git a/lib/routes/juejin/pins.js b/lib/routes/juejin/pins.js index 842c618547..dc9a6432e4 100644 --- a/lib/routes/juejin/pins.js +++ b/lib/routes/juejin/pins.js @@ -4,6 +4,7 @@ module.exports = async (ctx) => { const response = await got({ method: 'post', url: 'https://web-api.juejin.im/graphql', + json: true, data: { operationName: '', query: '', variables: { size: 20, after: '', afterPosition: '' }, extensions: { query: { id: '964dab26a3f9997283d173b865509890' } } }, headers: { 'X-Agent': 'Juejin/Web', diff --git a/lib/routes/laosiji/hotshow.js b/lib/routes/laosiji/hotshow.js index 8efcbffcfc..6bb9a62d74 100644 --- a/lib/routes/laosiji/hotshow.js +++ b/lib/routes/laosiji/hotshow.js @@ -1,6 +1,5 @@ const got = require('@/utils/got'); const parseDate = require('@/utils/date'); -const qs = require('querystring'); module.exports = async (ctx) => { const { id } = ctx.params; @@ -10,13 +9,13 @@ module.exports = async (ctx) => { url: 'http://www.laosiji.com/api/hotShow/program', headers: { Referer: link, - 'Content-Type': 'application/x-www-form-urlencoded', }, - data: qs.stringify({ + form: true, + data: { hotShowId: id, sort: 1, pageNo: 1, - }), + }, }); const data = response.data.body.hotshow; diff --git a/lib/routes/matters/latest.js b/lib/routes/matters/latest.js index eeea180b79..31c74d3ddd 100644 --- a/lib/routes/matters/latest.js +++ b/lib/routes/matters/latest.js @@ -5,6 +5,7 @@ module.exports = async (ctx) => { const response = await got({ method: 'post', url: 'https://server.matters.news/', + json: true, data: { operationName: 'NewestFeed', variables: { diff --git a/lib/routes/ncm/djradio.js b/lib/routes/ncm/djradio.js index 57f0e6f34b..2b2880d3de 100644 --- a/lib/routes/ncm/djradio.js +++ b/lib/routes/ncm/djradio.js @@ -1,5 +1,4 @@ const got = require('@/utils/got'); -const qs = require('querystring'); module.exports = async (ctx) => { const id = ctx.params.id; @@ -9,13 +8,13 @@ module.exports = async (ctx) => { url: 'http://music.163.com/api/dj/program/byradio', headers: { Referer: 'https://music.163.com/', - 'Content-Type': 'application/x-www-form-urlencoded', }, - data: qs.stringify({ + form: true, + data: { radioId: id, limit: 1000, offset: 0, - }), + }, }); const programs = response.data.programs || []; diff --git a/lib/routes/ncm/playlist.js b/lib/routes/ncm/playlist.js index 5da3b89274..f6ab58d485 100644 --- a/lib/routes/ncm/playlist.js +++ b/lib/routes/ncm/playlist.js @@ -1,5 +1,4 @@ const got = require('@/utils/got'); -const qs = require('querystring'); module.exports = async (ctx) => { const id = ctx.params.id; @@ -9,11 +8,11 @@ module.exports = async (ctx) => { url: 'https://music.163.com/api/v3/playlist/detail', headers: { Referer: 'https://music.163.com/', - 'Content-Type': 'application/x-www-form-urlencoded', }, - data: qs.stringify({ + form: true, + data: { id: id, - }), + }, }); const data = response.data.playlist; diff --git a/lib/routes/ncm/userplaylist.js b/lib/routes/ncm/userplaylist.js index 2de36e430c..49ff789da0 100644 --- a/lib/routes/ncm/userplaylist.js +++ b/lib/routes/ncm/userplaylist.js @@ -1,5 +1,4 @@ const got = require('@/utils/got'); -const qs = require('querystring'); module.exports = async (ctx) => { const uid = ctx.params.uid; @@ -9,13 +8,13 @@ module.exports = async (ctx) => { url: 'http://music.163.com/api/user/playlist', headers: { Referer: 'https://music.163.com/', - 'Content-Type': 'application/x-www-form-urlencoded', }, - data: qs.stringify({ + form: true, + data: { uid: uid, limit: 1000, offset: 0, - }), + }, }); const playlist = response.data.playlist || []; diff --git a/lib/routes/nga/forum.js b/lib/routes/nga/forum.js index 556bfed92b..9fd5b3cff8 100644 --- a/lib/routes/nga/forum.js +++ b/lib/routes/nga/forum.js @@ -1,21 +1,17 @@ const got = require('@/utils/got'); -const qs = require('querystring'); module.exports = async (ctx) => { const { fid } = ctx.params; - const gotInstance = got.extend({ - baseURL: 'https://ngabbs.com/app_api.php', + const homePage = await got({ + method: 'post', + url: 'https://ngabbs.com/app_api.php?__lib=subject&__act=list', headers: { - 'Content-Type': 'application/x-www-form-urlencoded', 'X-User-Agent': 'NGA_skull/6.0.5(iPhone10,3;iOS 12.0.1)', }, - }); - const homePage = await gotInstance.request({ - method: 'post', - url: '?__lib=subject&__act=list', - data: qs.stringify({ + form: true, + data: { fid, - }), + }, }); const list = homePage.data.result.data.filter(({ tid }) => tid); @@ -31,12 +27,16 @@ module.exports = async (ctx) => { }; const description = await ctx.cache.tryGet(`nga-forum: ${link}`, async () => { - const response = await gotInstance.request({ + const response = await got({ method: 'post', - url: '?__lib=post&__act=list', - data: qs.stringify({ + url: 'https://ngabbs.com/app_api.php?__lib=subject&__act=list?__lib=post&__act=list', + headers: { + 'X-User-Agent': 'NGA_skull/6.0.5(iPhone10,3;iOS 12.0.1)', + }, + form: true, + data: { tid, - }), + }, }); return response.data.result[0].content; diff --git a/lib/routes/nintendo/eshop_us.js b/lib/routes/nintendo/eshop_us.js index 63ca502f0e..d1fa49e8e2 100644 --- a/lib/routes/nintendo/eshop_us.js +++ b/lib/routes/nintendo/eshop_us.js @@ -4,6 +4,7 @@ module.exports = async (ctx) => { const response = await got({ method: 'post', url: `https://u3b6gr4ua3-dsn.algolia.net/1/indexes/*/queries?x-algolia-agent=Algolia%20for%20vanilla%20JavaScript%20(lite)%203.22.1%3BJS%20Helper%202.20.1&x-algolia-application-id=U3B6GR4UA3&x-algolia-api-key=9a20c93440cf63cf1a7008d75f7438bf`, + json: true, data: { requests: [ { diff --git a/lib/routes/tingdiantz/95598.js b/lib/routes/tingdiantz/95598.js index 7b23ad1c8f..75c02dc731 100644 --- a/lib/routes/tingdiantz/95598.js +++ b/lib/routes/tingdiantz/95598.js @@ -1,5 +1,4 @@ const got = require('@/utils/got'); -const qs = require('querystring'); module.exports = async (ctx) => { const { orgNo, provinceNo, scope = '', typeCode = '', lineName = '' } = ctx.params; @@ -14,10 +13,8 @@ module.exports = async (ctx) => { const response = await got({ method: 'post', url: 'http://www.95598.cn/95598/outageNotice/queryOutageNoticeList', - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - }, - data: qs.stringify({ + form: true, + data: { orgNo, outageStartTime, outageEndTime, @@ -26,7 +23,7 @@ module.exports = async (ctx) => { typeCode, lineName, anHui, - }), + }, }); const items = (response.data.seleList || []).map((item) => { diff --git a/lib/routes/universities/scut/jwc.js b/lib/routes/universities/scut/jwc.js index 1e8ba4b78b..fb6cb2a0ba 100644 --- a/lib/routes/universities/scut/jwc.js +++ b/lib/routes/universities/scut/jwc.js @@ -1,7 +1,6 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); const url = require('url'); -const qs = require('querystring'); const baseUrl = 'http://jwc.scuteo.com/'; @@ -21,14 +20,12 @@ module.exports = async (ctx) => { const listResponse = await got({ method: 'post', url: baseUrl + 'jiaowuchu/cms/category/index.do', - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - }, - data: qs.stringify({ + form: true, + data: { id: categoryData.id, offset: 0, pagesize: 20, - }), + }, }); const itemList = listResponse.data.results.splice(0, 10); diff --git a/lib/routes/westore/new.js b/lib/routes/westore/new.js index eab35d13a5..abe4a475a6 100644 --- a/lib/routes/westore/new.js +++ b/lib/routes/westore/new.js @@ -5,6 +5,7 @@ module.exports = async (ctx) => { const response = await got({ method: 'post', url: 'https://uapi.vip.qq.com/Api/api.brand.productssrf', + json: true, data: { page: 1, per_page: 20, diff --git a/lib/routes/ziroom/room.js b/lib/routes/ziroom/room.js index 9926f2f949..a2dd8749c8 100644 --- a/lib/routes/ziroom/room.js +++ b/lib/routes/ziroom/room.js @@ -1,5 +1,4 @@ const got = require('@/utils/got'); -const qs = require('querystring'); module.exports = async (ctx) => { const city = ctx.params.city || 'sh'; @@ -14,14 +13,15 @@ module.exports = async (ctx) => { headers: { Referer: `http://${domain}/${city.toUpperCase()}/search.html`, }, - data: qs.stringify({ + form: true, + data: { recent_money: 0, sort: 0, is_whole: iswhole, room: room, key_word: keyword, step: 0, - }), + }, }); let data = response.data.data; // 当查询的结果不存在时,该 data 是个对象 { info: '数据加载完毕' } // 判断数据的类型,如果有数据就是数组类型的,没有数据的话,就赋值为空数组 diff --git a/lib/utils/got.js b/lib/utils/got.js index 51d34982b3..e6ed120dc4 100644 --- a/lib/utils/got.js +++ b/lib/utils/got.js @@ -79,11 +79,7 @@ const custom = got.extend({ (options) => { // compatible with axios api if (options.data) { - if (typeof options.data === 'object') { - options.json = options.json || options.data; - } else { - options.body = options.body || options.data; - } + options.body = options.body || options.data; } if (options.responseType === 'buffer') { options.encoding = null;