mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-07 05:36:08 +08:00
feat: DHL 快递包裹追踪 (#2748)
This commit is contained in:
@@ -74,6 +74,12 @@ pageClass: routes
|
||||
|
||||
<Route author="kt286" example="/cnbeta" path="/cnbeta"/>
|
||||
|
||||
## DHL
|
||||
|
||||
### DHL 国际快递包裹追踪
|
||||
|
||||
<Route author="ntzyz" example="/dhl/12345678" path="/dhl/:shipment_id" :paramsDesc="['运单号']"/>
|
||||
|
||||
## Dilbert Comic Strip
|
||||
|
||||
<Route name="Daily Strip" author="Maecenas" example="/dilbert/strip" path="/dilbert/strip">
|
||||
|
||||
@@ -1597,6 +1597,9 @@ router.get('/aliyun/database_month', require('./routes/aliyun/database_month'));
|
||||
// 礼物说
|
||||
router.get('/liwushuo/index', require('./routes/liwushuo/index.js'));
|
||||
|
||||
// DHL
|
||||
router.get('/dhl/:id', require('./routes/dhl/shipment-tracking'));
|
||||
|
||||
// 中华人民共和国商务部
|
||||
router.get('/mofcom/article/:suffix', require('./routes/mofcom/article'));
|
||||
|
||||
|
||||
55
lib/routes/dhl/shipment-tracking.js
Normal file
55
lib/routes/dhl/shipment-tracking.js
Normal file
@@ -0,0 +1,55 @@
|
||||
const got = require('@/utils/got');
|
||||
|
||||
const monthMap = {
|
||||
一月: 0,
|
||||
二月: 1,
|
||||
三月: 2,
|
||||
四月: 3,
|
||||
五月: 4,
|
||||
六月: 5,
|
||||
七月: 6,
|
||||
八月: 7,
|
||||
九月: 8,
|
||||
十月: 9,
|
||||
十一月: 10,
|
||||
十二月: 11,
|
||||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params && ctx.params.id;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `https://www.logistics.dhl/shipmentTracking?AWB=${id}&countryCode=CN&languageCode=zh`,
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
},
|
||||
});
|
||||
const data = response.data;
|
||||
const result = data.results[0];
|
||||
|
||||
const link = `https://www.logistics.dhl/cn-zh/home/tracking/tracking-express.html?tracking-id=${id}`;
|
||||
|
||||
ctx.state.data = {
|
||||
title: `Shipment tracking for DHL (${id})`,
|
||||
link,
|
||||
item: result.checkpoints.map((checkpoint) => {
|
||||
const [, month, day, year] = checkpoint.date.match(/^[^,]+, ([^ ]+) (\d+), (\d+)/i);
|
||||
const [, hour, minute] = checkpoint.time.match(/(\d+):(\d+)/);
|
||||
const date = new Date();
|
||||
|
||||
date.setFullYear(year);
|
||||
date.setMonth(monthMap[month]);
|
||||
date.setDate(day);
|
||||
date.setHours(hour);
|
||||
date.setMinutes(minute);
|
||||
date.setSeconds(0);
|
||||
date.setMilliseconds(0);
|
||||
|
||||
return {
|
||||
title: checkpoint.description,
|
||||
pubDate: date.toUTCString(),
|
||||
};
|
||||
}),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user