using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Filters; using System; using System.Collections.Generic; using System.Linq; using System.Text; using dodohold.core; using Dataoke; using System.Text.RegularExpressions; using Org.BouncyCastle.Ocsp; using System.Diagnostics; using TencentCloud.Fmu.V20191213.Models; using Microsoft.VisualBasic; using System.Text.Json; using static System.Runtime.InteropServices.JavaScript.JSType; using System.Security.Cryptography; using Google.Protobuf.WellKnownTypes; using System.Threading.Channels; using TencentCloud.Tione.V20211111.Models; namespace molilian.core { public partial class ToolParsePlus { private static string _end_point; static ToolParsePlus() { _end_point = Environment.GetEnvironmentVariable("EndPoint"); } public static string GetLink(string content) { if (string.IsNullOrEmpty(content)) return content; string result = content; string pattern = @"https?:\/\/?([\da-z\.-]+)\.([a-z]{2,6})(:\d{1,5})?([\/\w\.-]*)*\/?(#[\S]+)?(\?[\S]+)?"; Regex regex = new(pattern); MatchCollection matches = regex.Matches(content); foreach (Match m in matches.Cast()) { string url = m.Value; return url; } return string.Empty; } public static ToolParseDataDTO GetFormattedObject(TkChannelEnum type, string content, string ip = "", string oaid = "") { string itemName = string.Empty; switch (type) { case TkChannelEnum.bdpan: itemName = "打开百度网盘"; break; case TkChannelEnum.wemeet: itemName = "加入腾讯会议"; break; } return new ToolParseDataDTO() { message = string.Empty, success = false, content = content, ip = ip, oaid = oaid, elapsedTime = 0, create_time = DateTime.Now, itemName = itemName, end_point = _end_point, }; } public static string GetPanLink(string text, ref string surl, ref string pwd) { surl = string.Empty; pwd = string.Empty; string result = string.Empty; string linkPattern = @"(https://pan\.baidu\.com/s/[A-Za-z0-9?\-_=]+)"; string codePattern = @"提取码[::]\s*([A-Za-z0-9]{4})"; Regex linkRegex = new(linkPattern); Regex codeRegex = new(codePattern); Match linkMatch = linkRegex.Match(text); if (linkMatch.Success) { result = linkMatch.Groups[1].Value; if (result.Contains("?pwd=")) { pwd = result.GetContentPart("?pwd=", ""); surl = result.GetContentPart("/s/1", "?pwd="); } else { surl = result.GetContentPart("/s/1", ""); // 匹配提取码 Match codeMatch = codeRegex.Match(text); if (codeMatch.Success) { pwd = codeMatch.Groups[1].Value; } } } return result; } public static void PanParse(string content, ref ToolParseDataDTO result) { string message = "OK"; string surl = string.Empty, pwd = string.Empty; string shortLinkurl = GetPanLink(content, ref surl, ref pwd); if (string.IsNullOrEmpty(surl)) { result.channel = TkChannelEnum.bdpan; result.content = content; result.success = false; result.message = "转链失败"; result.reason = "内容不匹配"; return; } var deeplink_url = $"bdnetdisk://n/action.SHARE_LINK?surl={surl}&pwd={pwd}"; result.channel = TkChannelEnum.bdpan; result.content = content; result.success = true; result.message = message; result.shortLinkurl = shortLinkurl; result.deeplink_url = deeplink_url; } public static void WemeetParse(string content, ref ToolParseDataDTO result) { string message = "OK"; string wemeetId = GetWemeetId(content); if (string.IsNullOrEmpty(wemeetId)) { result.channel = TkChannelEnum.wemeet; result.content = content; result.success = false; result.message = "转链失败"; result.reason = "内容不匹配"; return; } var deeplink_url = $"wemeet://page/inmeeting?meeting_code={wemeetId}"; result.channel = TkChannelEnum.wemeet; result.content = wemeetId; result.success = true; result.message = message; result.deeplink_url = deeplink_url; } public static string GetWemeetId(string content) { string pattern = @"#腾讯会议:(\d{3}-\d{3}-\d{3})"; Regex regex = new Regex(pattern); Match match = regex.Match(content); string meetingCode; // 判断是否匹配成功 if (match.Success) { // 提取会议编码 meetingCode = match.Groups[1].Value; meetingCode = meetingCode.Replace("-", ""); if (!string.IsNullOrEmpty(meetingCode)) return meetingCode; } meetingCode = GetWemeetIdFromUrl(content); return meetingCode; } public static string? GetDesiredUrl(string url) { try { WebClientUtility client = new() { AllowAutoRedirect = false }; var response = client.Request(url); if (!response.Successed) return null; return response.Body(); } catch (Exception ex) { } return null; } public static string GetWemeetIdFromUrl(string content) { { string pattern = @"https:\/\/meeting\.tencent\.com\/p\/([0-9]+)"; Regex regex = new Regex(pattern); Match match = regex.Match(content); // 判断是否匹配成功 if (match.Success) { // 提取会议编码 string meetingCode = match.Groups[1].Value; return meetingCode; } } { string pattern = @"https:\/\/meeting\.tencent\.com\/dm\/[a-zA-Z0-9]+"; Regex regex = new Regex(pattern); Match match = regex.Match(content); // 判断是否匹配成功 if (match.Success) { // 提取会议编码 string meeting_url = match.Value; var body = GetDesiredUrl(meeting_url); if (string.IsNullOrEmpty(body)) return string.Empty; string meetingCode = body.GetContentPart("\"meeting_code\":\"", "\""); return meetingCode; } return string.Empty; } } } }