两行代码给脚本增加强大的云端能力
xx 脚本开发 数据库使用
新增功能 2017.12.04
点击此链接 => 在线体验OCR识别功能
功能与优点
- 使用超级简单
- 不用自己搭服务器
- 可以统计用户的设备情况:用户ID,脚本引擎版本号,IMEI,分辨率,机型,是否越狱等
- 可以自己任意
添加想统计的字段
- 可以
更新指定的某一条数据的内容,比如存储用户打了多少次副本之类,或者取色的数据。
- 可以
获取指定的某条记录
- 强大的后台管理
Teemo 框架使用说明
- 下载 Teemo.lua
- 放在自己的工程目录中。确保能引用到 bb 库。
使用
require('teemo') -- 载入 teemo 框架。local tm = Teemo:new("xxxxxx") --实例化一次即可
函数:tm:add(recordTable)
函数功能:添加记录
函数实战:
//统计下用户的分辨率,引擎版本,顺便加几个自定义的字段--//获取分辨率local with,height = getScreenSize() --//创建对象xxx 是实际的 token。local tm = Teemo:new("xxxxxx") --实例化一次即可--//添加一条记录res, code = tm:add({pangciOwner = "凤姐", pangciStyle = "蕾丝",osType = getOSType(),resolution = with..","..height})
参数说明
| 参数 |
类型 |
说明 |
| recordTable |
table |
你要添加的数据字段 |
| 返回值 |
类型 |
说明 |
| res |
Table |
返回刚插入的那条记录 |
| err |
整数型 |
返回错误的类型:0 - 正常获取,1 - 网络错误,2 - 未知错误 |
//res 的返回值 格式{ ["status"] = 0,//数据是否正常,0表示正常 ["data"] = {// 记录中的字段 ["id"] = "5901b75444d90400690bff51", ["deviceIMEI"] = "864895023084989", ["dpi"] = 320, ["resolution"] = "720,1280", ["pangCiOwner"] = "凤姐", ["pangciStyle"] = "蕾丝", ["osType"] = "android", ["engine"] = "1.7.1", }, ["code"] = "ok",//异常的 code,暂时忽略}
函数: tm:update( id, data)
函数功能:根据 ID更新某条记录
函数实战:
// 把胖次的所有者从 凤姐 变成 审核君。其他字段不变res, code = tm:update("5901b28fda2f60005de7c4d1",{pangciOwner = "审核君"})
参数说明
| 参数 |
类型 |
说明 |
| id |
string |
要更新的数据的 ID |
| recordTable |
table |
你要更新的数据字段 |
| 返回值 |
类型 |
说明 |
| res |
Table |
返回刚插入的那条记录 |
| err |
整数型 |
返回错误的类型:0 - 正常获取,1 - 网络错误,2 - 未知错误 |
//更新成功后的结果{ "status": 0, "code": "ok", "data": { "id": "5901b75444d90400690bff51", "pangciOwner": "审核君" }}//失败的情况的返回值 { ["status"] = -1, ["msg"] = "没有 id", ["code"] = "unkown",}
函数: tm:uploadImage(fileName)
函数功能: 上传图片
函数实战:
流程:
1. 截图
2. 上传到服务器,服务器返回`图片地址`
3. 把返回的`图片地址`添加到数据库中
-- 截图snapshot('[public]ocr.jpg', 0,0, 400, 400, 0.7);-- 上传图片local imageUrl = tm.uploadImage('ocr.jpg')if imageUrl ~= '' then toast('上传成功') -- 自己定义「snapshot」这个字段,把图片存到数据库记录中 local res, errCode = tm:add({pangciOwner = "上传记录", pangciStyle = "自己随便写点数据",osType = getOSType(),resolution = width..","..height, snapshot = imageUrl}) print(res)end
参数说明
| 参数 |
类型 |
说明 |
| fileName |
string |
要上传的文件地址,遵循叉叉的截图目录 |
| 返回值 |
类型 |
说明 |
| res |
string |
返回上传后的图片地址 |
//成功后的结果实际的图片地址 "http://appimgs.hambases.com/FtUmNu3FM3zRd0OxFyWzHj1-L3w7"--失败的情况的返回 空字符串 ""
函数: tm:ocrText(fileName)
函数功能: 识别图片文字内容
- 只支持jpg 跟 png
- 无须取色,截图后直接识别
函数实战:
-- 截图snapshot('[public]ocr.jpg', 0,0, 400, 400, 0.7);-- 上传图片local res,errCode = tm:ocrText('ocr.jpg')print(res)
参数说明
| 参数 |
类型 |
说明 |
| fileName |
string |
要识别的文件地址,遵循叉叉的截图目录 |
| 返回值 |
类型 |
说明 |
| res |
Table |
识别后的文字内容跟对应的坐标 |
itemstring 识别后的文字itemcoord 文字在图像中的像素坐标,包括左上角坐标x,y,以及宽、高width, height
//成功后的结果{ "status": 0, "code": "ok", "data": [ { "itemstring": "点击邀请好友", "itemcoord": { "x": 1113, "y": 9, "width": 141, "height": 34 } }, { "itemstring": "绝地双雄", "itemcoord": { "x": 1228, "y": 440, "width": 74, "height": 32 } }, { "itemstring": "开始匹配", "itemcoord": { "x": 1107, "y": 669, "width": 122, "height": 39 } }, ]}--失败的情况的返回 空字符串 ""
识别结果

函数: tm:get( id)
函数功能:根据 ID更新某条记录
函数实战:
// 获取某ID 的信息res, code = tm:get("5901b28fda2f60005de7c4d1")
参数说明
| 参数 |
类型 |
说明 |
| id |
string |
要更新的数据的 ID |
| 返回值 |
类型 |
说明 |
| res |
Table |
返回刚插入的那条记录 |
| err |
整数型 |
返回错误的类型:0 - 正常获取,1 - 网络错误,2 - 未知错误 |
//成功后的结果{ "status": 0, "code": "ok", "data": [ { "id": "5901b75444d90400690bff51", "pangciOwner": "审核君", "resolution": "720,1280", "pangciStyle": "蕾丝" } ]}//失败的情况的返回值 { ["status"] = -1, ["msg"] = "没有 id", ["code"] = "unkown",}
方便的后台管理


后台登录地址
数据管理登录
体验帐号 looping81 密码 123zxc