Commit f1638d5b254c5bbbba023e758ce0176a4632376b
1 parent
b56a3961e5
Exists in
master
balance
Showing 1 changed file with 53 additions and 0 deletions Side-by-side Diff
partner-datacell.js
... | ... | @@ -20,6 +20,14 @@ function calculateSignature(userid, password, msisdn, timestamp) { |
20 | 20 | return xor.encode(a,b); |
21 | 21 | } |
22 | 22 | |
23 | +function calculateBalanceSignature(userid, password, timestamp) { | |
24 | + var a = '0000' + timestamp; | |
25 | + var b = userid.substr(0, 4) + password; | |
26 | + | |
27 | + return xor.encode(a,b); | |
28 | +} | |
29 | + | |
30 | + | |
23 | 31 | function createPayload(task) { |
24 | 32 | var timestamp = strftime('%H%M%S'); |
25 | 33 | |
... | ... | @@ -189,6 +197,51 @@ function createServer() { |
189 | 197 | }); |
190 | 198 | } |
191 | 199 | |
200 | +function balanceCheck() { | |
201 | + var timestamp = strftime('%H%M%S'); | |
202 | + | |
203 | + var payload = { | |
204 | + datacell: [ | |
205 | + {perintah: 'saldo'}, | |
206 | + {userid: config.h2h_out.userid}, | |
207 | + {time: timestamp}, | |
208 | + {sgn: calculateBalanceSignature(config.h2h_out.userid, config.h2h_out.password, timestamp)} | |
209 | + ] | |
210 | + }; | |
211 | + | |
212 | + var postRequest = { | |
213 | + host: "202.152.62.2", | |
214 | + path: "/RELOAD97.php", | |
215 | + port: 7713, | |
216 | + method: "POST", | |
217 | + headers: { | |
218 | + 'Content-Type': 'text/xml', | |
219 | + 'Content-Length': Buffer.byteLength(payload_xml) | |
220 | + } | |
221 | + }; | |
222 | + | |
223 | + var buffer = ""; | |
224 | + var req = http.request( postRequest, function( res ) { | |
225 | + | |
226 | + console.log('Status code: ' + res.statusCode ); | |
227 | + var buffer = ""; | |
228 | + res.on( "data", function( data ) { buffer = buffer + data; } ); | |
229 | + res.on( "end", function( data ) { | |
230 | + console.log('CHECK BALANCE RESULT:'); | |
231 | + console.log(buffer); | |
232 | + }); | |
233 | + | |
234 | + }); | |
235 | + | |
236 | + req.on('error', function(e) { | |
237 | + console.log('problem with request: ' + e.message); | |
238 | + }); | |
239 | + | |
240 | + req.write( payload_xml ); | |
241 | + req.end(); | |
242 | + | |
243 | +} | |
244 | + | |
192 | 245 | |
193 | 246 | function start(_config, _callbackReport) { |
194 | 247 | config = _config; |