Appearance
懒人对接
简介
懒人精灵网络验证SDK是专为懒人精灵平台开发的网络验证解决方案,支持卡密登录、账号密码登录、试用登录等多种验证方式,同时提供远程配置、远程变量、远程函数调用等高级功能。
快速开始
1. 下载SDK
首先下载SDK文件:
网盘中有懒人精灵的三个相关的文件
- verifyhub.luaej (插件版本 1.8.0的版本+ 都能用,且插件轻量更小
- 懒人精灵兼容所有版本示例-UTF8.zip (C语言动态库,支持所有的懒人版本 包体积会更大,里面有一个kauth.rc的资源 存放了C的库 不可删除
- 懒人精灵兼容所有版本示例-GBK.zip (C语言动态库,主要是老版本比如1.4.8,还是用的GBK编码,里面有一个kauth.rc的资源 存放了C的库 不可删除
- 他们只是SDK方式实现的加密解密有差异,其他的都一样
- 注意,注意 :C语言动态链接库用的是RSA PKCS#8的格式,插件版本用的是PKCS#1格式 接入的时候不要复制错密钥了,如果接入的时候提示RSA错误 大概率是密钥复制错了
快速接入卡密
lua
local verifyhub = require('verifyhub')
-- 配置参数
local paramApiDomain = "https://api.kauth.cn"
local paramProgramId = "222222222" --在后台系统 程序管理-> 程序列表 ->程序ID
local paramProgramSecret = "xxxxxxx" --在后台系统 程序管理-> 程序列表 ->程序密钥
local paramMerchantPublicKey ="xxxxxxx" --在后台系统 系统设置 -> 密钥配置 -> RSA公钥 -> (插件模式用PKCS#1格式 C语言动态库用PKCS#8格式)
local paramKauthSignType = "RSA"
local platformType = "lanren_mobile"
-- 初始化配置
verifyhub.initConfig(paramApiDomain, paramProgramId, paramMerchantPublicKey, paramProgramSecret, paramKauthSignType)
verifyhub.setDeviceId(verifyhub.getDeviceId())
local loginResult = verifyhub.kaLogin("8dj9t25k",platformType,"","")
print(loginResult)2. 使用WEB UI接入卡密
效果图

lua
local verifyhub = require('verifyhub')
-- 配置参数
local paramApiDomain = "https://api.kauth.cn"
local paramProgramId = "xxxx" --在后台系统的 程序管理 -> 程序列表 -> 程序id
local paramProgramSecret = "xxxx" --在后台系统的 程序管理 -> 程序列表 -> 程序密钥
local paramMerchantPublicKey ="xxxxx" --在后台系统的 系统设置 -> 密钥设置 -> RSA公钥 -> (插件模式用PKCS#1格式 C语言动态库用PKCS#8格式)
local paramKauthSignType = "RSA" --默认用RSA即可
local platformType = "lanren_mobile" -- 给平台级开发者专用的,一般用这个默认值即可
local autoLoginSuccess = false -- 是否自动登录成功
-- 初始化配置
verifyhub.initConfig(paramApiDomain , paramProgramId , paramMerchantPublicKey , paramProgramSecret , paramKauthSignType)
local deviceid = verifyhub.getDeviceId()
print("[kauth] deviceid:" .. deviceid)
verifyhub.setDeviceId(deviceid)
--一行代码热更新,打包的lrj文件要上传到后台系统
verifyhub.autoUpdateLrj("lanren_1", "1.0.0")
-- ==================== 登录成功回调 ====================
-- H5登录成功后调用此函数
function onLoginSuccess(resultJson)
print("[Lua] 登录成功回调:" , resultJson)
local msg = "1.0.0登录成功-" .. resultJson.msg
toast(msg , 0 , 0 , 12)
-- 这里可以做一些登录成功后的操作
ui.dismiss("layout1")
autoLoginSuccess = true --改为true 这样最下面的while循环就会停止
end
-- 卡密已经登录过的 自动登录,如果不需要自动登录功能,请删除该代码
local kaPwd = verifyhub.readLocalFile("kaPwd" , "")
autoLoginSuccess = false
if kaPwd and kaPwd ~= "" then
print("[Lua] 检测到保存的卡密,开始自动登录尝试")
-- 最多尝试登录10次
local MAX_AUTO_LOGIN_ATTEMPTS = 10
for i = 1 , MAX_AUTO_LOGIN_ATTEMPTS do
print("[Lua] 自动登录第 " .. i .. " 次尝试")
toast("自动登录中 第" .. i .. "次" , 0 , 0 , 12)
local result = verifyhub.kaLogin(kaPwd , platformType , "" , "")
print("自动登录结果" , result)
if result.code == 2000 or result.code == 1000 then
-- 错误码2000 |1000 不用重试了,比如卡密被禁用、被删除 等等
toast("自动登录失败:" .. result.msg , 0 , 0 , 12)
verifyhub.deleteLocalFile("kaPwd")
break
end
if result.success then
print("[Lua] 自动登录成功!")
autoLoginSuccess = true
onLoginSuccess(result)
break
else
print("[Lua] 自动登录失败,常见错误信息: " .. tostring(result.msg))
end
sleep(500)
end
if not autoLoginSuccess then
print("[Lua] 10次自动登录都失败,求助UI登录")
end
end
-- ==================== 单码体系操作 ====================
-- 卡密登录
function onCardLogin(cardKey)
print("[Lua] 卡密登录:" , cardKey)
local result = verifyhub.kaLogin(cardKey , platformType , "" , "")
print("[Lua] 卡密登录结果:" , result)
-- 回调H5结果
local resultJson = jsonLib.encode(result)
print("[Lua] 回调JSON:" , resultJson)
ui.callJs("webId" , "javascript:onLuaCallBack('cardLogin', " .. resultJson .. ")")
-- 如果登录成功
if result.success then
verifyhub.writeToLocalFile("kaPwd" , cardKey)
onLoginSuccess(result)
end
end
-- 以卡充卡
function onCardRecharge(currentCardKey , rechargeCardKey)
print("[Lua] 以卡充卡:" , currentCardKey , rechargeCardKey)
local result = verifyhub.rechargeKa(currentCardKey , rechargeCardKey)
print("[Lua] 以卡充卡结果:" , result)
local resultJson = jsonLib.encode(result)
ui.callJs("webId" , "javascript:onLuaCallBack('cardRecharge', " .. resultJson .. ")")
end
-- 卡密解绑
function onCardUnbind(cardKey)
print("[Lua] 卡密解绑:" , cardKey)
local result = verifyhub.unbindDeviceKaPwd(cardKey)
print("[Lua] 卡密解绑结果:" , result)
local resultJson = jsonLib.encode(result)
ui.callJs("webId" , "javascript:onLuaCallBack('cardUnbind', " .. resultJson .. ")")
end
-- ==================== 账密体系操作 ====================
-- 账密登录
function onAccountLogin(username , password)
print("[Lua] 账密登录:" , username)
local result = verifyhub.pwdLogin(username , password , "" , "")
print("[Lua] 账密登录结果:" , result)
local resultJson = jsonLib.encode(result)
ui.callJs("webId" , "javascript:onLuaCallBack('accountLogin', " .. resultJson .. ")")
if result.success then
onLoginSuccess(result)
end
end
-- 账号注册
function onAccountRegister(username , password , nickName , cardKey)
print("[Lua] 账号注册:" , username)
local result = verifyhub.register(username , password , nickName , cardKey , "" , "")
print("[Lua] 账号注册结果:" , result)
local resultJson = jsonLib.encode(result)
ui.callJs("webId" , "javascript:onLuaCallBack('accountRegister', " .. resultJson .. ")")
end
-- 账号改密
function onAccountChangePassword(username , oldPassword , newPassword)
print("[Lua] 账号改密:" , username)
local result = verifyhub.changePassword(username , newPassword , oldPassword , newPassword , "" , "")
print("[Lua] 账号改密结果:" , result)
local resultJson = jsonLib.encode(result)
ui.callJs("webId" , "javascript:onLuaCallBack('accountChangePassword', " .. resultJson .. ")")
end
-- 账号充值
function onAccountRecharge(username , cardKey)
print("[Lua] 账号充值:" , username)
local result = verifyhub.recharge(username , cardKey , "" , "")
print("[Lua] 账号充值结果:" , result)
local resultJson = jsonLib.encode(result)
ui.callJs("webId" , "javascript:onLuaCallBack('accountRecharge', " .. resultJson .. ")")
end
-- 账号解绑
function onAccountUnbind(username , password)
print("[Lua] 账号解绑:" , username)
local result = verifyhub.unbindDevice(username , password , "" , "")
print("[Lua] 账号解绑结果:" , result)
local resultJson = jsonLib.encode(result)
ui.callJs("webId" , "javascript:onLuaCallBack('accountUnbind', " .. resultJson .. ")")
end
-- 试用登录
function onTrial()
print("[Lua] 试用登录")
local trialLoginResult = verifyhub.trialLogin()
print("[Lua] 试用登录结果:" , trialLoginResult)
local resultJson = jsonLib.encode(trialLoginResult)
ui.callJs("webId" , "javascript:onLuaCallBack('trial', " .. resultJson .. ")")
-- 如果试用登录成功
if trialLoginResult.success then
onLoginSuccess(trialLoginResult)
end
end
function onRequestPasteboard(fieldIndex)
-- 读取粘贴板内容
local content = readPasteboard()
if not content or content == "" then
-- 返回空内容给H5
local resultJson = json.encode({
fieldIndex = fieldIndex ,
content = ""
})
ui.callJs("webId" , "javascript:onLuaCallBack('pasteboard', " .. resultJson .. ")")
return
end
-- 构建返回结果
local result = {
fieldIndex = fieldIndex ,
content = content
}
-- 转换为JSON字符串
local resultJson = jsonLib.encode(result)
-- 调用H5的回调函数,传递粘贴板内容和输入框索引
ui.callJs("webId" , "javascript:onLuaCallBack('pasteboard', " .. resultJson .. ")")
end
if autoLoginSuccess == false then
ui.newLayout("layout1")
--优先读取本地的卡密
local h5kapwd = verifyhub.readLocalFile("kaPwd" , "")
if h5kapwd == nil or h5kapwd == "" then
-- 本地没有卡密从粘贴板获取
h5kapwd = readPasteboard()
end
-- 自动填充卡密到输入框
ui.addWebView("layout1" , "webId" , "https://h5.kauth.cn/Lanren?platform=lanren&kapwd=" .. h5kapwd)
ui.show("layout1" , false , 1 , 0 , false)
while autoLoginSuccess == false do
sleep(1000)
end
end
-- ==================== 心跳失败回调 ====================
function onPongFail(reason)
print("[Lua] 心跳失败:" , reason)
-- 心跳失败回调,你可以在这里自定义处理逻辑,比如重新打开登录窗口 或者退出脚本
toast("即将退出脚本(心跳检测失败):" .. reason , 0 , 0 , 12)
sleep(3000)
exitScript()
end
-- 用户事件按钮点击事件,用来提示用户到期时间和连点退出登录
clickTime = {0 , 0 , 0}
setUserEventCallBack(function(type)
-- 记录点击时间
table.remove(clickTime , 1)
table.insert(clickTime , os.time())
-- 判断1秒内点击3次
if clickTime[3] - clickTime[1] <= 1 then
-- 退出登录(这里写你的退出逻辑)
-- logout()
toast("2秒后退出登录" , 0 , 0 , 12)
verifyhub.deleteLocalFile("kaPwd")
restartScript()
return
end
-- 原有业务逻辑
local userInfoResult = verifyhub.userInfo()
if userInfoResult.success ~= true then
toast(userInfoResult.msg , 0 , 0 , 12)
return
end
if userInfoResult.serverType == "time" then
toast("服务到期时间:"..userInfoResult.serverExpireTime.."连点3次退出登录" , 0 , 0 , 12)
end
if userInfoResult.serverType == "ci" then
toast("服务次数剩余:"..userInfoResult.serverRemainNum.."连点3次退出登录" , 0 , 0 , 12)
end
end)
-- 开启心跳,,最多允许10次失败,可自定义
verifyhub.pongServer(onPongFail , 10)
--请在下面开始编写您的脚本 不太建议这样裸奔,懒人脚本很容易被hook 不安全
-- 参考防破解方案 : https://docs.kauth.cn/guide/anticracking.html
print("要执行脚本了")
verifyhub.autoReptError(function()
-- 您可以选择在这里写您的脚本代码,如果产生错误 会自动上报堆栈信息,可在管理后台查看错误日志
--举个🌰
local obj = nil
print(obj.method()) -- 访问 nil 的方法 这时候就会报错
end , "模拟错误脚本")
-- 如果您不需要自动上报错误,可以注释掉上面那行代码,在下面开始编写您的脚本,建议在关键地方手动调用用户信息来判断登录失效
sleep(100000) --假装执行脚本
toast("脚本执行结束")热更lrj文件
自定义热更逻辑
lua
if scriptDownloadResult.success then
-- 下载文件,安装热更新
local lrPath = getSdPath() .. newestResult.versionNumber .. ".lr"
local downloadStatus = downloadFile(scriptDownloadResult, lrPath)
if downloadStatus == 0 then
installLrPkg(lrPath)
end
end如果嫌自己写逻辑麻烦,可以使用我们的一行代码热更
lua
-- 一行代码热更新,打包的lrj文件要上传到后台系统
verifyhub.autoUpdateLrj("lanren_1","1.0.0")使用远程脚本执行
lua
local scriptName = "test_script" -- 要个后台创建的脚本名称一致
local scriptInfo = verifyhub.getNewestScript(scriptName)
if scriptInfo.success then
print("脚本名称:" .. scriptInfo.scriptName)
print("版本号:" .. scriptInfo.versionNumber)
print("版本描述:" .. scriptInfo.versionDescription)
local downloadInfo = verifyhub.getScriptDownload(scriptName , scriptInfo.versionNumber)
if downloadInfo.success then
print("下载地址:" .. downloadInfo.downloadUrl)
local ret,code = httpGet(downloadInfo.downloadUrl)
--远程代码加载到lua中 如果有加密要求 请自己上传服务器的时候加密,执行前解密
local func, err = load(ret)
--执行远程代码
func()
else
print("获取下载地址失败:" .. downloadInfo.msg)
end
else
print("获取脚本信息失败:" .. scriptInfo.msg)
end新增远程脚本 (可以自行加密后上传)

远程脚本执行效果

卡密登录
lua
local loginResp = verifyhub.kaLogin("卡密", platformType, "", "")
if loginResp.success then
print("登录成功,用户ID:" .. loginResp.userId)
else
print("登录失败:" .. loginResp.msg)
end账号密码登录
lua
local loginResp = verifyhub.pwdLogin("用户名", "密码", "", "")
if loginResp.success then
print("登录成功,用户ID:" .. loginResp.userId)
else
print("登录失败:" .. loginResp.msg)
end试用登录
lua
local loginResp = verifyhub.trialLogin()
if loginResp.success then
print("试用登录成功,用户ID:" .. loginResp.userId)
else
print("试用登录失败:" .. loginResp.msg)
end获取用户信息
lua
local userInfo = verifyhub.userInfo()
if userInfo.success then
print("用户ID:" .. userInfo.userId)
print("服务到期时间:" .. userInfo.serverExpireTime)
print("服务类型:" .. userInfo.serverType)
else
print("获取用户信息失败:" .. userInfo.msg)
end修改密码
lua
local result = verifyhub.changePassword("用户名", "旧密码", "新密码", "确认新密码", "", "")
if result.success then
print("密码修改成功")
else
print("密码修改失败:" .. result.msg)
end退出登录
lua
local result = verifyhub.loginOut()
if result.success then
print("退出登录成功")
else
print("退出登录失败:" .. result.msg)
end查看到期时间
用户想看到到期时间怎么办? 用户想退出登录怎么办?
点击用户事件,会提示当前卡密的到期时间 | 当前卡密的剩余次数,连点3次后会退出登录,重启脚本重新回到登录页面

shell
-- 全局点击记录 放在执行你的脚本代码之前
clickTime = {0 , 0 , 0}
setUserEventCallBack(function(type)
-- 记录点击时间
table.remove(clickTime , 1)
table.insert(clickTime , os.time())
-- 判断1秒内点击3次
if clickTime[3] - clickTime[1] <= 1 then
-- 退出登录(这里写你的退出逻辑)
-- logout()
toast("2秒后退出登录" , 0 , 0 , 12)
verifyhub.deleteLocalFile("kaPwd")
restartScript()
return
end
-- 原有业务逻辑
local userInfoResult = verifyhub.userInfo()
if userInfoResult.success ~= true then
toast(userInfoResult.msg , 0 , 0 , 12)
return
end
if userInfoResult.serverType == "time" then
toast("服务到期时间:"..userInfoResult.serverExpireTime.."连点3次退出登录" , 0 , 0 , 12)
end
if userInfoResult.serverType == "ci" then
toast("服务次数剩余:"..userInfoResult.serverRemainNum.."连点3次退出登录" , 0 , 0 , 12)
end
end)获取卡密配置
lua
local config = verifyhub.getKaConfig()
if config.success then
print("卡密配置:" .. config.config)
else
print("获取卡密配置失败:" .. config.msg)
end修改卡密配置
lua
local result = verifyhub.updateKaConfig("新的配置内容")
if result.success then
print("卡密配置更新成功")
else
print("卡密配置更新失败:" .. result.msg)
end获取用户配置
lua
local config = verifyhub.getUserConfig()
if config.success then
print("用户配置:" .. config.config)
else
print("获取用户配置失败:" .. config.msg)
end修改用户配置
lua
local result = verifyhub.updateUserConfig("新的用户配置")
if result.success then
print("用户配置更新成功")
else
print("用户配置更新失败:" .. result.msg)
end添加远程数据
lua
local result = verifyhub.addRemoteData("键名", "值")
if result.success then
print("远程数据添加成功")
else
print("远程数据添加失败:" .. result.msg)
end获取远程数据
lua
local data = verifyhub.getRemoteData("键名")
if data.success then
print("远程数据值:" .. data.value)
else
print("获取远程数据失败:" .. data.msg)
end更新远程数据
lua
local result = verifyhub.updateRemoteData("键名", "新值")
if result.success then
print("远程数据更新成功")
else
print("远程数据更新失败:" .. result.msg)
end删除远程数据
lua
local result = verifyhub.deleteRemoteData("键名")
if result.success then
print("远程数据删除成功")
else
print("远程数据删除失败:" .. result.msg)
end获取远程变量
lua
local variable = verifyhub.getRemoteVar("变量名")
if variable.success then
print("远程变量值:" .. variable.value)
else
print("获取远程变量失败:" .. variable.msg)
end调用远程函数
lua
local functionParams = {
{
paramName = "param1",
paramValue = "值1"
},
{
paramName = "param2",
paramValue = "值2"
}
}
local result = verifyhub.callFunction("函数名", functionParams)
if result.success then
print("远程函数返回值:" .. result.result)
else
print("调用远程函数失败:" .. result.msg)
end获取最新脚本信息
lua
local scriptInfo = verifyhub.getNewestScript("脚本名称")
if scriptInfo.success then
print("脚本名称:" .. scriptInfo.scriptName)
print("版本号:" .. scriptInfo.versionNumber)
print("版本描述:" .. scriptInfo.versionDescription)
else
print("获取脚本信息失败:" .. scriptInfo.msg)
end获取脚本下载地址
lua
local downloadInfo = verifyhub.getScriptDownload("脚本名称", "版本号")
if downloadInfo.success then
print("下载地址:" .. downloadInfo.downloadUrl)
else
print("获取下载地址失败:" .. downloadInfo.msg)
end图形验证码
部分接口支持图形验证码功能:
lua
local captchaResult = verifyhub.getCaptcha(verifyhub.generateUUID())
if captchaResult.success then
print("验证码UUID:" .. captchaResult.uuid)
print("验证码图片Base64:" .. captchaResult.captchaBase64)
else
print("获取验证码失败:" .. captchaResult.msg)
end常见问题
1. 设备ID问题
懒人精灵在某些情况下可能无法正确获取设备ID,SDK提供了自动生成设备ID的方案:
lua
verifyhub.setDeviceId(verifyhub.getDeviceId()) -- 使用SDK自动生成的设备ID2. 网络请求失败
如果遇到网络请求失败的问题,请检查:
- 网络连接是否正常
- 服务器地址是否正确
- 程序ID和密钥是否正确
- 设备是否被封禁
3. 签名错误
如果出现签名错误,请检查:
- 时间是否同步
- 参数是否正确传递
- 密钥是否正确配置