Foros del Web » Programando para Internet » PHP »

.cs en PHP

Estas en el tema de .cs en PHP en el foro de PHP en Foros del Web. Hola, Hace poco me llego la tarea de conectar un "webservice" para validar un PIN de tarjetas, pero el codigo viene en C# y la ...
  #1 (permalink)  
Antiguo 15/12/2014, 07:51
 
Fecha de Ingreso: febrero-2011
Mensajes: 40
Antigüedad: 13 años, 1 mes
Puntos: 0
Pregunta .cs en PHP

Hola,

Hace poco me llego la tarea de conectar un "webservice" para validar un PIN de tarjetas, pero el codigo viene en C# y la verdad no entiendo mucho... la duda es como puedo ejecutar este codigo en php o si tengo que transformar para conectar y validar los PIN

Aquí dejo una parte del codigo

Código:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Net;

namespace PinTest
{
    public class PinTest
    {
        public static void Run()
        {
            PinTest test = new PinTest("https://url.com/pingen");
            var reply = test.CreatePin("XXX", "XXX", "000-000-001", 1000, 0, 6);
            DisplayXml(reply);

        }

        private string urlBase;

        public PinTest(string urlBase)
        {
            this.urlBase = urlBase;
        }

        private XmlDocument CreatePin(string authUser,
                                 string authPassword,
                                 string cardNumber,
                                 int creditAmount,
                                 int siteCode,
                                 int pinLength)
        {

            StringBuilder xml = new StringBuilder();
            xml.AppendLine("<PinRequest>");
            xml.AppendFormat("<AuthUser>{0}</AuthUser>\n", authUser);
            xml.AppendFormat("<AuthPassword>{0}</AuthPassword>\n", authPassword);
            xml.AppendFormat("<CardNumber>{0}</CardNumber>\n", cardNumber);
            xml.AppendFormat("<CreditAmount>{0}</CreditAmount>", creditAmount);
            xml.AppendFormat("<PINLength>{0}</PINLength>", pinLength);
            xml.AppendFormat("<SiteCode>{0}</SiteCode>", siteCode);
            xml.AppendLine("</PinRequest>");

            XmlDocument doc = this.DoHttpPost("createPIN", xml.ToString());

            if (doc.DocumentElement.Name != "PinResponse")
                throw new Exception("PinService.CreatePin: Unexpected Reply: \n" + doc.DocumentElement.OuterXml);

            return doc;
        }


        private XmlDocument DoHttpPost(string url, string xmlContent)
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(string.Format("{0}/PinService.svc/{1}", this.urlBase, url));

            byte[] xmlBytes = Encoding.UTF8.GetBytes(xmlContent);

            req.Method = "POST";
            req.ContentType = "text/xml;";
            req.ContentLength = xmlBytes.Length;

            req.GetRequestStream().Write(xmlBytes, 0, xmlBytes.Length);

            WebResponse resp = req.GetResponse();

            string contentType = resp.ContentType.Split(' ', ';')[0];


            switch (contentType)
            {
                case "application/xml":
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.Load(resp.GetResponseStream());
                        return doc;
                    }

                default:
                    throw new Exception("PinService.DoHttpPost: Unsupported Content Type: " + resp.ContentType);
            }

        }

        private static void DisplayXml(XmlDocument doc)
        {
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            XmlWriter writer = XmlWriter.Create(Console.Out, settings);
            doc.WriteTo(writer);
            writer.Flush();

        }

    }
}
Si me pueden dar alguna idea de que tengo que hacer para validar los PIN.

Slds!
  #2 (permalink)  
Antiguo 15/12/2014, 12:00
Avatar de enlinea777  
Fecha de Ingreso: mayo-2008
Ubicación: frente al pc
Mensajes: 1.830
Antigüedad: 15 años, 10 meses
Puntos: 127
Respuesta: .cs en PHP

compila el c#
luego valida con CGI
  #3 (permalink)  
Antiguo 22/12/2014, 07:07
 
Fecha de Ingreso: febrero-2011
Mensajes: 40
Antigüedad: 13 años, 1 mes
Puntos: 0
Respuesta: .cs en PHP

Disculpa,

Teoricamente compile el codigo, pero como hago eso de validar con CGI para usarlo en PHP (feel like webservice)

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:52.