插件源码


*/
let TUJIAN = (function () {
function TUJIAN(softid) {
this._uplodHost = "http://api.ttshitu.com/predict"
this._errerHost = "http://api.ttshitu.com/reporterror.json"
this._softid = softid || "409116c232d0412584f40366c396fe8f"
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 = image.toBase64Format(img, "png", 50)
try {
ret = http.httpPost(this._uplodHost, json, null, 60 * 1000, null)
ret = JSON.parse(ret)
bool = ret.code == 0 && ret.success == true
} catch (e) {
this.Debug("请求出错:", e)
return false
}
image.recycle(img)//回收图片

if (bool) {
this._codeId = ret.data.id
return {
"code": 0,
"result": ret.data.result
}
}
return {"code": ret.code, "result": ret.message}
}

//上报错误
TUJIAN.prototype.ReportAnError = function () {
if (!this._codeId) return this.Debug("请在识别图片后且结果不准确时调用!")
try {
let ret = http.httpPost(this._errerHost, {
id: this._codeId
})
if (ret) {
ret = JSON.parse(ret)
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
})()

使用说明

/**
* @author Mr_老冷 QQ:1920712147
* @description EasyClick教学咨询 688元VIP提高班
*/
//laoleng.js插件到QQ群647082990群文件获取laoleng超级拓展插件
laoleng.EC.init()
laoleng.EC.initImage()


let TJ = new TUJIAN()//创建图鉴对象,传入作者推荐码,用于分成。
// console.log(TJ)

TJ.debug = false//关闭调试输出,默认为开启
TJ.SetAccount("laoleng", "xxxxxx")//初始化图鉴账号密码

//截图方法,二选一
//截图方法,全屏截图
let img = image.captureFullScreen()

//读取图片,或者截取
let img = image.readImage("/sdcard/1.png")

//识别图片,传入打码类型和打码图片

//一、图片文字类型(默认 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("1", img)
if (ret && ret.code === 0) {
logd("识别成功,识别结果为" + ret.result)
}else{
logd("识别失败,原因为" + ret.result)
}

//成功返回{code:0,result:"识别结果"}
//失败返回{code:-1,result:"错误提示"} 或 false


//调用上报错误
// let res = TJ.ReportAnError()
// logd(res)
//无论成功与否,返回一个字符串提示