fix(route): 修复快递100快递订单追踪路由 (#11076)
* fix:修复快递100查询服务 * Update utils.js Extend the cookie cache time. * refactor: migrate to v2
This commit is contained in:
parent
79ec61a527
commit
cb0706b167
|
|
@ -309,24 +309,6 @@
|
|||
],
|
||||
grs: [{ title: '研究生院通知', docs: 'https://docs.rsshub.app/university.html#yun-nan-da-xue', source: '/*', target: '' }],
|
||||
},
|
||||
'kuaidi100.com': {
|
||||
_name: '快递100',
|
||||
'.': [
|
||||
{
|
||||
title: '快递追踪',
|
||||
docs: 'https://docs.rsshub.app/other.html#kuai-di-100',
|
||||
source: '/',
|
||||
target: (params, url, document) => {
|
||||
const postid = document && document.querySelector('#postid').value;
|
||||
const com = document && document.querySelector('#selectComBtn').childNodes[1].attributes[1].value;
|
||||
if (com && com !== 'default' && postid) {
|
||||
return `/kuaidi100/track/${com}/${postid}`;
|
||||
}
|
||||
},
|
||||
},
|
||||
{ title: '支持的快递公司列表', docs: 'https://docs.rsshub.app/other.html#kuai-di-100', source: '/', target: '/kuaidi100/company' },
|
||||
],
|
||||
},
|
||||
'japanpost.jp': {
|
||||
_name: '日本郵便',
|
||||
'trackings.post': [
|
||||
|
|
|
|||
|
|
@ -752,29 +752,6 @@ module.exports = {
|
|||
},
|
||||
],
|
||||
},
|
||||
'kuaidi100.com': {
|
||||
_name: '快递100',
|
||||
'.': [
|
||||
{
|
||||
title: '快递追踪',
|
||||
docs: 'https://docs.rsshub.app/other.html#kuai-di-100',
|
||||
source: '/',
|
||||
target: (params, url, document) => {
|
||||
const postid = document && document.querySelector('#postid').value;
|
||||
const com = document && document.querySelector('#selectComBtn').childNodes[1].attributes[1].value;
|
||||
if (com && com !== 'default' && postid) {
|
||||
return `/kuaidi100/track/${com}/${postid}`;
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '支持的快递公司列表',
|
||||
docs: 'https://docs.rsshub.app/other.html#kuai-di-100',
|
||||
source: '/',
|
||||
target: '/kuaidi100/company',
|
||||
},
|
||||
],
|
||||
},
|
||||
'hrbeu.edu.cn': {
|
||||
_name: '哈尔滨工程大学',
|
||||
yjsy: [
|
||||
|
|
|
|||
|
|
@ -2474,8 +2474,8 @@ router.get('/haohaozhu/discover/:keyword?', lazyloadRouteHandler('./routes/haoha
|
|||
// router.get('/neu/news/:type', lazyloadRouteHandler('./routes/universities/neu/news'));
|
||||
|
||||
// 快递100
|
||||
router.get('/kuaidi100/track/:number/:id/:phone?', lazyloadRouteHandler('./routes/kuaidi100/index'));
|
||||
router.get('/kuaidi100/company', lazyloadRouteHandler('./routes/kuaidi100/supported_company'));
|
||||
// router.get('/kuaidi100/track/:number/:id/:phone?', lazyloadRouteHandler('./routes/kuaidi100/index'));
|
||||
// router.get('/kuaidi100/company', lazyloadRouteHandler('./routes/kuaidi100/supported_company'));
|
||||
|
||||
// 稻草人书屋
|
||||
router.get('/dcrsw/:name/:count?', lazyloadRouteHandler('./routes/novel/dcrsw'));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
module.exports = {
|
||||
'/company': ['NeverBehave'],
|
||||
'/track/:number/:id/:phone?': ['NeverBehave'],
|
||||
};
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
module.exports = {
|
||||
'kuaidi100.com': {
|
||||
_name: '快递 100',
|
||||
'.': [
|
||||
{
|
||||
title: '快递订单追踪',
|
||||
docs: 'https://docs.rsshub.app/other.html#kuai-di-100',
|
||||
source: '/',
|
||||
target: (params, url, document) => {
|
||||
const postid = document && document.querySelector('#postid').value;
|
||||
const com = document && document.querySelector('#selectComBtn').childNodes[1].attributes[1].value;
|
||||
if (com && com !== 'default' && postid) {
|
||||
return `/kuaidi100/track/${com}/${postid}`;
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '支持的快递公司列表',
|
||||
docs: 'https://docs.rsshub.app/other.html#kuai-di-100',
|
||||
source: '/',
|
||||
target: '/kuaidi100/company',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
module.exports = (router) => {
|
||||
router.get('/company', require('./supported_company'));
|
||||
router.get('/track/:number/:id/:phone?', require('./index'));
|
||||
};
|
||||
|
|
@ -10,7 +10,6 @@ module.exports = async (ctx) => {
|
|||
title: item.name,
|
||||
description: item.number,
|
||||
category: item.comTypeName,
|
||||
pubDate: new Date().toUTCString(),
|
||||
link: item.siteUrl,
|
||||
})),
|
||||
};
|
||||
|
|
@ -1,6 +1,10 @@
|
|||
const got = require('@/utils/got');
|
||||
const wwwid_key = 'kuaidi100-wwwid';
|
||||
const csrf_key = 'kuaidi100-csrf';
|
||||
const globacsrftoken_key = 'kuaidi100-globacsrftoken';
|
||||
const dasddocTitl_key = 'kuaidi100-dasddocTitl';
|
||||
const dasddocReferrer_key = 'kuaidi100-dasddocReferrer';
|
||||
const dasddocHref_key = 'kuaidi100-dasddocHref';
|
||||
const query_count = 'kuaidi100-cookie-count';
|
||||
const max_query_count = 30;
|
||||
|
||||
|
|
@ -9,7 +13,11 @@ async function getCookie(ctx) {
|
|||
shouldUpdateCookie(ctx);
|
||||
let wwwid = await ctx.cache.get(wwwid_key);
|
||||
let csrf = await ctx.cache.get(csrf_key);
|
||||
if (!wwwid || !csrf) {
|
||||
let globacsrftoken = await ctx.cache.get(globacsrftoken_key);
|
||||
let dasddocTitl = await ctx.cache.get(dasddocTitl_key);
|
||||
let dasddocReferrer = await ctx.cache.get(dasddocReferrer_key);
|
||||
let dasddocHref = await ctx.cache.get(dasddocHref_key);
|
||||
if (!wwwid || !csrf || !dasddocTitl || !dasddocReferrer || !dasddocHref) {
|
||||
const indexResponse = await got({
|
||||
method: 'get',
|
||||
url: 'https://www.kuaidi100.com/?from=appstore',
|
||||
|
|
@ -25,12 +33,24 @@ async function getCookie(ctx) {
|
|||
wwwid = e.split(';')[0];
|
||||
} else if (e.indexOf('csrftoken') === 0) {
|
||||
csrf = e.split(';')[0];
|
||||
} else if (e.indexOf('globacsrftoken') === 0) {
|
||||
globacsrftoken = e.split(';')[0];
|
||||
} else if (e.indexOf('dasddocTitle') >= 0) {
|
||||
dasddocTitl = e.split(';')[0];
|
||||
} else if (e.indexOf('dasddocReferrer') >= 0) {
|
||||
dasddocReferrer = e.split(';')[0];
|
||||
} else if (e.indexOf('dasddocHref') >= 0) {
|
||||
dasddocHref = e.split(';')[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ctx.cache.set(wwwid_key, wwwid, 600);
|
||||
ctx.cache.set(csrf_key, csrf, 600);
|
||||
ctx.cache.set(globacsrftoken_key, globacsrftoken, 600);
|
||||
ctx.cache.set(dasddocTitl_key, dasddocTitl, 600);
|
||||
ctx.cache.set(dasddocReferrer_key, dasddocReferrer, 600);
|
||||
ctx.cache.set(dasddocHref_key, dasddocHref, 600);
|
||||
// We have acquired new cookie. It may due to cache timeout.
|
||||
// Force update counter and don't wait it finished.
|
||||
shouldUpdateCookie(ctx, true);
|
||||
|
|
@ -39,6 +59,10 @@ async function getCookie(ctx) {
|
|||
return {
|
||||
wwwid,
|
||||
csrf,
|
||||
globacsrftoken,
|
||||
dasddocTitl,
|
||||
dasddocReferrer,
|
||||
dasddocHref,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -61,11 +85,10 @@ async function getCookie(ctx) {
|
|||
"version": 776
|
||||
}
|
||||
*/
|
||||
async function getCompanyList(ctx) {
|
||||
function getCompanyList(ctx) {
|
||||
// Using date as cache key and it will automatically expired by 1d
|
||||
const key = `kuaidi100-company-name-${new Date().toISOString().split('T')[0]}`;
|
||||
let list = await ctx.cache.get(key);
|
||||
if (!list) {
|
||||
return ctx.cache.tryGet(key, async () => {
|
||||
const cookie = await getCookie(ctx);
|
||||
const wwwid = cookie.wwwid;
|
||||
const companyResponse = await got({
|
||||
|
|
@ -76,7 +99,7 @@ async function getCompanyList(ctx) {
|
|||
Cookie: wwwid,
|
||||
},
|
||||
});
|
||||
list = companyResponse.body;
|
||||
let list = companyResponse.body;
|
||||
|
||||
// Parsing the js file
|
||||
try {
|
||||
|
|
@ -87,11 +110,8 @@ async function getCompanyList(ctx) {
|
|||
throw new Error('无法正确获取快递公司列表:请稍后重试');
|
||||
}
|
||||
|
||||
ctx.cache.set(key, list);
|
||||
} else {
|
||||
list = JSON.parse(list);
|
||||
}
|
||||
return list;
|
||||
return list;
|
||||
});
|
||||
}
|
||||
|
||||
function shouldUpdateCookie(ctx, forcedUpdate = false) {
|
||||
|
|
@ -186,6 +206,17 @@ module.exports = {
|
|||
getQuery: async (ctx, number, id, phone) => {
|
||||
const query_key = `kuaidi100-query-${number}-${id}`;
|
||||
let query = await ctx.cache.get(query_key);
|
||||
// 组装日期与单号 日期为提前两个月
|
||||
const timestamp = Number.parseInt(new Date().getTime() / 1000);
|
||||
const lastTowMonth = new Date().getTime() - 60 * 60 * 24 * 60 * 1000;
|
||||
const dateString = new Date(lastTowMonth).toLocaleDateString('ZH').split('/').join('');
|
||||
const queryMeta = encodeURIComponent(
|
||||
JSON.stringify({
|
||||
date: dateString,
|
||||
nums: [id],
|
||||
})
|
||||
);
|
||||
|
||||
if (!query) {
|
||||
const cookie = await getCookie(ctx);
|
||||
const queryResponse = await got({
|
||||
|
|
@ -193,7 +224,11 @@ module.exports = {
|
|||
url: `https://www.kuaidi100.com/query?type=${number}&postid=${id}&temp=${Math.random()}&phone=${phone ? phone : ''}`,
|
||||
headers: {
|
||||
Referer: 'https://www.kuaidi100.com/',
|
||||
Cookie: `${cookie.csrf}; ${cookie.wwwid}`,
|
||||
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,ja;q=0.7',
|
||||
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36',
|
||||
Cookie: `${cookie.globacsrftoken}; ${cookie.csrf}; ${cookie.wwwid}; ${cookie.dasddocHref}; ${cookie.dasddocReferrer}; ${
|
||||
cookie.dasddocTitl
|
||||
}; addcom=${number}; addnu=${id}; snt_query_meta=${queryMeta}; sortStatus=0; Hm_lpvt_22ea01af58ba2be0fec7c11b25e88e6c=${timestamp}; Hm_lvt_22ea01af58ba2be0fec7c11b25e88e6c=${timestamp - 1642}`,
|
||||
},
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue