Files
KJD/Store.Framework/Services/CommonService.cs
T
2026-09-11 19:11:12 +08:00

84 lines
2.4 KiB
C#

using MAX.Core.DependencyInjection;
using MAX.Core.Helpers;
using Store.Client;
using Store.Client.Apis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Store.Client.Services
{
internal class CommonService : ITransientDependency
{
private readonly CommonApi _commonApi;
public CommonService(CommonApi commonApi)
{
_commonApi = commonApi;
}
/// <summary>
/// 获取签名配置
/// </summary>
public void LoadAuthConfig()
{
var value = _commonApi.GetAuthConfig();
if (!string.IsNullOrEmpty(value))
{
ServerConfig.IsNewSignatureAuth = value.Equals("1");
}
}
/// <summary>
/// 获取本地与服务器时间差
/// </summary>
public void LoadServerTimeSpan()
{
DateTime SDateTime = _commonApi.GetServerTime();
long s = DateHelper.GetUnixTimestampInSeconds(SDateTime);
long a = DateHelper.GetUnixTimestampInSeconds(DateTime.Now);
ServerConfig.TimeDifferent = s - a;
}
/// <summary>
/// 获取服务器时间戳
/// </summary>
/// <returns></returns>
public static long GetServerUnix()
{
return DateHelper.GetUnixTimestampInSeconds(DateTime.Now) + ServerConfig.TimeDifferent;
}
/// <summary>
/// 获取服务器时间
/// </summary>
/// <returns></returns>
public static DateTime GetServerDataTime()
{
return DateHelper.ConvertFromUnixTimestampInSeconds(GetServerUnix());
}
///// <summary>
///// 获取服务器图片缓存
///// </summary>
///// <param name="imgUrl"></param>
///// <returns></returns>
//public string GetImageCache(string imgUrl)
//{
// string imgurl = "";
// HttpResult result = _commonApi.GetImageCache(imgUrl);
// if (result.StatusCode == System.Net.HttpStatusCode.OK)
// {
// result.Html = result.Html.Trim();
// if (Regex.IsMatch(result.Html, "^http"))
// {
// imgurl = result.Html;
// }
// }
// return imgurl;
//}
}
}