Esempio n. 1
0
        public IActionResult TN_Service()
        {
            var     reader      = new StreamReader(Request.Body);
            var     Body        = reader.ReadToEnd();
            string  JsonContent = Body;
            var     ArrP        = JArray.Parse(JsonContent);
            var     ArrH        = JArray.Parse(ArrP[0].ToString());
            dynamic data        = JObject.Parse(ArrH[0].ToString());

            xmlData.SKU         = data.SKU;
            xmlData.PhoneNumber = data.Referencia;

            string service  = "getReloadClass";
            string response = "ReloadResponse";

            //Determinamos el tipo de servicio Saldo o Datos
            string[] prefixSku = xmlData.SKU.Split("-");

            var producto = _context.catalogos_Productos.First(a => a.SKU == xmlData.SKU);

            if (producto.IDProduct != "")
            {
                service            = "getReloadData";
                response           = "DataResponse";
                xmlData.ID_Product = producto.IDProduct;
            }
            xmlData.SKU = prefixSku[1];
            var credenciales = _context.conexion_Configs.Find(2);
            var item         = _context.conexion_Configs.Find(2);

            string[] credentials = new string[] { item.Url, item.Usr, item.Pwd };

            var      task        = Task.Run(() => { return(TNClass.Send_Request(service, xmlData, credentials)); });
            MyRelReq ResponseXml = new MyRelReq();

            try
            {
                var success = task.Wait(50000);
                if (!success)
                {
                    return(CR_TN_SERV(ResponseXml));
                }
                else
                {
                    ResponseXml = TNClass.Deserializer_Response(task.Result, service + "Result", response);
                }
            }
            catch (AggregateException ex)
            {
                throw ex.InnerException;
            }
            // 71 o 6
            if (ResponseXml.ResponseCode == "6" || ResponseXml.ResponseCode == "71")
            {
                return(CR_TN_SERV(ResponseXml));
            }


            return(Content(TNClass.jString(ResponseXml)));
        }
Esempio n. 2
0
        protected void SaveXML(MyRelReq xmlDatos)
        {
            var Transaction = _context.Set <Transaccion2>();

            Transaction.Add(
                new Transaccion2
            {
                SKU             = xmlDatos.SKU,
                ID_GRP          = xmlDatos.ID_GRP,
                ID_CHAIN        = xmlDatos.ID_CHAIN,
                ID_MERCHANT     = xmlDatos.ID_MERCHANT,
                ID_COUNTRY      = xmlDatos.ID_COUNTRY,
                ID_POS          = xmlDatos.ID_POS,
                ID_Product      = xmlDatos.ID_Product,
                Referencia      = xmlDatos.PhoneNumber,
                ID_CONFIG       = 2,
                Fecha           = xmlDatos.Datetime,
                TransNumber     = xmlDatos.TransNumber,
                TC              = xmlDatos.TC,
                Brand           = xmlDatos.Brand,
                Instr1          = xmlDatos.Instr1,
                Instr2          = xmlDatos.Instr2,
                ResponseCode    = xmlDatos.ResponseCode,
                DescripcionCode = xmlDatos.DescripcionCode,
                AutoNo          = xmlDatos.AutoNo,
                Monto           = Decimal.Parse(xmlDatos.Monto)
            }


                );
            _context.SaveChanges();
        }
        public MyRelReq Deserializer_Response(string xml, string path, string response)
        {
            XmlDocument xmldoc = new XmlDocument();

            xmldoc.LoadXml(xml);
            XmlNodeList nodeList = xmldoc.GetElementsByTagName(path);

            foreach (XmlNode node in nodeList)
            {
                xml = node.InnerText;
            }
            xml = xml.Replace(response, "MyRelReq");
            xmldoc.LoadXml(Un_ScapeXML(xml));
            nodeList = xmldoc.GetElementsByTagName("ResponseCode");

            XmlSerializer xmls = new XmlSerializer(typeof(MyRelReq));

            byte[]       byteArray = Encoding.UTF8.GetBytes(xml);
            MemoryStream stream    = new MemoryStream(byteArray);

            StreamReader sr     = new StreamReader(stream);
            MyRelReq     modelo = (MyRelReq)xmls.Deserialize(sr);

            return(modelo);
        }
        public string Send_Request(string servicio, MyRelReq xmlQuery, string[] credencial)
        {
            // Crea el xml de acuerdo  al procesos, ya sea  Recarga o consulta
            var sXML = Get_XMLs(xmlQuery, servicio);

            HttpWebRequest webRequest = CreateWebRequest(credencial[0], "http://www.pagoexpress.com.mx/ServicePX/" + servicio, credencial[1], credencial[2]);

            XmlDocument soapEnvelopeXml = CreateSoapEnvelope(servicio, sXML);

            InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);
            IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);

            asyncResult.AsyncWaitHandle.WaitOne();
            string soapResult = "";

            using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
            {
                using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
                {
                    soapResult = rd.ReadToEnd();
                }
                //Thread.Sleep(20000);
            }
            return(soapResult);
        }
        //Serializa en Objeto el xml de respuesta

        private string ReloadValidation(MyRelReq xml)
        {
            if (xml.PhoneNumber.ToString().Length > 10)
            {
                return("PhoneNumber lenght es mayor a 10");
            }

            return(null);
        }
Esempio n. 6
0
        public IActionResult CR_TN_SERV(MyRelReq ResponseXml)
        {
            var     reader      = new StreamReader(Request.Body);
            var     Body        = reader.ReadToEnd();
            string  JsonContent = Body;
            var     ArrP        = JArray.Parse(JsonContent);
            var     ArrH        = JArray.Parse(ArrP[0].ToString());
            dynamic data        = JObject.Parse(ArrH[0].ToString());

            xmlData.SKU         = data.SKU;
            xmlData.PhoneNumber = data.Referencia;



            // string a = Metodo(xmlData);
            string service  = "getQueryClass";
            string response = "QueryResponse";

            //Si existe producto desde la BD lo agrega
            if (xmlData.ID_Product != null)
            {
                service  = "getQueryDatClass";
                response = "DataQueryResponse";
            }
            //   MyRelReq ResponseXml = new MyRelReq();

            xmlData.Datetime = DateTime.Now;
            var item = _context.conexion_Configs.Find(2);

            //string xml = GetResponse(service, xmlData);

            string[] credentials = new string[] { item.Url, item.Usr, item.Pwd };
            var      task        = Task.Run(() => { return(TNClass.Send_Request(service, xmlData, credentials)); });

            try
            {
                var success = task.Wait(50000);
                if (!success)
                {
                    return(Content("Lo sentimos el servicio tardo mas de los esperado :( "));
                }
                else
                {
                    ResponseXml = TNClass.Deserializer_Response(task.Result, service + "Result", response);
                }
            }
            catch (AggregateException ex)
            {
                throw ex.InnerException;
            }
            return(Content(TNClass.jString(ResponseXml)));
        }
        //----------------------------------------------------------

        public string jString(MyRelReq ResponseXml)
        {
            string jsonFormat =
                "[" +
                "{\"sCampo\":\"" + nameof(ResponseXml.ID_GRP) + "\", \"iTipo\":0, \"iLongitud\":0, \"iClase\":0, \"sValor\":\"" + ResponseXml.ID_GRP + "\", \"bEncriptado\":false}," +
                "{\"sCampo\":\"ID_CHAIN\", \"iTipo\":0, \"iLongitud\":0, \"iClase\":0, \"sValor\":\"" + ResponseXml.ID_CHAIN + "\", \"bEncriptado\":false}," +
                "{\"sCampo\":\"ID_MERCHANT\", \"iTipo\":0, \"iLongitud\":0, \"iClase\":0, \"sValor\":\"" + ResponseXml.ID_MERCHANT + "\", \"bEncriptado\":false}," +
                "{\"sCampo\":\"ID_POS\", \"iTipo\":0, \"iLongitud\":0, \"iClase\":0, \"sValor\":\"" + ResponseXml.ID_POS + "\", \"bEncriptado\":false}," +
                "{\"sCampo\":\"DateTime\", \"iTipo\":0, \"iLongitud\":0, \"iClase\":0, \"sValor\":\"" + ResponseXml.Datetime + "\", \"bEncriptado\":false}," +
                "{\"sCampo\":\"PhoneNumber\", \"iTipo\":0, \"iLongitud\":0, \"iClase\":0, \"sValor\":\"" + ResponseXml.PhoneNumber + "\", \"bEncriptado\":false}," +
                "{\"sCampo\":\"TransNumber\", \"iTipo\":0, \"iLongitud\":0, \"iClase\":0, \"sValor\":\"" + ResponseXml.TransNumber + "\", \"bEncriptado\":false}," +
                "{\"sCampo\":\"ID_Product\", \"iTipo\":0, \"iLongitud\":0, \"iClase\":0, \"sValor\":\"" + ResponseXml.ID_Product + "\", \"bEncriptado\":false}," +
                "{\"sCampo\":\"Brand\", \"iTipo\":0, \"iLongitud\":0, \"iClase\":0, \"sValor\":\"" + ResponseXml.Brand + "\", \"bEncriptado\":false}," +
                "{\"sCampo\":\"Instr1\", \"iTipo\":0, \"iLongitud\":0, \"iClase\":0, \"sValor\":\"" + ResponseXml.Instr1 + "\", \"bEncriptado\":false}," +
                "{\"sCampo\":\"Instr2\", \"iTipo\":0, \"iLongitud\":0, \"iClase\":0, \"sValor\":\"" + ResponseXml.Instr2 + "\", \"bEncriptado\":false}," +
                "{\"sCampo\":\"AutoNo\", \"iTipo\":0, \"iLongitud\":0, \"iClase\":0, \"sValor\":\"" + ResponseXml.AutoNo + "\", \"bEncriptado\":false}," +
                "{\"sCampo\":\"ResponseCode\", \"iTipo\":0, \"iLongitud\":0, \"iClase\":0, \"sValor\":\"" + ResponseXml.ResponseCode + "\", \"bEncriptado\":false}," +
                "{\"sCampo\":\"DescripcionCode\", \"iTipo\":0, \"iLongitud\":0, \"iClase\":0, \"sValor\":\"" + ResponseXml.DescripcionCode + "\", \"bEncriptado\":false}," +
                "{\"sCampo\":\"Monto\", \"iTipo\":0, \"iLongitud\":0, \"iClase\":0, \"sValor\":\"" + ResponseXml.Monto + "\", \"bEncriptado\":false}" +
                "]";

            return(jsonFormat);
        }