本帖最后由 lon91ong 于 2019-12-25 10:59 编辑
这个是报错用的? 哪个是用来post验证码图片的?我的C知识都是十多年前学的, 现在主要用python, 所以代码基本都是拼凑的
我的思路是在本地模拟若快的端口, 返回数据格式可以自己定义, 或者坐标或者小图序号都行
下面是我拼凑的代码:
[C#] 纯文本查看 复制代码 using System;
using System.Collections.Generic;
using System.Drawing;
using TOBA.AutoVc;
using RestSharp;
using Newtonsoft.Json;
internal class LocalVcService : AbstractVerifyCodeRecognizeService
{
public LocalVcService()
{
base.Author = "lon91ong";
base.ErrorCodeQueryUrl = "localhost/"; //论坛权限不够发URL
base.Name = "本地打码";
base.WebUrl = "localhost/"; //论坛权限不够发URL
this.ProviderName = "本地打码";
}
public static string Post(string url, IDictionary<object, object> param, Image image)
{
ImageConverter _imageConverter = new ImageConverter();
byte[] imgBytes = (byte[])_imageConverter.ConvertTo(image, typeof(byte[]));
// Convert byte[] to Base64 String
// string base64img = Convert.ToBase64String(imgBytes);
RestClient client = new RestClient(url);
client.AddDefaultHeader("Accept", "application/json");
client.AddDefaultHeader("Accept-Encoding", "gzip");
RestRequest req = new RestRequest(Method.POST);
req.AddHeader("cache-control", "no-cache");
//使用了RestSharp库
req.AddFileBytes("image", imgBytes, "1.png");
IRestResponse resp = client.Execute(req);
//var result = client.Execute<IVerifyCodeRecognizeResult>(req);
dynamic json = JsonConvert.DeserializeObject(resp.Content);
return json.Result;
}
public override void Load()
{
base.Load();
base.Verified = true;
base.ErrorCode = 0;
}
public override bool DoLogin()
{
base.IsLoggedIn = true;
base.IsEnabled = true;
base.Score = 10000;
return true;
}
public override void MarkResult(IVerifyCodeRecognizeResult result, bool correct)
{
}
public override IVerifyCodeRecognizeResult GetCode(Image image)
{
var param = new Dictionary<object, object>
{
{"username","test"},
{"password","test"},
{"typeid",6113},
{"timeout","90"},
{"softid",2992},
{"softkey","9999999"}
};
//论坛权限不够发URL,下面的返回结果可以是序号格式:[1,3,6],也可以直接返回坐标:38.5,79.6|59.7,124.3
var res = Post("ht:/ 127.0.0.1:80/create.json", param, image);
return null; //<<<<<<<现在的问题主要在此,不知如何将识别结果返回
}
}
|