EasyClick 代码参考示例
function main(){
var url = "http://api.ttshitu.com/predict";
var username=xxx;
var password=xxx;
var typeid=3;//根据开发文档进行修改
var autoimg = image.captureScreen(3,0,0,300,400);//截图
var imageBase64=image.toBase64(autoimg);//图片转base64
//图片要回收
image.recycle(autoimg);
//下面是基本参数,需要其他参数的根据文档模仿添加
var pa = {"username":username,"password":password,"typeid":typeid,"image":imageBase64};
var x = http.postJSON(url, pa, 100 * 1000, null);
toast(" x返回数据-> " + x)
var jsonResult = JSON.parse(JSON.stringify(x));
if(jsonResult.success){
toast(" result-> " + jsonResult.data.result);//识别结果
toast(" id-> " + jsonResult.data.id);//用于报错
}else{
toast(" message-> " + jsonResult.message);//错误原因
}
}
main();
function 报错(){
var url = "http://api.ttshitu.com/reporterror.json";
var pa = {"id":xxxx};//填写上面识别成功返回的id
var x = http.postJSON(url, pa, 100 * 1000, null);
toast(" result-> " + x);
toast(" id-> " + x);
}
报错();
TC 代码示例
功能 接口上传()
变量 图片 = base64encodefile(进程路径&"24.jpg")
变量 header = 数组()
header["username"] = "账号"
header["password"] = "密码"
header["typeid"] = 识别类型看文档
header["image"] = 图片
header["angle"] = ""
header["remark"] = ""
header["step"] = ""
调试输出(header)
如果( 是否json(数组转jsonString(header)))
调试输出("没毛病")
结束
变量 body = http提交请求("post","http://api.ttshitu.com/predict",数组转jsonString(header),"utf-8")
调试输出(body)
结束
功能 数组转jsonString(数组名)
变量 b = 数组转字符串(数组名)
变量 c= 字符串修剪(b,"array")
c=字符串替换(c,"=",":")
c=字符串替换(c,"(","{")
c=字符串替换(c,")","}")
返回 c
结束
AutoJs 代码示例
var TUJIAN = (function () {
function TUJIAN(softid) {
this._uplodHost = "http://api.ttshitu.com/predict";
this._errerHost = "http://api.ttshitu.com/reporterror.json";
this._softid = softid || "";
this._userName = null;
this._password = null;
this._codeId = null;
this.debug = true;
}
//设置账户
TUJIAN.prototype.SetAccount = function (uesr, pass) {
this._userName = uesr;
this._password = pass;
}
//识别
TUJIAN.prototype.requestData = function (type, img) {
if (!this._userName || !this._password) {
this.Debug("请初始化账号");
return false;
}
http.__okhttp__.setTimeout(60000);
this._codeId = null;
let ret = null;
let bool = false;
let json = {};
json.username = this._userName;
json.password = this._password;
json.typeid = type;
json.softid = this._softid;
json.image = images.toBase64(img, format = "png",100);
try {
ret = http.post(this._uplodHost, json);
if(ret.statusCode == 200){
ret = ret.body.json();
bool = ret.code == 0 && ret.success == true
if (bool) {
this._codeId = ret.data.id;
return {
"code": 0,
"result": ret.data.result
}
}else{
return {
"code": ret.code,
"result": ret.message
}
}
}
} catch (e) {
this.Debug("请求出错:", e);
return false;
}
img.recycle();//回收图片
}
//上报错误
TUJIAN.prototype.ReportAnError = function () {
if (!this._codeId) return this.Debug("请在识别图片后且结果不准确时调用!")
try {
let ret = http.post(this._errerHost, {
id: this._codeId
});
if (ret.statusCode == 200) {
ret = ret.body.json();
return ret.code == 0 ? ret.data.result : ret.message;
}
} catch (e) {
return "请求出错:" + e;
}
}
//调试输出
TUJIAN.prototype.Debug = function (str) {
if (this.Debug) console.log(str)
}
return TUJIAN;
})()
var TJ = new TUJIAN("softid");//创建图鉴对象,传入作者推荐码,用于分成。
console.log(TJ)
TJ.Debug = false;//关闭调试输出,默认为开启
TJ.SetAccount("账号", "密码");//初始化图鉴账号密码
//读取图片,或者截取
let img = images.read("/sdcard/img.jpg");
//识别图片,传入打码类型和打码图片
//一、图片文字类型(默认 3 数英混合):
//1 : 纯数字
//1001:纯数字2
//2 : 纯英文
//1002:纯英文2
//3 : 数英混合
//1003:数英混合2
//4 : 闪动GIF
//7 : 无感学习(独家)
//11 : 计算题
//1005: 快速计算题
//16 : 汉字
//32 : 通用文字识别(证件、单据)
//66: 问答题
//49 :recaptcha图片识别
//二、图片旋转角度类型:
//29 : 旋转类型
//三、图片坐标点选类型:
//19 : 1个坐标
//20 : 3个坐标
//21 : 3 ~ 5个坐标
//22 : 5 ~ 8个坐标
//27 : 1 ~ 4个坐标
//48 : 轨迹类型
//四、缺口识别
//18:缺口识别
//五、拼图识别
//53:拼图识别
let ret = TJ.requestData("识别类型", img);
//成功返回{code:0,result:"识别结果"}
//失败返回{code:-1,result:"错误提示"} 或 false
//!!!!!!!注意:返回 人工不足等 错误情况 请加逻辑处理防止脚本卡死 继续重新 识别
//调用上报错误
let res = TJ.ReportAnError();
//无论成功与否,返回一个字符串提示