public async void ScanHomePage(Recommender r) { await Windows.System.Launcher.LaunchUriAsync(new Uri(_home_page + r.Zhihu_URL_Token)); }
/// <summary> /// 获取文章的推荐者 /// </summary> /// <param name="story_id"></param> /// <returns></returns> public async Task<List<Recommender>> GetRecommenders(string story_id) { try { if (NetworkManager.Current.Network == 4) { List<Recommender> lr = await FileHelper.Current.ReadObjectAsync<List<Recommender>>(story_id + "_recommenders.json"); return lr; } else { string url = string.Format(ServiceURL.Recommenders, story_id); JsonObject json = await GetJson(url); if (json != null) { List<Recommender> list = new List<Recommender>(); string avatar = "", bio = "", id, name, zhihu_url_token = ""; JsonArray ja = null; if (json.ContainsKey("items") && json["items"].GetArray().Count > 0) { ja = json["items"].GetArray()[0].GetObject()["recommenders"].GetArray(); } else { ja = json["editors"].GetArray(); } WriteableBitmap wb; string image_ext = "jpg"; string[] sitem = null; foreach (var jv in ja) { json = jv.GetObject(); avatar = ""; bio = ""; zhihu_url_token = ""; if (json.ContainsKey("avatar")) { avatar = json["avatar"].GetString(); } if (json.ContainsKey("bio")) { bio = json["bio"].GetString(); } if (json.ContainsKey("zhihu_url_token")) { zhihu_url_token = json["zhihu_url_token"].GetString(); } id = json["id"].GetNumber().ToString(); name = json["name"].GetString(); Recommender tmp = new Recommender { Avatar = avatar, Bio = bio, ID = id, Name = name, Zhihu_URL_Token = zhihu_url_token }; if (!await FileHelper.Current.CacheExist(tmp.ID + "_recommender_avatar." + image_ext)) //没有缓存 { wb = await GetImage(tmp.Avatar); if (!tmp.Avatar.Equals("")) { sitem = tmp.Avatar.Split('.'); image_ext = sitem[sitem.Count() - 1]; } await FileHelper.Current.SaveImageAsync(wb, tmp.ID + "_recommender_avatar." + image_ext); //保存图片 } if (!tmp.Avatar.Equals("")) { tmp.Avatar = _local_path + "\\images_cache\\" + tmp.ID + "_recommender_avatar." + image_ext; //图片路径重定向 } list.Add(tmp); } await FileHelper.Current.WriteObjectAsync<List<Recommender>>(list, story_id + "_recommenders.json"); return list; } else { return null; } } } catch { return null; } }