public void RequestApi() { _thread01 = new Thread(() => { var apiUrl = String.Format(StaticResources.ZHIHU_QUESTION_API, tb_question.Text, 20, 0); HttpComm httpComm = new HttpComm(); httpComm.Cookies = _cookieContainers; while (true) { try { httpComm.Request(apiUrl); var res = new string(Encoding.UTF8.GetChars(httpComm.ResponseBts)); var jsonObj = Newtonsoft.Json.JsonConvert.DeserializeObject <ResJsonResponse>(res); //data是否有数据 if (jsonObj.data != null && jsonObj.data.Count > 0) { for (int i = 0; i < jsonObj.data.Count; i++) { var url = string.Format(StaticResources.ZHIHU_ANSWER_API, _question, jsonObj.data[i].id); _urls.Enqueue(Tuple.Create(url, jsonObj.data[i].Copy())); } Invoke(new MethodInvoker(delegate() { rtb_msg.Text = "RequestApi:" + apiUrl + "(" + jsonObj.data.Count + ")" + "\r\n" + rtb_msg.Text; })); apiUrl = jsonObj.paging.next; } else { break; } } catch (Exception ex) { Invoke(new MethodInvoker(delegate() { rtb_errorMsg.Text = "RequestApi:" + ex.Message + "\r\n" + rtb_errorMsg.Text; })); break; } } Invoke(new MethodInvoker(delegate() { rtb_msg.Text = "RequestApi[done]" + _urls.Count.ToString() + "\r\n" + rtb_msg.Text; })); }); _thread01.Start(); }
private async Task ExecuteCommandAsync(Command command, int percentValue = 0) { var prefsInfo = new PrefsInfo(Prefs); if (prefsInfo.IsReady) { try { var url = FormatCommandResource(prefsInfo.Host, prefsInfo.Port, command, percentValue.Clamp(0, 100)); await HttpComm.Request() .WithContentType(HttpContentType.Html) .WithMethod(HttpMethod.Get) .WithUrl(url) .ExecuteAsync(); } catch (Exception) { } } }
private async Task <byte[]> GetSnapshotAsync() { var prefsInfo = new PrefsInfo(Prefs); if (prefsInfo.IsReady) { try { var url = FormatUrl(UrlSnapshotFormat, prefsInfo.Host, prefsInfo.Port); return(await HttpComm.Request() .WithContentType(HttpContentType.Jpeg) .WithMethod(HttpMethod.Get) .WithUrl(url) .GetResponseBytesAsync()); } catch (Exception) { return(null); } } return(null); }
private async Task <PlayerExecutionData> GetVariablesAsync() { var prefsInfo = new PrefsInfo(Prefs); if (prefsInfo.IsReady) { try { var url = FormatUrl(UrlVariablesFormat, prefsInfo.Host, prefsInfo.Port); var html = await HttpComm.Request() .WithContentType(HttpContentType.Html) .WithMethod(HttpMethod.Get) .WithUrl(url) .GetResponseStringAsync(); return(PlayerExecutionData.FromHtml(html)); } catch (Exception) { return(null); } } return(null); }
public void GetImgUrl() { _thread02 = new Thread(() => { HttpComm httpComm = new HttpComm(); // _driver = PhantomJSDriverComm.Driver; int count = 0; int imgCount = 0; while (true) { if (_urls.TryDequeue(out var answer)) { var url = answer.Item1; try { count++; httpComm.Request(url); var res = new string(Encoding.UTF8.GetChars(httpComm.ResponseBts)); var imgs = res.GetAnswerDivRichContent(); for (int i = 0; i < imgs.Count; i++) { _ImgUrls.Enqueue(Tuple.Create(imgs[i], answer.Item2.Copy())); } imgCount += imgs.Count; //_driver.Navigate().GoToUrl(url); //Thread.Sleep(100); ////if (_driver.Title.Contains("安全验证")) ////{ //// var captchaImg = _driver.FindElement(By.XPath("//button[@class='Button Unhuman-cofirm Button--primary Button--blue']")); ////} //var source = _driver.PageSource; //var richContentInner = _driver.FindElement(By.XPath("//div[@class='RichContent RichContent--unescapable']")); //var imgs = richContentInner.FindElements(By.XPath("//div[@class='VagueImage origin_image zh-lightbox-thumb']")); //for (int i = 0; i < imgs.Count; i++) //{ // _ImgUrls.Enqueue(Tuple.Create(imgs[i].GetAttribute("data-src"), Data.Copy(answer.Item2))); //} //imgCount += imgs.Count; Invoke(new MethodInvoker(delegate() { var message = string.Format("GetImgUrl:{0}({1})({2})({3})", url, count.ToString(), imgs.Count, imgCount); rtb_getImgUrl.Text = message + "\r\n" + rtb_getImgUrl.Text; })); } catch (Exception ex) { Invoke(new MethodInvoker(delegate() { rtb_errorMsg.Text = "GetImgUrl:" + ex.Message + "\r\n" + rtb_errorMsg.Text; })); } } else { Invoke(new MethodInvoker(delegate() { rtb_getImgUrl.Text = "GetImgUrl:" + count.ToString() + "\r\n" + rtb_getImgUrl.Text; })); Thread.Sleep(1000); } } }); _thread02.Start(); }
public void DownImg() { _thread03 = new Thread(() => { HttpComm httpComm = new HttpComm(); int count = 0; while (true) { if (_ImgUrls.TryDequeue(out var img)) { var url = img.Item1; var path01 = string.Format("{0}-{1}", img.Item2.question.id, img.Item2.question.title.ToDirectoryPath() ); var path02 = string.Format("{0}-{1}-{2}", img.Item2.id, img.Item2.author.name.ToDirectoryPath(), img.Item2.CreatedTime ); var fullPath = string.Empty; var fileNname = string.Empty; if (cb_isClassify.Checked) { fullPath = Path.Combine(path01, path02); fileNname = Guid.NewGuid().ToString() + Path.GetExtension(url); } else { fullPath = path01; fileNname = path02 + Guid.NewGuid().ToString() + Path.GetExtension(url); } if (!System.IO.Directory.Exists(fullPath)) { Directory.CreateDirectory(fullPath); } var path = Path.Combine(fullPath, fileNname); try { httpComm.Request(url); var byts = httpComm.ResponseBts; FileComm.WriteFile(path, byts); Invoke(new MethodInvoker(delegate() { rtb_downImg.Text = "DownImg:" + url + "\r\n" + rtb_downImg.Text; })); } catch (Exception ex) { Invoke(new MethodInvoker(delegate() { rtb_errorMsg.Text = "DownImg:" + ex.Message + "\r\n" + rtb_errorMsg.Text; })); } } else { Invoke(new MethodInvoker(delegate() { rtb_downImg.Text = "DownImg:" + (++count).ToString() + "\r\n" + rtb_downImg.Text; })); Thread.Sleep(1000); } } }); _thread03.Start(); }
static void Main(string[] args) { var session_id = "user_session_id"; var user_score = 999; var user_times = 74; Dictionary <string, string> header = new Dictionary <string, string> { { "charset", "utf-8" }, { "Accept-Encoding", "gzip" }, { "referer", " https://servicewechat.com/wx7c8d593b2c3a7703/5/page-frame.html" }, { "content-type", "application/json" }, { "User-Agent", "MicroMessenger/6.6.1.1220(0x26060133) NetType/WIFI Language/zh_CN" }, { "Host", "mp.weixin.qq.com" } }; var aes_key = session_id.Substring(0, 16); AESComm.CipherMode = System.Security.Cryptography.CipherMode.CBC; AESComm.Key = aes_key; AESComm.IV = aes_key; //其中game_data、musicList、touchList可以根据分数进行程序模拟生成 var action_data = Newtonsoft.Json.JsonConvert.SerializeObject( new { score = user_score, times = user_times, game_data = Newtonsoft.Json.JsonConvert.SerializeObject( new { seed = DateTime.Now.Ticks, action = new object[][] { new object[] { 0.8, 1.16, false }, new object[] { 0.592, 1.56, false }, new object[] { 0.816, 1.12, false }, new object[] { 0.852, 1.06, false }, new object[] { 0.512, 1.73, false }, new object[] { 0.626, 1.5, false }, new object[] { 0.101, 2.55, false }, new object[] { 0.083, 2.58, false }, new object[] { 0.8, 1.16, false }, new object[] { 0.592, 1.56, false }, new object[] { 0.816, 1.12, false }, new object[] { 0.852, 1.06, false }, new object[] { 0.512, 1.73, false }, new object[] { 0.626, 1.5, false }, new object[] { 0.101, 2.55, false }, new object[] { 0.083, 2.58, false } }, musicList = new bool[] { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false }, touchList = new object[][] { new object[] { 105.88172, 571.77454 }, new object[] { 106.875, 572.5244 }, new object[] { 108.28125, 573.9697 }, new object[] { 110.390625, 575.95703 }, new object[] { 111.18164, 578.125 }, new object[] { 110.74219, 577.7637 }, new object[] { 114.87305, 585.35156 }, new object[] { 112.67578, 585.89355 }, new object[] { 105.88172, 571.77454 }, new object[] { 106.875, 572.5244 }, new object[] { 108.28125, 573.9697 }, new object[] { 110.390625, 575.95703 }, new object[] { 111.18164, 578.125 }, new object[] { 110.74219, 577.7637 }, new object[] { 114.87305, 585.35156 }, new object[] { 112.67578, 585.89355 } }, version = "1" }) }); var encryptstr = AESComm.Encrypt(action_data); var pa = "{\"base_req\":{\"session_id\":\"" + session_id + "\",\"fast\":1},\"action_data\":\"" + encryptstr + "\"}"; var http = new HttpComm { Url = "https://mp.weixin.qq.com/wxagame/wxagame_settlement", Method = "post", Headers = header, Params = pa }; http.Request(); var res = Encoding.UTF8.GetString(http.ResponseBts); Console.WriteLine(res); Console.ReadKey(); }