Commit b2228e25 authored by 姜春辉's avatar 姜春辉

修正token 失效的bug

parent 939974cd
......@@ -13,6 +13,7 @@
<!-- 底部背景颜色-->
<Style x:Key="MainShell_FootBackground" TargetType="Grid">
<Setter Property="Background" Value="#121212"></Setter>
<Setter Property="Opacity" Value="0"/>
<Setter Property="Height" Value="45"></Setter>
</Style>
<Style x:Key="MainShell_FullBackground" TargetType="Grid">
......
......@@ -5,7 +5,7 @@
<Key Caption="人脸识别阀值" Name="FaceMinValue" Value="0.85"/>
<Key Caption="人证比对阀值" Name="FaceCardMatch" Value="0"/>
<Key Caption="心跳端口" Name="HeartPort" Value="18083"/>
<Key Caption="远程认证地址" Name="FaceWebSocket" Value="ws://192.168.1.7:15056/face/sdk2?persontype=访客"/>
<Key Caption="远程认证地址" Name="FaceWebSocket" Value="ws://192.168.1.7:15055/face/sdk2?persontype=访客"/>
</Dict>
<Dict Caption="识别方式配置" Name="authenticationconfig">
<Key Caption="人脸识别" Name="EnableFace" Value="true"/>
......
......@@ -13,6 +13,7 @@
<!-- 底部背景颜色-->
<Style x:Key="MainShell_FootBackground" TargetType="Grid">
<Setter Property="Background" Value="#121212"></Setter>
<Setter Property="Opacity" Value="0"/>
<Setter Property="Height" Value="45"></Setter>
</Style>
<Style x:Key="MainShell_FullBackground" TargetType="Grid">
......
......@@ -5,7 +5,7 @@
<Key Caption="人脸识别阀值" Name="FaceMinValue" Value="0.85"/>
<Key Caption="人证比对阀值" Name="FaceCardMatch" Value="0"/>
<Key Caption="心跳端口" Name="HeartPort" Value="18083"/>
<Key Caption="远程认证地址" Name="FaceWebSocket" Value="ws://192.168.1.7:15056/face/sdk2?persontype=访客"/>
<Key Caption="远程认证地址" Name="FaceWebSocket" Value="ws://192.168.1.7:15055/face/sdk2?persontype=访客"/>
</Dict>
<Dict Caption="识别方式配置" Name="authenticationconfig">
<Key Caption="人脸识别" Name="EnableFace" Value="true"/>
......
......@@ -112,6 +112,10 @@ namespace GS.Terminal.VisitorSelfService.Logic.Core
catch (Exception ex)
{
Program._Context.Logger.Error($"查询有效预约单异常", ex);
if (ex.InnerException != null)
{
Program._Context.Logger.Error($"查询有效预约单异常Inner", ex.InnerException);
}
MainShell.ShowPrompt($"通讯异常");
_faceValidating = false;
}
......@@ -193,7 +197,7 @@ namespace GS.Terminal.VisitorSelfService.Logic.Core
if (fid == _fid)
{
if (result == 1)
_faceWebSocket.Send(_currentFeature, 0, _currentFeature.Length);
_faceWebSocket?.Send(_currentFeature, 0, _currentFeature.Length);
else
MainShell.ShowPrompt($"面部识别失败,正在重试...");
}
......
......@@ -54,7 +54,7 @@ namespace GS.Terminal.VisitorSelfService.Logic.Core
{
Handlers.GetHandler<AppointmentDetailPageHandler>()?.ShowDetail(findResult,
mode == AuthenticationMode.IdCard ? ((dynamic)data).cardid : "",
mode == AuthenticationMode.IdCard ? File.ReadAllBytes(((dynamic)data).poto) : "");
mode == AuthenticationMode.IdCard ? File.ReadAllBytes(((dynamic)data).poto) : null);
}
else
{
......
......@@ -18,7 +18,7 @@ namespace GS.Terminal.VisitorSelfService.Logic
internal static IAddonContext _Context;
internal static IObjectSpace _ObjectSpace;
internal static Locator vmLocator;
internal static string _logicVersion = "0528.17";
internal static string _logicVersion = "0718.15";
public void Start(IAddonContext Context)
{
......@@ -47,12 +47,16 @@ namespace GS.Terminal.VisitorSelfService.Logic
Handlers.Product();
Task.Run(async () =>
{
RETRY:
var signature = await WebApi.SignatureAsync();
if (!signature.success)
{
var ex = new Exception($"终端注册失败,失败原因:{signature.message}");
_Context.Logger.Error("启动失败", ex);
throw ex;
//throw ex;
MainShell.ShowPrompt("终端注册失败,正在重试..");
await Task.Delay(5000);
goto RETRY;
}
TerminalConsole.StartHeart(LocalSetting.AppConfig.ServerIP, LocalSetting.AddonDefaultConfig.HeartPort, 30 * 1000);
ThirdAddon.LogicShell.ShowView(vmLocator.MenuPage);
......
......@@ -13,6 +13,7 @@ namespace GS.Terminal.VisitorSelfService.Logic.Remote
{
private static SafeObjectPool.ObjectPool<HttpClient> _httpclientPool = null;
private static string _token = "";
private static TerminalToken _terminaltoken = null;
static WebApi()
{
_httpclientPool = new SafeObjectPool.ObjectPool<HttpClient>(10, () =>
......@@ -28,6 +29,7 @@ namespace GS.Terminal.VisitorSelfService.Logic.Remote
}
public static async Task<T> GetTAsync<T>(string service)
{
CheckToken();
var _clientPoolObject = await _httpclientPool.GetAsync();
var _client = _clientPoolObject.Value;
try
......@@ -36,6 +38,7 @@ namespace GS.Terminal.VisitorSelfService.Logic.Remote
if (result.IsSuccessStatusCode)
{
var responseBody = await result.Content.ReadAsStringAsync();
Program._Context.Logger.Debug($"GET {service} <br /> {responseBody}");
return JsonConvert.DeserializeObject<T>(responseBody);
}
else
......@@ -53,13 +56,14 @@ namespace GS.Terminal.VisitorSelfService.Logic.Remote
}
finally
{
_httpclientPool.Return(_clientPoolObject);
_httpclientPool.Return(_clientPoolObject, isReset: true);
}
return default(T);
}
public static async Task<T> PostAsync<T>(string service, object requestBody)
{
CheckToken();
var bodyString = JsonConvert.SerializeObject(requestBody);
var content = new StringContent(bodyString);
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
......@@ -71,6 +75,7 @@ namespace GS.Terminal.VisitorSelfService.Logic.Remote
if (result.IsSuccessStatusCode)
{
var responseBody = await result.Content.ReadAsStringAsync();
Program._Context.Logger.Debug($"POST {service} <br /> {responseBody}");
return JsonConvert.DeserializeObject<T>(responseBody);
}
else
......@@ -87,13 +92,14 @@ namespace GS.Terminal.VisitorSelfService.Logic.Remote
}
finally
{
_httpclientPool.Return(_clientPoolObject);
_httpclientPool.Return(_clientPoolObject, isReset: true);
}
return default(T);
}
public static T Post<T>(string service, object requestBody)
{
CheckToken();
var bodyString = JsonConvert.SerializeObject(requestBody);
var content = new StringContent(bodyString);
var _clientPoolObject = _httpclientPool.Get();
......@@ -116,7 +122,7 @@ namespace GS.Terminal.VisitorSelfService.Logic.Remote
}
finally
{
_httpclientPool.Return(_clientPoolObject);
_httpclientPool.Return(_clientPoolObject, isReset: true);
}
return default(T);
}
......@@ -134,21 +140,29 @@ namespace GS.Terminal.VisitorSelfService.Logic.Remote
/// <returns></returns>
public static (bool success, string message) Signature()
{
var token = GetTAsync<TerminalToken>($"/api/GS.WebApi.Terminal/TerminalConsole/Signature?tCode={LocalSetting.AppConfig.tCode}&tMacCode={GetMACAddress()}").Result;
if (token == null) return (false, "网络异常,设备注册失败");
if (!token.Status) return (false, $"设备注册失败.原因:{token.Message}");
_token = token.tToken;
_terminaltoken = GetTAsync<TerminalToken>($"/api/GS.WebApi.Terminal/TerminalConsole/Signature?tCode={LocalSetting.AppConfig.tCode}&tMacCode={GetMACAddress()}").Result;
if (_terminaltoken == null) return (false, "网络异常,设备注册失败");
if (!_terminaltoken.Status) return (false, $"设备注册失败.原因:{_terminaltoken.Message}");
_token = _terminaltoken.tToken;
return (true, _token);
}
public static async Task<(bool success, string message)> SignatureAsync()
{
var token = await GetTAsync<TerminalToken>($"/api/GS.WebApi.Terminal/TerminalConsole/Signature?tCode={LocalSetting.AppConfig.tCode}&tMacCode={GetMACAddress()}");
if (token == null) return (false, "网络异常,设备注册失败");
if (!token.Status) return (false, $"设备注册失败.原因:{token.Message}");
_token = token.tToken;
_terminaltoken = await GetTAsync<TerminalToken>($"/api/GS.WebApi.Terminal/TerminalConsole/Signature?tCode={LocalSetting.AppConfig.tCode}&tMacCode={GetMACAddress()}");
if (_terminaltoken == null) return (false, "网络异常,设备注册失败");
if (!_terminaltoken.Status) return (false, $"设备注册失败.原因:{_terminaltoken.Message}");
_token = _terminaltoken.tToken;
return (true, _token);
}
private static void CheckToken()
{
if (_terminaltoken != null && _terminaltoken.expDate.AddMinutes(-30) < DateTime.Now)
{
Signature();
}
}
}
public class TerminalToken
{
......
......@@ -89,7 +89,7 @@
<!--信息-->
<Grid Grid.Row="1" Margin="130,70,130,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="245"/>
<ColumnDefinition Width="205"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
......@@ -111,8 +111,8 @@
<ContentControl Grid.Row="2" Template="{StaticResource AppointmentDetailPage_Line}" Grid.ColumnSpan="2"/>
<TextBlock Text="来访日期" Grid.Row="3" Style="{StaticResource AppointmentDetailPage_Title}"/>
<TextBlock Grid.Row="3" Style="{StaticResource AppointmentDetailPage_Value}"><Run Text="{Binding Appointment.startDate, StringFormat=\{0:yyyy-MM-dd\}}"/><Run Text=" "/><Run Text=" 到 "/><Run Text=" "/><Run Text="{Binding Appointment.endDate, StringFormat=\{0:yyyy-MM-dd\}}"/></TextBlock>
<TextBlock Text="来访时间" Grid.Row="3" Style="{StaticResource AppointmentDetailPage_Title}"/>
<TextBlock Grid.Row="3" Style="{StaticResource AppointmentDetailPage_Value}"><Run Text="{Binding Appointment.startDate, StringFormat=\{0:yyyy-MM-dd HH:mm\}}"/><Run Text=" ~ "/><Run Text="{Binding Appointment.endDate, StringFormat=\{0:yyyy-MM-dd HH:mm\}}"/></TextBlock>
<TextBlock Text="来访区域" Grid.Row="4" Style="{StaticResource AppointmentDetailPage_Title}"/>
<TextBlock Text="{Binding Appointment.areaName}" Grid.Row="4" Style="{StaticResource AppointmentDetailPage_Value}"/>
......
......@@ -76,9 +76,9 @@
<TextBlock HorizontalAlignment="Right" FontSize="30" Margin="0,20,0,0" Text="{Binding Phone}"/>
<TextBlock HorizontalAlignment="Right" FontSize="30" Margin="0,20,0,0" Text="{Binding VisitPerson}" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis"/>
<TextBlock HorizontalAlignment="Right" FontSize="30" Margin="0,20,0,0" >
<Run Text="{Binding StartDate,StringFormat='yyyy年MM月dd日'}"/>
<Run Text="{Binding StartDate,StringFormat='yyyy-MM-dd HH:mm'}"/>
<Run Text=" 到 "/>
<Run Text="{Binding EndDate,StringFormat='yyyy年MM月dd日'}"/>
<Run Text="{Binding EndDate,StringFormat='yyyy-MM-dd HH:mm'}"/>
</TextBlock>
<TextBlock x:Name="PART_STATUS" HorizontalAlignment="Right" FontSize="40" Margin="0,26,0,0" FontWeight="Black" />
</StackPanel>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment