From f69106c59b95d9d681c350f644eeecd69add0102 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 26 Mar 2024 11:21:18 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E7=94=9F=E6=88=90token=E5=B9=B6=E5=85=A5?= =?UTF-8?q?service=E7=A7=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SyncSapInfo/Services/IJinkoJIPService.cs | 2 ++ .../Services/Implements/JinkoJIPService.cs | 16 +++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/IJinkoJIPService.cs b/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/IJinkoJIPService.cs index 6d7917bc..fad41965 100644 --- a/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/IJinkoJIPService.cs +++ b/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/IJinkoJIPService.cs @@ -7,4 +7,6 @@ public interface IJinkoJIPService : ISingletonDependency Task UploadAttendancesAsync(List requests); Task SyncMealSupplementRecordsAsync(List requests); + + public string IssueToken(); } diff --git a/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/Implements/JinkoJIPService.cs b/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/Implements/JinkoJIPService.cs index eb9a1a3c..1142885d 100644 --- a/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/Implements/JinkoJIPService.cs +++ b/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/Implements/JinkoJIPService.cs @@ -26,10 +26,8 @@ public class JinkoJIPService : IJinkoJIPService { var httpClient = _httpClientFactory.CreateClient(); httpClient.BaseAddress = new Uri(_configuration.GetSection("JinkoOptions:Jip:BaseUrl").Value); - //httpClient.Timeout = TimeSpan.FromMinutes(10); - var key = _configuration.GetSection("JinkoOptions:Jip:Key").Value; - var secret = _configuration.GetSection("JinkoOptions:Jip:Secret").Value; - httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", IssueJwt(key, secret, 5)); + + httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", IssueToken()); return httpClient; } @@ -85,12 +83,12 @@ public class JinkoJIPService : IJinkoJIPService return responseJson; } - - //********************************************************************* help methods ***************************************************************************/ - - - private static string IssueJwt(string jwtKey, string jwtSecret, int mins) + public string IssueToken() { + var jwtKey = _configuration.GetSection("JinkoOptions:Jip:Key").Value; + var jwtSecret = _configuration.GetSection("JinkoOptions:Jip:Secret").Value; + var mins = 5; + var now = DateTime.Now.AddMinutes(-mins); var expires = DateTime.Now.AddMinutes(mins);