Пример #1
0
        public static AuthResponse authAuth(string login, string password)
        {
            // Создаем переменные
            WebRequest   Request;
            WebResponse  Response;
            StreamReader Reader;
            AuthResponse authResponse = new AuthResponse();

            // Создаем запрос "POST"
            Request        = WebRequest.Create(ReaderTestData.ReadCExel(13, 7) + "/api/auth/auth?login="******"&userType=Fttb");
            Request.Method = "PUT";
            ((HttpWebRequest)Request).UserAgent   = "Apache-HttpClient/4.2.3";
            ((HttpWebRequest)Request).KeepAlive   = true;
            ((HttpWebRequest)Request).Proxy       = null; //Ставим обязательно, это также ускоряет подключение.
            ((HttpWebRequest)Request).Referer     = ReaderTestData.ReadCExel(13, 7);
            ((HttpWebRequest)Request).ContentType = "application/json";

            string data = "{\"password\":\"" + password + "\"}";

            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            byte[] arr = encoding.GetBytes(data);
            ((HttpWebRequest)Request).ContentLength = arr.Length;
            Stream dataStream = Request.GetRequestStream();

            dataStream.Write(arr, 0, arr.Length);
            dataStream.Close();

            authResponse.request = Request.RequestUri.ToString();

            Response = Request.GetResponse();
            Reader   = new StreamReader(Response.GetResponseStream(),
                                        Encoding.GetEncoding("utf-8"));

            // Ставим true/false для перенаправления на другую страницу. Но нежелательно, т.к. могут потеряться куки, надо будет следить за каждым запросом
            ((HttpWebRequest)Request).AllowAutoRedirect = false;

            // Создаем переменную для страницы
            string response = Reader.ReadToEnd();

            authResponse.all = response;
            // string json =
            //     @"{""meta"":{""status"":""OK"",""code"":20000,""message"":null},""token"":""6111B5A3B91C717CA775D96FC5DE1885"",""tempPassInd"":false,""newUserInd"":false}";

            //десериализуем json, все данные будут в полях класса apiresponse
            RootObject apiresponse = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize <RootObject>(response);



            authResponse.code  = apiresponse.meta.code.ToString(); //response.Substring(30, 5);
            authResponse.token = apiresponse.token;
            if (apiresponse.meta.message != null)
            {
                authResponse.message = apiresponse.meta.message.ToString();
            }

            // Закрываем поток, освобождаем память
            Reader.Close();
            Response.Close();
            return(authResponse);
        }
Пример #2
0
        private string Aut()
        {
            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri(ReaderTestData.ReadCExel(2, 10)));

            req.Method = "POST";
            req.Headers.Add("Accept-Encoding", "gzip,deflate");
            req.ContentType     = "text/xml;charset=utf-8";
            req.Accept          = "text/xml";
            req.UserAgent       = "Apache-HttpClient/4.1.1 (java 1.5)";
            req.ProtocolVersion = HttpVersion.Version10;

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<?xml version=\"1.0\"?>");
            sb.AppendLine("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:auth=\"https://org.comverse.rtbd.sec/webservice/auth\">");
            sb.AppendLine(" <soapenv:Header/>");
            sb.AppendLine("  <soapenv:Body>");
            sb.AppendLine("  <auth:proxyLogin>");
            sb.AppendLine("  <String_1>sapiuser</String_1>");
            sb.AppendLine("  <String_2>sapipass1</String_2>");
            sb.AppendLine("  <String_3>SAPI</String_3>");
            sb.AppendLine("</auth:proxyLogin>");
            sb.AppendLine(" </soapenv:Body>");
            sb.AppendLine("</soapenv:Envelope>");
            using (Stream stm = req.GetRequestStream())
            {
                using (StreamWriter stmw = new StreamWriter(stm))
                {
                    stmw.Write(sb.ToString());
                }
            }

            XmlDocument xdoc = new XmlDocument();

            try
            {
                using (WebResponse response = req.GetResponse())
                {
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        if (responseStream != null)
                        {
                            using (StreamReader srreader = new StreamReader(responseStream))
                            {
                                xdoc.Load(srreader);
                                string token = xdoc.GetElementsByTagName("result")[0].InnerXml;
                                token = token.Remove(0, token.IndexOf("Token&gt;") + 9);
                                token = token.Remove(token.IndexOf("&lt;/Token"));
                                return(token);
                            }
                        }
                    }
                }
            }
            catch (WebException ex)
            {
                WebResponse errRsp = ex.Response;
                using (Stream responseStream = errRsp.GetResponseStream())
                {
                    if (responseStream != null)
                    {
                        using (StreamReader rdr = new StreamReader(responseStream))
                        {
                            string s = rdr.ReadToEnd();
                        }
                    }
                }
            }
            return(null);
        }
Пример #3
0
        public XmlDocument SetBalance(string phoneNumber, string cost)
        {
            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri(ReaderTestData.ReadCExel(2, 7)));

            req.Method = "POST";
            req.Headers.Add("Accept-Encoding", "gzip,deflate");
            req.ContentType     = "text/xml;charset=utf-8";
            req.Accept          = "text/xml";
            req.UserAgent       = "Apache-HttpClient/4.1.1 (java 1.5)";
            req.ProtocolVersion = HttpVersion.Version10;

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<?xml version=\"1.0\"?>");
            sb.AppendLine("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:com=\"http://www.comverse.com\">");
            sb.AppendLine(" <soapenv:Header/>");
            sb.AppendLine("  <soapenv:Body>");
            sb.AppendLine("  <com:SubscriberAdjustBalanceInstance>");
            sb.AppendLine("  <com:input>");
            sb.AppendLine(" <userIdName>sapiuser</userIdName>");
            sb.AppendLine(" <securityToken>" + Aut() + "</securityToken>");
            sb.AppendLine(" <subscriberId>");
            sb.AppendLine("<subscriberId set=\"true\">");
            sb.AppendLine(" <value>" + phoneNumber + "</value>");
            sb.AppendLine("</subscriberId>");
            sb.AppendLine(" <subscriberExternalIdType set=\"true\">");
            sb.AppendLine(" <value>1</value>");
            sb.AppendLine(" </subscriberExternalIdType>");
            sb.AppendLine(" </subscriberId>");
            sb.AppendLine(" <balanceName>CORE BALANCE</balanceName>");
            sb.AppendLine(" <valueDelta>" + cost + "</valueDelta>");
            sb.AppendLine(" <CurrencyCode value=\"RUR\"/>");
            sb.AppendLine(" <mtrComment>SCRIPT_ADJUST</mtrComment>");
            sb.AppendLine(" </com:input>");
            sb.AppendLine("</com:SubscriberAdjustBalanceInstance>");
            sb.AppendLine(" </soapenv:Body>");
            sb.AppendLine("</soapenv:Envelope>");

            using (Stream stm = req.GetRequestStream())
            {
                using (StreamWriter stmw = new StreamWriter(stm))
                {
                    stmw.Write(sb.ToString());
                }
            }

            XmlDocument xdoc = new XmlDocument();

            try
            {
                using (WebResponse response = req.GetResponse())
                {
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        if (responseStream != null)
                        {
                            using (StreamReader srreader = new StreamReader(responseStream))
                            {
                                xdoc.Load(srreader);
                            }
                        }
                    }
                }
            }
            catch (WebException ex)
            {
                WebResponse errRsp = ex.Response;
                using (Stream responseStream = errRsp.GetResponseStream())
                {
                    if (responseStream != null)
                    {
                        using (StreamReader rdr = new StreamReader(responseStream))
                        {
                            string s = rdr.ReadToEnd();
                        }
                    }
                }
            }
            return(null);
        }
Пример #4
0
        public static FinInfoResponse finInfo(string token)
        {
            // Создаем переменные
            WebRequest      Request;
            WebResponse     Response;
            StreamReader    Reader;
            FinInfoResponse finInfoResponse = new FinInfoResponse();

            // Создаем запрос "GET"
            Request        = WebRequest.Create(ReaderTestData.ReadCExel(13, 7) + "/api/1.0/inac/account/finInfo");
            Request.Method = "GET";
            ((HttpWebRequest)Request).UserAgent = "Apache-HttpClient/4.2.3";
            ((HttpWebRequest)Request).KeepAlive = true;
            ((HttpWebRequest)Request).Proxy     = null; //Ставим обязательно, это также ускоряет подключение.
            ((HttpWebRequest)Request).Referer   = ReaderTestData.ReadCExel(13, 7);
            //((HttpWebRequest)Request).ContentType = "application/json";
            CookieContainer cookies = new CookieContainer();
            Cookie          cookie  = new Cookie("token", token, "", "usssfttb-test.vimpelcom.ru");

            cookies.Add(cookie);
            ((HttpWebRequest)Request).CookieContainer = cookies;


            finInfoResponse.request = Request.RequestUri.ToString();


            Response = Request.GetResponse();
            Reader   = new StreamReader(Response.GetResponseStream(),
                                        Encoding.GetEncoding("utf-8"));

            // Ставим true/false для перенаправления на другую страницу. Но нежелательно, т.к. могут потеряться куки, надо будет следить за каждым запросом
            ((HttpWebRequest)Request).AllowAutoRedirect = false;

            // Создаем переменную для страницы
            string response = Reader.ReadToEnd();

            finInfoResponse.all = response;
            // string json =
            //     @"{""meta"":{""status"":""OK"",""code"":20000,""message"":null},""token"":""6111B5A3B91C717CA775D96FC5DE1885"",""tempPassInd"":false,""newUserInd"":false}";

            //десериализуем json, все данные будут в полях класса apiresponse
            RootObject apiresponse = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize <RootObject>(response);



            finInfoResponse.code = apiresponse.meta.code.ToString();
            if (apiresponse.meta.message != null)
            {
                finInfoResponse.message = apiresponse.meta.message.ToString();
            }
            DateTime.TryParse(apiresponse.bcEndDate, out finInfoResponse.bcEndDate);
            finInfoResponse.billType = apiresponse.billType;
            DateTime.TryParse(apiresponse.blockDate, out finInfoResponse.blockDate);
            DateTime.TryParse(apiresponse.blockDateEnd, out finInfoResponse.blockDateEnd);
            finInfoResponse.blockMaxLong = apiresponse.blockMaxLong;
            finInfoResponse.blockType    = apiresponse.blockType;
            finInfoResponse.countUnread  = apiresponse.countUnread;
            DateTime.TryParse(apiresponse.finBlockStartDate, out finInfoResponse.finBlockStartDate);
            finInfoResponse.monthlyPayment         = apiresponse.monthlyPayment;
            finInfoResponse.nextBCSum              = apiresponse.nextBCSum;
            finInfoResponse.promisedPaymentAllowed = apiresponse.promisedPaymentAllowed;
            // Закрываем поток, освобождаем память
            Reader.Close();
            Response.Close();
            return(finInfoResponse);
        }