|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.IO; |
| 6 | +using Newtonsoft.Json; |
| 7 | +using Newtonsoft.Json.Linq; |
| 8 | + |
| 9 | +namespace bestcaptchasolver |
| 10 | +{ |
| 11 | + public class BestCaptchaSolverAPI |
| 12 | + { |
| 13 | + private const string BASE_URL = "https://bcsapi.xyz/api"; |
| 14 | + private const string USER_AGENT = "csharpClient1.0"; |
| 15 | + private const int TIMEOUT = 30000; |
| 16 | + |
| 17 | + private string _access_token; |
| 18 | + private int _timeout; |
| 19 | + |
| 20 | + /// <summary> |
| 21 | + /// Constructor |
| 22 | + /// </summary> |
| 23 | + /// <param name="access_token"></param> |
| 24 | + /// <param name="timeout"></param> |
| 25 | + public BestCaptchaSolverAPI(string access_token, int timeout = 30000) |
| 26 | + { |
| 27 | + this._access_token = access_token; |
| 28 | + this._timeout = timeout; |
| 29 | + } |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// Get account's balance |
| 33 | + /// </summary> |
| 34 | + /// <returns></returns> |
| 35 | + public string account_balance() |
| 36 | + { |
| 37 | + var url = string.Format("{0}/user/balance?access_token={1}", BASE_URL, this._access_token); |
| 38 | + var resp = Utils.GET(url, USER_AGENT, TIMEOUT); |
| 39 | + dynamic d = JObject.Parse(resp); |
| 40 | + return string.Format("${0}", d.balance.ToString()); |
| 41 | + } |
| 42 | + |
| 43 | + /// <summary> |
| 44 | + /// Submit image captcha |
| 45 | + /// </summary> |
| 46 | + /// <param name="opts"></param> |
| 47 | + /// <returns>captchaID</returns> |
| 48 | + public string submit_image_captcha(Dictionary<string, string> opts) |
| 49 | + { |
| 50 | + Dictionary<string, string> dict = new Dictionary<string, string>(); |
| 51 | + var url = string.Format("{0}/captcha/image", BASE_URL); |
| 52 | + dict.Add("access_token", this._access_token); |
| 53 | + var image = ""; |
| 54 | + // if no b64 string was given, but image path instead |
| 55 | + if (File.Exists(opts["image"])) image = Utils.read_captcha_image(opts["image"]); |
| 56 | + else image = opts["image"]; |
| 57 | + dict.Add("b64image", image); |
| 58 | + // check case sensitive |
| 59 | + if (opts.ContainsKey("case_sensitive")) |
| 60 | + { |
| 61 | + if (opts["case_sensitive"].Equals("true")) dict.Add("case_sensitive", "1"); |
| 62 | + } |
| 63 | + // affiliate ID |
| 64 | + if (opts.ContainsKey("affiliate_id")) dict.Add("affiliate_id", opts["affiliate_id"]); |
| 65 | + var data = JsonConvert.SerializeObject(dict); |
| 66 | + var resp = Utils.POST(url, data, USER_AGENT, TIMEOUT); |
| 67 | + dynamic d = JObject.Parse(resp); |
| 68 | + return d.id.ToString(); |
| 69 | + } |
| 70 | + /// <summary> |
| 71 | + /// Submit image captcha |
| 72 | + /// </summary> |
| 73 | + /// <param name="opts"></param> |
| 74 | + /// <returns>captchaID</returns> |
| 75 | + public string submit_recaptcha(Dictionary<string, string> opts) |
| 76 | + { |
| 77 | + Dictionary<string, string> dict = new Dictionary<string, string>(); |
| 78 | + var url = string.Format("{0}/captcha/recaptcha", BASE_URL); |
| 79 | + dict.Add("access_token", this._access_token); |
| 80 | + dict.Add("page_url", opts["page_url"]); |
| 81 | + dict.Add("site_key", opts["site_key"]); |
| 82 | + if(opts.ContainsKey("proxy")) |
| 83 | + { |
| 84 | + dict.Add("proxy", opts["proxy"]); |
| 85 | + dict.Add("proxy_type", "HTTP"); |
| 86 | + } |
| 87 | + |
| 88 | + // optional params |
| 89 | + if (opts.ContainsKey("type")) dict.Add("type", opts["type"]); |
| 90 | + if (opts.ContainsKey("v3_action")) dict.Add("v3_action", opts["v3_action"]); |
| 91 | + if (opts.ContainsKey("v3_min_score")) dict.Add("v3_min_score", opts["v3_min_score"]); |
| 92 | + if (opts.ContainsKey("user_agent")) dict.Add("user_agent", opts["user_agent"]); |
| 93 | + if (opts.ContainsKey("affiliate_id")) dict.Add("affiliate_id", opts["affiliate_id"]); |
| 94 | + |
| 95 | + var data = JsonConvert.SerializeObject(dict); |
| 96 | + var resp = Utils.POST(url, data, USER_AGENT, TIMEOUT); |
| 97 | + dynamic d = JObject.Parse(resp); |
| 98 | + return d.id.ToString(); |
| 99 | + } |
| 100 | + |
| 101 | + /// <summary> |
| 102 | + /// Retrieve captcha text / gresponse using captcha ID |
| 103 | + /// </summary> |
| 104 | + /// <param name="captchaid"></param> |
| 105 | + /// <returns></returns> |
| 106 | + public Dictionary<string, string> retrieve(string captchaid) |
| 107 | + { |
| 108 | + var url = string.Format("{0}/captcha/{1}?access_token={2}", BASE_URL, captchaid, this._access_token); |
| 109 | + string resp = Utils.GET(url, USER_AGENT, TIMEOUT); |
| 110 | + JObject d = JObject.Parse(resp); |
| 111 | + // check if still in pending |
| 112 | + if (d.GetValue("status").ToString() == "pending") |
| 113 | + { |
| 114 | + var dd = new Dictionary<string, string>(); |
| 115 | + dd.Add("gresponse", ""); |
| 116 | + dd.Add("text", ""); |
| 117 | + return dd; |
| 118 | + } |
| 119 | + // we're good, create dict and return |
| 120 | + var dict = new Dictionary<string, string>(); |
| 121 | + foreach(var e in d) |
| 122 | + { |
| 123 | + dict.Add(e.Key, e.Value.ToString()); |
| 124 | + } |
| 125 | + return dict; |
| 126 | + } |
| 127 | + |
| 128 | + /// <summary> |
| 129 | + /// Set captcha bad |
| 130 | + /// </summary> |
| 131 | + /// <param name="captchaid"></param> |
| 132 | + /// <returns></returns> |
| 133 | + public string set_captcha_bad(string captchaid) |
| 134 | + { |
| 135 | + Dictionary<string, string> dict = new Dictionary<string, string>(); |
| 136 | + var url = string.Format("{0}/captcha/bad/{1}", BASE_URL, captchaid); |
| 137 | + dict.Add("access_token", this._access_token); |
| 138 | + var data = JsonConvert.SerializeObject(dict); |
| 139 | + var resp = Utils.POST(url, data, USER_AGENT, TIMEOUT); |
| 140 | + dynamic d = JObject.Parse(resp); |
| 141 | + return d.status.ToString(); |
| 142 | + } |
| 143 | + } |
| 144 | +} |
0 commit comments