封装函数
public static async Task captcha2(string VImage, int checkt = 0) { var secretKey = "b8*************"; //KEY var url = "https://2captcha.com/in.php?key=" + secretKey; var res = ""; using (HttpClient client = new HttpClient()) { var content = new MultipartFormDataContent("Upload----" + DateTime.Now.ToString(CultureInfo.InvariantCulture)); content.Add(new StringContent(VImage), "body"); //BASE64图片,不包括data:image/png;base64, content.Add(new StringContent("base64"), "method"); //BASE64图片 content.Add(new StringContent("en"), "lang"); //英文打码 content.Add(new StringContent("10"), "max_len"); //最大长度 content.Add(new StringContent("Choose a correct word or calculation"), "textinstructions"); //备注给打码人员看 content.Add(new StringContent("4497"), "soft_id"); //开发者ID 更多参数见 https://2captcha.com/2captcha-api var response = await client.PostAsync(url, content); var stringResponse = await response.Content.ReadAsStringAsync(); stringResponse = stringResponse.ToString(); if (stringResponse.Contains("OK|")) { var resid = stringResponse.Replace("OK|", "").Trim(); url = "https://2captcha.com/res.php?key=" + secretKey + "&action=get&id=" + resid; //获取结果 for (int k = 0; k < 10; k++) { string jsonStr = Main.GetHtml(url);//url if (jsonStr.Contains("ERROR_")) { //验证码识别失败 res = "ERROR"; break; }else if (jsonStr.Contains("OK|")) { //正确返回 res = jsonStr.Replace("OK|", "").Trim(); break; } else if (jsonStr.Contains("CAPCHA_NOT_READY")) { //正在识别中...... Delay(6000); } } if(res == "") { res = "ERROR"; } } else { res = "ERROR"; } } Console.WriteLine(res); return res; }
2captcha打码注册平台注册 =》 查看
文章评论