Exemple #1
0
        /// <summary>
        /// SMS_46780073 非正常开门 您好,您的朋友${uname}正在使用非正常指纹回家,请妥善处理!!!
        /// </summary>
        /// <param name="name">名称</param>
        /// <param name="mobile">手机</param>
        public void SendUnLockMsg(string name, string mobile)
        {
            String querys = string.Format("ParamString={0}&RecNum={1}&SignName={2}&TemplateCode=SMS_48945056", HttpUtility.UrlEncode("{\"uname\":\"" + name + "\"}", System.Text.Encoding.UTF8), mobile, HttpUtility.UrlEncode("艾力智能", System.Text.Encoding.UTF8));

            String url = "http://sms.market.alicloudapi.com/singleSendSms?" + querys;

            //ParamString%3d+%7b%22uname%22%3a%2213867911360%22%7d%26RecNum%3d13867911360%26SignName%3d%e8%89%be%e5%8a%9b%e9%9b%86%e6%88%90%26TemplateCode%3dSMS_46780073
            Crestron.SimplSharp.Net.Http.HttpClient client = new Crestron.SimplSharp.Net.Http.HttpClient();

            HttpClientRequest request = this.GetRequest(url);


            try
            {
                HttpClientResponse httpResponse = client.Dispatch(request);
                ILiveDebug.Instance.WriteLine("SMS:" + querys);
                httpResponse.Encoding = Encoding.UTF8;
                string html = httpResponse.ContentString;
                ILiveDebug.Instance.WriteLine(html);
            }
            catch (Exception ex)
            {
                ILiveDebug.Instance.WriteLine("ex:" + ex.Message);
            }
        }
        public string GetHttpText(string url)
        {
            var client   = new Crestron.SimplSharp.Net.Http.HttpClient();
            var response = client.GetResponse(url);

            return(response.ContentString);
        }
        public void Post(string url, string contents, Action <string> responseCallback)
        {
            var httpClient = new Crestron.SimplSharp.Net.Http.HttpClient();

            try {
                if (Debug == 1)
                {
                    CrestronConsole.PrintLine("Unity.HttpClient HttpRequest: {0} | {1}", url, contents);
                }
                var response = httpClient.Post(url, Encoding.ASCII.GetBytes(contents));
                responseCallback(response);
            }
            catch (Exception ex) {
                ErrorMessage.Error("Unity.HttpClient Error: {0}", ex.Message);
            }
            finally {
                httpClient.Abort();
                httpClient.Dispose();
            }
        }
        public string Get(string url)
        {
            var httpClient = new Crestron.SimplSharp.Net.Http.HttpClient();

            try {
                var results = httpClient.Get(url);
                if (Debug == 1)
                {
                    CrestronConsole.PrintLine("Unity.HttpClient.Get: {0}\r\n{1}", url, results);
                }
                return(results);
            }
            catch (Exception ex) {
                ErrorMessage.Error("Unity.HttpClient Get({1}) Error: {0}", ex.Message, url);
                return("");
            }
            finally {
                httpClient.Abort();
                httpClient.Dispose();
            }
        }
Exemple #5
0
        /// <summary>
        /// 入侵提醒SMS_46695144 您的${zonemsg}有人非法入侵,请您确认!
        /// </summary>
        /// <param name="zongmsg">报警区域</param>
        /// <param name="mobile">手机</param>
        public void SendAlarmMsg(string zongmsg, string mobile)
        {
            String querys = string.Format("ParamString={0}&RecNum={1}&SignName={2}&TemplateCode=SMS_48575136", HttpUtility.UrlEncode("{\"zonemsg\":\"" + zongmsg + "\"}", System.Text.Encoding.UTF8), mobile, HttpUtility.UrlEncode("艾力智能", System.Text.Encoding.UTF8));
            String url    = "http://sms.market.alicloudapi.com/singleSendSms?" + querys;

            Crestron.SimplSharp.Net.Http.HttpClient client = new Crestron.SimplSharp.Net.Http.HttpClient();

            HttpClientRequest request = this.GetRequest(url);


            try
            {
                HttpClientResponse httpResponse = client.Dispatch(request);
                httpResponse.Encoding = Encoding.UTF8;
                string html = httpResponse.ContentString;
            }
            catch (Exception ex)
            {
                ILiveDebug.Instance.WriteLine("ex:" + ex.Message);
            }
        }
        private void DispatchAsync(HttpClientRequest request, Action <string> callbackAction)
        {
            var httpClient = new Crestron.SimplSharp.Net.Http.HttpClient()
            {
                UseConnectionPooling = true, KeepAlive = false
            };
            var callbackObject = new AsyncCallbackObject
            {
                Url = request.Url.Url, Callback = callbackAction, HttpClient = httpClient, RequestType = request.RequestType, Request = request.ContentString
            };

            try {
                var error = httpClient.DispatchStringAsyncEx(request, Encoding.ASCII, AsyncCallback, callbackObject);
                if (error != Crestron.SimplSharp.Net.Http.HttpClient.DISPATCHASYNC_ERROR.PENDING)
                {
                    ErrorMessage.Error("Unity.HttpClient.DispatchAsync({0}) {2} Error: {1}\r\n", request.Url.Url, error.ToString(), request.RequestType.ToString());
                }
            }
            catch (Exception ex) {
                ErrorMessage.Error("Unity.HttpClient API Error: {0}", ex.Message);
            }
        }
Exemple #7
0
        public void UpdateHost(string user, string pass, string host)
        {
            String querys = string.Format(url, host);

            Crestron.SimplSharp.Net.Http.HttpClient client = new Crestron.SimplSharp.Net.Http.HttpClient();

            string            auth    = "Basic " + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(user + ":" + pass));
            HttpClientRequest request = this.GetRequest(querys, auth);


            try
            {
                ILiveDebug.Instance.WriteLine("ILiveOray:" + querys);
                HttpClientResponse httpResponse = client.Dispatch(request);
                httpResponse.Encoding = Encoding.UTF8;
                string html = httpResponse.ContentString;
                ILiveDebug.Instance.WriteLine(html);
            }
            catch (Exception ex)
            {
                ILiveDebug.Instance.WriteLine("ex:" + ex.Message);
            }
        }