/// <summary> /// 删除Cookie信息 /// </summary> /// <param name="info">Cookie信息,其中必须设置Name或Cookie属性</param> public void RemoveCookieInfo(CookieInfo info) { try { XmlDocument doc = new XmlDocument(); doc.Load(this.fileName); XmlNode root = doc.DocumentElement; //获取所有Cookie节点 XmlNodeList cookies = root.SelectNodes("ItemGroup/Cookie"); //寻找同一Cookie XmlNode removeNeededNode = null; foreach (XmlNode cookie in cookies) { if (cookie.Attributes["name"].Value == info.Name || cookie.InnerText == info.Cookie) { removeNeededNode = cookie; } } if (removeNeededNode != null) { //删除Cookie removeNeededNode.ParentNode.RemoveChild(removeNeededNode); doc.Save(this.fileName); } } catch (Exception ex) { } }
private CookieInfo XmlNode2CookieInfo(XmlNode userNode) { var cookieInfo = new CookieInfo(); cookieInfo.Cookie = userNode.InnerText; cookieInfo.Name = GetNodeAttribute(userNode, "name", ""); long temp = 0; if (long.TryParse(GetNodeAttribute(userNode, "id", null), out temp)) { cookieInfo.Id = temp; } cookieInfo.CertData = GetNodeAttribute(userNode, "certData", null); return(cookieInfo); }
/// <summary> /// 处理程序参数 /// </summary> /// <param name="args"></param> private static void HandleArgs(string[] args) { if (args.Length == 1 && args[0].StartsWith("/u:")) { string name = args[0].Substring(3); CookieInfo cookieInfoFound = GlobalContext.HistoryCookies.Find( match => match.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)); if (cookieInfoFound != null) { var helper = new PapdHelper(); var info = helper.QueryRewardInfo(cookieInfoFound.Cookie, 3000); if (!info.IsPreMoneyFetch()) { helper.FetchReward(cookieInfoFound.Cookie, info.preRewardId); } } Environment.Exit(0); } }
private void 切换账号ToolStripMenuItem_Click(object sender, EventArgs e) { if (this.listView1.SelectedItems.Count < 1) { return; } var item = this.listView1.SelectedItems[0]; CookieInfo cookieInfo = item.Tag as CookieInfo; string cookie = cookieInfo.Cookie; var frmLogin = new FrmLogin(cookie, true); if (frmLogin.ShowDialog() == System.Windows.Forms.DialogResult.OK) { GlobalContext.MainForm.ChangeLoginState(frmLogin.MyUserInfo, frmLogin.CookieString, frmLogin.CertPath); } frmLogin.Dispose(); }
/// <summary> /// 获取配置信息 /// </summary> /// <returns></returns> public ConfigInfo GetConfigInfo() { ConfigInfo info = new ConfigInfo(); info.HistoryCookies = new List <CookieInfo>(); info.IsTestMode = false; try { XmlDocument doc = new XmlDocument(); doc.Load(this.fileName); XmlNode root = doc.DocumentElement; //历史Cookies XmlNodeList historyCookieNodes = root.SelectNodes("ItemGroup/Cookie"); foreach (XmlNode cookieNode in historyCookieNodes) { var cookieInfo = new CookieInfo(); cookieInfo.Cookie = cookieNode.InnerText.Trim(); cookieInfo.Name = GetNodeAttribute(cookieNode, "name", ""); var strId = GetNodeAttribute(cookieNode, "id", null); var id = 0l; if (long.TryParse(strId, out id)) { cookieInfo.Id = id; } cookieInfo.CertData = GetNodeAttribute(cookieNode, "certData", null); info.HistoryCookies.Add(cookieInfo); } //是否为测试模式 XmlNode isTestModeNode = root.SelectSingleNode("PropertyGroup/IsTestMode"); bool isTestMode; if (bool.TryParse(isTestModeNode.InnerText, out isTestMode)) { info.IsTestMode = isTestMode; } // 随机步数 XmlNode randomStepNode = root.SelectSingleNode("PropertyGroup/RandomStep"); info.RandomMinStep = Convert.ToInt32(GetNodeAttribute(randomStepNode, "min", ConfigInfo.Default_Random_Min_Step.ToString())); info.RandomMaxStep = Convert.ToInt32(GetNodeAttribute(randomStepNode, "max", ConfigInfo.Default_Random_Max_Step.ToString())); // 请求设置 XmlNode reqNode = root.SelectSingleNode("PropertyGroup/Request"); info.RequestTimeoutInSeconds = Convert.ToInt32(GetNodeAttribute(reqNode, "timeout", ConfigInfo.Default_Request_Timeout.ToString())); info.IsAutoFetchYesterdayBonus = Convert.ToBoolean(GetNodeValue( root.SelectSingleNode("PropertyGroup/IsAutoFetchYesterdayBonus"), "true")); info.IsAutoGrabGold = Convert.ToBoolean(GetNodeValue( root.SelectSingleNode("PropertyGroup/IsAutoGrabGold"), "true")); info.IsAutoGrabTreasure = Convert.ToBoolean(GetNodeValue( root.SelectSingleNode("PropertyGroup/IsAutoGrabTreasure"), "false")); info.IsAutoUploadWalkData = Convert.ToBoolean(GetNodeValue( root.SelectSingleNode("PropertyGroup/IsAutoUploadWalkData"), "false")); info.CreateOrderTimespan = Convert.ToInt32(GetNodeValue(root.SelectSingleNode("PropertyGroup/CreateOrderTimespan"), "false")); } catch (Exception ex) { // 修复配置文件不存在时,导致读取的RequestTimeoutInSeconds为0,从而查询接口时超时的bug info.RandomMinStep = 30000; info.RandomMaxStep = 40000; info.IsTestMode = false; info.IsAutoFetchYesterdayBonus = true; info.IsAutoGrabGold = true; info.IsAutoGrabTreasure = true; info.IsAutoUploadWalkData = true; info.RequestTimeoutInSeconds = 15000; info.CreateOrderTimespan = 14; } return(info); }
/// <summary> /// 更新Cookie信息,不存在时,则新增 /// </summary> /// <param name="info"></param> public void UpdateCookieInfo(CookieInfo info) { // 用户id不能为空 if (info.Id == null) { return; } if (!IsFileValid()) { CreateNewFile(); } try { XmlDocument doc = new XmlDocument(); doc.Load(this.fileName); var rootNode = doc.DocumentElement; var cookies = rootNode.SelectNodes("ItemGroup/Cookie"); XmlNode sameNode = null; foreach (XmlNode cookie in cookies) { string id = cookie.Attributes["id"].InnerText.Trim(); if (id == info.Id.ToString()) { //已经存在该账号,则更新 sameNode = cookie; break; } } if (sameNode == null) { //不存在该账号,则新增 sameNode = doc.CreateElement("Cookie"); sameNode.Attributes.Append(doc.CreateAttribute("id")); sameNode.Attributes.Append(doc.CreateAttribute("name")); sameNode.Attributes.Append(doc.CreateAttribute("certData")); var parentNode = rootNode.SelectSingleNode("ItemGroup"); parentNode.AppendChild(sameNode); } if (info.Id != null) { SetNodeAttribute(sameNode, "id", info.Id); } if (!Util.StringTool.IsNullOrWhitespace(info.Name)) { SetNodeAttribute(sameNode, "name", info.Name); } if (!Util.StringTool.IsNullOrWhitespace(info.CertData)) { SetNodeAttribute(sameNode, "certData", info.CertData); } if (!Util.StringTool.IsNullOrWhitespace(info.Cookie)) { sameNode.InnerText = info.Cookie; } doc.Save(this.fileName); } catch (Exception ex) { } }
private void toolStripButton2_Click(object sender, EventArgs e) { if (this.listView1.CheckedItems.Count < 1) { MsgBox.ShowInfo("请勾选账号!"); return; } List <int> checkedRows = new List <int>(); for (int i = 0; i < this.listView1.CheckedItems.Count; i++) { checkedRows.Add(this.listView1.CheckedItems[i].Index); } ThreadPool.QueueUserWorkItem(o => { var configInfo = ConfigStorage.GetInstance().GetConfigInfo(); SetControlEnabled(this.toolStrip1, false); for (int i = 0; i < checkedRows.Count; i++) { int index = checkedRows[i]; CookieInfo cookieInfo = GetListViewItemTag <CookieInfo>(this.listView1, index); string cookie = cookieInfo.Cookie; string id = cookieInfo.Id.ToString(); string cert = cookieInfo.CertPath; bool fetchYestodayReward = true; if (configInfo.IsAutoFetchYesterdayBonus) { #region 领取昨日奖励 SetListViewItemValue(this.listView1, index, 7, "正在领取奖励"); try { var rewardInfo = PH.QueryRewardInfo(cookie, 3000); if (!rewardInfo.IsPreMoneyFetch()) { var fetchRewardResult = PH.FetchReward(cookie, rewardInfo.preRewardId); SetListViewItemValue(this.listView1, index, 7, "昨日奖励领取成功!"); } else { SetListViewItemValue(this.listView1, index, 7, "昨日奖励已领取。"); } } catch (Exception ex) { SetListViewItemValue(this.listView1, index, 7, "昨日奖励领取失败!"); fetchYestodayReward = false; } #endregion } Thread.Sleep(1000); int grabGoldSuccess = 0; if (configInfo.IsAutoGrabGold) { #region 抢金 SetListViewItemValue(this.listView1, index, 7, "正在抢金"); try { var grabGoldInfo = PH.GetGrabGoldInfo(cookie, 1); for (int j = 0; j < grabGoldInfo.userRankingList.Length; j++) { var user = grabGoldInfo.userRankingList[j]; if (!user.IsGrabGoldAvailable()) { continue; } try { PH.GrabGoldFromFollower(cookie, user.userInfo.userId); grabGoldSuccess++; } catch (Exception ex) { SetListViewItemValue(this.listView1, index, 7, "抢金错误"); } } SetListViewItemValue(this.listView1, index, 7, "成功抢金" + grabGoldSuccess + "个好友!"); } catch (Exception ex) { SetListViewItemValue(this.listView1, index, 7, "抢金失败"); } #endregion } int fetchBoxCount = 0; if (configInfo.IsAutoGrabTreasure) { #region 步步夺宝 SetListViewItemValue(this.listView1, index, 7, "正在夺宝..."); var fetchBoxFuncList = new List <Func <string, PajkResultList <PajkFetchBoxResult> > >(); fetchBoxFuncList.Add(PH.FetchBoxByShareReading); fetchBoxFuncList.Add(PH.FetchBoxByWalkMall); fetchBoxFuncList.Add(PH.FetchBoxByInviteFriend); fetchBoxFuncList.Add(PH.FetchBoxByVideo); for (int j = 0; j < fetchBoxFuncList.Count; j++) { try { var fetchResult = fetchBoxFuncList[j](cookie); Thread.Sleep(1200); SetListViewItemValue(this.listView1, index, 7, "得到宝箱:" + fetchResult.Content[0].BoxGiftList[0].GiftName); fetchBoxCount += fetchResult.Content[0].BoxGiftList.Length; } catch (Exception ex) { } } #endregion } Thread.Sleep(1000); bool uploadWalkData = true; float sc = 0f; if (configInfo.IsAutoUploadWalkData) { #region 走步数据 SetListViewItemValue(this.listView1, index, 7, "正在上传走步数据"); try { var downloadResult = PH.DownloadWalkData(id, cookie, cert); if (downloadResult != null) { PajkWalkDataInfo today = null; if (downloadResult.Content[0].walkDataInfos == null || (today = downloadResult.Content[0].walkDataInfos.Find( match => match.walkDate == DateTime.Now.ToString("yyyyMMdd"))) == null) { int stepCount = new Random((int)DateTime.Now.Ticks).Next( GlobalContext.CurrentConfigInfo.RandomMinStep, GlobalContext.CurrentConfigInfo.RandomMaxStep); sc = stepCount; var result = PH.UploadWalkData(id, cookie, cert, stepCount); if (result.Content[0].Value) { SetListViewItemValue(this.listView1, index, 7, "成功上传走步" + stepCount + "!"); } else { throw new Exception(result.Stat.Code.ToString()); } } else { sc = today.stepCount; SetListViewItemValue(this.listView1, index, 7, "今天已上传走步" + today.stepCount + "。"); } } } catch (Exception ex) { SetListViewItemValue(this.listView1, index, 7, "上传走步失败"); uploadWalkData = false; } #endregion } SetListViewItemValue(this.listView1, index, 7, string.Format("领取昨日奖励:{0},上传走步:{1},成功抢金:{2}个,得到宝箱:{3}个", fetchYestodayReward?"成功":"失败", uploadWalkData?sc.ToString():"失败", grabGoldSuccess, fetchBoxCount)); } SetControlEnabled(this.toolStrip1, true); }); }