using Azylee.Core.DataUtils.CollectionUtils;
using Azylee.Jsons;
using Azylee.YeahWeb.HttpUtils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
namespace Azylee.YeahWeb.ExtWebAPI.BingWebAPI.WallpaperUtils
{
///
/// Bing壁纸工具类
///
public static class WallpaperTool
{
// 图片尺寸信息
// 1920x1200 1920x1080 1366x768 1280x768
// 1024x768 800x600 800x480 768x1280
// 720x1280 640x480 480x800 400x240
// 320x240 240x320
const string URL = "https://cn.bing.com/HPImageArchive.aspx?format=js&idx={0}&n=8";
///
/// 获取今天的壁纸
///
///
public static WallpaperWebModel GetToday()
{
return GetSomeday(0);
}
///
/// 获取昨天的壁纸
///
///
public static WallpaperWebModel GetYesterday()
{
return GetSomeday(1);
}
public static List GetLast10Days()
{
List result = new List();
for (var i = 0; i < 10; i++)
{
WallpaperModel model = GetSomeday(i);
if (model != null && Ls.Ok(model.images))
{
foreach (var img in model.images)
{
if (!result.Any(x => x.hsh == img.hsh))
{
result.Add(img);
}
}
}
}
return result;
}
///
/// 获取某一天的壁纸(每天8张)
///
///
///
public static WallpaperWebModel GetSomeday(int day)
{
WallpaperWebModel model = null;
try
{
string rs = HttpTool.Get(string.Format(URL, day));
model = Json.String2Object(rs);
return model;
}
catch (Exception e) { return null; }
}
}
}