diff --git a/JodelAPI/JodelAPI/Internal/ApiCall.cs b/JodelAPI/JodelAPI/Internal/ApiCall.cs index 3055fbc..f117a79 100644 --- a/JodelAPI/JodelAPI/Internal/ApiCall.cs +++ b/JodelAPI/JodelAPI/Internal/ApiCall.cs @@ -1,11 +1,16 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Net.Http; +using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using JodelAPI.Json.Request; +using JodelAPI.Json.Response; using JodelAPI.Shared; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; namespace JodelAPI.Internal { @@ -29,7 +34,7 @@ internal class ApiCall /// API version to be used /// Action to be applied to post /// true if authorization bearer needs to be added to request header, otherwise false - internal ApiCall(System.Net.Http.HttpMethod method, string url, string version = "v3", string postAction = "", bool authorize = true) + internal ApiCall(HttpMethod method, string url, string version = "v3", string postAction = "", bool authorize = true) { Method = method; Url = url; @@ -38,6 +43,30 @@ internal ApiCall(System.Net.Http.HttpMethod method, string url, string version = Authorize = authorize; } + internal JsonCaptcha.RootObject GetCaptcha(User user) + { + string url = "https://" + Links.ApiBaseUrl + "/api/" + Version + Url + user.Token.Token; + var json = JsonConvert.DeserializeObject(new WebClient().DownloadString(url)); + return json; + } + + internal bool PostCaptcha(User user, Captcha captcha, int[] answer) + { + string url = "https://" + Links.ApiBaseUrl + "/api/" + Version + Url + user.Token.Token; + string an = "["; + for (var index = 0; index < answer.Length; index++) + { + var a = answer[index]; + an += a; + if (an.Length != index + 1) + an += ","; + else + an += "]"; + } + var json = JObject.Parse(new WebClient().UploadString(url, "{\"key\":\"" + captcha.Key + "\",\"answer\":" + an + "}")); + return json.Value("verified"); + } + internal string ExecuteRequest(User user, Dictionary parameters = null, JsonRequest payload = null, string postId = null) { string plainJson = null; diff --git a/JodelAPI/JodelAPI/Internal/Constants.cs b/JodelAPI/JodelAPI/Internal/Constants.cs index 0098f30..62baec0 100644 --- a/JodelAPI/JodelAPI/Internal/Constants.cs +++ b/JodelAPI/JodelAPI/Internal/Constants.cs @@ -10,9 +10,9 @@ namespace JodelAPI.Internal internal class Constants { // Key Values - public const string Key = "plerFToqEdWlzShdZlTywaCHRuzlKIMsNmOJVDGE"; + public const string Key = "LDWWpuUigOnKCbCLpoNMDHCqHCWbLKPzHbnIUKIf"; public const string ClientId = "81e8a76e-1e02-4d17-9ba0-8a7020261b26"; - public const string AppVersion = "4.31.1"; + public const string AppVersion = "4.33.2"; // Headers diff --git a/JodelAPI/JodelAPI/Internal/Links.cs b/JodelAPI/JodelAPI/Internal/Links.cs index 866a3d6..6095424 100644 --- a/JodelAPI/JodelAPI/Internal/Links.cs +++ b/JodelAPI/JodelAPI/Internal/Links.cs @@ -34,6 +34,8 @@ internal static class Links public static readonly ApiCall GetMyPopularPosts = new ApiCall(HttpMethod.Get, "/posts/mine/popular/", "v2"); public static readonly ApiCall GetMyMostDiscussedPosts = new ApiCall(HttpMethod.Get, "/posts/mine/discussed/", "v2"); public static readonly ApiCall GetMyPinnedPosts = new ApiCall(HttpMethod.Get, "/posts/mine/pinned/", "v2"); + public static readonly ApiCall GetCaptcha = new ApiCall(HttpMethod.Get, "/user/verification/imageCaptcha?access_token="); + public static readonly ApiCall VerifyCaptcha = new ApiCall(HttpMethod.Post, "/user/verification/imageCaptcha?access_token="); #endregion diff --git a/JodelAPI/JodelAPI/Jodel.cs b/JodelAPI/JodelAPI/Jodel.cs index 3c45793..37262d7 100644 --- a/JodelAPI/JodelAPI/Jodel.cs +++ b/JodelAPI/JodelAPI/Jodel.cs @@ -110,6 +110,17 @@ public void SetLocation() Links.SendUserLocation.ExecuteRequest(Account, payload: payload); } + public Captcha GetCaptcha(bool advanced = false) + { + var captchaRoot = Links.GetCaptcha.GetCaptcha(Account); + return advanced ? new Captcha(new JodelWebClient().DownloadData(captchaRoot.image_url), captchaRoot.key, captchaRoot.image_url, captchaRoot.image_size) : new Captcha(new JodelWebClient().DownloadData(captchaRoot.image_url), captchaRoot.key, captchaRoot.image_url); + } + + public bool SolveCaptcha(Captcha captcha, int[] answer) + { + return Links.VerifyCaptcha.PostCaptcha(Account, captcha, answer); + } + #endregion #region Channels diff --git a/JodelAPI/JodelAPI/JodelAPI.csproj b/JodelAPI/JodelAPI/JodelAPI.csproj index 43b98e4..149b18b 100644 --- a/JodelAPI/JodelAPI/JodelAPI.csproj +++ b/JodelAPI/JodelAPI/JodelAPI.csproj @@ -63,6 +63,7 @@ + @@ -86,6 +87,7 @@ + diff --git a/JodelAPI/JodelAPI/Json/Response/JsonCaptcha.cs b/JodelAPI/JodelAPI/Json/Response/JsonCaptcha.cs new file mode 100644 index 0000000..49c10ab --- /dev/null +++ b/JodelAPI/JodelAPI/Json/Response/JsonCaptcha.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JodelAPI.Json.Response +{ + internal class JsonCaptcha + { + public class RootObject + { + public string key { get; set; } + public string image_url { get; set; } + public int image_size { get; set; } + } + } +} diff --git a/JodelAPI/JodelAPI/Shared/Captcha.cs b/JodelAPI/JodelAPI/Shared/Captcha.cs new file mode 100644 index 0000000..94b02cf --- /dev/null +++ b/JodelAPI/JodelAPI/Shared/Captcha.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JodelAPI.Shared +{ + public class Captcha + { + public Captcha(byte[] image, string key, string imageUrl) + { + Image = image; + Key = key; + ImageUrl = imageUrl; + } + + public Captcha(byte[] image, string key, string imageUrl, int imageSize) + { + Image = image; + Key = key; + ImageUrl = imageUrl; + ImageSize = imageSize; + } + + public byte[] Image { get; } + public string Key { get; } + public string ImageUrl { get; } + public int ImageSize { get; } + } +} diff --git a/JodelAPI/JodelAPITests/JodelTests.cs b/JodelAPI/JodelAPITests/JodelTests.cs index 5c607d8..d522579 100644 --- a/JodelAPI/JodelAPITests/JodelTests.cs +++ b/JodelAPI/JodelAPITests/JodelTests.cs @@ -42,17 +42,26 @@ public void GetRecommendedChannelsTest() } [TestMethod()] - public void GetFollowedChannelsMetaTest() + public void GetPostLocationComboTest() { Assert.IsTrue(jodel.GenerateAccessToken()); - Assert.IsNotNull(jodel.GetFollowedChannelsMeta()); + Assert.IsNotNull(jodel.GetPostLocationCombo()); } [TestMethod()] - public void GetPostLocationComboTest() + public void GetCaptcha() { - Assert.IsTrue(jodel.GenerateAccessToken()); - Assert.IsNotNull(jodel.GetPostLocationCombo()); + Assert.IsNotNull(jodel.GetCaptcha()); + Console.WriteLine(jodel.GetCaptcha().ImageUrl + ":" + jodel.GetCaptcha().Key); + } + + [TestMethod()] + public void SolveCaptcha() + { + var captcha = jodel.GetCaptcha(); + Assert.IsNotNull(captcha); + Console.WriteLine(captcha.ImageUrl + ":" + captcha.Key); + Assert.IsInstanceOfType(jodel.SolveCaptcha(captcha, new[] {1}), typeof(bool)); } } } \ No newline at end of file