一键玩 代码

一键玩是一款主要用于手机游戏自动化脚本开发的平台,使用的脚本语言有其自身的语法特点。

一键玩 代码

 
-- 定义最大查询次数
local MAX_QUERY_TIMES = 60
-- 定义查询间隔时间(单位:毫秒)
local QUERY_INTERVAL = 1000

-- 上传图片并携带参数,返回图片索引相关信息
function uploadImageWithParams(imagePath, uploadUrl, parameters)
    local httpClient = require("http.client")
    local boundary = "----WebKitFormBoundary7MA4YWxkTrZu0gW"
    local requestBody = ""

    -- 构建参数部分的请求体内容
    for key, value in pairs(parameters) do
        requestBody = requestBody.. "--".. boundary.. "\r\n"
        requestBody = requestBody.. "Content-Disposition: form-data; name=\"".. key.. "\"\r\n\r\n"
        requestBody = requestBody.. value.. "\r\n"
    end

    -- 添加图片文件部分到请求体
    requestBody = requestBody.. "--".. boundary.. "\r\n"
    requestBody = requestBody.. "Content-Disposition: form-data; name=\"pic\"; filename=\"".. string.match(imagePath, "[^/]+$").. "\"\r\n"
    requestBody = requestBody.. "Content-Type: image/jpeg\r\n\r\n"

    local request = httpClient.request("POST", uploadUrl)
    request:setHeader("Content-Type", "multipart/form-data; boundary=".. boundary)
    request:setBody(requestBody)

    local response, err = request:send()
    if err then
        return "#".. err
    end
    return response
end

-- 根据图片索引查询图片在服务器上的处理信息
function queryImageInfo(imageIndex)
    local queryUrl = "http://dt1.hyocr.com:8080/Query.php?sid=".. imageIndex
    local queryTimes = 0
    while queryTimes < MAX_QUERY_TIMES do
        local httpClient = require("http.client")
        local request = httpClient.request("GET", queryUrl)
        local response, err = request:send()
        if err then
            print("查询图片信息时请求出错,错误信息: ".. err)
            break
        end
        local result = string.trim(response)
        if result == "" then
            print("服务器仍在处理图片,请稍候...")
        elseif string.sub(result, 1, 1) == "#" then
            print("图片处理出错,错误信息: ".. result)
            break
        else
            print("图片处理成功,信息: ".. result)
            break
        end
        queryTimes = queryTimes + 1
        mSleep(QUERY_INTERVAL)
    end
    if queryTimes == MAX_QUERY_TIMES then
        print("已达到最大查询次数,仍未获取到有效图片处理信息")
    end
end

-- 主函数,模拟调用示例,实际使用时替换下面参数为真实值
function main()
    local imagePath = "/sdcard/pictures/test.jpg"  -- 替换为实际图片路径
    local uploadUrl = "http://dt1.hyocr.com:8080/uploadpic.php"  -- 替换为真实服务器上传地址
    local parameters = {
        dati_type = "8091",                         ---答题类型
        acc_str = "xxxxxxxxxxxx",                   ---用户自己的答题串 以便计费 登录账号查询自己的答题密码串
        extra_str = "题目是",                        ---描述内容,以便答题人员能够理解答题
        zz = "",                                    ---作者帐号(给予返利)
        pri = "9",                                  ---优先级
        timeout = "70",                             ---答题时间不要太小,否则容易超时而不能返回结果
    }

    local imageIndex = uploadImageWithParams(imagePath, uploadUrl, parameters)
    if imageIndex and string.sub(imageIndex, 1, 1) ~= "#" then
        queryImageInfo(imageIndex)
    else
        print("图片上传出错,错误信息: ".. imageIndex)
    end
end

main()

说明:xxxxxxxxxxxxxxx替换成密码串 提交成功后会返回一组字符串 直接用这个字符串每1秒循环get提交到http://dt1.hyocr.com:8080/Query.php 即可 一直取到答案为止 取到答案判断 一下答案的第一个字符串 如果为“#” 即为报错了 如果不是#开头 即为返回的答案