From 78b5e0a2e4c48239983e236c48f8c0b897d69f9e Mon Sep 17 00:00:00 2001
From: sunpengfei <i@angelzzz.com>
Date: 星期二, 09 九月 2025 09:38:00 +0800
Subject: [PATCH] feat:开发

---
 FlexJobApi.Core/Utils/JwtUtils/JwtHandler.cs |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/FlexJobApi.Core/Utils/JwtUtils/JwtHandler.cs b/FlexJobApi.Core/Utils/JwtUtils/JwtHandler.cs
index e024dd2..d395149 100644
--- a/FlexJobApi.Core/Utils/JwtUtils/JwtHandler.cs
+++ b/FlexJobApi.Core/Utils/JwtUtils/JwtHandler.cs
@@ -1,7 +1,18 @@
-锘縰sing Furion.Authorization;
+锘縰sing FlexJobApi.Core.Entities.Common;
+using Furion;
+using Furion.Authorization;
+using Furion.DatabaseAccessor;
 using Furion.DataEncryption;
+using Furion.DistributedIDGenerator;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Controllers;
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
 using System.Threading.Tasks;
 
 namespace FlexJobApi.Core;
@@ -15,7 +26,52 @@
         {
             await AuthorizeHandleAsync(context);
         }
-        else context.Fail();
+        else
+        {
+
+            var resourceLog = new ResourceLog();
+            resourceLog.CreatedTime = DateTimeOffset.Now;
+            var stopwatch = Stopwatch.StartNew();
+            var serviceScopeFactory = App.GetService<IServiceScopeFactory>();
+            var serviceScope = serviceScopeFactory.CreateScope();
+            var rep = serviceScope.ServiceProvider.GetRequiredService<IRepository<ResourceLog, LogDbContextLocator>>();
+            resourceLog.Id = IDGen.NextID();
+            resourceLog.TraceId = App.GetTraceId();
+            resourceLog.Method = EnumUtils.GetEnum<EnumResourceMethod>(httpContext.Request.Method);
+            resourceLog.Domain = $"{httpContext.Request.Scheme}://{httpContext.Request.Host}";
+            resourceLog.Path = httpContext.Request.Path;
+            resourceLog.ClientIpAddress = httpContext.GetRemoteIpAddressToIPv4();
+            if (httpContext.Request.ContentType?.Contains("application/json") == true)
+            {
+                httpContext.Request.EnableBuffering(); // 鍏佽澶氭璇诲彇
+                var body = await new StreamReader(httpContext.Request.Body).ReadToEndAsync();
+                httpContext.Request.Body.Position = 0; // 閲嶇疆娴佷綅缃�
+                resourceLog.Request = body;
+            }
+            else
+            {
+                resourceLog.Request = httpContext.Request.Query.ToJson();
+            }
+            resourceLog.RequestHeaders = httpContext.Request.Headers.ToJson();
+
+            context.Fail();
+
+            resourceLog.UpdatedTime = DateTimeOffset.Now;
+            resourceLog.Response = new FriendlyResult<object>
+            {
+                TraceId = resourceLog.TraceId,
+                Code = 401,
+                Success = false,
+                Timestamp = DateTime.Now.ToTimeStamp()
+            }.ToJson();
+            resourceLog.ResponseHeaders = httpContext.Response.Headers.ToJson();
+            resourceLog.IsSuccess = false;
+
+            stopwatch.Stop();
+            resourceLog.ElapsedMilliseconds = stopwatch.ElapsedMilliseconds;
+
+            await rep.InsertNowAsync(resourceLog);
+        }
     }
 
     /// <summary>

--
Gitblit v1.9.1