Пример #1
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        //[STAThread]
        static void Main(string[] args)
        {
            Console.WriteLine("Is running.");
            VolatileStanSequencer _sequencer;
            Socket        _socket;
            AddressFamily _family;

            _sequencer = new VolatileStanSequencer();
            Iso8583Message echoMsg = new Iso8583Message(800);

            echoMsg.Fields.Add(Field3ProcCode, "990000");
            DateTime transmissionDate = DateTime.Now;

            echoMsg.Fields.Add(Field7TransDateTime, string.Format("{0}{1}", string.Format("{0:00}{1:00}", transmissionDate.Month, transmissionDate.Day), string.Format("{0:00}{1:00}{2:00}", transmissionDate.Hour, transmissionDate.Minute, transmissionDate.Second)));
            echoMsg.Fields.Add(Field11Trace, _sequencer.Increment().ToString());
            echoMsg.Fields.Add(Field24Nii, "101");
            echoMsg.Fields.Add(Field41TerminalCode, "12131415");
            echoMsg.Fields.Add(Field42MerchantCode, "000000852963  ");
            IMessageFormatter _formatter = new Iso8583Bin1987MessageFormatter();

            //formatterContext.GetData();
            echoMsg.Formatter = _formatter;
            //echoMsg.Formatter.Format(echoMsg, ref formatterContext);

            byte[] bBufferRecive;
            byte[] bBuffer = echoMsg.GetBytes();
            byte[] bHeader = Hex2Byte("6000018000");
            int    iTalla  = bBuffer.Length + bHeader.Length;

            byte[] bTalla = Hex2Byte(Convert.ToString(iTalla, 16).PadLeft(4, '0'));
            _family = AddressFamily.InterNetwork;
            _socket = new Socket(_family, SocketType.Stream, ProtocolType.Tcp);
            _socket.Connect("192.168.123.39", 9004);
            _socket.Send(bTalla);
            _socket.Send(bHeader);
            _socket.Send(bBuffer);
            Console.WriteLine(Byte2Hex(bTalla) + Byte2Hex(bHeader) + Byte2Hex(bBuffer));
            _socket.ReceiveTimeout = 10000;
            bBufferRecive          = new byte[_socket.ReceiveBufferSize];
            _socket.Receive(bBufferRecive);
            Hashtable ISO = TransaformaIso(bBufferRecive);

            byte[] bBody = (byte[])ISO["Body"];
            //FormatterContext formatterContext = new FormatterContext(FormatterContext.DefaultBufferSize);
            //formatterContext.Write(bBody);
            ParserContext _parserContext = new ParserContext(bBody.Length);

            _parserContext.Initialize();
            _parserContext.ResizeBuffer(bBody.Length);
            _parserContext.Write(bBody);

            Iso8583Message echoMsgResp = (Iso8583Message)echoMsg.Formatter.Parse(ref _parserContext);

            //echoMsg.Formatter.Format(echoMsg, ref formatterContext);
            Console.WriteLine(Byte2Hex(bBody));
            Console.WriteLine(echoMsgResp.ToString());
            _socket.Close();
            Console.ReadLine();
        }
Пример #2
0
        private byte[] TransformaISOByte(Iso8583Message isoMSG, String sTPDU)
        {
            byte[] bIsoByte = null;
            byte[] bBuffer  = isoMSG.GetBytes();
            byte[] bHeader  = UTILIDADES.Hex2Byte(sTPDU);
            int    iTalla   = bBuffer.Length + bHeader.Length;

            byte[] bTalla = UTILIDADES.Hex2Byte(Convert.ToString(iTalla, 16).PadLeft(4, '0'));
            bIsoByte = new byte[iTalla + 2];
            Buffer.BlockCopy(bTalla, 0, bIsoByte, 0, bTalla.Length);
            Buffer.BlockCopy(bHeader, 0, bIsoByte, bTalla.Length, bHeader.Length);
            Buffer.BlockCopy(bBuffer, 0, bIsoByte, bTalla.Length + bHeader.Length, bBuffer.Length);
            return(bIsoByte);
        }
Пример #3
0
        public String EnvioRequerimiento()
        {
            String         _respuesta = "";
            String         sError     = "";
            String         sPosteo;
            String         sFileName;
            String         sFecha;
            ParserContext  parserContext;
            Hashtable      ISO;
            Iso8583Message isoMsgResp;
            Socket         socket;

            byte[] bBody;
            byte[] bBufferRecive;
            byte[] bBufferEnvio;
            int    iLargoBody;

            if (this._trama.Length != _lengthTrama)
            {
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("POS   : " + "Longitud de trama Plana de requerimiento no es valida", "LogEvent", "log");
                }
                return("");
            }
            if (this._iGrabaLog == 1)
            {
                UTILIDADES.mensaje("INPUT METODO : " + UTILIDADES.ProtegeTramaPlana(_trama), "LogTracer", "log");
            }
            try
            {
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "Previo Socket", "LogEvent", "log");
                }
                socket = InicializaSocket();
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "Despues Socket", "LogEvent", "log");
                }
            }
            catch (System.Net.Sockets.SocketException e)
            {
                sError += e.Message;
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("POS   : " + e.Message, "LogEvent", "log");
                }
                throw new Exception(sError);
            }
            try
            {
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "Antes de ISO to BYTE", "LogEvent", "log");
                }
                bBufferEnvio = TransformaISOByte(_ISOMsg, "6000081000");
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "Despues de ISO to BYTE", "LogEvent", "log");
                }
            }
            catch (Exception e)
            {
                sError += e.Message;
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("POS   : " + e.Message, "LogEvent", "log");
                }
                throw new Exception(sError);
            }
            try
            {
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "Antes de Envio", "LogEvent", "log");
                }
                socket.Send(bBufferEnvio);
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "Despues de Envio", "LogEvent", "log");
                }
                if (this._iGrabaLog == 1)
                {
                    UTILIDADES.mensaje("OUTPUT DLL   : " + _ISOMsg.ToString(), "LogTracer", "log");
                }
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "TimeOut Definido", "LogEvent", "log");
                }
                socket.ReceiveTimeout = Convert.ToInt32(_timeoutPos);
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "TimeOut Definido", "LogEvent", "log");
                }
                bBufferRecive = new byte[socket.ReceiveBufferSize];
                socket.Receive(bBufferRecive);
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "Buffer recibido", "LogEvent", "log");
                }
                ISO = TransaformaIso(bBufferRecive);
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "Transforma buffer ISO", "LogEvent", "log");
                }
                bBody         = (byte[])ISO["Body"];
                iLargoBody    = bBody.Length;
                parserContext = new ParserContext(iLargoBody);
                parserContext.Initialize();
                parserContext.ResizeBuffer(iLargoBody);
                parserContext.Write(bBody);
                isoMsgResp = (Iso8583Message)_ISOMsg.Formatter.Parse(ref parserContext);
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "Finaliza buffer ISO", "LogEvent", "log");
                }
                if (this._iGrabaLog == 1)
                {
                    UTILIDADES.mensaje("INPUT DLL    : " + isoMsgResp.ToString(), "LogTracer", "log");
                }
            }
            catch (Exception e)
            {
                sError += e.Message;
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("DEBUG : " + "Excepcion :" + sError, "LogEvent", "log");
                }
                if (((Field)_ISOMsg.Fields[3]).Value.ToString().CompareTo("003000") == 0)
                {
                    try
                    {
                        if (this._iGrabaMsg == 1)
                        {
                            UTILIDADES.mensaje("DEBUG : " + "Inicia Posteo", "LogEvent", "log");
                        }
                        sPosteo = UTILIDADES.F3DESEncriptarBloque(UTILIDADES.padMultiplo(UTILIDADES.Byte2Hex(_ISOMsg.GetBytes()), 16, "1C"), _sLlaveKEKIzquierda, _sLlaveKEKDerecha);
                        if (this._iGrabaMsg == 1)
                        {
                            UTILIDADES.mensaje("DEBUG : " + "Finaliza cifrado", "LogEvent", "log");
                        }
                        sFecha = DateTime.Now.ToString("HHmmss");
                        String sRuta = UTILIDADES.AppPath(true) + "Saf\\";
                        if (this._iGrabaMsg == 1)
                        {
                            UTILIDADES.mensaje("DEBUG : " + "Valida Ruta de Posteo", "LogEvent", "log");
                        }
                        Directory.CreateDirectory(sRuta);
                        sFileName = Convert.ToString(_ISOMsg.MessageTypeIdentifier) + ((Field)_ISOMsg.Fields[11]).Value.ToString() + ((Field)_ISOMsg.Fields[41]).Value.ToString() + ((Field)_ISOMsg.Fields[112]).Value.ToString() + sFecha + ".saf";
                        //new GrabaArchivo(sFileName, sPosteo, false);
                        if (this._iGrabaMsg == 1)
                        {
                            UTILIDADES.mensaje("DEBUG : " + "Guarda Archivo de Posteo", "LogEvent", "log");
                        }
                        UTILIDADES.almacenarArchivo(sRuta, sFileName, false, sPosteo);
                        if (this._iGrabaMsg == 1)
                        {
                            UTILIDADES.mensaje("DEBUG : " + "Ejecuta Posteo", "LogEvent", "log");
                        }
                        new Posteo(_ip, _puerto, _timeoutPos, _iGrabaLog, _iGrabaMsg, _sLlaveKEKIzquierda, _sLlaveKEKDerecha, _formato);
                        if (this._iGrabaMsg == 1)
                        {
                            UTILIDADES.mensaje("DEBUG : " + "Finaliza Posteo", "LogEvent", "log");
                        }
                        if (socket != null)
                        {
                            socket.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        sError += "\t" + ex.Message;
                        if (this._iGrabaMsg == 1)
                        {
                            UTILIDADES.mensaje("POS   : " + ex.Message, "LogEvent", "log");
                        }
                    }
                }
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("POS   : " + e.Message, "LogEvent", "log");
                }
                throw new Exception(sError);
            }
            try
            {
                socket.Close();
            }
            catch (Exception e)
            {
                sError += e.Message;
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("POS   : " + e.Message, "LogEvent", "log");
                }
            }
            try
            {
                new Posteo(_ip, _puerto, _timeoutPos, _iGrabaLog, _iGrabaMsg, _sLlaveKEKIzquierda, _sLlaveKEKDerecha, _formato);
            }
            catch (Exception e)
            {
                sError += e.Message;
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("POS   : " + e.Message, "LogEvent", "log");
                }
            }
            try
            {
                _respuesta = camposTramaPlano(isoMsgResp);
            }
            catch (Exception e)
            {
                sError += e.Message;
                if (this._iGrabaMsg == 1)
                {
                    UTILIDADES.mensaje("POS   : " + e.Message, "LogEvent", "log");
                }
            }
            if (this._iGrabaLog == 1)
            {
                UTILIDADES.mensaje("OUTPUT METODO: " + _respuesta, "LogTracer", "log");
            }
            if (_respuesta.Length > 0)
            {
                return(_respuesta);
            }
            return("");
        }