Skip to content

Commit

Permalink
* fixed an issue in JNT is not working
Browse files Browse the repository at this point in the history
  • Loading branch information
egg- committed Nov 3, 2021
1 parent 1ce4015 commit 1b45dc3
Show file tree
Hide file tree
Showing 6 changed files with 1,884 additions and 22 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 2.7.1
* fixed an issue in JNT is not working

# 2.7.0
* add canada post

# 2.6.1
* add courier namespace for DHL.

Expand Down
58 changes: 38 additions & 20 deletions lib/courier/jnt.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,27 @@ var tracker = require('../')

var trackingInfo = function (number) {
return {
method: 'POST',
url: 'https://www.jtexpress.ph/index/router/index.html',
json: true,
body: {
method: 'app.findTrack',
data: {
billcode: number,
lang: 'en',
source: 3
cookie: {
url: 'https://www.jtexpress.ph/index/query/gzquery.html',
method: 'GET'
},
track: {
method: 'POST',
url: 'https://www.jtexpress.ph/index/router/index.html',
json: true,
headers: {
'X-SimplyPost-Id': 'testtesttest',
'X-SimplyPost-Signature': '712d5af47cd24adf54fe39ebc4ed0aea'
},
body: {
method: 'app.findTrack',
data: {
billcode: number,
lang: 'en',
source: 3
},
pId: 'testtesttest',
pst: '712d5af47cd24adf54fe39ebc4ed0aea'
}
}
}
Expand Down Expand Up @@ -67,23 +79,29 @@ module.exports = function () {
trackingInfo: trackingInfo,
trace: function (number, cb) {
var tracking = trackingInfo(number)
var req = request.defaults({ jar: true })

request(tracking, function (err, res, body) {
req(tracking.cookie, function (err, res, body) {
if (err) {
return cb(err)
}
req(tracking.track, function (err, res, body) {
if (err) {
return cb(err)
}

try {
if (res.statusCode !== 200) {
return cb(tracker.error(res.statusMessage))
} else if (body.code !== 20000) {
return cb(tracker.error(body.code, body.desc))
try {
if (res.statusCode !== 200) {
return cb(tracker.error(res.statusMessage))
} else if (body.code !== 20000) {
return cb(tracker.error(body.code, body.desc))
}
var result = parser.trace(JSON.parse(body.data))
cb(result ? null : tracker.error(tracker.ERROR.INVALID_NUMBER), result)
} catch (e) {
cb(tracker.error(e.message))
}
var result = parser.trace(JSON.parse(body.data))
cb(result ? null : tracker.error(tracker.ERROR.INVALID_NUMBER), result)
} catch (e) {
cb(tracker.error(e.message))
}
})
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "delivery-tracker",
"version": "2.7.0",
"version": "2.7.1",
"author": {
"name": "egg",
"email": "[email protected]"
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/jnt-DELIVERED

This file was deleted.

Loading

0 comments on commit 1b45dc3

Please sign in to comment.