WallpaperTool.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using Azylee.Core.DataUtils.CollectionUtils;
  2. using Azylee.Jsons;
  3. using Azylee.YeahWeb.HttpUtils;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Net;
  8. using System.Text;
  9. namespace Azylee.YeahWeb.ExtWebAPI.BingWebAPI.WallpaperUtils
  10. {
  11. /// <summary>
  12. /// Bing壁纸工具类
  13. /// </summary>
  14. public static class WallpaperTool
  15. {
  16. // 图片尺寸信息
  17. // 1920x1200 1920x1080 1366x768 1280x768
  18. // 1024x768 800x600 800x480 768x1280
  19. // 720x1280 640x480 480x800 400x240
  20. // 320x240 240x320
  21. const string URL = "https://cn.bing.com/HPImageArchive.aspx?format=js&idx={0}&n=8";
  22. /// <summary>
  23. /// 获取今天的壁纸
  24. /// </summary>
  25. /// <returns></returns>
  26. public static WallpaperWebModel GetToday()
  27. {
  28. return GetSomeday(0);
  29. }
  30. /// <summary>
  31. /// 获取昨天的壁纸
  32. /// </summary>
  33. /// <returns></returns>
  34. public static WallpaperWebModel GetYesterday()
  35. {
  36. return GetSomeday(1);
  37. }
  38. public static List<ImagesItem> GetLast10Days()
  39. {
  40. List<ImagesItem> result = new List<ImagesItem>();
  41. for (var i = 0; i < 10; i++)
  42. {
  43. WallpaperWebModel model = GetSomeday(i);
  44. if (model != null && Ls.Ok(model.images))
  45. {
  46. foreach (var img in model.images)
  47. {
  48. if (!result.Any(x => x.hsh == img.hsh))
  49. {
  50. result.Add(img);
  51. }
  52. }
  53. }
  54. }
  55. return result;
  56. }
  57. /// <summary>
  58. /// 获取某一天的壁纸(每天8张)
  59. /// </summary>
  60. /// <param name="day"></param>
  61. /// <returns></returns>
  62. public static WallpaperWebModel GetSomeday(int day)
  63. {
  64. WallpaperWebModel model = null;
  65. try
  66. {
  67. string rs = HttpTool.Get(string.Format(URL, day));
  68. model = Json.String2Object<WallpaperWebModel>(rs);
  69. return model;
  70. }
  71. catch (Exception e) { return null; }
  72. }
  73. }
  74. }