ToolParsePlus.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc.Controllers;
  3. using Microsoft.AspNetCore.Mvc.Filters;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using dodohold.core;
  9. using Dataoke;
  10. using System.Text.RegularExpressions;
  11. using Org.BouncyCastle.Ocsp;
  12. using System.Diagnostics;
  13. using TencentCloud.Fmu.V20191213.Models;
  14. using Microsoft.VisualBasic;
  15. using System.Text.Json;
  16. using static System.Runtime.InteropServices.JavaScript.JSType;
  17. using System.Security.Cryptography;
  18. using Google.Protobuf.WellKnownTypes;
  19. using System.Threading.Channels;
  20. using TencentCloud.Tione.V20211111.Models;
  21. namespace molilian.core
  22. {
  23. public partial class ToolParsePlus
  24. {
  25. public static string GetLink(string content)
  26. {
  27. if (string.IsNullOrEmpty(content)) return content;
  28. string result = content;
  29. string pattern = @"https?:\/\/?([\da-z\.-]+)\.([a-z]{2,6})(:\d{1,5})?([\/\w\.-]*)*\/?(#[\S]+)?(\?[\S]+)?";
  30. Regex regex = new(pattern);
  31. MatchCollection matches = regex.Matches(content);
  32. foreach (Match m in matches.Cast<Match>())
  33. {
  34. string url = m.Value;
  35. return url;
  36. }
  37. return string.Empty;
  38. }
  39. public static ToolParseDataDTO GetFormattedObject(string content, string ip = "", string oaid = "")
  40. {
  41. return new ToolParseDataDTO()
  42. {
  43. message = string.Empty,
  44. success = false,
  45. content = content,
  46. ip = ip,
  47. oaid = oaid,
  48. elapsedTime = 0,
  49. create_time = DateTime.Now,
  50. };
  51. }
  52. public static string GetPanLink(string text, ref string surl, ref string pwd)
  53. {
  54. surl = string.Empty;
  55. pwd = string.Empty;
  56. string result = string.Empty;
  57. string linkPattern = @"(https://pan\.baidu\.com/s/[A-Za-z0-9?=]+)";
  58. string codePattern = @"提取码:([A-Za-z0-9]{4})";
  59. Regex linkRegex = new(linkPattern);
  60. Regex codeRegex = new(codePattern);
  61. Match linkMatch = linkRegex.Match(text);
  62. if (linkMatch.Success)
  63. {
  64. result = linkMatch.Groups[1].Value;
  65. if (result.Contains("?pwd="))
  66. {
  67. pwd = result.GetContentPart("?pwd=", "");
  68. surl = result.GetContentPart("/s/1", "?pwd=");
  69. }
  70. else
  71. {
  72. surl = result.GetContentPart("/s/1", "");
  73. // 匹配提取码
  74. Match codeMatch = codeRegex.Match(text);
  75. if (codeMatch.Success)
  76. {
  77. pwd = codeMatch.Groups[1].Value;
  78. }
  79. }
  80. }
  81. return result;
  82. }
  83. public static void PanParse(string content, ref ToolParseDataDTO result)
  84. {
  85. string message = "OK";
  86. string surl = string.Empty, pwd = string.Empty;
  87. string shortLinkurl = GetPanLink(content, ref surl, ref pwd);
  88. if (string.IsNullOrEmpty(surl))
  89. {
  90. result.channel = TkChannelEnum.bdpan;
  91. result.content = content;
  92. result.success = false;
  93. result.message = "转链失败";
  94. result.reason = "内容不匹配";
  95. return;
  96. }
  97. var deeplink_url = $"bdnetdisk://n/action.SHARE_LINK?surl={surl}&pwd={pwd}";
  98. result.channel = TkChannelEnum.bdpan;
  99. result.content = content;
  100. result.success = true;
  101. result.message = message;
  102. result.shortLinkurl = shortLinkurl;
  103. result.deeplink_url = deeplink_url;
  104. }
  105. public static void WemeetParse(string content, ref ToolParseDataDTO result)
  106. {
  107. string message = "OK";
  108. string wemeetId = GetWemeetId(content);
  109. if (string.IsNullOrEmpty(wemeetId))
  110. {
  111. result.channel = TkChannelEnum.wemeet;
  112. result.content = content;
  113. result.success = false;
  114. result.message = "转链失败";
  115. result.reason = "内容不匹配";
  116. return;
  117. }
  118. var deeplink_url = $"wemeet://page/inmeeting?meeting_code={wemeetId}";
  119. result.channel = TkChannelEnum.wemeet;
  120. result.content = wemeetId;
  121. result.success = true;
  122. result.message = message;
  123. result.deeplink_url = deeplink_url;
  124. }
  125. public static string GetWemeetId(string content)
  126. {
  127. string pattern = @"#腾讯会议:(\d{3}-\d{3}-\d{3})";
  128. Regex regex = new Regex(pattern);
  129. Match match = regex.Match(content);
  130. string meetingCode;
  131. // 判断是否匹配成功
  132. if (match.Success)
  133. {
  134. // 提取会议编码
  135. meetingCode = match.Groups[1].Value;
  136. meetingCode = meetingCode.Replace("-", "");
  137. if (!string.IsNullOrEmpty(meetingCode)) return meetingCode;
  138. }
  139. meetingCode = GetWemeetIdFromUrl(content);
  140. return meetingCode;
  141. }
  142. public static string? GetDesiredUrl(string url)
  143. {
  144. try
  145. {
  146. WebClientUtility client = new()
  147. {
  148. AllowAutoRedirect = false
  149. };
  150. var response = client.Request(url);
  151. if (!response.Successed) return null;
  152. return response.Body();
  153. }
  154. catch (Exception ex)
  155. {
  156. }
  157. return null;
  158. }
  159. public static string GetWemeetIdFromUrl(string content)
  160. {
  161. string pattern = @"https:\/\/meeting\.tencent\.com\/dm\/[a-zA-Z0-9]+";
  162. Regex regex = new Regex(pattern);
  163. Match match = regex.Match(content);
  164. // 判断是否匹配成功
  165. if (match.Success)
  166. {
  167. // 提取会议编码
  168. string meeting_url = match.Value;
  169. var body = GetDesiredUrl(meeting_url);
  170. if (string.IsNullOrEmpty(body)) return string.Empty;
  171. string meetingCode = body.GetContentPart("\"meeting_code\":\"", "\"");
  172. return meetingCode;
  173. }
  174. return string.Empty;
  175. }
  176. }
  177. }