IndexService.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. using IES.ExamServer.Helpers;
  2. using Microsoft.Extensions.Caching.Memory;
  3. using System.Diagnostics;
  4. using System.Net.NetworkInformation;
  5. using System.Net;
  6. using System.Runtime.InteropServices;
  7. using System.Text.Json.Nodes;
  8. using System.Text.RegularExpressions;
  9. using IES.ExamServer.Models;
  10. using System.Text;
  11. using IES.ExamServer.DI;
  12. using IES.ExamServer.Helper;
  13. namespace IES.ExamServer.Services
  14. {
  15. public static class IndexService
  16. {
  17. public static async Task<(string content_response, HttpStatusCode code)> GetMusicServer_thirdLocalCacheConfig(IHttpClientFactory httpClientFactory, CenterServiceConnectionService _connectionService , string requestBody)
  18. {
  19. string content_response = string.Empty;
  20. HttpStatusCode code = HttpStatusCode.OK ;
  21. try {
  22. string url = _connectionService!.musicUrl!;
  23. var client = httpClientFactory.CreateClient();
  24. //client.DefaultRequestHeaders.Add("Accept", "application/json, text/plain, */*");
  25. client.DefaultRequestHeaders.Add("appId", Constant._MusicAIServerAppId);
  26. client.DefaultRequestHeaders.Add("encrypt", "1");
  27. client.DefaultRequestHeaders.Add("schoolCode", _connectionService.serverDevice?.school?.id);
  28. var content = new StringContent(requestBody, Encoding.UTF8, "application/json");
  29. // 发送 PUT 请求
  30. HttpResponseMessage response = await client.PutAsync($"{url}/musicLocalCache/thirdLocalCacheConfig", content);
  31. // 处理响应
  32. if (response.IsSuccessStatusCode)
  33. {
  34. content_response = await response.Content.ReadAsStringAsync();
  35. //Console.WriteLine("Response: " + responseData);
  36. }
  37. else
  38. {
  39. // Console.WriteLine("Error: " + response.StatusCode);
  40. code=response.StatusCode;
  41. content_response = await response.Content.ReadAsStringAsync();
  42. }
  43. } catch (Exception ex) {
  44. code= HttpStatusCode.InternalServerError;
  45. content_response = ex.Message;
  46. }
  47. return (content_response, code);
  48. }
  49. public static ServerDevice GetServerDevice( string remote,string region)
  50. {
  51. string hostName = $"{Environment.UserName}-{Dns.GetHostName()}";
  52. string os = RuntimeInformation.OSDescription;
  53. //获取当前客户端的服务端口
  54. string currentUserName = Environment.UserName;
  55. string MachineName =Environment.MachineName;
  56. //var s = Environment;
  57. ServerDevice device = new ServerDevice { name =hostName, userName=currentUserName, os= os,region=region,remote=remote };
  58. int CpuCoreCount = 0;
  59. long MenemorySize = 0;
  60. if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
  61. {
  62. CpuCoreCount = Environment.ProcessorCount;
  63. MenemorySize = MemoryInfo.GetTotalPhysicalMemory();
  64. //using (PerformanceCounter pc = new PerformanceCounter("Memory", "Available Bytes"))
  65. //{
  66. // // 获取可用内存
  67. // AvailableMemory = (long)pc.NextValue();
  68. //}
  69. //using (PerformanceCounter pc = new PerformanceCounter("Memory", "Committed Bytes"))
  70. //{
  71. // // 获取可用内存
  72. // CommittedMemory= (long)pc.NextValue();
  73. //}
  74. //MenemorySize=AvailableMemory+CommittedMemory;
  75. //
  76. // 获取CPU核心数
  77. //int processorCount = Environment.ProcessorCount;
  78. //Console.WriteLine("CPU 核心数: " + processorCount);
  79. //using (ManagementClass managementClass = new ManagementClass("Win32_Processor"))
  80. //{
  81. // using (ManagementObjectCollection managementObjectCollection = managementClass.GetInstances())
  82. // {
  83. // foreach (ManagementObject managementObject in managementObjectCollection)
  84. // {
  85. // CpuCoreCount += Convert.ToInt32(managementObject.Properties["NumberOfLogicalProcessors"].Value);
  86. // }
  87. // }
  88. //}
  89. //using (ManagementObjectSearcher searcher1 = new ManagementObjectSearcher("SELECT TotalPhysicalMemory FROM Win32_ComputerSystem"))
  90. //{
  91. // foreach (ManagementObject obj in searcher1.Get())
  92. // {
  93. // long MenemorySizes1 = Convert.ToInt64(obj["TotalPhysicalMemory"]);
  94. // break; // 只需要第一个结果
  95. // }
  96. //}
  97. //using (ManagementClass mc = new ManagementClass("Win32_ComputerSystem"))
  98. //{
  99. // using (ManagementObjectCollection moc = mc.GetInstances())
  100. // {
  101. // foreach (ManagementObject mo in moc)
  102. // {
  103. // if (mo["TotalPhysicalMemory"]!= null)
  104. // {
  105. // MenemorySize = Convert.ToInt64(mo["TotalPhysicalMemory"]);
  106. // }
  107. // }
  108. // }
  109. //}
  110. if (Environment.Is64BitOperatingSystem)
  111. {
  112. device.bit="64";
  113. }
  114. else
  115. {
  116. device.bit="32";
  117. }
  118. //ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Name, MaxClockSpeed FROM Win32_Processor");
  119. //foreach (ManagementObject mo in searcher.Get())
  120. //{
  121. // string? cpuName = mo["Name"].ToString();
  122. // string? clockSpeed = mo["MaxClockSpeed"].ToString();
  123. // //Console.WriteLine($"CPU 名称: {cpuName}");
  124. // //Console.WriteLine($"CPU 主频: {clockSpeed} MHz");
  125. // device.cpuInfos.Add(new CPUInfo { name = cpuName, hz = clockSpeed });
  126. //}
  127. string cpuName = MemoryInfo.GetCpuName();
  128. var clockSpeed = MemoryInfo.GetCpuSpeed();
  129. device.cpuInfos.Add(new CPUInfo { name = cpuName, hz = $"{clockSpeed}" });
  130. }
  131. else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
  132. {
  133. //int processorCount = Environment.ProcessorCount;
  134. // Console.WriteLine("CPU 核心数: " + processorCount);
  135. try {
  136. string cpuInfo = File.ReadAllText("/proc/cpuinfo");
  137. string[] cpu_lines = cpuInfo.Split('\n');
  138. CpuCoreCount= cpu_lines.Count(line => line.StartsWith("processor", StringComparison.OrdinalIgnoreCase));
  139. string? cpuNameLine = cpuInfo.Split('\n').FirstOrDefault(line => line.StartsWith("model name"));
  140. string? clockSpeedLine = cpuInfo.Split('\n').FirstOrDefault(line => line.StartsWith("cpu MHz"));
  141. string cpuName = string.Empty;
  142. string clockSpeed = string.Empty;
  143. if (cpuNameLine!= null)
  144. {
  145. cpuName = cpuNameLine.Split(':').Last().Trim();
  146. }
  147. if (clockSpeedLine!= null)
  148. {
  149. clockSpeed = clockSpeedLine.Split(':').Last().Trim();
  150. }
  151. device.cpuInfos.Add(new CPUInfo { name = cpuName, hz = clockSpeed });
  152. } catch (Exception ex)
  153. {
  154. }
  155. string[] mem_lines = File.ReadAllLines("/proc/meminfo");
  156. var match = mem_lines.FirstOrDefault(line => line.StartsWith("MemTotal:"));
  157. if (match != null)
  158. {
  159. var matchResult = Regex.Match(match, @"\d+");
  160. if (matchResult.Success)
  161. {
  162. MenemorySize= long.Parse(matchResult.Value);
  163. }
  164. }
  165. }
  166. else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
  167. {
  168. try {
  169. using (var process = new Process())
  170. {
  171. process.StartInfo.FileName = "/usr/sbin/sysctl";
  172. process.StartInfo.Arguments = "-n hw.ncpu";
  173. process.StartInfo.RedirectStandardOutput = true;
  174. process.StartInfo.UseShellExecute = false;
  175. process.Start();
  176. string output = process.StandardOutput.ReadToEnd().Trim();
  177. int coreCount;
  178. if (int.TryParse(output, out coreCount))
  179. {
  180. CpuCoreCount= coreCount;
  181. }
  182. }
  183. }
  184. catch (Exception ex) { }
  185. try
  186. {
  187. using (var process = new Process())
  188. {
  189. process.StartInfo.FileName = "/usr/sbin/sysctl";
  190. process.StartInfo.Arguments = "-n hw.memsize";
  191. process.StartInfo.RedirectStandardOutput = true;
  192. process.StartInfo.UseShellExecute = false;
  193. process.Start();
  194. string output = process.StandardOutput.ReadToEnd().Trim();
  195. long memorySize;
  196. if (long.TryParse(output, out memorySize))
  197. {
  198. MenemorySize= memorySize;
  199. }
  200. }
  201. }
  202. catch (Exception ex) { }
  203. try
  204. {
  205. using (var process = new Process())
  206. {
  207. process.StartInfo.FileName = "/usr/sbin/sysctl";
  208. process.StartInfo.Arguments = "-n machdep.cpu.brand_string";
  209. process.StartInfo.RedirectStandardOutput = true;
  210. process.StartInfo.UseShellExecute = false;
  211. process.Start();
  212. string cpuName = process.StandardOutput.ReadToEnd().Trim();
  213. process.StartInfo.FileName = "/usr/sbin/sysctl";
  214. process.StartInfo.Arguments = "-n hw.cpu.frequency";
  215. process.StartInfo.RedirectStandardOutput = true;
  216. process.StartInfo.UseShellExecute = false;
  217. process.Start();
  218. string clockSpeed = process.StandardOutput.ReadToEnd().Trim();
  219. //Console.WriteLine($"CPU 名称: {cpuName}");
  220. //Console.WriteLine($"CPU 主频: {clockSpeed} Hz");
  221. device.cpuInfos.Add(new CPUInfo { name = cpuName, hz = clockSpeed });
  222. }
  223. }
  224. catch (Exception ex)
  225. {
  226. Console.WriteLine($"出现错误: {ex.Message}");
  227. }
  228. if (Environment.Is64BitOperatingSystem)
  229. {
  230. device.bit="64";
  231. }
  232. else
  233. {
  234. device.bit="32";
  235. }
  236. }
  237. if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
  238. {
  239. device.arch="ARM64";
  240. }
  241. else if (RuntimeInformation.ProcessArchitecture == Architecture.Arm)
  242. {
  243. device.arch="ARM32";
  244. }
  245. else if (RuntimeInformation.ProcessArchitecture == Architecture.X64)
  246. {
  247. device.arch="X64";
  248. }
  249. else if (RuntimeInformation.ProcessArchitecture == Architecture.X86)
  250. {
  251. device.arch="X86";
  252. }
  253. else
  254. {
  255. device.arch=$"未知({device.arch})";
  256. }
  257. //Console.WriteLine("CPU 核心数: " + CpuCoreCount+",RAM 大小:"+MenemorySize);
  258. device.cpu=CpuCoreCount;
  259. device.ram=MenemorySize;
  260. var nics = NetworkInterface.GetAllNetworkInterfaces();
  261. foreach (var nic in nics)
  262. {
  263. int physical = 0;
  264. if (nic.OperationalStatus == OperationalStatus.Up)
  265. {
  266. //该方法并不能判断是否是物理网卡
  267. //if (nic.NetworkInterfaceType== NetworkInterfaceType.Ethernet//- 以太网接口,通常用于有线网络连接。
  268. // ||nic.NetworkInterfaceType== NetworkInterfaceType.TokenRing//- 令牌环网接口,一种较早的局域网技术。
  269. // ||nic.NetworkInterfaceType== NetworkInterfaceType.Fddi//- 光纤分布式数据接口,用于光纤网络。
  270. // ||nic.NetworkInterfaceType== NetworkInterfaceType.Ethernet3Megabit//- 3兆比特以太网接口,一种较早的以太网标准。
  271. // ||nic.NetworkInterfaceType== NetworkInterfaceType.FastEthernetT// 快速以太网接口(100Base-T),用于双绞线网络。
  272. // ||nic.NetworkInterfaceType== NetworkInterfaceType.FastEthernetFx//快速以太网接口(100Base-FX),用于光纤网络。
  273. // ||nic.NetworkInterfaceType== NetworkInterfaceType.Wireless80211//无线局域网接口(Wi-Fi)。
  274. // ||nic.NetworkInterfaceType== NetworkInterfaceType.GigabitEthernet //千兆以太网接口,提供1 Gbps的数据速率。
  275. // ||nic.NetworkInterfaceType== NetworkInterfaceType.Wman// 移动宽带接口,用于WiMax设备。
  276. // ||nic.NetworkInterfaceType== NetworkInterfaceType.Wwanpp//移动宽带接口,用于GSM设备。
  277. // ||nic.NetworkInterfaceType== NetworkInterfaceType.Wwanpp2//移动宽带接口,用于CDMA设备。
  278. // )
  279. //{
  280. // physical=1;
  281. //}
  282. if (IsPhysicalNetworkInterface(nic))
  283. {
  284. physical = 1;
  285. }
  286. var name = $"{nic.Name}-{nic.Description}";
  287. var mac = nic.GetPhysicalAddress().ToString();
  288. var properties = nic.GetIPProperties();
  289. var unicastAddresses = properties.UnicastAddresses;
  290. foreach (var unicast in unicastAddresses)
  291. {
  292. if (unicast.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
  293. {
  294. var ip = unicast.Address.ToString();
  295. // 绑定域名 优先绑定
  296. Network network = new Network() { mac=mac, ip=ip, name= name, physical=physical };
  297. if (!string.IsNullOrWhiteSpace(mac.ToString()) && !mac.Equals("000000000000"))
  298. {
  299. device.networks.Add(network);
  300. }
  301. }
  302. }
  303. }
  304. }
  305. //if (_url!.IsNotEmpty())
  306. //{
  307. // List<UriInfo> ports = new List<UriInfo>();
  308. // foreach (var url in _url!)
  309. // {
  310. // Uri uri = new Uri(url);
  311. // device.uris.Add(new UriInfo { port= uri.Port, protocol= uri.Scheme });
  312. // }
  313. //}
  314. //else
  315. //{
  316. // throw new Exception("未获取到端口信息!");
  317. //}
  318. var networks = device.networks.ToList();
  319. if (device.networks.IsNotEmpty())
  320. {
  321. var order= device.networks.OrderByDescending(x => x.physical).ToList();
  322. for (int i=0; i<order.Count();i++)
  323. {
  324. order[i].domain="exam.habook.local";
  325. }
  326. //优先以物理网卡来生成hash,如果没有则以所有网卡生成hash
  327. var physical = order.FindAll(x => x.physical==1);
  328. if (physical.IsNotEmpty())
  329. {
  330. networks=physical;
  331. }
  332. }
  333. StringBuilder sb= new StringBuilder();
  334. sb.Append(device.name);//设备名称
  335. sb.Append(device.os);//系统名称
  336. sb.Append(device.bit);//系统位
  337. sb.Append(device.arch);//指令架构
  338. sb.Append(device.cpu);//cpu核心树
  339. sb.Append(string.Join(",", device.cpuInfos.Select(x=>$"{x.name}{x.hz}")));//cpu名称和频率
  340. sb.Append(device.ram);//内存
  341. sb.Append(string.Join(",", networks.Select(x => $"{x.mac}-{x.name}")));//网卡地址和名称
  342. //暂不使用远程ip和局域网内ip作为hash,可能发生变化
  343. string hashData = ShaHashHelper.GetSHA256(sb.ToString());
  344. device.deviceId=hashData;
  345. device.id= hashData;
  346. return device;
  347. }
  348. public static bool IsPhysicalNetworkInterface(NetworkInterface nic)
  349. {
  350. // 排除虚拟网卡的关键词
  351. string[] virtualKeywords = { "virtual", "hyper-v", "virtualbox", "vmware", "veth","virbr", "tunnel", "docker", "loopback", "vpn","ppp", "slip", "bridge",
  352. "vnic", "vif", "tap", "vlan", "vswitch", "vxlan", "gre", "ipsec", "vrf", "vport", "vnet", "vmac", "vxnet"};
  353. // 检查网卡描述或名称中是否包含虚拟关键词
  354. string description = nic.Description.ToLower();
  355. string name = nic.Name.ToLower();
  356. foreach (var keyword in virtualKeywords)
  357. {
  358. if (description.Contains(keyword,StringComparison.OrdinalIgnoreCase) || name.Contains(keyword, StringComparison.OrdinalIgnoreCase))
  359. {
  360. return false; // 是虚拟网卡
  361. }
  362. }
  363. // 排除一些常见的虚拟网卡类型
  364. if (nic.NetworkInterfaceType == NetworkInterfaceType.Loopback ||
  365. nic.NetworkInterfaceType == NetworkInterfaceType.Tunnel ||
  366. nic.NetworkInterfaceType == NetworkInterfaceType.Ppp ||
  367. nic.NetworkInterfaceType == NetworkInterfaceType.Slip||
  368. nic.NetworkInterfaceType == NetworkInterfaceType.Unknown
  369. )
  370. {
  371. return false; // 是虚拟网卡
  372. }
  373. // 默认认为是物理网卡
  374. return true;
  375. }
  376. /// <summary>
  377. /// 直接获取设备。
  378. /// </summary>
  379. /// <param name="httpContext"></param>
  380. /// <param name="IP"></param>
  381. /// <param name="device_timeSpan"></param>
  382. /// <param name="_azureRedis"></param>
  383. /// <returns></returns>
  384. public static string GetDevice(HttpContext httpContext, IMemoryCache _memoryCache)
  385. {
  386. string IP= GetIP(httpContext);
  387. var cookie = httpContext.Request.Cookies;
  388. string device =string.Empty;
  389. if (cookie != null)
  390. {
  391. ///设备是否存在
  392. foreach (var ck in cookie)
  393. {
  394. if (ck.Key.Equals("device"))
  395. {
  396. //redis如果存在则
  397. var fingerprint = ck.Value.Split("-");
  398. if (fingerprint.Length == 2 && IP.Equals(fingerprint[1]))
  399. {
  400. if (!_memoryCache.TryGetValue<string>($"device:{fingerprint[0]}:{IP}", out device))
  401. {
  402. _memoryCache.Set($"device:{fingerprint[0]}:{IP}", $"{fingerprint[0]}-{IP}");
  403. device = $"{fingerprint[0]}-{IP}";
  404. }
  405. }
  406. }
  407. }
  408. }
  409. return device;
  410. }
  411. public static string GetIP(HttpContext httpContext)
  412. {
  413. var IpPort = httpContext.Request.Headers["X-Forwarded-For"].FirstOrDefault();
  414. if (string.IsNullOrEmpty(IpPort))
  415. {
  416. IpPort = $"{httpContext.Connection.RemoteIpAddress}";
  417. }
  418. if (IpPort.Contains("::"))
  419. {
  420. IpPort = "127.0.0.1";
  421. }
  422. return IpPort;
  423. }
  424. /// <summary>
  425. /// 初始化设备
  426. /// </summary>
  427. /// <param name="httpContext"></param>
  428. /// <param name="fingerprint">浏览器指纹</param>
  429. /// <param name="IP"></param>
  430. /// <param name="device_timeSpan"></param>
  431. /// <param name="_azureRedis"></param>
  432. /// <returns></returns>
  433. public static string GetDeviceInit(this HttpContext httpContext, string fingerprint, string IP, IMemoryCache _memoryCache)
  434. {
  435. string device = $"{fingerprint}-{IP}";
  436. List<string> cookieString = new List<string>();
  437. var cookie = httpContext.Request.Cookies;
  438. int status = 1;
  439. if (cookie != null)
  440. {
  441. ///设备是否存在
  442. foreach (var ck in cookie)
  443. {
  444. if (ck.Key.Equals("device"))
  445. {
  446. if (device.Contains("-") && device.Contains("."))
  447. {
  448. //如果匹配的是fingerprint-IP 则是已经存在的。
  449. if (ck.Value.Equals(device))
  450. {
  451. //redis如果存在则
  452. _memoryCache.TryGetValue<string>($"device:{fingerprint}:{IP}", out string device_exist);
  453. // 返回的则应该是ck.Value=exist_device_exist的数据
  454. if (device_exist!=null)
  455. {
  456. if (!string.IsNullOrWhiteSpace($"{device_exist}"))
  457. {
  458. //0是代表指纹和IP匹配,正常返回的
  459. status = 1;
  460. }
  461. else
  462. {
  463. //需要新建 fingerprint-IP
  464. status = 1;
  465. }
  466. }
  467. else
  468. {
  469. status = 1;
  470. }
  471. }
  472. else
  473. {
  474. string ck_ip = ck.Value.Split("-")[1];
  475. if (ck_ip.Equals(IP))
  476. {
  477. //传入的指纹和cookie的不一致,仍然以cookie的为准。
  478. status = 1;
  479. fingerprint = ck.Value.Split("-").First();
  480. device = ck.Value;
  481. }
  482. }
  483. }
  484. else
  485. {
  486. //如果匹配的是fingerprint则是一个新的设备。
  487. if (ck.Value.Equals(fingerprint))
  488. {
  489. //检查设备是否被占用
  490. //var device_exist = _azureRedis.GetRedisClient(8).HashExists($"device:{fingerprint}", IP);
  491. _memoryCache.TryGetValue<JsonNode>($"device:{fingerprint}:{IP}", out JsonNode device_exist);
  492. if (device_exist!=null)
  493. {
  494. //需要新建 sha1(fingerprint+uuid)-IP
  495. status = 2;
  496. }
  497. else
  498. {
  499. //0是代表指纹和IP匹配,正常返回的
  500. status = 1;
  501. }
  502. }
  503. else
  504. {
  505. //匹配的都不是,新设备。
  506. status = 1;
  507. }
  508. }
  509. }
  510. else
  511. {
  512. cookieString.Add($"{ck.Key}{ck.Value}");
  513. }
  514. }
  515. }
  516. /*
  517. httpContext.Request.Headers.TryGetValue("accept-language", out var accept_language);
  518. httpContext.Request.Headers.TryGetValue("sec-ch-ua", out var chua);
  519. httpContext.Request.Headers.TryGetValue("sec-ch-ua-platform", out var platform);
  520. httpContext.Request.Headers.TryGetValue("user-agent", out var useragent);
  521. httpContext.Request.Headers.TryGetValue("accept", out var accept);
  522. httpContext.Request.Headers.TryGetValue("accept-encoding", out var accept_encoding);
  523. device = ShaHashHelper.GetSHA1($"{IP}{accept_language}{chua}{platform}{useragent}{accept}{accept_encoding}{string.Join("", cookieString)}");
  524. */
  525. if (status == 2)
  526. {
  527. fingerprint = ShaHashHelper.GetSHA1(fingerprint + Guid.NewGuid().ToString());
  528. device = $"{fingerprint}-{IP}";
  529. }
  530. //else if (status == 1)
  531. //{
  532. // device = $"{fingerprint}-{IP}";
  533. //}
  534. //await _azureRedis.GetRedisClient(8).HashSetAsync($"device:{fingerprint}", IP, new { device }.ToJsonString());
  535. //await _azureRedis.GetRedisClient(8).KeyExpireAsync($"device:{fingerprint}", device_timeSpan);
  536. _memoryCache.Set($"device:{fingerprint}:{IP}", device);
  537. httpContext.Response.Cookies.Append("device", device, new CookieOptions { HttpOnly = true, MaxAge = new TimeSpan(24 * 7, 0, 0) });
  538. return device;
  539. }
  540. }
  541. public class UriInfo
  542. {
  543. public string? protocol { get; set; }
  544. public int port { get; set; }
  545. }
  546. }