// Get new cookie values and store them public async Task <bool> GetCookies(jsonClasses.Account user) { var handler = new HttpClientHandler { UseCookies = false }; var client = new HttpClient(handler); // Add request headers client.DefaultRequestHeaders.Add("Accept", "*/*"); client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate, br"); client.DefaultRequestHeaders.Add("Accept-Language", "it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7"); client.DefaultRequestHeaders.Add("Cache-Control", "max-age=0"); client.DefaultRequestHeaders.Add("Connection", "keep-alive"); client.DefaultRequestHeaders.Add("DNT", "1"); client.DefaultRequestHeaders.Add("Host", "collectioning.mcdonalds.it"); client.DefaultRequestHeaders.Add("Referer", "https://collectioning.mcdonalds.it/verify/otp"); client.DefaultRequestHeaders.Add("Upgrade-Insecure-Requests", "1"); client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0"); client.DefaultRequestHeaders.Add("Cookie", user.mc4u); // Get webpage var response = await client.GetAsync("https://collectioning.mcdonalds.it/la-raccolta"); try { // mc4u in the header user.mc4u = response.Headers.GetValues("Set-Cookie").First().Split(";")[0]; // Parse webpage var page = await response.Content.ReadAsStringAsync(); // Other cookies values user.bearer = page.Substring(page.IndexOf("APP.USER.user_laravel = '") + 25, 358); user.token = page.Substring(page.IndexOf("APP.TOKEN = \"") + 13, 40); return(true); } catch { return(false); } }
// Redeem a coupon code for an account public async Task <string> PostPromo(string couponCode, jsonClasses.Account user) { var handler = new HttpClientHandler { UseCookies = false }; var client = new HttpClient(handler); // Add request headers client.DefaultRequestHeaders.Add("Accept", "*/*"); client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate, br"); client.DefaultRequestHeaders.Add("Accept-Language", "it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7"); client.DefaultRequestHeaders.Add("Authorization", "Bearer " + user.bearer); client.DefaultRequestHeaders.Add("Connection", "keep-alive"); client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Length", "69"); client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); client.DefaultRequestHeaders.TryAddWithoutValidation("DNT", "1"); client.DefaultRequestHeaders.Add("Host", "collectioning.mcdonalds.it"); client.DefaultRequestHeaders.Add("Origin", "https://collectioning.mcdonalds.it"); client.DefaultRequestHeaders.Add("Referer", "https://collectioning.mcdonalds.it/inserisci-scontrino"); client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0"); client.DefaultRequestHeaders.Add("X-Requested-With", "XMLHttpRequest"); client.DefaultRequestHeaders.Add("Cookie", user.mc4u); client.DefaultRequestHeaders.Add("X-CSRF-Token", user.token); // POST parameters var content = new Dictionary <string, string> { { "_token", user.token }, { "receipt", couponCode } }; // send request and return response string var response = await client.PostAsync("https://collectioning.mcdonalds.it/api/me/receipts", new FormUrlEncodedContent(content)); return(await response.Content.ReadAsStringAsync()); }
// Async method that insert a coupon code into an account public static async Task <Tuple <string, string> > insert(jsonClasses.Account user, int index, coupon.Coupon gen, int number) { var httpSend = new McSend(); // Number of coupons with 0 points inside. int zeroPoints = 0; // Number of coupons already inserted (check for another bot). int alreadyInserted = 0; // A start txId (nased on current cycle iteration). int txId = (index * 20) + 1; // Log Console.WriteLine("Recharching account N. " + number); // Cycle that lasts until the account is full while (true) { // If too many fails, change location and reset variables if (alreadyInserted >= 8 || txId > 150 || zeroPoints >= 9) { zeroPoints = 0; alreadyInserted = 0; txId = (index * 20) + 1; gen.ChangeLocation(); } // Insert generated coupon to the account jsonClasses.PromoResponse promoInfo; try { promoInfo = new jsonClasses.PromoResponse(await httpSend.PostPromo(gen.GetTazza(txId), user)); } catch { await Task.Delay(1000); Console.WriteLine("Network error. Retrying."); // Restart cycle continue; } // If user is unauthorized, skip this user. if (await promoInfo.IsUnauthorized()) { Console.WriteLine("Unauthorized"); break; } else if (await promoInfo.GetStatusCode() == 200) { // if status code is ok, continue, resetting the alreadyInserted variable. alreadyInserted = 0; txId += 1; // Get coupon status var status = await promoInfo.GetPromoStatus(); // Check for status number if (status == "2") { if (promoInfo.HasProducts()) { // If ok and there are points, reset zeroPoints variable and print coupon points. zeroPoints = 0; Console.WriteLine("Coupon points: " + await promoInfo.GetCouponPoints()); } else { // If is ok but there aren't products, zeroPoints += 1 zeroPoints += 1; Console.WriteLine("Non sono presenti prodotti aderenti all'iniziativa."); // Correspondent error code on website } } else if (status == "10") { Console.WriteLine("Codice scontrino non approvato, assicurati di averlo digitato correttamente."); // Correspondent error code on website zeroPoints += 1; } else if (status == "6") { Console.WriteLine("This restaurant doesn't support this initiative."); // Change location alreadyInserted = 0; zeroPoints = 0; txId = (index * 20) + 1; gen.ChangeLocation(); } else { Console.WriteLine("Unknown status: " + status); Console.WriteLine("LOG: " + promoInfo.GetResponse()); } } else if (await promoInfo.GetErrorCode() == "existing_receipt" || await promoInfo.GetErrorCode() == "wrong_format") { alreadyInserted += 1; txId += 1; Console.WriteLine("Risultato: Codice già esistente!"); } else if (await promoInfo.GetErrorCode() == "too_many_receipt" || await promoInfo.GetErrorCode() == "throttle_limit") { // Account is full so exit Console.WriteLine("Result: Account full!"); break; } else { // Unknown, log. Console.WriteLine(promoInfo.GetResponse()); } // Delay for next iteration (to avoid ban) await Task.Delay(100); } // Save new cookies await Task.Delay(300); _ = await httpSend.GetCookies(user); // Get points number as string string points; try { var pointsResponse = new jsonClasses.PointsResponse(await httpSend.GetPoints(user.bearer, user.mc4u, user.token)); points = await pointsResponse.GetPoints(); } catch { points = ""; } // Return result (email and points) return(Tuple.Create(user.email, points)); }