|
|
|
@ -0,0 +1,121 @@
|
|
|
|
|
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)
|
|
|
|
|
};
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 闸机开
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static async Task<bool> 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<RemoteShutdownResp>(s);
|
|
|
|
|
if (succ.code == 1)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($" BramekApi GetLaneInformationOpen ,e={e}");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 闸机关
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static async Task<bool> 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<RemoteShutdownResp>(s);
|
|
|
|
|
if (succ.code == 1)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($" BramekApi GetLaneInformationDown ,e={e}");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取车道信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static async Task<GetLaneInformationResp> 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<GetLaneInformationResp>(s);
|
|
|
|
|
if (succ != null)
|
|
|
|
|
{
|
|
|
|
|
return succ;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($" BramekApi GetLaneInformation ,e={e}");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|