Untitled
user_2299906
plain_text
2 years ago
8.7 kB
10
Indexable
public RestClient Client { set; get; } private RestClientOptions options; private RestRequest request; public string LSD { set; get; } public string Fb_dtsg { set; get; } public string Jazoest { set; get; } public string ResponseURI { set; get; } public string User { set; get; } public string UID { set; get; } public string datapost { set; get; } private string html; public RequestFb(string cookies = null, string userAgent = null, string ProxyUrl = null) { datapost = ""; User = ""; Setoptions(userAgent); SetProxy(ProxyUrl); Client = new RestClient(options); SetCookie(cookies); } public RequestFb(Worker pro) { datapost = ""; User = ""; Setoptions(pro.UserAgent); SetProxy(pro.ProxyUrl); Client = new RestClient(options); SetCookie(pro.Cookie); } public void ResetToken(string HTML = "") { if (!string.IsNullOrEmpty(HTML)) html = HTML; if (!string.IsNullOrEmpty(html)) { Fb_dtsg = RegexMatch(html.Replace("\\", string.Empty), "DTSGInitialData\",(.*?),{\"token\":\"(.*?)\"").Groups[2].Value; Jazoest = RegexMatch(html.Replace("\\", string.Empty), "jazoest=(\\d+)").Groups[1].Value; if (string.IsNullOrEmpty(Jazoest)) Jazoest = RegexMatch(html.Replace("\\", string.Empty), "jazoest\",\"version\":2,\"should_randomize\":false},(\\d+)").Groups[1].Value; LSD = RegexMatch(html.Replace("\\", string.Empty), "LSD\",(.*?),{\"token\":\"(.*?)\"").Groups[2].Value; } } private void Setoptions(string userAgent) { if (string.IsNullOrEmpty(userAgent)) userAgent = UserAgentDefaut; if (options == null) options = new RestClientOptions() { MaxTimeout = 60000, CookieContainer = new System.Net.CookieContainer(), UserAgent = userAgent, Encoding = Encoding.UTF8, Expect100Continue = true, MaxRedirects = 100, FollowRedirects = true, ThrowOnAnyError = false, FailOnDeserializationError = false, ThrowOnDeserializationError = false , RemoteCertificateValidationCallback = new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return true; }), PreAuthenticate = true }; } public string _Cookie { set; get; } private void SetCookie(string cookies) { if (string.IsNullOrEmpty(cookies)) cookies = "locale=vi_VN;"; _Cookie = cookies; if (string.IsNullOrEmpty(UID)) UID = RegexMatch(cookies, "c_user=(\\d+)").Groups[1].Value; foreach (string coo in cookies.Split(new[] { ";", " " }, StringSplitOptions.RemoveEmptyEntries)) { if(coo.Contains("useragent=")) continue; if (coo.Contains("i_user")) continue; string[] temp = coo.Split('='); if (temp.Length == 2) Client.CookieContainer.Add(new Cookie(temp[0], temp[1], "/", "facebook.com")); } } public void setDatapost(string uid, string user) { datapost = $"av={user}&__user={uid}&__a=1&__dyn=&__csr=&__req=&__hs=&dpr=&__ccg=&__rev=&__s=&__hsi=&__comet_req=15&fb_dtsg={Fb_dtsg}&jazoest={Jazoest}&lsd={LSD}&__spin_r=&__spin_b=&__spin_t=&fb_api_caller_class=RelayModern"; } public void SetProxy(string ProxyUrl) { if (!string.IsNullOrEmpty(ProxyUrl)) { string[] prox = ProxyUrl.Replace(" ","").Replace("|", ":").Split(':'); string proxyUserName = ""; string proxyPassword = ""; string proxyHost = prox[0]; string proxyPort = ""; if (!string.IsNullOrEmpty(proxyHost) && prox.Length >= 2) { proxyPort = prox[1]; var proxy = new WebProxy(proxyHost, int.Parse(proxyPort)); if (prox.Length > 2) { proxyUserName = prox[2]; proxyPassword = prox[3]; proxy.Credentials = new NetworkCredential(userName: proxyUserName, password: proxyPassword); } options.Proxy = proxy; } } } public Task<string> Post(string url, string data,bool isPage = false) { var restk = Task.Run(async () => { if (string.IsNullOrEmpty(User)) User = UID; if (string.IsNullOrEmpty(datapost) || isPage) datapost = $"av={User}&__user={UID}&__a=1&__dyn=&__csr=&__req=&__hs=&dpr=&__ccg=&__rev=&__s=&__hsi=&__comet_req=15&fb_dtsg={Fb_dtsg}&jazoest={Jazoest}&lsd={LSD}&__spin_r=&__spin_b=&__spin_t=&fb_api_caller_class=RelayModern"; url = url.Replace("{Var:Data}", datapost).Replace("{Var:Fb_dtsg}", Fb_dtsg).Replace("{Var:LSD}", LSD).Replace("{Var:Jazoest}", Jazoest); request = new RestRequest(url); request.AddHeader("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"); request.AddHeader("sec-fetch-site", "same-origin"); request.AddHeader("sec-fetch-dest", "empty"); request.AddHeader("accept-language", "en-US,en;q=0.9"); request.AddHeader("sec-fetch-mode", "cors"); request.AddHeader("referer", "https://www.facebook.com/"); request.AddHeader("sec-ch-ua-platform", "\"Windows\""); if (!string.IsNullOrEmpty(LSD)) request.AddHeader("x-fb-lsd", LSD); if (string.IsNullOrEmpty(data) || (!data.Contains("&__user=") && !data.Contains("fb_dtsg"))) data = datapost + data; else data = data.Replace("{Var:Fb_dtsg}", Fb_dtsg).Replace("{Var:LSD}", LSD).Replace("{Var:Jazoest}", Jazoest); request.AddStringBody(data, "application/x-www-form-urlencoded"); request.Method = Method.Post; var res = await Client.ExecuteAsync(request); html = res?.Content; return res?.Content; }); return restk; } public Task<string> GraphApi(string data) { var restk = Task.Run(async () => { if (string.IsNullOrEmpty(LSD) && _Cookie != "locale=vi_VN;") { Get("https://www.facebook.com/").Wait(); } request = new RestRequest("https://www.facebook.com/api/graphql/"); request.AddHeader("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"); request.AddHeader("sec-fetch-site", "same-origin"); request.AddHeader("sec-fetch-dest", "empty"); request.AddHeader("accept-language", "en-US,en;q=0.9"); request.AddHeader("sec-fetch-mode", "cors"); request.AddHeader("referer", "https://www.facebook.com/"); request.AddHeader("sec-ch-ua-platform", "\"Windows\""); if (!string.IsNullOrEmpty(LSD)) { request.AddHeader("x-fb-lsd", LSD); if (string.IsNullOrEmpty(User)) User = UID; if (string.IsNullOrEmpty(datapost) || User != UID) datapost = $"av={User}&__user={UID}&__a=1&__dyn=&__csr=&__req=&__hs=&dpr=&__ccg=&__rev=&__s=&__hsi=&__comet_req=15&fb_dtsg={Fb_dtsg}&jazoest={Jazoest}&lsd={LSD}&__spin_r=&__spin_b=&__spin_t=&fb_api_caller_class=RelayModern"; } if (!string.IsNullOrEmpty(data)) data = data.Replace("{Var:UID}", UID); if (!data.Contains("&__user=") && !string.IsNullOrEmpty(UID)) data = datapost + data; else data = data.Replace("{Var:Fb_dtsg}", Fb_dtsg).Replace("{Var:LSD}", LSD).Replace("{Var:Jazoest}", Jazoest); request.AddStringBody(data, "application/x-www-form-urlencoded"); request.Method = Method.Post; var res = await Client.ExecuteAsync(request); html = res?.Content; return res?.Content; }); return restk; }
Editor is loading...