Пример #1
0
        /// <summary>
        /// Retrieve recaptcha response using captcha ID
        /// </summary>
        /// <param name="captcha_id"></param>
        /// <returns></returns>
        public string retrieve_captcha(string captcha_id)
        {
            // check if ID is OK
            if (string.IsNullOrWhiteSpace(captcha_id))
            {
                throw new Exception("captcha ID is null or empty");
            }

            string url = "";
            // init params object
            Dictionary <string, string> d = new Dictionary <string, string>();

            d.Add("action", "GETTEXT");
            d.Add("captchaid", captcha_id);

            if (!string.IsNullOrWhiteSpace(this._username))
            {
                d.Add("username", this._username);
                d.Add("password", this._password);
                url = RECAPTCHA_RETRIEVE_ENDPOINT;
            }
            else
            {
                d.Add("token", this._access_token);
                url = RECAPTCHA_RETRIEVE_ENDPOINT_TOKEN;
            }

            var    post_data = Utils.list_to_params(d);                               // transform dict to params
            string response  = Utils.POST(url, post_data, USER_AGENT, this._timeout); // make request

            if (response.Contains("ERROR:"))
            {
                var response_err = response.Split(new string[] { "ERROR:" }, StringSplitOptions.None)[1].Trim();
                // in this case, if we get NOT_DECODED, we don't need it saved to obj
                // because it's used by bool in_progress(int captcha_id) as well
                if (!response_err.Contains("NOT_DECODED"))
                {
                    this._error = response_err;
                }
                throw new Exception(response_err);
            }

            // set as recaptcha response and return
            this._recaptcha = new Recaptcha(captcha_id);
            this._recaptcha.set_response(response);
            return(this._recaptcha.response());        // return captcha text
        }
Пример #2
0
        //public string submit_recaptcha(string page_url, string sitekey, string proxy = "")
        /// <summary>
        /// Submit recaptcha and get it's captcha ID
        /// Check API docs for more info on how to get page_url and sitekey
        /// </summary>
        /// <param name="d">Dictionary containing submission parameters</param>
        /// <returns></returns>
        public string submit_recaptcha(Dictionary <string, string> d)
        {
            string page_url = d["page_url"];
            string sitekey  = d["sitekey"];
            string proxy    = "";

            if (d.ContainsKey("proxy"))
            {
                proxy = d["proxy"];
            }

            // check given vars
            if (string.IsNullOrWhiteSpace(page_url))
            {
                throw new Exception("page_url variable is null or empty");
            }
            if (string.IsNullOrWhiteSpace(sitekey))
            {
                throw new Exception("sitekey variable is null or empty");
            }

            string url = "";
            // create dict (params)
            Dictionary <string, string> data = new Dictionary <string, string>();

            data.Add("action", "UPLOADCAPTCHA");
            data.Add("pageurl", page_url);
            data.Add("googlekey", sitekey);

            // add proxy params if given
            if (!string.IsNullOrWhiteSpace(proxy))
            {
                data.Add("proxy", proxy);
            }

            if (!string.IsNullOrWhiteSpace(this._username))
            {
                data.Add("username", this._username);
                data.Add("password", this._password);
                url = RECAPTCHA_SUBMIT_ENDPOINT;
            }
            else
            {
                data.Add("token", this._access_token);
                url = RECAPTCHA_SUBMIT_ENDPOINT_TOKEN;
            }

            // affiliate id
            if (!string.IsNullOrWhiteSpace(this._affiliateid) && this._affiliateid.ToString() != "0")
            {
                data.Add("affiliateid", this._affiliateid);
            }

            // user agent
            if (d.ContainsKey("user_agent"))
            {
                data.Add("useragent", d["user_agent"]);
            }

            // v3
            data.Add("recaptchatype", "0");
            if (d.ContainsKey("type"))
            {
                data["recaptchatype"] = d["type"];
            }
            if (d.ContainsKey("v3_action"))
            {
                data.Add("captchaaction", d["v3_action"]);
            }
            if (d.ContainsKey("v3_min_score"))
            {
                data.Add("score", d["v3_min_score"]);
            }

            var    post_data = Utils.list_to_params(data);                            // transform dict to params
            string response  = Utils.POST(url, post_data, USER_AGENT, this._timeout); // make request

            if (response.Contains("ERROR:"))
            {
                var response_err = response.Split(new string[] { "ERROR:" }, StringSplitOptions.None)[1].Trim();
                this._error = response_err;
                throw new Exception(response_err);
            }

            // set as recaptcha [id] response and return
            var r = new Recaptcha(response);

            this._recaptcha = r;
            return(this._recaptcha.captcha_id());        // return captcha id
        }