protected virtual void GetGValue(BattleCharItem item) { if (null == item) { return; } //index=0&xtoken=74c15f4a-347a-4c8e-b7aa-26704ac45ad9 const string PostGFormat = "index={0}{1}"; //lastMailId=0&xtoken=24d9b826-251b-4e42-ad80-dc775ad6ccee const string firstPostGFormate = "lastMailId=0{0}"; string gUrl = this.DetectionParamsItem.CurrentGameServer.BattleGSelectCharUrl; string postData = string.Empty; if (item.Index <= 0) { postData = string.Format(firstPostGFormate, this.GetGxstoken()); } else { postData = string.Format(PostGFormat, item.Index, this.GetGxstoken()); } string html = string.Empty; if (item.Index > 0) { html = this.ReadUrlContent(gUrl, postData); } //html = this.ReadFromUrl(item.Href); if (!isQueryed) { this.httpHeaderType = HttpHeaderType.XmlHttpRequest; html = this.ReadFromUrl(this.DetectionParamsItem.CurrentGameServer.BattleGetGUrl); this.httpHeaderType = HttpHeaderType.Normal; isQueryed = true; } int i = 0; do { this.httpHeaderType = HttpHeaderType.Json; html = this.ReadFromUrl(this.DetectionParamsItem.CurrentGameServer.BattleGetGUrlMoney, true); this.httpHeaderType = HttpHeaderType.Normal; string moneyDiv = "\"money\""; if (TextHelper.IsContains(html, moneyDiv)) { JsonData jd = JsonMapper.ToObject(html); int money = (int)jd["money"]; item.Money = money.ToString(); item.Gold = money / 10000; item.Sliver = (money - item.Gold * 10000) / 100; item.Copper = money - item.Gold * 10000 - item.Sliver * 100; return; } this.LogManager.Error(string.Format("Char:{0} get G 值失败,开始重试:{1}", item.Name, postData)); } while (i++ < 1); item.Money = "取不到G值或者出错"; }
public List <BattleCharItem> GetCharacter() { string url = this.DetectionParamsItem.CurrentGameServer.BattleCharacterUrl; string html = this.ReadFromUrl(url); characterList.Clear(); if (TextHelper.IsContains(html, "No game license was found. Please add one under your account", "No characters were found.") && !TextHelper.IsContains(html, "<div class=\"no-results hide\">No characters were found</div>")) { return(characterList); } //Remove duplicate chars int startIndex = html.IndexOf("Manage Characters"); if (startIndex > 0) { html = html.Substring(startIndex); } string enCharStart_1 = "<a href=\"/wow/en/character/"; string enCharStart_2 = "class=\"char pinned\""; string enCharStart_3 = "<a href=\"javascript:;\""; while (TextHelper.IsContains(html, enCharStart_1, enCharStart_2, enCharStart_3)) { //The first char isn't have index string item = HtmlParser.GetOuterTextFromHtml(enCharStart_3, "</a>", 1, html); if (string.IsNullOrEmpty(item)) { item = HtmlParser.GetOuterTextFromHtml(enCharStart_1, "</a>", 1, html); } if (string.IsNullOrEmpty(item)) { item = HtmlParser.GetOuterTextFromHtml(enCharStart_2, "</a>", 1, html); } if (!string.IsNullOrEmpty(item)) { html = html.Replace(item, ""); if (!TextHelper.IsContains(item, "CharSelect.pin(", "<span class=\"name\">", "class=\"icon-frame frame-14 \"")) { continue; } int index = GetIndex(item); string name = TextHelper.TrimHtml(GetName(item)); string lvlStr = TextHelper.TrimHtml(GetLvlStr(item)); int lvl = GetLvl(lvlStr); string realm = TextHelper.TrimHtml(GetRealm(item)); string href = GetItemHref(item); //May some char not as up format if (string.IsNullOrEmpty(lvlStr) || string.IsNullOrEmpty(name)) { name = HtmlParser.GetOutterPropertyFromHtml(item, "data-tooltip"); item = item.Replace(HtmlParser.GetOuterTextFromHtml("<img src=", "/>", 1, item), ""); item = item.Replace(HtmlParser.GetOuterTextFromHtml("<img src=", "/>", 1, item), ""); lvlStr = HtmlParser.GetInnerTextFromHtml(item); lvl = GetLvl(lvlStr); string[] values = name.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (string s in values) { if (s.StartsWith("(")) { realm = s; break; } } } if (!string.IsNullOrEmpty(lvlStr) && !string.IsNullOrEmpty(name)) { BattleCharItem ci = new BattleCharItem() { Index = index, Name = name, LevelStr = lvlStr, Level = lvl, Realm = realm, Href = string.Format("{0}{1}", this.GameServer.DomainUrl, href) }; if (lvl >= availableLeve) { characterList.Add(ci); } } } } if (this.DetectionParamsItem.IsGetGValue) { this.GetGValue(characterList); } return(characterList); }