LEIYI 4 ay önce
ebeveyn
işleme
4b70ad0616

+ 24 - 4
OASystem/OASystem.Api/Middlewares/RecordAPIOperationMiddleware.cs

@@ -12,6 +12,7 @@ using static OASystem.API.OAMethodLib.JWTHelper;
 using UAParser;
 using System.Collections.Generic;
 using XAct;
+using NPOI.SS.Formula.Functions;
 
 namespace OASystem.API.Middlewares
 {
@@ -145,8 +146,9 @@ namespace OASystem.API.Middlewares
                     remoteIp = context.Request.Headers["X-Forwarded-For"].ToString().Split(',', StringSplitOptions.RemoveEmptyEntries)[0];
                 }
 
-                remoteIp = await GetExternalIp();
-                location = await GetIpLocation(remoteIp);
+                (remoteIp, location) = await GetIpInfo();
+                //remoteIp = await GetExternalIp();
+                //location = await GetIpLocation(remoteIp);
 
                 string deviceType = string.Empty, browser = string.Empty, os = string.Empty;
                 var userAgent = context.Request.Headers["User-Agent"].FirstOrDefault();
@@ -190,7 +192,7 @@ namespace OASystem.API.Middlewares
                     RemoteIp = remoteIp,
                     Location = location,
                     RequestParam =!string.IsNullOrEmpty(requestBodyText) ? JsonConvert.SerializeObject(requestBodyText) : null,
-                    ReturnResult = !string.IsNullOrEmpty(responseBodyText) ? JsonConvert.SerializeObject(requestBodyText) : null,
+                    ReturnResult = !string.IsNullOrEmpty(responseBodyText) ? JsonConvert.SerializeObject(responseBodyText) : null,
                     Elapsed = duration,
                     Status = context.Response.StatusCode.ToString(),
                     CreateUserId = userId,
@@ -268,6 +270,24 @@ namespace OASystem.API.Middlewares
             return 0;
         }
 
+        private async Task<(string ip,string local)> GetIpInfo()
+        {
+            string ip = string.Empty, local = string.Empty;
+            var response = await _httpClient.GetAsync("https://api.vore.top/api/IPdata");
+
+            response.EnsureSuccessStatusCode();
+            var json = await response.Content.ReadAsStringAsync();
+            var ipInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(json);
+            if (ipInfo.code == 200)
+            {
+                ip = ipInfo.ipinfo.text;
+                local = $"{ipInfo.adcode.o}";
+            }
+
+            return (ip,local);
+        }
+
+
         private async Task<string> GetExternalIp()
         {
             var response = await _httpClient.GetAsync("https://ifconfig.me");
@@ -277,7 +297,7 @@ namespace OASystem.API.Middlewares
 
         private async Task<string> GetIpLocation(string ip)
         {
-            var response = await _httpClient.GetAsync($"https://ipinfo.io/{ip}/json");
+            var response = await _httpClient.GetAsync($"https://ipinfo.io/{ip}/json?&language=zh-CN");
             response.EnsureSuccessStatusCode();
             var json = await response.Content.ReadAsStringAsync();
             var ipInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(json);

+ 1 - 0
OASystem/OASystem.Api/OAMethodLib/GeneralMethod.cs

@@ -72,6 +72,7 @@ namespace OASystem.API.OAMethodLib
             userDepDatas.Insert(0, new GroupOpAffiliationBranchView() { text = "全部", value = "全部" });
             userDepDatas.Insert(1, new GroupOpAffiliationBranchView() { text = "国交部", value = "国交部" });
             userDepDatas.Insert(2, new GroupOpAffiliationBranchView() { text = "市场部", value = "市场部" });
+            userDepDatas.Insert(3, new GroupOpAffiliationBranchView() { text = "策划部", value = "策划部" });
 
             return userDepDatas;
         }