using HybirdFrameworkCore.Entity;
using log4net;
using Newtonsoft.Json;
using Service.Bramek.Bramek;
namespace Service.Execute.Api;
public class BramekApi
{
private static readonly ILog Log = LogManager.GetLogger("BramekApi");
private static readonly string GetLaneInformationOpenBASE_URL = "http://openapi.szymzh.com/Api/Inform/OpenGate";
private static readonly string GetLaneInformationDownBASE_URL = "http://openapi.szymzh.com/Api/Inform/CloseGate";
private static readonly string RemoteShutdownBASE_URL = "http://openapi.szymzh.com/Api/Inquire/GetVehicleInfo";
private static readonly HttpClient _httpClient = new ()
{
Timeout = TimeSpan.FromSeconds(60)
};
///
/// 闸机开
///
///
public static async Task GetLaneInformationOpen()
{
Log.Info($" BramekApi GetLaneInformationOpen");
string url = GetLaneInformationOpenBASE_URL;
try
{
string s = await _httpClient.GetStringAsync(url);
if (!String.IsNullOrWhiteSpace(s))
{
Log.Info($" BramekApi GetLaneInformationOpen recesive{s}");
RemoteShutdownResp? succ = JsonConvert.DeserializeObject(s);
if (succ.code == 1)
{
return true;
}
else
{
return false;
}
}
return false;
}
catch (Exception e)
{
Log.Error($" BramekApi GetLaneInformationOpen ,e={e}");
return false;
}
}
///
/// 闸机关
///
///
public static async Task GetLaneInformationDown()
{
Log.Info($" BramekApi GetLaneInformationDown");
string url = GetLaneInformationDownBASE_URL;
try
{
string s = await _httpClient.GetStringAsync(url);
if (!String.IsNullOrWhiteSpace(s))
{
Log.Info($" BramekApi GetLaneInformationDown recesive{s}");
RemoteShutdownResp? succ = JsonConvert.DeserializeObject(s);
if (succ.code == 1)
{
return true;
}
else
{
return false;
}
}
return false;
}
catch (Exception e)
{
Log.Error($" BramekApi GetLaneInformationDown ,e={e}");
return false;
}
}
///
/// 获取车道信息
///
///
public static async Task GetLaneInformation()
{
Log.Info($" BramekApi GetLaneInformation");
string url = RemoteShutdownBASE_URL;
try
{
string s = await _httpClient.GetStringAsync(url);
if (!String.IsNullOrWhiteSpace(s))
{
Log.Info($" BramekApi GetLaneInformation recesive{s}");
GetLaneInformationResp? succ = JsonConvert.DeserializeObject(s);
if (succ != null)
{
return succ;
}
else
{
return null;
}
}
return null;
}
catch (Exception e)
{
Log.Error($" BramekApi GetLaneInformation ,e={e}");
return null;
}
}
}