Exemple #1
0
        public bool Send(Sms sms)
        {
            Uri server = new Uri(hostAddress);

            HuaweiAuthorizer authorizer = new HuaweiAuthorizer(hostAddress);
            AuthParams       authParams = authorizer.Authorize();

            // получим список смс
            HttpWebRequest sendRequest = WebRequest.Create(new Uri(server, "/api/sms/send-sms")) as HttpWebRequest;

            sendRequest.CookieContainer = authParams.Container;
            sendRequest.Headers.Add("__RequestVerificationToken", authParams.CsrfToken);

            sendRequest.Method = "POST";
            using (Stream dataStream = sendRequest.GetRequestStream())
            {
                string xmlRequest = $"<?xml version=\"1.0\" encoding=\"UTF-8\"?><request><Index>-1</Index><Phones><Phone>{sms.Phone}</Phone></Phones><Sca></Sca><Content>{sms.Message}</Content><Length>{sms.Message.Length}</Length><Reserved>1</Reserved><Date>{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}</Date></request>";
                byte[] byteArray  = Encoding.UTF8.GetBytes(xmlRequest);
                dataStream.Write(byteArray, 0, byteArray.Length);
                dataStream.Close();
            }
            using (HttpWebResponse deleteResponse = sendRequest.GetResponse() as HttpWebResponse)
            {
                using (var reader = new System.IO.StreamReader(deleteResponse.GetResponseStream()))
                {
                    string responseText = reader.ReadToEnd();
                    if (responseText.Contains("<response>OK</response>"))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public bool Delete(int index)
        {
            Uri server = new Uri(hostAddress);

            HuaweiAuthorizer authorizer = new HuaweiAuthorizer(hostAddress);
            AuthParams       authParams = authorizer.Authorize();

            // получим список смс
            HttpWebRequest deleteRequest = WebRequest.Create(new Uri(server, "/api/sms/delete-sms")) as HttpWebRequest;

            deleteRequest.CookieContainer = authParams.Container;
            deleteRequest.Headers.Add("__RequestVerificationToken", authParams.CsrfToken);

            deleteRequest.Method = "POST";
            using (Stream dataStream = deleteRequest.GetRequestStream())
            {
                string xmlRequest = $"<?xml version=\"1.0\" encoding=\"UTF-8\"?><request><Index>{index}</Index></request>";
                byte[] byteArray  = Encoding.UTF8.GetBytes(xmlRequest);
                dataStream.Write(byteArray, 0, byteArray.Length);
                dataStream.Close();
            }
            using (HttpWebResponse deleteResponse = deleteRequest.GetResponse() as HttpWebResponse)
            {
                using (var reader = new System.IO.StreamReader(deleteResponse.GetResponseStream()))
                {
                    string responseText = reader.ReadToEnd();
                    if (responseText.Contains("<response>OK</response>"))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #3
0
        public XmlDocument Read()
        {
            Uri server = new Uri(hostAddress);

            HuaweiAuthorizer authorizer = new HuaweiAuthorizer(hostAddress);
            AuthParams       authParams = authorizer.Authorize();

            // получим список смс
            HttpWebRequest smsRequest = WebRequest.Create(new Uri(server, "api/sms/sms-list")) as HttpWebRequest;

            smsRequest.CookieContainer = authParams.Container;
            smsRequest.Headers.Add("__RequestVerificationToken", authParams.CsrfToken);

            smsRequest.Method = "POST";
            using (Stream dataStream = smsRequest.GetRequestStream())
            {
                string xmlRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><request><PageIndex>1</PageIndex><ReadCount>50</ReadCount><BoxType>1</BoxType><SortType>0</SortType><Ascending>0</Ascending><UnreadPreferred>0</UnreadPreferred></request>";
                byte[] byteArray  = System.Text.Encoding.UTF8.GetBytes(xmlRequest);
                dataStream.Write(byteArray, 0, byteArray.Length);
                dataStream.Close();
            }
            using (HttpWebResponse smsResponse = smsRequest.GetResponse() as HttpWebResponse)
            {
                using (var reader = new System.IO.StreamReader(smsResponse.GetResponseStream()))
                {
                    using (XmlTextReader xmlReader = new XmlTextReader(reader))
                    {
                        XmlDocument xmldoc = new XmlDocument();
                        xmldoc.Load(xmlReader);
                        return(xmldoc);
                    }
                }
            }
        }