public void SetUserCookieAnUserLoginStatus(string url) { Uri uri = new Uri(url); var loginRedirectURL = uri.Scheme + "://" + uri.Host + "/ytRedirect.html#" + url; //var ret = WebHttpHeper.GetRequest(loginRedirectURL, ref cookie); //txtLogs.AppendText("------登录跳转------\r\n"); var setCookieUrl = uri.Scheme + "://" + uri.Host + "/Ajax/setUserCookie"; //var rets = WebHttpHeper.PostJSONRequest(JSON.Serialize(new { url = url }), loginRedirectURL, setCookieUrl, ref cookie); var rets = WebHttpHeper.PostFormRequest("url=" + url, loginRedirectURL, setCookieUrl, ref cookie); txtLogs.AppendText("------登录成功-------\r\n"); }
/// <summary> /// /// </summary> /// <param name="url">标链接</param> /// <param name="ibnum">标号</param> /// <param name="lunchId">红包ID</param> /// <param name="amount">投资金额</param> private void InvestToRemote(string url, string retHTML, string ibnum, int lunchId, int amount)//红包ID,投资金额(根据红包来) { //html 解析值 var userID = ""; //用户ID; CUID var uniqKey = ""; //唯一key var _hash = ""; //hash 值 HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument(); document.LoadHtml(retHTML); HtmlNode cuidNode = document.GetElementbyId("cuid"); userID = cuidNode.Attributes["value"].Value; HtmlNode uniqKeyNode = document.GetElementbyId("uniqKey"); uniqKey = uniqKeyNode.Attributes["value"].Value; HtmlNode _hashNode = document.GetElementbyId("J_form_msg2").SelectSingleNode("//input[@name='__hash__']"); _hash = _hashNode.Attributes["value"].Value; //密码加密 //var ppay = Encrypt(txtPayPWD.Text, uniqKey); //支付密码 Thread.Sleep(3000); string utf8Str = (string)webBrowser1.Document.InvokeScript("utf16to8", new string[] { txtPayPWD.Text }); string xxteaEncryptStr = (string)webBrowser1.Document.InvokeScript("xxtea_encrypt", new string[] { utf8Str, uniqKey }); string ppay = (string)webBrowser1.Document.InvokeScript("encode64", new string[] { xxteaEncryptStr }); //encode64(xxtea_encrypt(utf16to8(ppay), $("#uniqKey").val())) //txtLogs.AppendText("utf8Str:" + utf8Str); //txtLogs.AppendText("xxteaEncryptStr:" + xxteaEncryptStr); txtLogs.AppendText("ppay:" + ppay); string paramStr = string.Format("p_pay={0}&user_id={1}&ibnum={2}&lunchId={3}&amount={4}&__hash__={5}&vcode=", ppay, userID, ibnum, lunchId, amount, _hash); txtLogs.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + paramStr + "\r\n"); var result = WebHttpHeper.PostFormRequest(paramStr, url, PageURL_InvestCheckPPay, ref cookie); var resultText = JSON.DeserializeDynamic(result).ToString(); txtLogs.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + resultText + "\r\n"); }
private void btn_Login_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtPayPWD.Text)) { txtLogs.AppendText("请输入支付密码!!!!\r\n"); return; } try { string file = null; if (rdoNewUser.Checked) { string userName = txt_UserName.Text.Trim(); string pwd = txt_Password.Text.Trim(); string dateStr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); string encryptPWD = Encrypt(dateStr + pwd, "oZ3qvmx4BTATvbI7", "oZ3qvmx4BTATvbI7"); var param = string.Format(@"format=json&appKey=00001&v=1.0×tamp={0}&method=sso.login&origin=1&source=1&vcode=''&cookieAge=7200&u={1}&p={2}&synUrl=https://jr.yatang.cn/index.php?s=/index/index/*type:1", dateStr, userName, encryptPWD); string res = WebHttpHeper.PostFormRequest(param, PageURL_Login, PageURL_LoginPost, ref cookie); dynamic data = null; data = JSON.DeserializeDynamic(res); if (data.code == "0") { lblUserName.Text = txt_UserName.Text; PnOptor.Show(); PnLogin.Hide(); if (!Directory.Exists(cookiesDir)) { Directory.CreateDirectory(cookiesDir); } file = cookiesDir + "/" + lblUserName.Text; WriteCookiesToDisk(file, cookie); if (data.isRedirect) { SetUserCookieAnUserLoginStatus(data.redirectUrl.ToString().Trim('"')); return; } //其他处理 return; } txtLogs.AppendText(data.message.ToString() + data.data + "\r\n"); } else { lblUserName.Text = cboSelectUser.SelectedItem.ToString(); cookie = CookiesDict[lblUserName.Text]; SetUserCookieAnUserLoginStatus("https://jr.yatang.cn/index.php?s=/index/index/*type:1"); PnLogin.Hide(); PnOptor.Show(); } CookieCollection collection = cookie.GetCookies(new Uri(PageURL_Base, UriKind.Absolute)); Cookie ckItem = collection["PayPWD"]; if (ckItem == null) { cookie.SetCookies(new Uri(PageURL_Base, UriKind.Absolute), "PayPWD=" + txtPayPWD.Text); file = cookiesDir + "/" + lblUserName.Text; WriteCookiesToDisk(file, cookie); } lblPayPWD.Text = txtPayPWD.Text; } catch (Exception ex) { txtLogs.AppendText("系统异常:" + ex.Message + "\r\n"); } }
// 用户数据,红包列表 private dynamic GetUserLuckMoney(string headerURL, dynamic invest, out bool luckMoneyDataIsNotNull) { luckMoneyRate = Convert.ToInt32(txtLuckMoneyRate.Text); string name = invest.name.ToString().Trim('"'); var retLuckMoney = WebHttpHeper.PostFormRequest("investMoney=&borrowNum=121" + name.Substring(name.IndexOf('_') + 1) + "&pageNum=1", headerURL, PageURL_GetUserCoupon, ref cookie); var data = JSON.DeserializeDynamic(retLuckMoney); luckMoneyDataIsNotNull = true; if (data.status == 0) { txtLogs.AppendText("---拉取红包" + Convert.ToString(data.info) + "\r\n"); txtLogs.AppendText("---" + data.ToString() + "\r\n"); string info = data.info.ToString().Trim('"'); //判断是否登录过期 if (info == "请先登陆") { luckMoneyDataIsNotNull = false; PnLogin.Visible = true; PnOptor.Visible = false; } else { luckMoneyDataIsNotNull = info != "暂无适合使用的红包"; } } if (data.data != null) { double withDrawal_Cash = Convert.ToDouble(data.withdrawal_cash.ToString().Trim('"')); dynamic luckMoney = null; foreach (var item in data.data) { if (invest.remain < item.user_constraint) { continue; //剩余金额小于红包金额 } //红包比例 int currRate = (int)(item.user_constraint / item.value); if (currRate <= luckMoneyRate) { double userConstraint = Convert.ToDouble(item.user_constraint.ToString()); //剩余可用红包金额大于,红包金额时 if (withDrawal_Cash > userConstraint) { //如果使用 if (luckMoney == null) { luckMoney = item; } else { int luckRate = (int)(luckMoney.user_constraint / luckMoney.value); //红包比例更小 if (currRate < luckRate) { //红包比例更小优先 luckMoney = item; continue; } else if (currRate == luckRate)//红包比例相等,优先大额 { if (item.user_constraint > luckMoney.user_constraint) { luckMoney = item; } //红包比例相等,额度相等,优先快过期 else if (item.user_constraint == luckMoney.user_constraint) { if (item.nearExpire == 1) { luckMoney = item; } } } } } } } return(luckMoney); } return(null); }
// 融资标列表 private void StartAutoInvest() { tmrRandFloat.Stop(); //用户是否有红包 bool luckMoneyDataIsNotNull = true; bool isInvestIng = false; try { //var result = WebHttpHeper.PostFormRequest("aprrange=1&selectdate=2&repaystyle=1&page_href=", "https://jr.yatang.cn/Financial/asset", "https://jr.yatang.cn/Financial/getAssetList", ref cookie); var result = WebHttpHeper.PostFormRequest("aprrange=0&selectdate=0&repaystyle=0&page_href=", "https://jr.yatang.cn/Financial/asset", "https://jr.yatang.cn/Financial/getAssetList", ref cookie); var financeData = JSON.DeserializeDynamic(result); txtLogs.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + financeData.ToString() + "\r\n"); if (financeData.status == 1 && financeData.list.Count > 0) { dynamic maxRemain = null; List <dynamic> financeList = new List <dynamic>(); //抓取剩余金额最大的一个 foreach (var item in financeData.list) { if (maxRemain == null) { maxRemain = item; } else if (item.remain > maxRemain.remain) { maxRemain = item; } financeList.Add(item); } //投标 URL string investDetailURL = PageURL_InvestDetail + maxRemain.id.ToString().Trim('"'); //请求页面,解析 html {hash,uniqKey} var retHTML = WebHttpHeper.GetRequest(investDetailURL, ref cookie); //获取用户红包 var data = GetUserLuckMoney(investDetailURL, maxRemain, out luckMoneyDataIsNotNull); //没有可用红包继续轮询 if (data != null) { //自动投资 string name = maxRemain.name.ToString().Trim('"'); string ibnum = "121" + name.Substring(name.IndexOf('_') + 1); InvestToRemote(investDetailURL, retHTML, ibnum, Convert.ToInt32(data.id.ToString().Trim('"')), Convert.ToInt32(data.user_constraint.ToString())); } //不使用红包 if (!chkUseLuckMoney.Checked) { //自动投资 string name = maxRemain.name.ToString().Trim('"'); string ibnum = "121" + name.Substring(name.IndexOf('_') + 1); InvestToRemote(investDetailURL, retHTML, ibnum, 0, Convert.ToInt32(txtInvestValue.Text)); isInvestIng = true; } } } catch (Exception ex) { txtLogs.AppendText("系统异常:" + ex.Message + "\r\n"); } finally { //使用红包,不适用红包投资中 if ((chkUseLuckMoney.Checked && luckMoneyDataIsNotNull) || (!chkUseLuckMoney.Checked && !isInvestIng)) { tmrAutoInvest.Start(); } } }