Exemple #1
0
        static void Main(string[] args)
        {
            //EPAY_POS_GateWay.Proccess.TopupInterface ttt = new EPAY_POS_GateWay.Proccess.TopupInterface();
            //ttt.testTopupInterface();

            Transaction transObj       = new Transaction();
            TcpListener TcpListenerObj = new TcpListener(String2IPAddress(AppConfiguration.Server_IP_Address), AppConfiguration.Server_Port);

            //TcpListener TcpListenerObj = new TcpListener(9999);
            try
            {
                TcpListenerObj.Start();
            }
            catch (Exception ex)
            {
                transObj.WriteLog("Fail to start server(" + AppConfiguration.Server_IP_Address + "), port(" + AppConfiguration.Server_Port.ToString() + "), ex=" + ex.ToString());
            }

            transObj.WriteLog("EPAY_POS_GateWay Started at " + DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss:tt"));
            transObj.WriteLog("IP Address: " + AppConfiguration.Server_IP_Address + "), Port: " + AppConfiguration.Server_Port.ToString());
            transObj.WriteLog("Received messages:");

            try
            {
                mfact = new MessageFactory();
                //@"D:\Working\Projects\pTopup\sources\POS_Gateway\POS_GW_Console\EPAY_POS_GateWay\POSConfig_ISOFile.xml"
                mfact = ConfigParser.CreateFromFile(AppConfiguration.App_Path + AppConfiguration.POSConfig_ISOFile);
            }
            catch (Exception ex)
            {
                transObj.WriteLog("Fail to load ISO config, ex=" + ex.ToString());
            }

            //transObj.WriteLog("test interface");
            //Proccess.TopupInterface TopupObj = new EPAY_POS_GateWay.Proccess.TopupInterface();
            //TopupObj.testTopupInterface();
            int nMessageCounter = 0;

            while (true)
            {
                try
                {
                    TcpClient client = TcpListenerObj.AcceptTcpClient();
                    Server    sproc  = new Server(client);
                    nMessageCounter++;
                    Console.Out.Write(nMessageCounter.ToString() + ". (" + DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss:tt") + ")");
                    new Thread(new ThreadStart(sproc.Listen)).Start();
                }
                catch (Exception ex)
                {
                    transObj.WriteLog("Fail to listen client, ex=" + ex.ToString());
                }

                //Console.ReadLine();
            }
        }
Exemple #2
0
        /// <summary>
        /// SignOn/Off as POS
        /// ChungNN 03/2009
        /// </summary>
        /// <param name="request">IsoMessage</param>
        /// <returns>IsoMessage</returns>
        public IsoMessage PosSignOnOff(IsoMessage request)
        {
            topupObj = new TopupInterface();
            mfact    = new MessageFactory();
            mfact    = ConfigParser.CreateFromFile(AppConfiguration.App_Path + AppConfiguration.POSConfig_ISOFile);
            IsoMessage response = mfact.CreateResponse(request);

            string strRequestCode      = request.GetField(70).Value.ToString();
            int    nPos_ID             = int.Parse(request.GetField(52).Value.ToString());
            string strPosAdminPassword = request.GetField(48).Value.ToString();
            string strRequest          = request.GetField(11).Value.ToString();

            try
            {
                //Signon
                if (strRequestCode == "001")
                {
                    if (topupObj.PosLogon(nPos_ID, ref strRequest, strPosAdminPassword))
                    {
                        mfact.Setfield(11, strRequest, ref response);
                        mfact.Setfield(39, "00", ref response);
                        transObj.WriteLog("->POS signon(" + request.GetField(52).Value.ToString() + "|" + request.GetField(48).Value.ToString() + ") successfull");
                    }
                    else
                    {
                        mfact.Setfield(11, request.GetField(11), ref response);
                        mfact.Setfield(39, "01", ref response);
                        transObj.WriteLog("->POS signon(" + request.GetField(52).Value.ToString() + "|" + request.GetField(48).Value.ToString() + ") fail");
                    }
                }
                //Signoff
                else if (strRequestCode == "002")
                {
                    if (topupObj.PosLogout(nPos_ID, strRequest))
                    {
                        mfact.Setfield(11, request.GetField(11), ref response);
                        mfact.Setfield(39, "00", ref response);
                        transObj.WriteLog("->POS Signof successfull");
                    }
                    else
                    {
                        mfact.Setfield(11, request.GetField(11), ref response);
                        mfact.Setfield(39, "01", ref response);
                        transObj.WriteLog("->POS Signof fail");
                    }
                }

                //Key Exchange
                else if (strRequestCode == "161")
                {
                    transObj.WriteLog("->POS Key Exchange");
                }
            }
            catch (Exception ex)
            {
                transObj.WriteLog("->Exception=" + ex.Message);
                mfact.Setfield(39, "01", ref response);
            }

            mfact.Setfield(7, DateTime.Now.ToString("ddMMhhmmss"), ref response);

            return(response);
        }
Exemple #3
0
        //private static bool SendMessage(string MSISDN, Int32 Amount, string Counter)
        public bool SendMessage(string MSISDN, Int32 Amount, string Counter, ref OutputVTload OutputVTObj)
        {
            //Send ISO message to VietTel Topup Gateway
            //ChungNN 02/2009 --------
            //----------------------------------------
            TransferProcess transObj       = new TransferProcess();
            bool            blnReturnValue = false;

            try
            {
                Encrypt.DigitalSign SignObj = new DigitalSign(AppConfiguration.AppPath + AppConfiguration.ViettelCerFilePath, AppConfiguration.AppPath + AppConfiguration.AppRSAPrivateKeyFilePath, AppConfiguration.AppRSAPrivateKeyPassword);
                string strDigitalSign       = string.Empty;


                MessageFactory mfact = ConfigParser.CreateFromFile(AppConfiguration.AppPath + AppConfiguration.ViettelConfig_ISOFile);
                mfact.AssignDate = true;
                //mfact.TraceGenerator = new i
                IsoMessage m = null;
                TcpClient  sock;

                byte[] lenbuf = new byte[1024];
                try
                {
                    sock = new TcpClient(AppConfiguration.ViettelServerAddress, AppConfiguration.ViettelServerPort);
                }
                catch
                {
                    return(blnReturnValue);
                    //throw (ex);
                }
                if ((sock == null) || !sock.Connected)
                {
                    return(blnReturnValue);
                }

                //if (MSISDN.Substring(0, 2) != "84")
                //    MSISDN = "84" + MSISDN;

                //fill ISO8583 message fields
                m = mfact.NewMessage(0x200);
                mfact.Setfield(2, MSISDN, ref m);
                mfact.Setfield(3, 0, ref m);
                mfact.Setfield(4, Amount, ref m);
                mfact.Setfield(7, DateTime.Now.ToString("yyyyMMddHHMMss"), ref m);
                mfact.Setfield(11, Counter, ref m);
                mfact.Setfield(63, AppConfiguration.ViettelClientID, ref m);

                //create Digital Signature
                if (m.HasField(2) && m.GetField(2) != null)
                {
                    strDigitalSign += m.GetField(2).ToString();
                }
                if (m.HasField(3) && m.GetField(3) != null)
                {
                    strDigitalSign += m.GetField(3).ToString();
                }
                if (m.HasField(4) && m.GetField(4) != null)
                {
                    strDigitalSign += m.GetField(4).ToString();
                }
                if (m.HasField(7) && m.GetField(7) != null)
                {
                    strDigitalSign += m.GetField(7).ToString();
                }
                if (m.HasField(11) && m.GetField(11) != null)
                {
                    strDigitalSign += m.GetField(11).ToString();
                }
                if (m.HasField(63) && m.GetField(63) != null)
                {
                    strDigitalSign += m.GetField(63).ToString();
                }

                OutputVTObj.request_transaction_time = m.GetField(7).ToString();
                //verify du lieu nhan dc tu server
                //SignObj._VerifyData("123456", strOub);

                //sign du lieu truoc khi gui di
                SignObj._signData(strDigitalSign, ref strDigitalSign);

                mfact.Setfield(64, strDigitalSign, ref m);
                m.Write(sock.GetStream(), 4, false);

                //<field num="2" type="LLVAR" length="0" />     <!--MSISDN-->
                //<field num="3" type="NUMERIC" length="6" />     <!--Processing Code-->
                //<field num="4" type="NUMERIC" length="12" />    <!--Transaction Amount-->
                //<field num="7" type="NUMERIC" length="14"/>     <!--Transmission Date & Time-->
                //<field num="11" type="NUMERIC" length="15" />   <!--System Trace Audit Number-->
                //<field num="39" type="NUMERIC" length="2" />    <!--Response Code-->
                //<field num="63" type="LLVAR" length="0" />      <!--Client ID-->
                //<field num="64" type="LLLVAR" length="0" />     <!--Message Signature-->

                //send ISO8583 message
                //Console.Out.Write(Encoding.ASCII.GetString(m.getByte(4, false)));

                Thread.Sleep(AppConfiguration.ViettelTimeout);

                while ((sock != null) && sock.Connected == true)
                {
                    try
                    {
                        Thread.Sleep(1000);
                        if (sock.GetStream().Read(lenbuf, 0, 4) == 4)
                        {
                            int size, k;
                            size = 0;

                            for (k = 0; k < 4; k++)
                            {
                                size = size + (int)(lenbuf[k] - 48) * (int)(Math.Pow(10, 3 - k));
                            }

                            byte[] buf = new byte[size + 1];
                            //We're not expecting ETX in this case
                            sock.GetStream().Read(buf, 0, buf.Length);

                            //Console.Out.Write(Encoding.ASCII.GetString(buf));
                            IsoMessage incoming = mfact.ParseMessage(buf, 0);

                            if (Convert.ToInt16(incoming.GetField(39).Value) == 0)
                            {
                                blnReturnValue = true;
                                //Ghi giao dich phuc vu doi soat
                                OutputVTObj.response_transaction_time = incoming.GetField(7).ToString();  //Response Transmission Time
                                OutputVTObj.response_code             = incoming.GetField(39).ToString(); //Response Code
                            }
                            else
                            {
                                //Ghi giao dich phuc vu doi soat
                                OutputVTObj.response_transaction_time = incoming.GetField(7).ToString();  //Response Transmission Time
                                OutputVTObj.response_code             = incoming.GetField(39).ToString(); //Response Code
                                blnReturnValue = true;
                            }
                        }
                        else
                        {
                            OutputVTObj.response_transaction_time = ""; //Response Transmission Time
                            OutputVTObj.response_code             = ""; //Response Code
                            blnReturnValue = false;
                        }
                    }
                    catch
                    {
                        //Console.Out.Write(ex.ToString());
                        blnReturnValue = false;
                    }
                }
            }
            catch //(Exception ex)
            {
                blnReturnValue = false;
            }

            return(blnReturnValue);
        }
Exemple #4
0
        /// <summary>
        /// POS download softpin
        /// ChungNN 03/2009
        /// </summary>
        /// <param name="request">IsoMessage</param>
        /// <returns>IsoMessage</returns>
        public IsoMessage Download(IsoMessage request)
        {
            topupObj = new TopupInterface();

            //create response message
            mfact = new MessageFactory();
            mfact = ConfigParser.CreateFromFile(AppConfiguration.App_Path + AppConfiguration.POSConfig_ISOFile);
            IsoMessage response            = mfact.CreateResponse(request);
            bool       blnDownloadTemplate = !request.HasField(48);
            string     strRequest          = request.GetField(11).Value.ToString();
            int        nMerchant_ID        = int.Parse(request.GetField(2).Value.ToString());
            int        nPos_ID             = int.Parse(request.GetField(52).Value.ToString());

            //if exist session
            if (!Common.ServiceSessionManager.GetSessionInstance().IsExistedSession(nPos_ID.ToString(), strRequest))
            {
                mfact.Setfield(39, "01", ref response);
                transObj.WriteLog("->download fail, session not exist");
            }
            else
            {
                //Download template
                if (blnDownloadTemplate)
                {
                    try
                    {
                        //get request values
                        topupObj = new TopupInterface();
                        BatchBuyObject buyObj = new BatchBuyObject();

                        //String[] arrRequestValues = request.GetField(48).Value.ToString().Split(AppConfiguration.POS_Seperator_Char);
                        //string strCategoryName = arrRequestValues[0];
                        //string strServiceProviderName = arrRequestValues[1];
                        //int nProductValue = int.Parse(arrRequestValues[2]);
                        //int nStockQuantity = int.Parse(arrRequestValues[3]);
                        //int nDownloadQuantity = int.Parse(arrRequestValues[4]);

                        object[] SoftpinStock = new object[1];

                        StockObject stockObj = new StockObject();
                        stockObj.ProductValue        = 10000;
                        stockObj.CategoryName        = "Thẻ ĐTDĐ";
                        stockObj.ServiceProviderName = "Vinaphone";
                        stockObj.StockQuantity       = 0;
                        SoftpinStock[0] = stockObj;

                        buyObj = topupObj.PosDownloadSoftpinTemplate(nPos_ID, nMerchant_ID, strRequest, SoftpinStock);

                        if (buyObj.ErrorCode == 0)
                        {
                            mfact.Setfield(39, "00", ref response);
                            transObj.WriteLog("->download template successfull");
                        }
                        else
                        {
                            mfact.Setfield(39, "01", ref response);
                            transObj.WriteLog("->download template fail");
                        }
                    }
                    catch (Exception ex)
                    {
                        transObj.WriteLog("->download template execption =" + ex.ToString());
                        throw (ex);
                    }
                }
                //Download single
                else
                {
                    try
                    {
                        //get request values
                        topupObj = new TopupInterface();
                        BatchBuyObject buyObj = new BatchBuyObject();

                        String[] arrRequestValues       = request.GetField(48).Value.ToString().Split(AppConfiguration.POS_Seperator_Char);
                        string   strCategoryName        = arrRequestValues[0];
                        string   strServiceProviderName = arrRequestValues[1];
                        int      nProductValue          = int.Parse(arrRequestValues[2]);
                        int      nStockQuantity         = int.Parse(arrRequestValues[3]);
                        int      nDownloadQuantity      = int.Parse(arrRequestValues[4]);

                        buyObj = topupObj.PosDownloadSingleSoftpin(nPos_ID, nMerchant_ID, strRequest, strCategoryName, strServiceProviderName, nProductValue, nStockQuantity, nDownloadQuantity);

                        if (buyObj.ErrorCode == 0)
                        {
                            mfact.Setfield(39, "00", ref response);
                            transObj.WriteLog("->download single successfull");
                        }
                        else
                        {
                            mfact.Setfield(39, "01", ref response);
                            transObj.WriteLog("->download single fail");
                        }

                        //create response message
                        mfact    = new MessageFactory();
                        mfact    = ConfigParser.CreateFromFile(AppConfiguration.App_Path + AppConfiguration.POSConfig_ISOFile);
                        response = mfact.CreateResponse(request);
                    }
                    catch (Exception ex)
                    {
                        transObj.WriteLog("->download single execption =" + ex.ToString());
                        throw (ex);
                    }
                }
            }

            return(response);
        }