예제 #1
0
        private static async Task <string> ProcessTask(AnticaptchaTask task)
        {
            AnticaptchaResult response;

            do
            {
                response = AnticaptchaApiWrapper.GetTaskResult(Host, ClientKey, task);

                if (response.GetStatus().Equals(AnticaptchaResult.Status.ready))
                {
                    break;
                }

                Console.WriteLine("Not done yet, waiting...");
                await Task.Delay(1000);
            } while (response != null && response.GetStatus().Equals(AnticaptchaResult.Status.processing));

            if (response == null || response.GetSolution() == null)
            {
                Console.WriteLine("Unknown error occurred...");
                Console.WriteLine("Response dump:");
                Console.WriteLine(response);
            }
            else
            {
                Console.WriteLine("The answer is '" + response.GetSolution() + "'");
            }

            return(response.GetSolution());
        }
예제 #2
0
        private static async Task <string> ProcessTask(AnticaptchaTask task, string apikey)
        {
            AnticaptchaResult response;

            do
            {
                response = AnticaptchaApiWrapper.GetTaskResult(Host, apikey, task);

                if (response.GetStatus().Equals(AnticaptchaResult.Status.ready))
                {
                    break;
                }

                await Task.Delay(3000);
            } while (response != null && response.GetStatus().Equals(AnticaptchaResult.Status.processing));

            if (response == null || response.GetSolution() == null)
            {
                Logger.Write("Unknown error occurred...", LogLevel.Error);
                //Console.WriteLine("Response dump:");
                //Console.WriteLine(response);
            }
            else
            {
                //Console.WriteLine("The answer is '" + response.GetSolution() + "'");
            }

            return(response.GetSolution());
        }
예제 #3
0
        public static AnticaptchaResult GetTaskResult(string host, string clientKey, AnticaptchaTask task)
        {
            var jObj = new JObject();

            jObj["clientKey"] = clientKey;
            jObj["taskId"]    = task.GetTaskId();

            try
            {
                dynamic resultJson = JsonPostRequest(host, "getTaskResult",
                                                     JsonConvert.SerializeObject(jObj, Formatting.Indented));

                var status = AnticaptchaResult.Status.unknown;

                try
                {
                    status = resultJson.status.ToString().Equals("ready")
                        ? AnticaptchaResult.Status.ready
                        : AnticaptchaResult.Status.processing;
                }
                catch
                {
                    // ignored
                }

                string solution;
                int?   errorId          = null;
                string errorCode        = null;
                string errorDescription = null;
                double?cost             = null;
                string ip         = null;
                int?   createTime = null;
                int?   endTime    = null;
                int?   solveCount = null;

                try
                {
                    solution = resultJson.solution.gRecaptchaResponse.ToString();
                }
                catch
                {
                    try
                    {
                        solution = resultJson.solution.text.ToString();
                    }
                    catch
                    {
                        solution = null;
                    }
                }

                try
                {
                    errorId = resultJson.errorId;
                }
                catch
                {
                    // ignored
                }

                try
                {
                    errorCode = resultJson.errorCode;
                }
                catch
                {
                    // ignored
                }

                try
                {
                    errorDescription = resultJson.errorDescription;
                }
                catch
                {
                    // ignored
                }

                try
                {
                    cost = double.Parse(resultJson.cost.ToString().Replace(',', '.'), CultureInfo.InvariantCulture);
                }
                catch
                {
                    // ignored
                }

                try
                {
                    createTime = resultJson.createTime;
                }
                catch
                {
                    // ignored
                }

                try
                {
                    endTime = resultJson.endTime;
                }
                catch
                {
                    // ignored
                }

                try
                {
                    solveCount = resultJson.solveCount;
                }
                catch
                {
                    // ignored
                }

                try
                {
                    ip = resultJson.ip;
                }
                catch
                {
                    // ignored
                }

                return(new AnticaptchaResult(
                           status,
                           solution,
                           errorId,
                           errorCode,
                           errorDescription,
                           cost,
                           ip,
                           createTime,
                           endTime,
                           solveCount
                           ));
            }
            catch
            {
                // ignored
            }

            return(null);
        }