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

修正token 失效的bug

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