Beispiel #1
0
        public static StatementCollection Parse(string content)
        {
            var statements = new StatementCollection();

            statements.Balance = _balance;
            var doc = new HtmlDocument();

            doc.LoadHtml(content);
            var rows = doc.DocumentNode.SelectNodes("/html[1]/body[1]/div[1]/div[4]/div[1]/div[2]/table[1]/tbody[1]/tr[position()>1]");

            if (rows != null)
            {
                for (int i = 0; i < rows.Count - 2; i++)
                {
                    var row    = rows[i];
                    var fields = row.SelectNodes("./td");
                    if (fields == null)
                    {
                        continue;
                    }
                    // data/transaction/debit/credit/balance
                    if (fields.Count == 5)
                    {
                        var statement = new Statement();
                        statement.ID   = RemoveComma(CryptographyHelper.MD5(row.InnerHtml));
                        statement.Date = RemoveComma(ContentHelper.Clear(fields[0].InnerHtml, " "));

                        statement.Description = RemoveComma(ContentHelper.Clear(fields[1].InnerHtml, " "));
                        statement.Debit       = ContentHelper.Clear(fields[2].InnerHtml).Replace(".", "").Replace(",", ".");
                        statement.Credit      = ContentHelper.Clear(fields[3].InnerHtml).Replace(".", "").Replace(",", ".");
                        statement.Balance     = ContentHelper.Clear(fields[4].InnerHtml).Replace(".", "").Replace(",", ".");
                        statements.Add(statement);
                    }
                }
            }

            statements.Balance = (statements[statements.Count - 1] as Statement).Balance;

            return(statements);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Cookies = new CookieContainer();
            Client  = new HttpClient(new HttpClientHandler {
                CookieContainer = Cookies, AllowAutoRedirect = true
            })
            {
                Timeout = new TimeSpan(0, 3, 0)
            };
            Client.DefaultRequestHeaders.UserAgent.TryParseAdd(Request.UserAgents.Chrome);


            var loginUrl   = "https://ib.bri.co.id/ib-bri/Login.html";
            var captchaUrl = "https://ib.bri.co.id/ib-bri/login/captcha";

            using (var rsp = Client.GetAsync(loginUrl).Result)
            {
                var page = rsp.Content.ReadAsStringAsync().Result;

                var matcher = REG_CSRF.Value.Match(page);

                _csrf = matcher.Groups[1].Value;
            }
            string CaptchaMidasService = string.Format("{0}/Captcha/GetCaptchaResult", "http://192.168.102.247:8001");
            //var captcha = await RecognizeCaptchaAsync(Client, captchaUrl);
            var captcha = RecognizeCaptchaAsync(Client, captchaUrl, CaptchaMidasService);

            if (captcha.Error)
            {
                Console.WriteLine("Captcha Error");
            }

            Random rnd         = new Random();
            var    loginParams = new Parameters();

            loginParams["csrf_token_newib"] = _csrf;
            loginParams["j_password"]       = "******";
            loginParams["j_username"]       = "******";
            loginParams["j_plain_username"] = "******";
            //loginParams["j_password"] = "******";
            //loginParams["j_username"] = "******";
            //loginParams["j_plain_username"] = "******";
            loginParams["j_plain_password"] = "";
            loginParams["j_captcha"]        = captcha.Data;
            loginParams["j_language"]       = "en_US";
            loginParams["x"] = rnd.Next(1, 100).ToString();
            loginParams["y"] = rnd.Next(1, 24).ToString();
            string LastPage = "";

            using (var rsp = Client.PostAsync("https://ib.bri.co.id/ib-bri/Homepage.html",
                                              loginParams.ToFormEncodedData()).Result)
            {
                LastPage = rsp.Content.ReadAsStringAsync().Result;
                File.WriteAllText("WaitTenMinutes.html", LastPage);
                if (LastPage.Contains("please wait 10 minutes"))
                {
                    Console.WriteLine("please wait 10 minutes");
                }
                if (!LastPage.Contains("Welcome to BRI Internet Banking"))
                {
                    Console.WriteLine("Login failed");
                }
                //    return new ReturnObject(MonitorRequestStatus.LoginFailed, null, "Welcome to BRI Internet Banking");
            }

            var response = Client.GetAsync("https://ib.bri.co.id/ib-bri/MyAccount.html").Result;

            using (var rsp = Client.GetAsync("https://ib.bri.co.id/ib-bri/BalanceInquiry.html").Result)
            {
                LastPage = rsp.Content.ReadAsStringAsync().Result;
                File.WriteAllText("LoginComplete.html", LastPage);
                var matcher = REG_CSRF.Value.Match(LastPage);
                _csrf = matcher.Groups[1].Value;

                var doc = new HtmlDocument();
                doc.LoadHtml(LastPage);
                var rows = doc.DocumentNode.SelectNodes("html[1]/body[1]/div[1]/div[4]/div[2]/table[1]/tbody[1]/tr");

                if (rows != null)
                {
                    for (int i = 0; i < rows.Count; i++)
                    {
                        var row    = rows[i];
                        var fields = row.SelectNodes("./td");
                        var accNo  = ContentHelper.Clear(fields[0].InnerHtml, " ").Trim();
                        //if (accNo == "012201000644569")
                        if (accNo == "210201000187565")
                        {
                            _balance = ContentHelper.Clear(fields[4].InnerHtml, " ").Trim();
                            break;
                        }
                    }
                }
                else
                {
                    Console.WriteLine("parse failed", LastPage);
                }
            }

            using (var rsp = Client.GetAsync("https://ib.bri.co.id/ib-bri/AccountStatement.html").Result)
            {
                LastPage = rsp.Content.ReadAsStringAsync().Result;
                var matcher = REG_CSRF.Value.Match(LastPage);
                _csrf = matcher.Groups[1].Value;
            }
            var FromDate     = DateTime.Now;
            var ToDate       = DateTime.Now;
            var reportParams = new Parameters();

            reportParams["csrf_token_newib"] = _csrf;
            reportParams["FROM_DATE"]        = FromDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
            reportParams["TO_DATE"]          = ToDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
            reportParams["download"]         = "";
            //reportParams["ACCOUNT_NO"] = "012201000644569";
            reportParams["ACCOUNT_NO"]   = "210201000187565";
            reportParams["VIEW_TYPE"]    = "2";
            reportParams["DDAY1"]        = FromDate.Day.ToString("00");
            reportParams["DMON1"]        = FromDate.Month.ToString("00");
            reportParams["DYEAR1"]       = FromDate.Year.ToString("0000");
            reportParams["DDAY2"]        = ToDate.Day.ToString("00");
            reportParams["DMON2"]        = ToDate.Month.ToString("00");
            reportParams["DYEAR2"]       = ToDate.Year.ToString("0000");
            reportParams["MONTH"]        = DateTime.Now.Month.ToString("00");
            reportParams["YEAR"]         = DateTime.Now.Year.ToString("0000");
            reportParams["submitButton"] = DateTime.Now.Year.ToString("View");

            using (var rsp = Client.PostAsync("https://ib.bri.co.id/ib-bri/Br11600d.html",
                                              reportParams.ToFormEncodedData()).Result)
            {
                LastPage = rsp.Content.ReadAsStringAsync().Result;
                File.WriteAllText("AccountMutation.html", LastPage);
                if (!LastPage.Contains("Account Mutation"))
                {
                    Console.WriteLine("page does not contain keyworkd \"Account Mutation\".");
                }

                var test = Parse(LastPage);
            }

            var response1 = Client.GetAsync("https://ib.bri.co.id/ib-bri/login/logout").Result;

            using (var rsp = Client.GetAsync("https://ib.bri.co.id/ib-bri/en/logout.htm").Result)
            {
                var page = rsp.Content.ReadAsStringAsync().Result;
                if (page.Contains("Thank You"))
                {
                    Console.WriteLine("Logout finished !");
                }
                else
                {
                    Console.WriteLine("page does not contain keyword \"Thank You\".");
                }
            }

            Console.WriteLine("finish");
            Console.Read();
        }