# 懒人精灵 接入
7c云网络验证提供了官方的 懒人精灵 插件,方便 懒人精灵 开发者接入。
# 接入须知
# 对接视频
# 获取方式
下载地址:
或者加群675107742
在群文件下载SDK,有问题也可在此群交流。
# 使用方式
先将下载到的QCYSDK.luae
文件解压出来,然后右键点击你的懒人精灵项目的插件目录》添加》已有项》找到解压目录选择QCYSDK.luae
然后在脚本中通过 qcysdk = require("QCYSDK")
引入。
压缩包中包含卡密登录例子,和用户登录例子。
# 卡密登录例子
-- 此例子有界面,请加群675107742下载此例子源码
qcysdk = require("QCYSDK")
-- 保存token的路径, 可以更换定义
token_path = "/sdcard/token.txt"
-- 开启掉线重连
isLoginAgain = true -- false 关闭掉线重连
-- 初始化sdk AppKey 和 AppSecret 在7c云开发者后台获取
appKey = ""
appSecret = ""
qcysdk.init(appKey, appSecret, token_path, isLoginAgain)
qcysdk.debug = false -- 开发过程中建议开启debug模式,会打印每次请求的详细信息
--按钮点击事件
function onClickEvent(handle,id)
if id == "cardUbind" then --卡密解绑
qcysdk.setCard(getEditText(handle,"cardPassword"))
ret = qcysdk.CardUnbindDevice()
print("卡密解绑:"..jsonLib.encode(ret))
if ret.code == 0 then
toast("解绑成功",0,0,12)
else
toast(jsonLib.encode(ret.message),0,0,12)
end
elseif id == "cardRecharge" then --卡密充值
card = getEditText(handle,"cardPassword")
useCard = getEditText(handle,"useCard")
ret = qcysdk.CardRecharge(card, useCard)
print("卡密充值:"..jsonLib.encode(ret))
if ret.code == 0 then
toast("充值成功",0,0,12)
else
toast(jsonLib.encode(ret.message),0,0,12)
end
end
end
setStopCallBack(function(error)
local file = io.open(token_path, "r")
if file ~= nil then
token = file:read("*a")
file:close()
if token ~= "" and token ~= nil then
qcysdk.CardLogout(token)
end
end
end)
w,h = getDisplaySize()
action,arr = showUI("卡密登录例子.ui",w,h,onLoadEvent,onClickEvent,onCloseEvent,onSelectEvent)
if action == 1 then
-- 设置卡密
qcysdk.setCard(arr["cardPassword"])
-- 心跳失败回调
qcysdk.onHeartbeatFailed(function(ret)
toast(ret.message)
print(ret.message)
sleep(3000)
setTimer(exitScript,10) -- 退出脚本
end)
--如果开启 限制登录次数 每次卡密登录前需要调用退出登录, 没有开启 限制登录次数 这里不用管
--从token_path路径 读取token
local file = io.open(token_path, "r")
if file ~= nil then
token = file:read("*a")
file:close()
if token ~= "" and token ~= nil then
qcysdk.CardLogout(token)
end
end
local device_id = getDeviceId()
if device_id == "" then
-- 获取不到设备号
-- 请传入保存设备号文本路径,如文件不存在则会自动创建
qcysdk.my_device("/sdcard/deviceid.txt")
end
-- 卡密登录
local ret = qcysdk.CardLogin()
print(jsonLib.encode(ret))
if ret.code ~= 0 then -- 如果登录失败
toast(ret.message)
sleep(3000)
setTimer(exitScript,2) -- 退出脚本
end
toast("登录成功")
sleep(2000)
local lret = qcysdk.login_result -- 登录成功后获取登录结果
toast(string.format("卡类:%s\n过期时间:%s\n过期时间戳:%d\n卡密配置:%s\n是否是试用:%s",
lret.cardType, lret.expires, lret.expires_ts, lret.config, qcysdk.is_trial)
)
-- 测试用,hold住主线程不要退出,记得删除,后面是你的代码了
while true do
toast("剩余时间:"..tostring(qcysdk.GetTimeRemaining()).."秒")
sleep(1000)
end
else
setTimer(exitScript,2) -- 退出脚本
end
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# 用户登录例子
-- 此例子有界面,请加群675107742下载此例子源码
qcysdk = require("QCYSDK")
-- 保存token的路径, 可以更换定义
token_path = "/sdcard/token.txt"
-- 开启掉线重连
isLoginAgain = true -- false 关闭掉线重连
-- 初始化sdk AppKey 和 AppSecret 在7c云开发者后台获取
appKey = ""
appSecret = ""
qcysdk.init(appKey, appSecret, token_path, isLoginAgain)
qcysdk.debug = false -- 开发过程中建议开启debug模式,会打印每次请求的详细信息
--按钮点击事件
function onClickEvent(handle,id)
if id == "UserUnbind" then --用户解绑
username = getEditText(handle,"username")
ret = qcysdk.UserUnbindDevice(username)
print("用户解绑:"..jsonLib.encode(ret))
if ret.code == 0 then
toast("解绑成功",0,0,12)
else
toast(jsonLib.encode(ret.message),0,0,12)
end
elseif id == "UserRegister" then --注册账号
card = getEditText(handle,"registerCard")
username = getEditText(handle,"username")
password = getEditText(handle,"password")
ret = qcysdk.UserRegister(username, password, card)
print("注册账号"..jsonLib.encode(ret))
if ret.code == 0 then
toast("注册成功",0,0,12)
else
toast(jsonLib.encode(ret.message),0,0,12)
end
elseif id == "UserRecharge" then --充值账号
username = getEditText(handle,"username")
card = getEditText(handle,"rechargeCard")
ret = qcysdk.UserRecharge(username, card)
print("充值账号"..jsonLib.encode(ret))
if ret.code == 0 then
toast("充值成功",0,0,12)
else
toast(jsonLib.encode(ret.message),0,0,12)
end
elseif id == "UserChangePassword" then --修改密码
newPassword = getEditText(handle,"newPassword")
username = getEditText(handle,"username")
password = getEditText(handle,"password")
ret = qcysdk.UserChangePassword(username, password, newPassword)
print("修改密码:"..jsonLib.encode(ret))
if ret.code == 0 then
toast("修改密码成功",0,0,12)
else
toast(jsonLib.encode(ret.message),0,0,12)
end
end
end
setStopCallBack(function(error)
local file = io.open(token_path, "r")
if file ~= nil then
token = file:read("*a")
file:close()
if token ~= "" and token ~= nil then
qcysdk.UserLogout(token)
end
end
end)
w,h = getDisplaySize()
action,arr = showUI("用户登录例子.ui",w,h,onLoadEvent,onClickEvent,onCloseEvent,onSelectEvent)
if action == 1 then
-- 设置用户名,密码
qcysdk.setUser(arr["username"], arr["password"])
-- 心跳失败回调
qcysdk.onHeartbeatFailed(function(ret)
toast(ret.message)
print(ret.message)
sleep(3000)
setTimer(exitScript,10) -- 退出脚本
end)
--如果开启 限制登录次数 每次卡密登录前需要调用退出登录, 没有开启 限制登录次数 这里不用管
--从token_path路径 读取token
local file = io.open(token_path, "r")
if file ~= nil then
token = file:read("*a")
file:close()
if token ~= "" and token ~= nil then
qcysdk.UserLogout(token)
end
end
local device_id = getDeviceId()
if device_id == "" then
-- 获取不到设备号
-- 请传入保存设备号文本路径,如文件不存在则会自动创建
qcysdk.my_device("/sdcard/deviceid.txt")
end
-- 用户登录
local ret = qcysdk.UserLogin()
print(jsonLib.encode(ret))
if ret.code ~= 0 then -- 如果登录失败
toast(ret.message)
sleep(3000)
setTimer(exitScript,2) -- 退出脚本
end
toast("登录成功")
sleep(2000)
local lret = qcysdk.login_result -- 登录成功后获取登录结果
toast(string.format("卡类:%s\n过期时间:%s\n过期时间戳:%d\n卡密配置:%s\n是否是试用:%s",
lret.cardType, lret.expires, lret.expires_ts, lret.config, qcysdk.is_trial)
)
-- 测试用,hold住主线程不要退出,记得删除,后面应该是你的代码了
while true do
sleep(1000)
toast("剩余时间:"..tostring(qcysdk.GetTimeRemaining()).."秒")
end
else
setTimer(exitScript,2) -- 退出脚本
end
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# 试用登录例子
-- 此例子有界面,请加群675107742下载此例子源码
qcysdk = require("QCYSDK")
-- 保存token的路径,可以自己更改路径
token_path = "/sdcard/token.txt"
-- 开启掉线重连
isLoginAgain = true -- false 关闭掉线重连
-- 初始化sdk AppKey 和 AppSecret 在7c云开发者后台获取
appKey = ""
appSecret = ""
qcysdk.init(appKey, appSecret, token_path, isLoginAgain)
qcysdk.debug = false -- 开发过程中建议开启debug模式,会打印每次请求的详细信息
setStopCallBack(function(error)
ret = qcysdk.CardLogout()
end)
-- w,h = getDisplaySize()
action,arr = showUI("试用.ui",w,h,onLoadEvent,onClickEvent,onCloseEvent,onSelectEvent)
if action == 1 then
-- 心跳失败回调
qcysdk.onHeartbeatFailed(function(ret)
toast(ret.message)
print(ret.message)
sleep(3000)
setTimer(exitScript,10) -- 退出脚本
end)
local device_id = getDeviceId()
if device_id == "" then
-- 获取不到设备号
-- 请传入保存设备号文本路径,如文件不存在则会自动创建
qcysdk.my_device("/sdcard/deviceid.txt")
end
-- 卡密登录
local ret = qcysdk.TrialLogin()
print(jsonLib.encode(ret))
if ret.code ~= 0 then -- 如果登录失败
toast(ret.message)
sleep(3000)
setTimer(exitScript,2) -- 退出脚本
end
toast("登录成功")
sleep(2000)
local lret = qcysdk.login_result -- 登录成功后获取登录结果
toast(string.format("卡类:%s\n过期时间:%s\n过期时间戳:%d\n卡密配置:%s\n是否是试用:%s",
lret.cardType, lret.expires, lret.expires_ts, lret.config, qcysdk.is_trial)
)
-- 测试用,hold住主线程不要退出,记得删除,后面是你的代码了
i = 0
while true do
i = i + 1
print(i)
--toast("剩余时间:"..tostring(qcysdk.GetTimeRemaining()).."秒")
sleep(1000)
end
else
setTimer(exitScript,2) -- 退出脚本
end
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 初始化
# 初始化SDK
# 语法
qcysdk.init(appKey, appSecret, token_path, isLoginAgain)
# 参数
参数名 | 必传 | 类型 | 参数说明 |
---|---|---|---|
appKey | 是 | string | 软件的appKey |
appSecret | 是 | string | 软件的appSecret |
token_path | 是 | string | 登录成功令牌保存的路径 |
isLoginAgain | 是 | boolean | true开启断线重登,false关闭断线重登 |
# 初始化卡密
# 语法
qcysdk.SetCard(card)
# 参数
参数名 | 必传 | 类型 | 参数说明 |
---|---|---|---|
card | 是 | string | 用户填写的卡密(长度不超过45位) |
# 初始化用户账号
# 语法
qcysdk.SetUser(username, password)
# 参数
参数名 | 必传 | 类型 | 参数说明 |
---|---|---|---|
username | 是 | string | 用户名(长度不能超过20位) |
password | 是 | string | 用户密码(长度6-30位) |
# 获取时间戳(网络时间)
# 语法
local ret = qcysdk.getTimestamp()
# 参数
无
# 返回值
数字类型,列如: 1624110613
# 获取剩余时长
# 语法
local ret = qcysdk.GetTimeRemaining()
# 参数
无
# 返回值
数字类型,剩余多少秒,例:1024
# 卡密登录
注意
调用此接口前需调用 qcysdk.SetCard(card)
初始化卡密
登录成功后将自动启动一个线程发送心跳包,开发者就无需关注发送心跳包的细节。
# 语法
local ret = qcysdk.CardLogin()
# 参数
无
# 返回值
Object类型,例:{ result: { cardType: '月卡', token: '8wr17hGcTs5lVVJ0liL97d6McNEaDTKk', expires: '2021-09-17 01:49:38', expires_ts: '1631814578', config: '', server_time: 1624110506 }, message: 'ok', code: 0 }
# 卡密退出登录
# 语法
local ret = qcysdk.CardLogout(token)
# 参数
参数名 | 必传 | 类型 | 参数说明 |
---|---|---|---|
token | 是 | string | 登录成功时获取的token |
# 返回值
Object类型,例:{"code": 0, "message": "OK"}
# 卡密解绑设备
注意
请先进入开发者后台软件管理页面,配置软件开启设备绑定且可解除绑定。
# 语法
local ret = qcysdk.CardUnbindDevice()
# 参数
无
# 返回值
Object类型,例:{"code": 0, "message": "OK"}
# 卡密绑定设备上解绑
注意
请先进入开发者后台软件管理页面,配置软件开启设备绑定且可解除绑定。
# 语法
local ret = qcysdk.CardUnbindDeviceBybindDevice()
# 参数
无
# 返回值
Object类型,例:{"code": 0, "message": "OK"}
# 卡密设置解绑密码
说明
请先进入开发者后台软件管理页面,配置软件开启设备绑定且可解除绑定。 该密码用于绑定设备丢失或者其它原因导致无法在老设备登录时解绑设备。
# 语法
local ret = qcysdk.SetCardUnbindPassword(password)
# 参数
参数名 | 必传 | 类型 | 参数说明 |
---|---|---|---|
password | 是 | string | 解绑密码(6-10位数字和字母组合的字符串) |
# 返回值
Object类型,例:{"code": 0, "message": "OK"}
# 卡密通过密码解绑设备
说明
请先进入开发者后台软件管理页面,配置软件开启设备绑定且可解除绑定。 该接口用于绑定设备丢失或者其它原因导致无法在老设备登录时,通过解绑密码解绑设备。
# 语法
local ret = qcysdk.CardUnbindDeviceByPassword(password)
参数名 | 必传 | 类型 | 参数说明 |
---|---|---|---|
password | 是 | string | 解绑密码(6-10位数字和字母组合的字符串) |
# 返回值
Object类型,例:{"code": 0, "message": "OK"}
# 卡密充值(以卡充卡)
# 语法
local ret = qcysdk.CardRecharge(card, useCard)
# 参数
参数名 | 必传 | 类型 | 参数说明 |
---|---|---|---|
card | 是 | string | 被充值的卡密(长度不超过45位) |
useCard | 是 | string | 充值使用的卡密(长度不超过45位) |
# 返回值
Object类型,例:{"code": 0, "message": "OK"}
# 用户注册(通过卡密)
# 语法
local ret = qcysdk.UserRegister(username, password, card)
# 参数
参数名 | 必传 | 类型 | 参数说明 |
---|---|---|---|
username | 是 | string | 用户名(长度不能超过20位) |
password | 是 | string | 用户密码(长度6-30位) |
card | 是 | string | 注册使用的卡密(长度不超过45位) |
# 返回值
Object类型,例:{"code": 0, "message": "ok"}
# 用户登录
注意
调用此接口前需调用 qcysdk.SetUser(username, password)
初始化用户账号密码
登录成功后将自动启动一个线程发送心跳包,开发者就无需关注发送心跳包的细节。
# 语法
qcysdk.SetUser(username, password)
local ret = qcysdk.UserLogin()
2
# 参数
无
# 返回值
Object类型
# 用户退出登录
# 语法
local ret = qcysdk.UserLogout(token)
# 参数
参数名 | 必传 | 类型 | 参数说明 |
---|---|---|---|
token | 是 | string | 登录成功时获取的token |
# 返回值
Object类型,例:{"code": 0, "message": "OK"}
# 用户修改密码
# 语法
local ret = qcysdk.UserChangePassword(username, password, newPassword)
# 参数
参数名 | 必传 | 类型 | 参数说明 |
---|---|---|---|
username | 是 | string | 用户名(长度不能超过20位) |
password | 是 | string | 用户密码(长度6-30位) |
newPassword | 是 | string | 新密码(长度6-30位) |
# 返回值
Object类型,例:{"code": 0, "message": "OK"}
# 用户充值(通过卡密)
# 语法
local ret = qcysdk.UserRecharge(username, card)
# 参数
参数名 | 必传 | 类型 | 参数说明 |
---|---|---|---|
username | 是 | string | 用户名(长度不能超过20位) |
card | 是 | string | 充值使用的卡密(长度不超过45位) |
# 返回值
Object类型,例:{"code": 0, "message": "OK"}
# 用户解绑设备
# 语法
local ret = qcysdk.UserUnbindDevice()
# 参数
无
# 返回值
Object类型,例:{"code": 0, "message": "OK"}
# 试用登录
注意
登录成功后将自动启动一个线程发送心跳包,开发者就无需关注发送心跳包的细节。
# 语法
local ret = qcysdk.TrialLogin()
# 参数
无
# 返回值
Object类型
# 试用退出登录
# 语法
local ret = qcysdk.TrialLogout()
# 参数
无
# 返回值
Object类型,例:{"code": 0, "message": "OK"}
# 获取卡密配置
# 语法
local ret = qcysdk.GetCardConfig()
# 参数
无
# 返回值
Object类型,例:{ result: { config: '', server_time: 1624120946 }, message: 'ok', code: 0 }
# 更改卡密配置
# 语法
local ret = qcysdk.UpdateCardConfig(config)
# 参数
参数名 | 必传 | 类型 | 参数说明 |
---|---|---|---|
config | 是 | string | 自定义配置(长度不能超过512位) |
# 返回值
Object类型,例:{"code": 0, "message": "OK"}
# 获取用户配置
# 语法
local ret = qcysdk.GetUserConfig()
# 参数
无
# 返回值
Object类型,例:{ result: { config: '迪迦', server_time: 1624121563 }, message: 'ok', code: 0 }
# 更改用户配置
# 语法
local ret = qcysdk.UpdateUserConfig(config)
# 参数
参数名 | 必传 | 类型 | 参数说明 |
---|---|---|---|
config | 是 | string | 自定义配置(长度不能超过512位) |
# 返回值
Object类型,例:{"code": 0, "message": "OK"}
# 获取软件配置
# 语法
local ret = qcysdk.GetSoftwareConfig()
# 参数
无
# 返回值
Object类型,例:{ result: { config: '迪迦', server_time: 1624121758 }, message: 'ok', code: 0 }
# 获取软件公告
# 语法
local ret = qcysdk.GetSoftwareNotice()
# 参数
无
# 返回值
Object类型,例:{ result: { server_time: 1624121862, notice: '泰罗' }, message: 'ok', code: 0 }
# 获取软件版本号和下载链接
# 语法
local ret = qcysdk.GetSoftwareVersion()
# 参数
无
# 返回值
Object类型,例:{ result: { server_time: 1624121862, version: '1.0.1', url:'www.baidu.com' }, message: 'ok', code: 0 }
# 获取远程变量
注意
调用此接口前 需要登录成功后才能调用。
# 语法
local ret = qcysdk.GetRemoteVar(key)
# 参数
参数名 | 必传 | 类型 | 参数说明 |
---|---|---|---|
key | 是 | string | 远程变量名(长度不能超过64位) |
# 返回值
Object类型,例:{ result: { server_time: 1624122124, varValue: '斯奥特曼' }, message: 'ok', code: 0 }
# 获取远程数据
注意
调用此接口前 需要登录成功后才能调用。
# 语法
local ret = qcysdk.GetRemoteData(key)
# 参数
参数名 | 必传 | 类型 | 参数说明 |
---|---|---|---|
key | 是 | string | 远程数据key(长度不能超过64位) |
# 返回值
Object类型,例:{ result: { server_time: 1624122295, value: '奥特曼' }, message: 'ok', code: 0 }
# 操作远程数据
注意
调用此接口前 需要登录成功后才能调用。
# 新增远程数据
# 语法
local ret = qcysdk.CreateRemoteData(key, value)
# 参数
参数名 | 必传 | 类型 | 参数说明 |
---|---|---|---|
key | 是 | string | 远程数据key(长度不能超过64位) |
value | 是 | string | 远程数据值(长度不能超过256位) |
# 返回值
Object类型,例:{ result: { server_time: 1624122453 }, message: 'ok', code: 0 }
# 修改远程数据
注意
调用此接口前 需要登录成功后才能调用。
# 语法
local ret = qcysdk.UpdateRemoteData(key, value)
# 参数
参数名 | 必传 | 类型 | 参数说明 |
---|---|---|---|
key | 是 | string | 远程数据key(长度不能超过64位) |
value | 是 | string | 远程数据值(长度不能超过256位) |
# 返回值
Object类型,例:{ result: { server_time: 1624122453 }, message: 'ok', code: 0 }
# 删除远程数据
注意
调用此接口前 需要登录成功后才能调用。
# 语法
local ret = qcysdk.DeleteRemoteData(key)
# 参数
参数名 | 必传 | 类型 | 参数说明 |
---|---|---|---|
key | 是 | string | 远程数据key(长度不能超过64位) |
# 返回值
Object类型,例:{ result: { server_time: 1624122453 }, message: 'ok', code: 0 }
# 云函数
注意
调用此接口前 需要登录成功后才能调用。
# 语法
local ret = qcysdk.CallRemoteFn(fnName, params);
# 参数
参数名 | 必传 | 类型 | 参数说明 |
---|---|---|---|
fnName | 是 | string | 云函数名(长度不能超过64位) |
params | 是 | string | 调用云函数时传入的参数 |
# 返回值
Object类型,例:{"result":{"return":"55","server_time":1689788200},"message":"ok","sign":"236cd75d551fb991ac88684761778a17","nonce":"vwWSKfwOgbLocFzg15OX","code":0}