Jump to content

Consular lista de documentos (recibos)


Babayaga
 Share

Recommended Posts

 			CookieContainer cookieJar = new CookieContainer();
            HttpClientHandler handler = new HttpClientHandler()
            {
                CookieContainer = cookieJar
            };
            handler.UseCookies = true;
            handler.UseDefaultCredentials = false;

            HttpClient hc = new HttpClient(handler);

            var loginRequest = hc.GetStringAsync("https://www.acesso.gov.pt/jsp/loginRedirectForm.jsp?path=painelAdquirente.action&partID=EFPF");
            var htmlLogin = new HtmlAgilityPack.HtmlDocument();
            htmlLogin.LoadHtml(loginRequest.Result);

            var _csrf = htmlLogin.DocumentNode.SelectSingleNode("//input[@name='_csrf']/@value").GetAttributeValue("value", "");

            var resultLogin = hc.PostAsync("https://www.acesso.gov.pt/jsp/submissaoFormularioLogin?path=painelAdquirente.action&partID=EFPF&authVersion=1&selectedAuthMethod=N", new StringContent("username=" + txtUtilizador.Text + "&password=" + txtPalavraPasse.Text + "&_csrf=" + _csrf, Encoding.UTF8, "application/x-www-form-urlencoded"));
            var contents = resultLogin.Result.Content.ReadAsStringAsync();
            var htmlLogin2 = new HtmlAgilityPack.HtmlDocument();
            htmlLogin2.LoadHtml(contents.Result);
            var sign = htmlLogin2.DocumentNode.SelectSingleNode("//input[@name='sign']/@value").GetAttributeValue("value", "");
            var userID = htmlLogin2.DocumentNode.SelectSingleNode("//input[@name='userID']/@value").GetAttributeValue("value", "");
            var sessionID = htmlLogin2.DocumentNode.SelectSingleNode("//input[@name='sessionID']/@value").GetAttributeValue("value", "");
            var nif = htmlLogin2.DocumentNode.SelectSingleNode("//input[@name='nif']/@value").GetAttributeValue("value", "");
            var tc = htmlLogin2.DocumentNode.SelectSingleNode("//input[@name='tc']/@value").GetAttributeValue("value", "");
            var tv = htmlLogin2.DocumentNode.SelectSingleNode("//input[@name='tv']/@value").GetAttributeValue("value", "");
            var userName = htmlLogin2.DocumentNode.SelectSingleNode("//input[@name='userName']/@value").GetAttributeValue("value", "");
            var partID = htmlLogin2.DocumentNode.SelectSingleNode("//input[@name='partID']/@value").GetAttributeValue("value", "");

            var formVariables = new List<KeyValuePair<string, string>>();
            formVariables.Add(new KeyValuePair<string, string>("sign", sign));
            formVariables.Add(new KeyValuePair<string, string>("userID", userID));
            formVariables.Add(new KeyValuePair<string, string>("sessionID", sessionID));
            formVariables.Add(new KeyValuePair<string, string>("nif", nif));
            formVariables.Add(new KeyValuePair<string, string>("tc", tc));
            formVariables.Add(new KeyValuePair<string, string>("tv", tv));
            formVariables.Add(new KeyValuePair<string, string>("userName", userName));
            formVariables.Add(new KeyValuePair<string, string>("partID", partID));
            var formContent = new FormUrlEncodedContent(formVariables);

            //TODO: await? e ai nao usa o result, retorno do metodo tb precisa ser async Task
            var painelAdquirentePost = hc.PostAsync("https://faturas.portaldasfinancas.gov.pt/painelAdquirente.action", formContent).Result;

            var url = "";
            Task<string> json = null;
            dynamic stuff;

            //primeiro tenta pegar do ano todo
            url = string.Format("https://faturas.portaldasfinancas.gov.pt/json/obterDocumentosAdquirente.action?dataInicioFilter={0}&dataFimFilter={1}&ambitoAquisicaoFilter=TODOS", dateTimePicker1.Value.ToString("yyyy-MM-dd"), dateTimePicker2.Value.ToString("yyyy-MM-dd"));
            json = hc.GetStringAsync(url);
            stuff = JObject.Parse(json.Result); //stuff.totalElementos
            var linhas = (Newtonsoft.Json.Linq.JArray)stuff.linhas;
            this.Faturas = new List<Fatura>();
 
Link to comment
Share on other sites

Deixo aqui um bocado de código em c#, para recibos verdes o caminho é outro, que inclusive contêm mais info. No efaturas é possivel ver os recibos verdes como Fatura-Recibo, mas sem info sobre a retenção.

https://irs.portaldasfinancas.gov.pt/recibos/api/obtemDocumentos?dataEmissaoFim=2021-09-30&dataEmissaoInicio=2021-07-01&isAutoSearchOn=on&modoConsulta=Adquirente&nifAdquirente=999999990&tipoPesquisa=1

Edited by Babayaga
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.