示例#1
0
        //direct topup progress
        //ChungNN 26/11/2008
        public OutputInfo load(string UserName, string Session_ID, string Request_ID, string MerchantID, string targetMsIsdn, Int32 amount)
        {
            //targetMsIsdn: so thue bao can nap tien (vd: 0912368466)
            //amount:       so tien can nap (vd: 10000)

            Security   secObj = new Security();
            OutputInfo retObj = new OutputInfo();

            EPaySoap.TransferProcess proObj = new EPaySoap.TransferProcess();

            string strUserName = UserName.Trim();
            string strSession_ID = Session_ID.Trim();
            string strRequest_ID = Request_ID.Trim();
            string strMerchantID = MerchantID.Trim();
            string strtargetMsIsdn = targetMsIsdn.Trim();
            string strProviderCode = string.Empty;
            string strRequest_Time, strResponse_Time;

            retObj = secObj.CheckValid(strUserName, strSession_ID, strRequest_ID, strMerchantID, strtargetMsIsdn, amount, ref strProviderCode);

            //if login failure (status in(1,2,3,4,5))
            if (retObj.status != "0")
            {
                return(retObj);
            }

            //If login successfull
            else
            {
                //log pending status before load
                strRequest_Time = DateTime.Now.ToString();
                proObj.WriteLog_Load(strUserName, strSession_ID, strRequest_ID, strMerchantID, HttpContext.Current.Request.UserHostAddress, "2", "", "0x200", strtargetMsIsdn, amount, "", "", strRequest_Time, strRequest_Time, "00", "log before load", strProviderCode);

                switch (strProviderCode)
                {
                    #region Vinaphone
                case "01":
                    try
                    {
                        //process transfer for VinaPhone e-load system
                        strRequest_Time = DateTime.Now.ToString();
                        retObj          = proObj.VinaLoad(strMerchantID, strtargetMsIsdn, amount);
                        //Thread.Sleep(AppConfiguration.VinaPhoneTimeout);

                        //log load result
                        strResponse_Time = DateTime.Now.ToString();
                        proObj.WriteLog_Load(strUserName, strSession_ID, strRequest_ID, strMerchantID, HttpContext.Current.Request.UserHostAddress, retObj.status, retObj.trans_id, "0x200", strtargetMsIsdn, amount, "", "", strRequest_Time, strResponse_Time, "00", "message=" + retObj.message, strProviderCode);
                    }
                    catch (Exception ex)
                    {
                        strResponse_Time = DateTime.Now.ToString();
                        retObj.status    = "6";
                        retObj.message   = "Fail, occur an exception.";
                        proObj.WriteLog("load on VinaPhone ( targetMsIsdn=" + targetMsIsdn + ", amount = " + amount.ToString() + " ) failure." + Environment.NewLine + "Exception=" + ex.ToString());
                        proObj.WriteLog_Load(strUserName, strSession_ID, strRequest_ID, strMerchantID, HttpContext.Current.Request.UserHostAddress, "1", retObj.trans_id, "0x200", strtargetMsIsdn, amount, "", "", strRequest_Time, strResponse_Time, "01", "Fail, occur an exception.", strProviderCode);
                    }
                    break;
                    #endregion

                    #region Viettel
                case "02":
                    try
                    {
                        //add "84" prefix if Viettel
                        if (strtargetMsIsdn.Substring(0, 1) != "84")
                        {
                            strtargetMsIsdn = "84" + strtargetMsIsdn.Substring(1, strtargetMsIsdn.Length - 2);
                        }

                        //process transfer for Viettel topup system
                        OutputVTload OutputVTObj = new OutputVTload();
                        retObj = proObj.ViettelLoad(strMerchantID, strtargetMsIsdn, amount, OutputVTObj);
                        //Thread.Sleep(AppConfiguration.VinaPhoneTimeout);

                        //log load result
                        proObj.WriteLog_Load(strUserName, strSession_ID, strRequest_ID, strMerchantID, HttpContext.Current.Request.UserHostAddress, retObj.status, retObj.trans_id, "0x200", strtargetMsIsdn, amount, AppConfiguration.ViettelClientID, "", OutputVTObj.request_transaction_time, OutputVTObj.response_transaction_time, OutputVTObj.response_code, "message=" + retObj.message, strProviderCode);
                    }
                    catch (Exception ex)
                    {
                        strResponse_Time = DateTime.Now.ToString();
                        retObj.status    = "6";
                        retObj.message   = "Fail, occur an exception.";
                        proObj.WriteLog("load on Viettel ( targetMsIsdn=" + targetMsIsdn + ", amount = " + amount.ToString() + " ) failure." + Environment.NewLine + "Exception=" + ex.ToString());
                        proObj.WriteLog_Load(strUserName, strSession_ID, strRequest_ID, strMerchantID, HttpContext.Current.Request.UserHostAddress, "1", retObj.trans_id, "0x200", strtargetMsIsdn, amount, "", "", strRequest_Time, strResponse_Time, "01", "Fail, occur an exception.", strProviderCode);
                    }
                    break;
                    #endregion

                    #region Mobifone
                case "03":
                    try
                    {
                        //process transfer for Viettel MobiEz system
                        strRequest_Time = DateTime.Now.ToString();
                        retObj          = proObj.MobiLoad(strMerchantID, targetMsIsdn, (decimal)amount);

                        //log load result
                        strResponse_Time = DateTime.Now.ToString();
                        proObj.WriteLog_Load(strUserName, strSession_ID, strRequest_ID, strMerchantID, HttpContext.Current.Request.UserHostAddress, retObj.status, retObj.trans_id, "0x200", strtargetMsIsdn, amount, "", "", strRequest_Time, strResponse_Time, "00", "message=" + retObj.message, strProviderCode);
                    }
                    catch (Exception ex)
                    {
                        strResponse_Time = DateTime.Now.ToString();
                        retObj.status    = "6";
                        retObj.message   = "Fail, occur an exception.";
                        proObj.WriteLog("load on Mobifone ( targetMsIsdn=" + targetMsIsdn + ", amount = " + amount.ToString() + " ) failure." + Environment.NewLine + "Exception=" + ex.ToString());
                        proObj.WriteLog_Load(strUserName, strSession_ID, strRequest_ID, strMerchantID, HttpContext.Current.Request.UserHostAddress, "1", retObj.trans_id, "0x200", strtargetMsIsdn, amount, "", "", strRequest_Time, strResponse_Time, "01", "Fail, occur an exception.", strProviderCode);
                    }
                    break;
                    #endregion

                default:
                    retObj.status  = "1";
                    retObj.message = "invalid provider.";
                    break;
                }
            }

            return(retObj);
        }
示例#2
0
        //Input:    UserName, Session_ID
        //ChungNN - 01/2009
        public OutputInfo CheckValid(string UserName, string Session_ID, string Request_ID, string MerchantID, string targetMsIsdn, Int32 amount, ref string ProviderCode)
        {
            OutputInfo      outObj        = new OutputInfo();
            TransferProcess proObj        = new TransferProcess();
            HttpApplication appObj        = new HttpApplication();
            string          strIPAddress  = HttpContext.Current.Request.UserHostAddress;
            string          strSession_ID = Session_ID;
            byte            nErrorNum     = 0;
            string          strLogMessage = string.Empty;

            //0: Successful
            //1: Invalid userName or Session_ID
            //2: Invalid IP Address
            //3: Invalid targetMsIsdn or provider is not exist
            //4: Request_ID is exist
            //5: Invalid amount


            DataSet   dsDataList = new DataSet();
            DataTable tblResult  = new DataTable();

            #region Check username and Session_ID.
            nErrorNum = 1;
            //check username and password is null?
            if (UserName != null && Session_ID != null)
            {
                //check if sessionid is existed
                if (ServiceSessionManager.GetSessionInstance().IsExistedSession(UserName, Session_ID))
                {
                    nErrorNum = 0;
                }
            }
            #endregion Check username and Session_ID

            #region Check IP address if login successfull

            if (nErrorNum == 0)
            {
                nErrorNum = (byte)((Check_Valid_IPAddress(strIPAddress)? 0:2));
            }
            #endregion Check IP address if login successfull

            #region Check valid targetMsIsdn
            if (nErrorNum == 0)
            {
                dsDataList = null;
                dsDataList = Xml_2_DateSet(HttpContext.Current.Server.MapPath("") + "\\" + AppConfiguration.AppData_FileName);
                tblResult  = dsDataList.Tables["ProviderList"];
                HttpContext hc = HttpContext.Current;

                if (targetMsIsdn.Length < 10 || targetMsIsdn.Length > 15)
                {
                    nErrorNum = 3;
                }
                //if no provider to check
                else if (tblResult.DefaultView.Count == 0)
                {
                    nErrorNum = 3;
                }
                else
                {
                    nErrorNum = 3;
                    string strPrefix = string.Empty;
                    for (int i = 0; i < tblResult.DefaultView.Count; i++)
                    {
                        strPrefix = tblResult.DefaultView[i].Row["Prefix"].ToString();
                        if (targetMsIsdn.IndexOf(strPrefix, 0, strPrefix.Length) != -1)
                        {
                            nErrorNum    = 0;
                            ProviderCode = tblResult.DefaultView[i].Row["ProviderCode"].ToString().Trim();
                            break;
                        }
                    }
                }

                tblResult  = null;
                dsDataList = null;
            }

            #endregion Check valid targetMsIsdn

            #region Check valid acmount

            if (nErrorNum == 0)
            {
                if (Array.IndexOf(AppConfiguration.AppAmountArray, amount) == -1)
                {
                    nErrorNum = 5;
                }
            }

            #endregion Check valid acmount

            #region Check valid Request_ID

            if (nErrorNum == 0)
            {
                if (UserName != null && Request_ID != null)
                {
                    //check if Request_ID is existed
                    if (ServiceRequestManager.GetInstance().IsContainRequest(Request_ID, UserName))
                    {
                        nErrorNum = 4;
                    }
                    else
                    {
                        ServiceRequestManager.GetInstance().AddRequest(Request_ID, UserName);
                        nErrorNum = 0;
                    }
                }
            }

            #endregion Check valid Trans_ID

            #region return and log

            if (nErrorNum == 0)
            {
                outObj.status = "0";
                //outObj.message = "Login successfull.";
                //strLogMessage = "Login EPay sucessfull. (RequestID=" + Request_ID + ", UserName="******", IPAddress=" + strIPAddress + ")";
            }
            else
            {
                outObj.status   = nErrorNum.ToString();
                outObj.trans_id = "0";

                if (nErrorNum == 1)
                {
                    outObj.message = "Invalid user name or session_id.";
                    strLogMessage  = "Load fail, invalid user name or session_id. (RequestID=" + Request_ID + ", UserName="******", IPAddress=" + strIPAddress + ")";
                }
                else if (nErrorNum == 2)
                {
                    outObj.message = "Invalid IP address.";
                    strLogMessage  = "Load failure, invalid IP address. (RequestID=" + Request_ID + ", UserName="******", IPAddress=" + strIPAddress + ")";
                }
                else if (nErrorNum == 3)
                {
                    outObj.message = "Invalid phone number or service provider not exist.";
                    strLogMessage  = "Load failure, invalid targetMsIsdn or provider is not exist. (RequestID=" + Request_ID + ", UserName="******", IPAddress=" + strIPAddress + ")";
                }
                else if (nErrorNum == 4)
                {
                    outObj.message = "Request_ID is exist.";
                    strLogMessage  = "Load failure, request_id is exist. (RequestID=" + Request_ID + ", UserName="******", IPAddress=" + strIPAddress + ")";
                }
                else if (nErrorNum == 5)
                {
                    outObj.message = "Invalid amount." + amount.ToString();
                    strLogMessage  = "Load failure, ivalid amount. (RequestID=" + Request_ID + ", UserName="******", IPAddress=" + strIPAddress + ")";
                }

                //write log if error
                proObj.WriteLog(strLogMessage);
            }


            #endregion return and log

            return(outObj);
        }