Advertisement
L3V147H4N

Untitled

May 16th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. var soap = require('soap'),
  4.   fs = require('fs'),
  5.   exec = require('child_process').exec,
  6.   moment = require('moment'),
  7.   ticketRequest = require('./tra/tra-generator'),
  8.   uniqueId = moment().valueOf(),
  9.   generationDate = moment().format(),
  10.   expirationTime = moment().add(1,'d').format(),
  11.   service = 'wsfe',
  12.   url = 'https://wsaa.afip.gov.ar/ws/services/LoginCms?wsdl',
  13.   options = {},
  14.   args = {
  15.     in0 : null
  16.   };
  17.  
  18. ticketRequest(uniqueId, generationDate, expirationTime, service)
  19.   .then(v => {
  20.     console.log('done');
  21.  
  22.     execCommand();
  23.   })
  24.   .catch(err => {
  25.     console.log(err);
  26.   });
  27.  
  28.  
  29.  
  30. function execCommand () {
  31.   exec('openssl smime -sign -in ./TRA.xml -signer ./certificate.crt -inkey ./MiClavePrivada.key -out ./TRA.cms -nodetach', function (err, stdout, stderr) {
  32.     if (err) {
  33.       console.log(err)
  34.     } else {
  35.       fs.readFile('./TRA.cms', 'utf-8', (err, data) => {
  36.         if (err) {
  37.           console.log(err)
  38.         } else {
  39.           args.in0 = data.substr(188, data.length).trim();
  40.           console.log(args.in0);
  41.         }
  42.         soap.createClient(url, options, function(err, client) {
  43.           client.loginCms(args, function(err, result) {
  44.             if (err) {
  45.               console.log('err', err)
  46.             } else {
  47.               console.log('result', result)
  48.             }
  49.  
  50.           });
  51.         });
  52.       });
  53.     }
  54.  
  55.   });
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement