一、打码平台很多,这里选择两个:联众和斐斐
联众开发文档:
https://www.jsdati.com/docs/guide
斐斐开发文档:
http://docs.fateadm.com/web/#/1?page_id=1
二、联众打码
从文档可以看到联众的接口是 https://v2-api.jsdama.com/upload
大多数验证码类型是四位数字字母,从这里可以看到我们需要的类型是1001.查看类型地址:https://www.jsdati.com/docs/price
获取需要的参数并发送post请求即可:
public class LianzhongRun
{
private const string ApiCode = "https://v2-api.jsdama.com/upload";
public static string LianZhongCode(string imgUrl)
{
var img64 = NetHandle.GetImageAsBase64Url(imgUrl).Result;
LianZhongRequestModel param = new LianZhongRequestModel();
param.captchaData = img64;
param.softwareId = ;
param.softwareSecret = "";
param.username = "";
param.password = "";
// captchaType 类型,查看:https://www.jsdati.com/docs/price
param.captchaType = ;
using (var _client = new HttpClient())
{
_client.DefaultRequestHeaders.Add("host", "v2-api.jsdama.com");
_client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36");
StringContent content = new StringContent(JsonConvert.SerializeObject(param), Encoding.UTF8,
"application/json");
HttpResponseMessage response = _client.PostAsync(ApiCode, content).Result;
string result = response.Content.ReadAsStringAsync().Result;
Console.WriteLine("返回结果--" + result);
if (!result.Contains("recognition")) return string.Empty;
dynamic resultObj = JsonConvert.DeserializeObject(result);
var data = resultObj["data"];
string recognition = data["recognition"];
Console.WriteLine("验证码:" + recognition);
return recognition.Trim();
}
}
}
三、斐斐打码
同样的方式,斐斐接口的请求代码如下
public class FeifeiRun
{
private static string ApiCode = "http://pred.fateadm.com/api/capreg";
private static string PdId = "";
private static string PdKey = "";
private static string AppKey = "";
private static string AppId = ""; /// <summary>
/// 斐斐打码
/// </summary>
/// <param name="imgUrl"></param>
/// <returns></returns>
public static string FeifeiCode(string imgUrl)
{
var img64 = NetHandle.GetImageAsBase64Url(imgUrl).Result;
var timestamp = TimeHelper.GetCurrentTimeUnix();
string cur_tm = TimeHelper.GetCurrentTimeUnix();
string sign = SecurityHelper.CalcSign(PdId, PdKey, cur_tm);
string asign = SecurityHelper.CalcSign(AppId, AppKey, cur_tm);
var predict_type = "";
var imgBytes = NetHandle.ReadBytes(imgUrl);
var values = new Dictionary<string, string>
{
{ "user_id",PdId},
{ "timestamp",timestamp},
{ "sign",sign},
{ "app_id",AppId},
{ "asign",asign},
{ "predict_type",predict_type},
{ "img_data",img64}
}; using (var _client = new HttpClient())
{
var content = new FormUrlEncodedContent(values);
HttpResponseMessage response = _client.PostAsync(ApiCode, content).Result;
string result = response.Content.ReadAsStringAsync().Result;
var data = JsonConvert.DeserializeObject<HttpRspData>(result);
if (!string.IsNullOrEmpty(data.RspData))
{
// 附带附加信息
HttpExtraInfo einfo = JsonConvert.DeserializeObject<HttpExtraInfo>(data.RspData);
data.einfo = einfo;
}
var resultCode = data.einfo.result.Trim();
Console.WriteLine("code:" + resultCode);
return resultCode;
}
}
}
五、完整代码
https://github.com/DavideYang125/VerificationCodeObtainDemo
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)