Esempio n. 1
0
        static void Main(string[] args)
        {
            TimeSpan ts    = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1);
            Int32    ticks = System.Convert.ToInt32(ts.TotalSeconds);
            //当前UTC时间戳,从1970年1月1日0点0 分0 秒开始到现在的秒数(String)
            String curTime   = ticks.ToString();
            String appSecret = "ec4573c39376";
            //随机数(最大长度128个字符)
            string nonce  = "12345";
            string random = new Random().ToString();
            //SHA1(AppSecret + Nonce + CurTime),三个参数拼接的字符串,进行SHA1哈希计算,转化成16进制字符(String,小写)
            String checkSum = CheckSumBuilder.getCheckSum(appSecret, nonce, curTime);
            string url      = "https://api.netease.im/sms/sendtemplate.action";

            url += "?templateid=3063716&mobiles=[\"18611693213\"]&params=[\"7点15分\"]";//306371
            var http = NetworkRequest.CreateHttp(url);

            http.Request.Headers["AppKey"]      = "78d74476f41e6d9bf1429118bf5316bd";
            http.Request.Headers["Nonce"]       = nonce;
            http.Request.Headers["CurTime"]     = curTime;
            http.Request.Headers["CheckSum"]    = checkSum;
            http.Request.Headers["ContentType"] = "application/x-www-form-urlencoded;charset=utf-8";
            var bytes = http.Post();

            if (bytes != null)
            {
                string str = Encoding.UTF8.GetString(bytes);
                Console.WriteLine(str);
            }
            Console.ReadLine();
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the async http retransmission.
        /// </summary>
        /// <returns>The async string result.</returns>
        /// <param name="path">url path</param>
        /// <param name="httpContext">original HttpContext.</param>
        public async Task <string> GetAsync(string path, HttpContext httpContext)
        {
            INetworkHttpRequest networkRequest = NetworkRequest.CreateHttp(httpRetransmitConfig.GetUrl(path));

            networkRequest.Request.Headers["channel"] = "app";
            networkRequest.Request.Accept             = "application/json";
            foreach (var key in httpContext.Request.Headers.Keys)
            {
                networkRequest.Request.Headers[key] = httpContext.Request.Headers[key];
            }

            if (!string.IsNullOrWhiteSpace(httpRetransmitConfig.Token))
            {
                networkRequest.Request.Headers["Authorization"] = httpRetransmitConfig.Token;
            }
            // cookie process
            // Microsoft.AspNetCore.Http.Internal.RequestCookieCollection
            // var cookieContainer = new System.Net.CookieContainer ();
            // HttpWebResponse response;
            // response.Cookies;
            // httpContext.Response.Cookies

            // foreach (var keyValuePair in httpContext.Request.Cookies)
            // {
            //     cookieContainer.Add(new Cookie(keyValuePair.Key, keyValuePair.Value));
            // }
            // networkRequest.Request.CookieContainer = cookieContainer;
            // ------
            var bytes = await networkRequest.GetAsync();

            return(bytes != null?Encoding.UTF8.GetString(bytes) : "");
        }
Esempio n. 3
0
        private async void GetHttpRequest_Click(object sender, RoutedEventArgs e)
        {
            string url = "http://baike.baidu.com/cms/global/lemma_config.json";

            byte[] bytes = null;
            string str   = null;


            NetworkRequest request = NetworkRequest.CreateHttp("http://baike.baidu.com/cms/global/lemma_config.json?cl=2&rn=20&tn=news");

            bytes = request.Get();

            request = NetworkRequest.CreateHttp("http://p5.sinaimg.cn/2776321060/180/73181353913818");
            bytes   = await request.GetAsync();

            str             = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
            this.img.Source = await ToolsLib.Utility.GetBitmapImageAsync(bytes);

            request      = NetworkRequest.CreateHttp(url);
            request.Body = "name=123";
            bytes        = request.Post();

            request = NetworkRequest.CreateHttp(url);
            bytes   = await request.PostAsync();

            str = Encoding.UTF8.GetString(bytes, 0, bytes.Length);

            this.result_tbk.Text = str;
        }
Esempio n. 4
0
        public async Task <bool> GetUserInfo()
        {
            GetUserInforRequestParams sParams = new GetUserInforRequestParams();

            sParams.deviceId = Configuration.GetDeviceUniqueId();
            HttpSerializeData <GetUserInforRequestParams> httpSerializeData = new HttpSerializeData <GetUserInforRequestParams>("getUserInfo.html", sParams);
            NetworkRequest networkRequest = NetworkRequest.CreateHttp(httpSerializeData.GetURL());
            var            resultJson     = await networkRequest.PostAsync <string>(JsonAnalysis.Serialize(httpSerializeData));

            if (!string.IsNullOrEmpty(resultJson))
            {
                HttpDeserializeData <GetUserInforResponseData> sData = JsonAnalysis.Deserialize <HttpDeserializeData <GetUserInforResponseData> >(resultJson);

                if (sData.result.error == "01")   // 未绑定账户
                {
                    //todo:跳转到绑定页面,进行用户绑定
                    (Window.Current.Content as Frame).Navigate(typeof(BindDevicePage));
                }
                else if (sData.status.code.Equals("0000"))
                {
                    //todo:跳转到签到页面
                    (Window.Current.Content as Frame).Navigate(typeof(SignPage));
                }
                else
                {
                }
                return(true);
            }
            return(false);
        }
Esempio n. 5
0
        /// <summary>
        /// Posts the async retransmission.
        /// </summary>
        /// <returns>The async string result.</returns>
        /// <param name="path">url path.</param>
        /// <param name="httpContext">original HttpContext.</param>
        public async Task <string> PostAsync(string path, HttpContext httpContext)
        {
            string uri = httpRetransmitConfig.GetUrl(path);
            INetworkHttpRequest networkRequest = NetworkRequest.CreateHttp(uri);

            networkRequest.Request.Headers["channel"] = "app";
            networkRequest.Request.Accept             = "application/json";
            networkRequest.Request.ContentType        = "application/json";
            foreach (var key in httpContext.Request.Headers.Keys)
            {
                networkRequest.Request.Headers[key] = httpContext.Request.Headers[key];
            }
            if (!string.IsNullOrWhiteSpace(httpRetransmitConfig.Token))
            {
                networkRequest.Request.Headers["Authorization"] = httpRetransmitConfig.Token;
            }
            // todo: cockie process
            // ------
            string requestBody = "";

            using (var bodyStreamReader = new StreamReader(httpContext.Request.Body))
            {
                requestBody = await bodyStreamReader.ReadToEndAsync();
            }
            networkRequest.Body = requestBody;
            //http.Body="{\"pagination\":{\"current\":1,\"pageSize\":10},\"stcd\":\"0\"}";
            var bytes = await networkRequest.PostAsync();

            return(bytes != null?Encoding.UTF8.GetString(bytes) : "");
        }
Esempio n. 6
0
        public async Task <ActionResult> Index(string path = "")
        {
            path = path.Trim('/');
            if (!path.EndsWith(".md"))
            {
                path += ".md";
            }

            var    cataloguePath = path.Substring(0, path.LastIndexOf('/') + 1);
            var    nr            = NetworkRequest.CreateHttp($"http://localhost:5000/api/file/content/{path}");
            string fContent      = await nr.GetAsync <string>();

            var    categoryR   = NetworkRequest.CreateHttp($"http://localhost:5000/api/file/fileInfo/note");
            string categoryCnt = await categoryR.GetAsync <string>();

            var    catalogueInfoRequest = NetworkRequest.CreateHttp($"http://localhost:5000/api/file/fileInfo/{cataloguePath}");
            string catalogueInfo        = await catalogueInfoRequest.GetAsync <string>();

            JObject o = JObject.Parse(catalogueInfo);

            // JArray fileInfoArray = (JArray)o.SelectToken("children");
            // ViewBag.Catalogue = fileInfoArray;

            // catalogue
            ViewBag.AllCatalogue = o;
            // menu
            ViewBag.JCategory = JObject.Parse(categoryCnt);
            return(View((object)fContent));
        }
Esempio n. 7
0
        /// <summary>
        /// 签到,查询
        /// <param name="queryOnly">true:查询 false:签到</param>
        /// </summary>
        /// <returns></returns>
        public async Task <DoSignResponseData> DoSign(string queryOnly)
        {
            DoSignRequestParams sParams = new DoSignRequestParams();

            sParams.deviceId = Configuration.GetDeviceUniqueId();
            sParams.queryOny = queryOnly;
            HttpSerializeData <DoSignRequestParams> httpSerializeData = new HttpSerializeData <DoSignRequestParams>("doSign.html", sParams);
            NetworkRequest networkRequest = NetworkRequest.CreateHttp(httpSerializeData.GetURL());
            var            resultJson     = await networkRequest.PostAsync <string>(JsonAnalysis.Serialize(httpSerializeData));

            HttpDeserializeData <DoSignResponseData> sData = JsonAnalysis.Deserialize <HttpDeserializeData <DoSignResponseData> >(resultJson);

            if (queryOnly.Equals("false"))
            {
            }
            if (sData.result.error == "00")// 签到成功
            {
                return(sData.result);
            }
            else if (sData.status.code.Equals("0000"))
            {
                return(sData.result);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 8
0
        public async Task <string> Get(string fileName = "")
        {
            var http = NetworkRequest.CreateHttp("https://ras.ccb.com/religion/api/im/cptlwarnpcs/search");

            http.Request.Headers["channel"]       = "app";
            http.Request.Headers["Authorization"] = "BearereyJhbGciOiJIUzUxMiJ9.eyJjaXR5Q2QiOm51bGwsInpvbkNkIjpudWxsLCJwcm92Q2QiOiIzMjAwMDAwMDAwMDAiLCJzdHJDZCI6bnVsbCwiZXhwIjoxNTQwMzcwNjczLCJ1c2VybmFtZSI6IjEyMzQ1Njc4OTExIn0.aFdHv32ow8gcoC3nqwzzv_6s3hEga5xYiX3UjUC5ln9RrI8cUJjF5V85DirdKxViDBnsv5hJNY1f_WGrQ5yMJg";
            http.Request.Accept      = "application/json";
            http.Request.ContentType = "application/json";
            // http.Body="{pagination: {current: 1, pageSize: 10}, stcd: \"0\"}";
            http.Body = "{\"pagination\":{\"current\":1,\"pageSize\":10},\"stcd\":\"0\"}";
            var bytes = await http.PostAsync();

            string fileInfoStr = Encoding.UTF8.GetString(bytes);

            return(fileInfoStr);



            // // var http = NetworkRequest.CreateHttp("http://localhost:58221/api/localFile/userinfo.json");
            // var http = NetworkRequest.CreateHttp("https://ras.ccb.com/religion/fetchuserinfo");
            // http.Request.Headers["channel"] = "app";
            // http.Request.Headers["Authorization"] = "BearereyJhbGciOiJIUzUxMiJ9.eyJjaXR5Q2QiOm51bGwsInpvbkNkIjpudWxsLCJwcm92Q2QiOiIzMjAwMDAwMDAwMDAiLCJzdHJDZCI6bnVsbCwiZXhwIjoxNTQwMzcwNjczLCJ1c2VybmFtZSI6IjEyMzQ1Njc4OTExIn0.aFdHv32ow8gcoC3nqwzzv_6s3hEga5xYiX3UjUC5ln9RrI8cUJjF5V85DirdKxViDBnsv5hJNY1f_WGrQ5yMJg";
            // http.Request.Accept = "application/json";
            // var bytes = await http.GetAsync();
            // string fileInfoStr = Encoding.UTF8.GetString(bytes);

            // return fileInfoStr;
        }
Esempio n. 9
0
        public static bool SendNotice(string templateId, string[] phoneNums, string[] smsParams)
        {
            TimeSpan ts    = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1);
            Int32    ticks = System.Convert.ToInt32(ts.TotalSeconds);

            //当前UTC时间戳,从1970年1月1日0点0 分0 秒开始到现在的秒数(String)
            String curTime = ticks.ToString();

            //随机数(最大长度128个字符)
            string nonce = "12345";

            string random = new Random().ToString();

            //SHA1(AppSecret + Nonce + CurTime),三个参数拼接的字符串,进行SHA1哈希计算,转化成16进制字符(String,小写)
            String checkSum = CheckSumBuilder.getCheckSum(APP_SECRET, nonce, curTime);

            StringBuilder phoneNumStringBuider = new StringBuilder();

            for (int i = 0; i < phoneNums.Count(); i++)
            {
                if (i == phoneNums.Count() - 1)
                {
                    phoneNumStringBuider.Append("\"" + phoneNums[i] + "\"");
                }
                else
                {
                    phoneNumStringBuider.Append("\"" + phoneNums[i] + "\"" + ",");
                }
            }
            StringBuilder smsParamsStringBuider = new StringBuilder();

            for (int i = 0; i < smsParams.Count(); i++)
            {
                if (i == smsParams.Count() - 1)
                {
                    smsParamsStringBuider.Append("\"" + smsParams[i] + "\"");
                }
                else
                {
                    smsParamsStringBuider.Append("\"" + smsParams[i] + "\"" + ",");
                }
            }

            string url = $"https://api.netease.im/sms/sendtemplate.action?templateid={templateId}&mobiles=[{phoneNumStringBuider.ToString()}]&params=[{smsParamsStringBuider.ToString()}]";
            //url += "?templateid=3063716&mobiles=[\"18611693213\"]&params=[\"7点15分\"]";//306371
            var http = NetworkRequest.CreateHttp(url);

            http.Request.Headers["AppKey"]      = APP_KEY;
            http.Request.Headers["Nonce"]       = nonce;
            http.Request.Headers["CurTime"]     = curTime;
            http.Request.Headers["CheckSum"]    = checkSum;
            http.Request.Headers["ContentType"] = "application/x-www-form-urlencoded;charset=utf-8";
            var bytes = http.Post();

            if (bytes != null)
            {
                string str = Encoding.UTF8.GetString(bytes);
            }
            return(true);
        }
Esempio n. 10
0
        public async Task <string> Get(string fileName = "")
        {
            var http  = NetworkRequest.CreateHttp("http://localhost:58221/api/localFile/chartData.json");
            var bytes = await http.GetAsync();

            string dataStr = Encoding.UTF8.GetString(bytes);

            return(dataStr);
        }
Esempio n. 11
0
        // GET: Blog
        public async Task <ActionResult> Index()
        {
            var http  = NetworkRequest.CreateHttp("http://localhost:5000/api/file/fileInfo/Documents/app");
            var bytes = await http.GetAsync();

            string  fileInfoStr   = Encoding.UTF8.GetString(bytes);
            JObject o             = JObject.Parse(fileInfoStr);
            JArray  fileInfoArray = (JArray)o.SelectToken("children");

            return(View(fileInfoArray));
        }
Esempio n. 12
0
        private async void BindDevice()
        {
            BindDeviceRequest sParams = new BindDeviceRequest();

            sParams.deviceId = Configuration.GetDeviceUniqueId();
            sParams.userName = "******";

            HttpSerializeData <BindDeviceRequest> httpSerializeData = new HttpSerializeData <BindDeviceRequest>("bindDevice.html", sParams);
            string         url            = httpSerializeData.GetURL();
            NetworkRequest networkRequest = NetworkRequest.CreateHttp(httpSerializeData.GetURL());
            var            result         = await networkRequest.PostAsync <string>(JsonAnalysis.Serialize(httpSerializeData));
        }
Esempio n. 13
0
        /// <summary>
        /// 签到,查询
        /// <param name="queryOnly">true:查询 false:签到</param>
        /// </summary>
        /// <returns></returns>
        public async Task <DoSignResponseData> DoSign(string queryOnly)
        {
            DoSignRequestParams sParams = new DoSignRequestParams();

            sParams.deviceId = Configuration.GetDeviceUniqueId();
            sParams.queryOny = queryOnly;
            HttpSerializeData <DoSignRequestParams> httpSerializeData = new HttpSerializeData <DoSignRequestParams>("doSign.html", sParams);
            NetworkRequest networkRequest = NetworkRequest.CreateHttp(httpSerializeData.GetURL());
            var            resultJson     = await networkRequest.PostAsync <string>(JsonAnalysis.Serialize(httpSerializeData));

            HttpDeserializeData <DoSignResponseData> sData = JsonAnalysis.Deserialize <HttpDeserializeData <DoSignResponseData> >(resultJson);

            if (sData == null)
            {
                //todo:报错
                var res = CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    var msg = new MessageDialog("网络请求错误!").ShowAsync();
                });
            }
            if (queryOnly.Equals("false"))
            {
            }
            if (sData.result.error == "00")// 签到成功
            {
                this.SystemTime  = sData.result.sysTime;
                this.SignInTime  = sData.result.signInTime;
                this.SignOutTime = sData.result.signOutTime;
                this.UserName    = sData.result.realName;
                return(sData.result);
            }
            else if (sData.status.code.Equals("0000"))
            {
                this.SystemTime  = sData.result.sysTime;
                this.SignInTime  = sData.result.signInTime;
                this.SignOutTime = sData.result.signOutTime;
                this.UserName    = sData.result.realName;
                if (queryOnly.Equals("false"))
                {
                    //todo:报错
                    var res = CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        var msg = new MessageDialog(sData.result.errorMsg).ShowAsync();
                    });
                }
                return(sData.result);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 14
0
        private async void PostHttpRequest_Async_Click(object sender, RoutedEventArgs e)
        {
            string url = "http://baike.baidu.com/cms/global/lemma_config.json";

            byte[]         bytes   = null;
            string         str     = null;
            NetworkRequest request = NetworkRequest.CreateHttp(url);

            bytes = await request.PostAsync();

            str = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
            this.result_tbk.Text = str;
        }
Esempio n. 15
0
        public Task <string> m()
        {
            TaskCompletionSource <string> task = new TaskCompletionSource <string>();

            Task.Run(async() =>
            {
                string str             = null;
                NetworkRequest request = NetworkRequest.CreateHttp("http://baike.baidu.com/cms/global/lemma_config.json");
                str = await request.GetAsync <string>();
                task.SetResult(str);
            });
            return(task.Task);
        }
Esempio n. 16
0
        public async Task <string> BindDevice(string userName)
        {
            BindDeviceRequest sParams = new BindDeviceRequest();

            sParams.deviceId = Configuration.GetDeviceUniqueId();
            sParams.userName = userName;

            HttpSerializeData <BindDeviceRequest> httpSerializeData = new HttpSerializeData <BindDeviceRequest>("bindDevice.html", sParams);
            string         url            = httpSerializeData.GetURL();
            NetworkRequest networkRequest = NetworkRequest.CreateHttp(httpSerializeData.GetURL());
            var            result         = await networkRequest.PostAsync <string>(JsonAnalysis.Serialize(httpSerializeData));

            return(result);
        }
Esempio n. 17
0
        private async void GetHttpRequest_Async_Click(object sender, RoutedEventArgs e)
        {
            //byte[] bytes = null;
            //string str = null;
            //HttpRequest request = HttpRequest.CreatHttp("http://p5.sinaimg.cn/2776321060/180/73181353913818");
            //bytes = await request.GetAsync();
            //str = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
            //this.img.Source = await ToolsLib.Utility.GetBitmapImageAsync(bytes);

            NetworkRequest request = NetworkRequest.CreateHttp("http://p5.sinaimg.cn/2776321060/180/73181353913818");

            //this.img.Source = await request.GetBitmapImageAsync();
            this.img.Source = await request.GetAsync <BitmapImage>();
        }
Esempio n. 18
0
        private void GetHttpRequest_Sync_Click(object sender, RoutedEventArgs e)
        {
            //var dd = m().Result;


            //byte[] bytes = null;
            //string str = null;
            //HttpRequest request = HttpRequest.CreatHttp("http://baike.baidu.com/cms/global/lemma_config.json");
            //bytes = request.Get();
            //str = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
            //this.result_tbk.Text = str;


            NetworkRequest request = NetworkRequest.CreateHttp("http://baike.baidu.com/cms/global/lemma_config.json");

            this.result_tbk.Text = request.Get <string>();
        }
Esempio n. 19
0
        async void OnItemSelected(object sender, SelectedItemChangedEventArgs args)
        {
            var item = args.SelectedItem as Item;

            if (item == null)
            {
                return;
            }
            //var Request = WebRequest.CreateHttp("http://www.zoupenghui.com");
            //var str = await NetworkRequest.CreateHttp("http://www.zoupenghui.com").GetAsync();
            //var content = Encoding.UTF8.GetString(str);
            //Debug.Write(content);
            string htmlContent = await NetworkRequest.CreateHttp("http://www.zoupenghui.com").GetAsync <string>();

            Debug.Write(htmlContent);

            await Navigation.PushAsync(new ItemDetailPage(new ItemDetailViewModel(item)));

            // Manually deselect item
            ItemsListView.SelectedItem = null;
        }
Esempio n. 20
0
        private async void GetUserInfo()
        {
            GetUserInforRequestParams sParams = new GetUserInforRequestParams();

            sParams.deviceId = Configuration.GetDeviceUniqueId();
            HttpSerializeData <GetUserInforRequestParams> httpSerializeData = new HttpSerializeData <GetUserInforRequestParams>("getUserInfo.html", sParams);
            NetworkRequest networkRequest = NetworkRequest.CreateHttp(httpSerializeData.GetURL());
            var            resultJson     = await networkRequest.PostAsync <string>(JsonAnalysis.Serialize(httpSerializeData));

            HttpDeserializeData <GetUserInforResponseData> sData = JsonAnalysis.Deserialize <HttpDeserializeData <GetUserInforResponseData> >(resultJson);

            if (sData.result.error == "01")   // 未绑定账户
            {
                //todo:跳转到绑定页面,进行用户绑定
            }
            else if (sData.status.code.Equals("0000"))
            {
                //todo:跳转到签到页面
            }
            else
            {
            }
        }