Ejemplo n.º 1
0
        public string ConsultaCFDIRelacionadosRequest(string RfcPacEnviaSolicitud, string RfcReceptor, string RfcEmisor, string Uuid)
        {
            AccesoServicios ser           = new AccesoServicios();
            IList           uuidsCancelar = new List <string>();

            uuidsCancelar.Add(Uuid.ToUpper());
            string result;

            using (new NtLinkLocalServiceEntities())
            { string        path = "";
              NtLinkEmpresa nle  = new NtLinkEmpresa();
              if (!string.IsNullOrEmpty(RfcEmisor))
              {
                  empresa empresa = nle.GetByRfc(RfcEmisor);
                  SAT.CFDI.Cliente.Procesamiento.Encabezado encLMetadata2 = new SAT.CFDI.Cliente.Procesamiento.Encabezado(RfcEmisor, this.FechaHoy(), uuidsCancelar);
                  path = Path.Combine(ConfigurationManager.AppSettings["Resources"], RfcEmisor);
                  string pathCer = Path.Combine(path, "Certs", "csd.cer");
                  string pathKey = Path.Combine(path, "Certs", "csd.key");
                  string pass    = empresa.PassKey;
                  SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignatureType asignature = ser.Asignature(pathKey, encLMetadata2, pass, pathCer);
                  result = ser.ConsultaCFDIRelacionadosRequest(RfcPacEnviaSolicitud, RfcReceptor, RfcEmisor, Uuid, asignature);
              }
              else
              {
                  empresa empresa = nle.GetByRfc(RfcReceptor);
                  SAT.CFDI.Cliente.Procesamiento.Encabezado encLMetadata2 = new SAT.CFDI.Cliente.Procesamiento.Encabezado(RfcReceptor, this.FechaHoy(), uuidsCancelar);
                  path = Path.Combine(ConfigurationManager.AppSettings["Resources"], RfcReceptor);
                  string pathCer = Path.Combine(path, "Certs", "csd.cer");
                  string pathKey = Path.Combine(path, "Certs", "csd.key");
                  string pass    = empresa.PassKey;
                  SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignatureType asignature = ser.Asignature(pathKey, encLMetadata2, pass, pathCer);
                  result = ser.ConsultaCFDIRelacionadosRequest(RfcPacEnviaSolicitud, RfcReceptor, RfcEmisor, Uuid, asignature);
              } }
            return(result);
        }
Ejemplo n.º 2
0
        public string ConsultaCFDI(string expresion, string uudi, string rfcReceptor)//no necesita asignature
        {
            AccesoServicios serv = new AccesoServicios();

            SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignatureType asignature = new SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignatureType();
            return(serv.ConsultaCFDI(expresion, uudi, rfcReceptor, asignature));
        }
Ejemplo n.º 3
0
 public SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignatureType Asignature(string strPPrivada, Encabezado encLMetadata, string pass, string strCertificado)
 {
     SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignatureType result;
     try
     {
         string strPXmlFirmado = "";
         SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignatureType Asig = new SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignatureType();
         Asig.Id            = "Signature";
         Asig.SignedInfo    = new SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignedInfoType();
         Asig.SignedInfo.Id = "Signature-SignedInfo";
         Asig.SignedInfo.CanonicalizationMethod           = new SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.CanonicalizationMethodType();
         Asig.SignedInfo.CanonicalizationMethod.Algorithm = "http://www.w3.org/TR/2001/REC-xml-c14n20010315";
         Asig.SignedInfo.SignatureMethod           = new SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignatureMethodType();
         Asig.SignedInfo.SignatureMethod.Algorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
         Asig.SignedInfo.Reference     = new SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.ReferenceType();
         Asig.SignedInfo.Reference.URI = "#Certificate1";
         List <SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.TransformType> T = new List <SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.TransformType>();
         T.Add(new SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.TransformType
         {
             Algorithm = "http://www.w3.org/2000/09/xmldsig#envelopedsignature"
         });
         Asig.SignedInfo.Reference.Transforms             = T.ToArray();
         Asig.SignedInfo.Reference.DigestMethod           = new SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.DigestMethodType();
         Asig.SignedInfo.Reference.DigestMethod.Algorithm = "http://www.w3.org/2000/09/xmldsig#sha1";
         if (File.Exists(strPPrivada + ".pem"))
         {
             strPPrivada += ".pem";
         }
         string ext = Path.GetExtension(strPPrivada);
         AccesoServicios.SignXmlFile(this.ArmarXmlPreFirma(encLMetadata), ref strPXmlFirmado, OpensslKey.DecodePrivateKey(File.ReadAllBytes(strPPrivada), pass, ext));
         string hex = strPXmlFirmado.Substring(strPXmlFirmado.IndexOf("<DigestValue>") + 13, strPXmlFirmado.IndexOf("</DigestValue>") - strPXmlFirmado.IndexOf("<DigestValue>") - 13);
         Asig.SignedInfo.Reference.DigestValue = Convert.FromBase64String(hex);
         Asig.SignatureValue = Convert.FromBase64String(strPXmlFirmado.Substring(strPXmlFirmado.IndexOf("<SignatureValue>") + 16, strPXmlFirmado.IndexOf("</SignatureValue>") - strPXmlFirmado.IndexOf("<SignatureValue>") - 16));
         X509Certificate2 x509 = new X509Certificate2(strCertificado);
         Asig.KeyInfo          = new SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.KeyInfoType();
         Asig.KeyInfo.X509Data = new SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.X509DataType();
         Asig.KeyInfo.X509Data.X509Certificate = File.ReadAllBytes(strCertificado);
         Asig.KeyInfo.Id = "Certificate1";
         result          = Asig;
     }
     catch (Exception exception)
     {
         AccesoServicios.Log.Error("(Asignature) Error al generar la firma de los CFDI's " + exception.ToString());
         result = null;
     }
     return(result);
 }
Ejemplo n.º 4
0
        public string ConsultaCFDIRelacionadosRequest(string RfcPacEnviaSolicitud, string RfcReceptor, string RfcEmisor, string Uuid, SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignatureType asig)
        {
            string result;

            try
            {
                PeticionConsultaRelacionados          D    = new PeticionConsultaRelacionados();
                CfdiConsultaRelacionadosServiceClient CFDI = new CfdiConsultaRelacionadosServiceClient();
                D.RfcPacEnviaSolicitud = RfcPacEnviaSolicitud;
                if (!string.IsNullOrEmpty(RfcReceptor))
                {
                    D.RfcReceptor = RfcReceptor;
                }
                D.Signature = asig;
                D.Uuid      = Uuid;
                if (!string.IsNullOrEmpty(RfcEmisor))
                {
                    D.RfcEmisor = RfcEmisor;
                }
                HttpRequestMessageProperty tokenAutenticacion = this.AutenticaServicio();
                using (new OperationContextScope(CFDI.InnerChannel))
                {
                    OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = tokenAutenticacion;
                    ConsultaRelacionados x = CFDI.ProcesarRespuesta(D);
                    string xml             = AccesoServicios.GetXMLFromObject(x);
                    result = xml;
                }
            }
            catch (Exception exception)
            {
                AccesoServicios.Log.Error("(ConsultaRelacionados) Error al consultar los CFDI's " + exception.ToString());
                result = null;
            }
            return(result);
        }
Ejemplo n.º 5
0
        public string ConsultaCFDIRelacionados(string RfcPacEnviaSolicitud, string RfcReceptor, string Uuid, SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignatureType asig)
        {
            string result;

            try
            {
                PeticionConsultaRelacionados          D    = new PeticionConsultaRelacionados();
                CfdiConsultaRelacionadosServiceClient CFDI = new CfdiConsultaRelacionadosServiceClient();
                D.RfcPacEnviaSolicitud = RfcPacEnviaSolicitud;
                D.RfcReceptor          = RfcReceptor;
                D.Signature            = asig;
                D.Uuid = Uuid;
                HttpRequestMessageProperty tokenAutenticacion = this.AutenticaServicio();
                using (new OperationContextScope(CFDI.InnerChannel))
                {
                    OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = tokenAutenticacion;
                    ConsultaRelacionados x = CFDI.ProcesarRespuesta(D);
                    if (!x.Resultado.Contains("Clave: 2000"))
                    {
                        result = "Cancelable";
                    }
                    else
                    {
                        result = "No Cancelable";
                    }
                }
            }
            catch (Exception exception)
            {
                AccesoServicios.Log.Error("(ConsultaRelacionados) Error al consultar los CFDI's " + exception.ToString());
                result = null;
            }
            return(result);
        }
Ejemplo n.º 6
0
        public string ConsultaCFDI(string expresion, string uuid, string rfcReceptor, SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignatureType asig)
        {
            string result;

            try
            {
                /*
                 * if (expresion.Contains("&id="))
                 * {
                 *  expresion = expresion.Replace("&id=", "&amp;id=");
                 * }
                 * if (expresion.Contains("&re="))
                 * {
                 *  expresion = expresion.Replace("&re=", "&amp;re=");
                 * }
                 * if (expresion.Contains("&rr="))
                 * {
                 *  expresion = expresion.Replace("&rr=", "&amp;rr=");
                 * }
                 * if (expresion.Contains("&tt="))
                 * {
                 *  expresion = expresion.Replace("&tt=", "&amp;tt=");
                 * }
                 * if (expresion.Contains("&fe="))
                 * {
                 *  expresion = expresion.Replace("&fe=", "&amp;fe=");
                 * }
                 */

                int i = expresion.IndexOf("&rr=");
                i += 4;
                int    j = expresion.IndexOf("&tt=");
                string c = expresion.Substring(i, j - i);
                string z = c.Replace("&", "&amp;");
                expresion = expresion.Replace(c, z);
                i         = expresion.IndexOf("&re=");
                i        += 4;
                j         = expresion.IndexOf("&rr=");
                c         = expresion.Substring(i, j - i);
                z         = c.Replace("&", "&amp;");
                expresion = expresion.Replace(c, z);



                ConsultaCFDIServiceClient CFDI = new ConsultaCFDIServiceClient();
                SAT.CFDI.Cliente.Procesamiento.ServicioConsultaCFDI.Acuse x = CFDI.Consulta(expresion);
                if (x.Estado != "No Encontrado")
                {
                    if (x.Estado == "Vigente")
                    {
                        if (x.EsCancelable != "No Cancelable")
                        {
                            result = "OK";
                        }
                        else
                        {
                            result = x.EsCancelable;
                        }
                    }
                    else if (x.Estado == "Cancelado")
                    {
                        result = "OK";
                    }
                    else
                    {
                        result = x.Estado;
                    }
                }
                else
                {
                    result = x.Estado;
                }
            }
            catch (Exception exception)
            {
                AccesoServicios.Log.Error("(ConsultaCFDI) Error al consultar los CFDI's  expresion:" + expresion + "---" + exception.ToString());
                result = null;
            }
            return(result);
        }