本帖最后由 lon91ong 于 2019-12-28 13:24 编辑
首先感谢鱼大的回应。
看到你给出的代码,我第一印象就是“这个方法我已经试过了”,参见大前天的帖子8#
但我还是不自信,跟着你的代码重新做了一遍,问题照旧!
怀疑自己对C#的返回值格式有错误的理解,直接在dll项目上调试也不会,新建了console项目测试过了返回值,也没有发现问题
So,耐心基本耗光了,自身也没有太强的抢票需求,放弃了
放出全部代码,会有接盘侠吗
[C#] 纯文本查看 复制代码 using System;
using System.Drawing;
using RestSharp;
using Newtonsoft.Json;
using System.Net;
namespace TOBA.AutoVc {
internal class VerifyCodeRecognizeResult: IVerifyCodeRecognizeResult {
public Image Image { get; }
public string Code { get; }
public string Id { get; }
public VerifyCodeRecognizeType CodeType { get; }
public Point[] Points { get; }
public VerifyCodeRecognizeResult(string id, VerifyCodeRecognizeType type, string code, Point[] points, Image img) {
Image = img;
Code = code;
Id = id;
CodeType = type;
points = Points;
}
public static IVerifyCodeRecognizeResult CreatePointsResultFromText(string id, string text, Image img) {
var arr = text.Split(',');
var pts = new Point[arr.Length / 2];
for (int i = 0; i < pts.Length; i++) {
pts[i] = new Point(int.Parse(arr[i * 2]), int.Parse(arr[i * 2 + 1]));
}
return new VerifyCodeRecognizeResult(id, VerifyCodeRecognizeType.Points, null, pts, img);
}
}
internal class LocalVcService: AbstractVerifyCodeRecognizeService {
public LocalVcService() {
base.Author = "lon91ong";
base.ErrorCodeQueryUrl = "http: /localhost:80/"; //没有发URL权限
base.Name = "本地打码";
base.WebUrl = "http: /localhost:80/"; //没有发URL权限
this.ProviderName = "本地打码";
}
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 bool Logout() {
base.IsLoggedIn = false;
base.IsEnabled = false;
return true;
}
public override bool RefreshScore() {
base.Score = 10000;
return true;
}
public override string Id {
get {
return "localVc";
}
}
public override void MarkResult(IVerifyCodeRecognizeResult result, bool correct) {}
public override IVerifyCodeRecognizeResult GetCode(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("http: /127.0.0.1:80/"); //没有发URL权限
client.AddDefaultHeader("Accept", "application/json");
client.AddDefaultHeader("Accept-Encoding", "gzip");
RestRequest req = new RestRequest("create.json", Method.POST);
req.AddHeader("cache-control", "no-cache");
req.AddParameter("soft_id", "2992", ParameterType.QueryString);
req.AddFileBytes("image", imgBytes, "1.png");
IRestResponse resp = client.Execute(req);
dynamic json = JsonConvert.DeserializeObject(resp.Content);
/*var sArray = json.Result.Split(',');
var pts = new Point[sArray.Length >> 1 ];
for(int i=0;i<pts.Length;i++)
{
pts[i] = new Point(int.Parse(sArray[2*i]), int.Parse(sArray[2*i + 1]));
}
return new VerifyCodeRecognizeResult("00000201912300992999", VerifyCodeRecognizeType.Text, json.Result, null, image);*/
return VerifyCodeRecognizeResult.CreatePointsResultFromText(null, json.Result, image);
}
}
}
|