通用识别(JSON / Base64)
uses
System.SysUtils, System.Classes, System.JSON, System.NetEncoding,
REST.Client, REST.Types;
procedure PredictBase64;
var
Client: TRESTClient;
Request: TRESTRequest;
Response: TRESTResponse;
JsonObj: TJSONObject;
ImgStream: TFileStream;
ImgBytes: TBytes;
ImgBase64: string;
begin
Client := TRESTClient.Create('http://api.kuaishibie.cn/predict');
Request := TRESTRequest.Create(nil);
Response := TRESTResponse.Create(nil);
JsonObj := TJSONObject.Create;
try
Request.Client := Client;
Request.Response := Response;
Request.Method := rmPOST;
Request.Timeout := 60000; // 建议超时 60 秒
ImgStream := TFileStream.Create('C:\temp\captcha.jpg', fmOpenRead);
try
SetLength(ImgBytes, ImgStream.Size);
ImgStream.ReadBuffer(ImgBytes, ImgStream.Size);
ImgBase64 := TNetEncoding.Base64.EncodeBytesToString(ImgBytes);
finally
ImgStream.Free;
end;
JsonObj.AddPair('username', '你的账号');
JsonObj.AddPair('password', '你的密码');
JsonObj.AddPair('typeid', '3'); // 数英混合
JsonObj.AddPair('image', ImgBase64);
Request.AddBody(JsonObj.ToJSON, ctAPPLICATION_JSON);
Request.Execute;
Writeln(Response.Content);
// success=true 时 data.result 为识别结果,data.id 可用于报错
finally
JsonObj.Free;
Response.Free;
Request.Free;
Client.Free;
end;
end;
报错脚本
// POST http://api.kuaishibie.cn/reporterror.json
// JSON: {"id":"识别成功返回的id"}
余额查询(GET)
// GET http://api.kuaishibie.cn/queryAccountInfo.json?username=你的账号&password=你的密码
// 返回 data.balance / data.consumed / data.successNum / data.failNum