예제 #1
0
        public static async Task <ZZAccount> Login(ProperHttpClient client, string number, string password)
        {
            var loginParams = new Dictionary <string, string>()
            {
                { "grant_type", "password" },
                { "scope", "userpriceplans%20accountinformation%20userbucketbalance" },                         // Pietiekams atlikuma noskaidrošanai.
                // Pilns scope, kuru izmanto Android lietotne: temporarypassword%20balanceprolongation%20voucherrefill%20userpriceplans%20priceplanordering%20offeredpriceplans%20userservices%20serviceordering%20offerings%20registergcmtoken%20accountinformation%20subscription%20userbucketbalance%20billinglanguage%20whois
                { "client_id", ClientId },
                { "client_secret", ClientSecret },
                { "username", number },
                { "password", password },
                { "auth_by_IP", "false" },
                { "version_no", ClientVersion }
            };

            var oauth = await client.PostAsync <OAuthToken>("https://app.zeltazivtina.lv/thin/rest/Auth", new HttpFormUrlEncodedContent(loginParams));

            if (oauth == null)
            {
                return(null);
            }
            System.Diagnostics.Debug.WriteLine("ZZ access token " + oauth.access_token);
            var account = new ZZAccount(null);

            account.SetTokens(oauth);
            return(account);
        }
예제 #2
0
        public override async Task SetBalance(ProperHttpClient client)
        {
            if (accessToken == null || tokenExpires < DateTime.Now)
            {
                var refreshParams = new Dictionary <string, string>()
                {
                    { "grant_type", "refresh_token" },
                    { "client_id", ClientId },
                    { "client_secret", ClientSecret },
                    { "refresh_token", Token },
                    { "version_no", ClientVersion }
                };
                // Saņem jaunu sesijas kodu.
                var oauth = await client.PostAsync <OAuthToken>("https://app.zeltazivtina.lv/thin/rest/Auth", new HttpFormUrlEncodedContent(refreshParams));

                if (oauth == null)
                {
                    return;
                }
                System.Diagnostics.Debug.WriteLine("ZZ access token " + oauth.access_token);
                SetTokens(oauth);
            }

            var request = new HttpRequestMessage(HttpMethod.Get, new Uri("https://app.zeltazivtina.lv/thin/rest/getsummaryinfo"));

            request.Headers.Authorization = new HttpCredentialsHeaderValue("bearer", accessToken);
            var info = await client.SendAsync <ZZBalance>(request);

            if (info == null)
            {
                return;
            }
            this.Balance = new AccountBalance(info.Balance, info.BalanceExpirationDate);
            var balances = new List <IBalance>(4);

            if (info.AddonSecondsBalance.HasValue)
            {
                balances.Add(new VoiceBalance(TimeSpan.FromSeconds(info.AddonSecondsBalance.Value), info.AddonSecondsBalanceExpirationDate.Value));
            }
            if (info.AddonSmsBalanceExpirationDate.HasValue)
            {
                balances.Add(new SmsBalance(info.AddonSmsBalance.HasValue ? info.AddonSmsBalance.Value:int.MaxValue, info.AddonSmsBalanceExpirationDate.Value));
            }
            if (info.DataUsedToday != 0)
            {
                balances.Add(new DataBalance(info.DataUsedToday, DateTime.Today.AddSeconds(23 * 60 * 60 + 59 * 60 + 59), false));
            }
            else if (info.AddonDataBalance.HasValue)
            {
                balances.Add(new DataBalance(info.AddonDataBalance.Value, info.AddonDataBalanceExpirationDate.Value, true));
            }
            if (info.PricePlanList[0].ID != 102 && info.PricePlanList[0].ValidUntil.HasValue)
            {
                balances.Add(new PriceBalance(info.PricePlanList[0].Name, info.PricePlanList[0].ValidUntil.Value));
            }
            this.Balances    = balances;
            this.RefreshDate = DateTime.Now;
            Settings.PutAccountBalances(this);
            UpdateTile();
        }
예제 #3
0
        private static async Task <BiteResponse <TResult> > CallService <TResult>(ProperHttpClient client, int requestLength, object request)
        {
            var          sb = new StringBuilder(requestLength);
            StringWriter sw = new StringWriter(sb);

            using (JsonTextWriter jsonWriter = new JsonTextWriter(sw))
                client.Serializer.Serialize(jsonWriter, request);
            string json = sw.ToString();

            System.Diagnostics.Debug.WriteLine(json);

            var content = new HttpStringContent(json);

            content.Headers.ContentType = new HttpMediaTypeHeaderValue("application/json");
            var httpRequest = new HttpRequestMessage(HttpMethod.Post, new Uri("https://213.226.139.54/prest/android.json"));

            httpRequest.Content = content;
            var response = await client.SendAsync <BiteResponse <TResult> >(httpRequest);

            if (response != null && response.error != null)
            {
                System.Diagnostics.Debug.WriteLine("Bite error message: " + response.error.message);
                throw new Exception(response.error.message);
            }
            return(response);
        }
예제 #4
0
        public override async Task SetBalance(ProperHttpClient client)
        {
            // Oriģināla programma padod masīvu ar vienu elementu uz androidb.json (cita adrese).
            // Laikam tā var prasīt atlikumu par vairākiem kontiem, bet mūsu arhitektūra to neļauj, tāpēc izmantojam adresi, kura sagaida vienīgo elementu.
            var response = await CallService <BiteBalance>(client, 113, new BiteRequest {
                method  = "getData",
                @params = new Dictionary <string, string>(1)
                {
                    { "securityKey", Token }
                }
            });

            if (response == null)
            {
                return;
            }
            var data = response.result;

            this.Balance = new AccountBalance(data.customerAmount,
                                              (data.customerType == BiteCustomer.PREPAID ? data.customerBalanceExp:data.customerRatePlanExp).Value);
            var balances = new List <IBalance>(1);

            if (data.customerDataUsage != 0)
            {
                balances.Add(new DataBalance(data.customerDataUsage * DataBalance.MB, this.Balance.Expires, false));
            }
            this.Balances    = balances;
            this.RefreshDate = DateTime.Now;
            Settings.PutAccountBalances(this);
        }
예제 #5
0
        public static async Task RequestPassword(ProperHttpClient client, string number)
        {
            var response = await CallService <object>(client, 80, new BiteRequest {
                method  = "authMSISDN",
                @params = new Dictionary <string, string>(1)
                {
                    { "msisdn", "371" + number }
                }
            });

            return;
        }
예제 #6
0
        public override async Task SetBalance(ProperHttpClient client)
        {
            if (!balanceSetInLogin)
            {
                var balance = await GetBalance(client, Token.Substring(0, 8), Token.Substring(8));

                if (balance == null)
                {
                    return;
                }
                this.Balance = balance;
            }
            balanceSetInLogin = false;
            this.RefreshDate  = DateTime.Now;
            Settings.PutAccountBalances(this);
            UpdateTile();
        }
예제 #7
0
        public static async Task <OAccount> Login(ProperHttpClient client, string number, string password)
        {
            // Ar pieteikšanos pietiktu numura un paroles pārbaudei, bet vajag atsijāt pastāvīgā pieslēguma īpašniekus, jo tiem atlikums izskatās savādāk un pašlaik netiek atbalstīts.
            var balance = await GetBalance(client, number, password);

            if (balance == null)
            {
                return(null);
            }
            var account = new OAccount(null)
            {
                Token             = number + password,
                Balance           = balance,
                balanceSetInLogin = true
            };

            return(account);
        }
예제 #8
0
        public static async Task <BiteAccount> Login(ProperHttpClient client, string number, string password)
        {
            var response = await CallService <BiteLogin>(client, 102, new BiteRequest {
                method  = "authPassword",
                @params = new Dictionary <string, string>(2)
                {
                    { "password", password },
                    { "msisdn", "371" + number }
                }
            });

            if (response == null)
            {
                return(null);
            }
            var account = new BiteAccount(null);

            account.Token = response.result.securityKey;
            System.Diagnostics.Debug.WriteLine("Bite token " + account.Token);
            return(account);
        }
예제 #9
0
        private static async Task <AccountBalance> GetBalance(ProperHttpClient clientWrapper, string number, string password)
        {
            var cookiesUri = new Uri("https://mans.lmt.lv/");

            // Dzēš iepriekšējās sesijas kūkas. ToList novēŗš dzēšanas konfliktu.
            foreach (var cookie in clientWrapper.CookieManager.GetCookies(cookiesUri).ToList())
            {
                clientWrapper.CookieManager.DeleteCookie(cookie);
            }

            var client = clientWrapper.Client;
            // Ielādē sākumlappusi. Sāk sesiju un noskaidro pieteikšanās žetonu.
            var response = await client.SendRequestAsync(new HttpRequestMessage(HttpMethod.Head, new Uri("https://mans.lmt.lv/lv/auth")));

            Debug.WriteLine("LMT home " + response.StatusCode);
            if (response.StatusCode != HttpStatusCode.Ok)
            {
                return(null);
            }

            string csrf       = clientWrapper.CookieManager.GetCookies(cookiesUri).First(c => c.Name == "lmt_csrf_cookie_name").Value;
            var    jsonHeader = new HttpMediaTypeWithQualityHeaderValue("application/json");
            var    xhrHeader  = new KeyValuePair <string, string>("X-Requested-With", "XMLHttpRequest");

            // Piesakās ar tālruņa numuru un paroli. Nodotās galvenes ir obligātas.
            var request = new HttpRequestMessage(HttpMethod.Post, new Uri("https://mans.lmt.lv/lv/auth/login"));

            request.Headers.Accept.Add(jsonHeader);
            request.Headers.Add(xhrHeader);
            request.Content = new HttpFormUrlEncodedContent(new Dictionary <string, string>(4)
            {
                { "lmt_csrf_name", csrf },
                { "login-name", number },
                { "login-pass", password }
                //{ "login-code", string.Empty }
            });
            response = await client.SendRequestAsync(request);

            Debug.WriteLine("LMT login " + response.StatusCode);
            // {"success":true,"step":"\/lv\/auth\/access_info"}
            var json = await response.Content.ReadAsStringAsync();

            Debug.WriteLine(json);
            if (response.StatusCode != HttpStatusCode.Ok || !json.StartsWith("{\"success\":true"))
            {
                return(null);
            }

            // Lai mazinātu varbūtību, ka nākamais izsaukums atgriezīs "wait", gaida 2 sekundes tāpat kā LMT skripts.
            await Task.Delay(2000);

            // Apstiprina pieteikšanos. Vienkārši obligāts solis.
            request = new HttpRequestMessage(HttpMethod.Get, new Uri("https://mans.lmt.lv/lv/auth/access_info"));
            request.Headers.Accept.Add(jsonHeader);
            request.Headers.Add(xhrHeader);
            response = await client.SendRequestAsync(request);

            Debug.WriteLine("LMT authenticate " + response.StatusCode);
            // {"redirect":"\/lv\/index.php"} vai {"wait":true}
            json = await response.Content.ReadAsStringAsync();

            Debug.WriteLine(json);
            if (response.StatusCode != HttpStatusCode.Ok || !json.StartsWith("{\"redirect\":"))
            {
                return(null);
            }

            // Iziet caur pāradresācijām, pieprasot lappusi ar atlikuma datiem.
            response = await client.GetAsync(new Uri("https://mans.lmt.lv/lv/index.php"));

            Debug.WriteLine("LMT balance redirect 1 {0} {1}", response.StatusCode, response.Headers.Location);
            if (response.StatusCode != HttpStatusCode.Found)
            {
                return(null);
            }
            response = await client.GetAsync(new Uri("https://mans.lmt.lv/lv/"));           // https://mans.lmt.lv/lv/

            Debug.WriteLine("LMT balance redirect 2 {0} {1}", response.StatusCode, response.Headers.Location);
            if (response.StatusCode != HttpStatusCode.Found)
            {
                return(null);
            }
            response = await client.GetAsync(response.Headers.Location);           // https://mans.lmt.lv/lv/icenter/info.php

            Debug.WriteLine("LMT balance redirect 3 {0} {1}", response.StatusCode, response.Headers.Location);
            if (response.StatusCode != HttpStatusCode.Found)
            {
                return(null);
            }
            response = await client.GetAsync(response.Headers.Location);           // https://mans.lmt.lv/lv/icenter/

            Debug.WriteLine("LMT balance " + response.StatusCode);
            if (response.StatusCode != HttpStatusCode.Ok)
            {
                return(null);
            }

            string html = await response.Content.ReadAsStringAsync();

            // HTMLā ir dažādas rindu pārneses, bet šajā blokā CR-LF. Lauka nosaukums un datuma formāts krievu valodā atšķiras, bet šeit visi pieprasījumi attiecas uz latviešu valodu.
            var      match   = Regex.Match(html, @"<td class=""text okavanss""><span class=""ls"">Ls</span><span class=""eiro"">€</span> *([0-9]+\.[0-9][0-9])</td>.+Avansa derīguma termiņš</a></th>\r\n\s+<td class=""text okavanss"">([0-3][0-9]\.[01][0-9]\.[0-9]{4})\. plkst\. ([012][0-9]:[0-5][0-9])</td>", RegexOptions.Singleline);
            decimal  amount  = decimal.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture);
            DateTime expires = DateTime.ParseExact(match.Groups[2].Value, "dd.MM.yyyy", CultureInfo.InvariantCulture).Add(TimeSpan.ParseExact(match.Groups[3].Value, "hh\\:mm", CultureInfo.InvariantCulture));

            Debug.WriteLine("LMT amount " + amount + " expires " + expires.ToString("F"));
            // Aizver sesiju. Sesijas ilgums kopš pieteikšanās ir viena stunda.
            response = await client.GetAsync(new Uri("https://mans.lmt.lv/lv/?logout=true"));

            Debug.WriteLine("LMT logout " + response.StatusCode);
            // Ignorē pāradresācijas, jo galvenais izsaukums jau veikts.
            if (response.StatusCode != HttpStatusCode.Found)
            {
                return(null);
            }
            return(new AccountBalance(amount, expires));
        }
예제 #10
0
 public abstract Task SetBalance(ProperHttpClient client);