cekstatus.js
3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
var request = require('request');
var xpath = require('xpath');
var parse5 = require('parse5');
var xmlser = require('xmlserializer');
var dom = require('xmldom').DOMParser;
var xml2js = require('xml2js').parseString;
var config = {
webreport: {
login_url: 'http://103.11.75.142:9009/dealer/index.php/admin/login',
username: 'reload97',
password: '903333',
}
};
function login() {
var jar = request.jar();
var options = {
url: config.webreport.login_url,
jar: jar,
followAllRedirects: true,
form: {
username: config.webreport.username,
password: config.webreport.password,
Submit: 'Login',
},
};
//console.log('Requesting', options);
request.post(options, function(error, httpResponse, body) {
if (error) {
console.log('Error retrieving login');
return;
}
if (body.search('Incorrect username') >= 0) {
console.log('Salah username / password');
return;
}
getTrxStatusPage(jar);
});
}
function getTrxStatusPage(jar) {
var options = {
url: 'http://103.11.75.142:9009/dealer/index.php/transaction/index',
jar: jar,
followAllRedirects: true,
form: {
startdate: '2016-01-27',
enddate: '2016-01-27',
pdate: '',
trxid: '40477696',
destmisdn: '',
type: 0,
ts: '',
submit: 'Find',
},
};
request.post(options, function(error, httpResponse, body) {
if (error) {
console.log('Error retrieving trx status page');
return;
}
body = body.replace(/<\/thead>\s<\/tbody>/, "</thead>\n<tbody>");
var document = parse5.parse(body);
var xhtml = xmlser.serializeToString(document);
var doc = new dom().parseFromString(xhtml);
var select = xpath.useNamespaces({"x": "http://www.w3.org/1999/xhtml"});
var nodes = select('//x:*[@id="dirlist"]/x:tbody/x:tr/x:td', doc);
var status = {
trxId: nodes[0].firstChild.data,
trxDate: nodes[1].firstChild.data,
updateDate: nodes[2].firstChild.data,
product: nodes[3].firstChild.data,
amount: nodes[4].firstChild.data,
msisdn: nodes[5].firstChild.data,
reffId: nodes[6].firstChild.data,
status: nodes[7].firstChild.data,
response: nodes[8].toString(),
}
status.response = status.response.replace('<td>', '');
status.response = status.response.replace('</td>', '');
status.response = status.response.replace(/\n/g, '');
status.response = status.response.trim();
//status.response_raw = status.response;
xml2js(status.response, function (err, result) {
if (err) {
console.log('Gagal parsing XML');
return;
}
status.response = result.result;
console.log(status);
});
});
}
login();