# Auto.js 接入

7c云网络验证提供了官方的 Autojs 封装库,方便 Autojs 开发者接入。

# 接入须知

# 对接视频

autojs对接视频 (opens new window)

# 获取方式

下载地址: 或者加群675107742在群文件下载SDK,有问题也可在此群交流。

# 使用方式

先将下载到的QCYSDK.js文件用编辑器打开,选中所有复制粘贴到你自己的main.js代码文件中

# 卡密登录例子

// 有问题请加群 675107742
"ui";
//=======================================界面============================================
ui.layout(
  <ScrollView>
    <vertical>
      <toolbar bg="#009688" gravity="center" marginBottom="3">
        <text w="*" text="7c云" gravity="center" textColor="#ffffff" textSize="25sp" />
      </toolbar>
      <horizontal marginTop="10sp">
        <text text="卡密:" textColor="black" textSize="15sp" marginLeft="10sp" />
        <input id="card" hint="" textSize="15sp" marginLeft="5sp" w="*" />
      </horizontal>
      <horizontal marginTop="10sp">
        <text text="充值使用的卡密:" textColor="black" textSize="15sp" marginLeft="10sp" />
        <input id="use_card" hint="" textSize="15sp" marginLeft="5sp" w="*" />
      </horizontal>
      <button id="unbind_card" text="解绑" marginLeft="10" marginRight="10" marginBottom="20" />
      <button id="recharge" text="充值卡密" marginLeft="10" marginRight="10" marginBottom="20" />
      <button id="start" text="启动脚本" marginLeft="10" marginRight="10" />
    </vertical>
  </ScrollView>
);

let QCYSDK = require("./QCYSDK");
let AppKey = "";//7c云开发后台软件管理里面获取
let AppSecret = "";//7c云开发后台软件管理里面获取
let qcysdk = new QCYSDK(AppKey, AppSecret);
qcysdk._protocol = "http"
qcysdk.debug = false; //关闭debug不会打印输出
// 开启断线重连
let isLoginAgain = true //false 关闭断线重连
qcysdk.SetCard(ui.card.text());


let tokenPath = "/sdcard/token.txt"//保存token的路径
let token = ""

//充值卡密点击事件
ui.recharge.click(() => {
  if (!ui.card.text() || !ui.use_card.text()) return toastLog("请输入卡密,和充值使用的卡密")
  let ret = qcysdk.CardRecharge(ui.card.text(), ui.use_card.text())
  if (ret.code === 0) {
    toastLog("卡密充值成功")
  } else {
    toastLog(ret.message)
  }
})

//解绑卡密点击事件
ui.unbind_card.click(() => {
  if (!ui.card.text()) return toastLog("请输入需要解绑的卡密")
  qcysdk.SetCard(ui.card.text());
  let ret = qcysdk.CardUnbindDevice()
  if (ret.code === 0) {
    toastLog("解绑成功")
  } else {
    toastLog(ret.message)
  }
})

// 监听心跳失败事件
qcysdk.event.on("heartbeat_failed", function (hret) {
  log("心跳失败,尝试重登...")
  sleep(2000);
  if (isLoginAgain) {
    let login_ret = qcysdk.CardLogin();
    if (login_ret.code == 0) {
      files.write(tokenPath, login_ret.result.token);
      log("重登成功");
    } else {
      toastLog(login_ret.message);  // 重登失败
      sleep(200);
      exit();  // 退出脚本
    }
  }
});

// 当脚本正常或者异常退出时会触发exit事件
events.on("exit", function () {
  qcysdk.CardLogout(token); // 调用退出登录
  log("结束运行");
});

//启动脚本点击事件
ui.start.click(() => {
  //如果开启 控制在线数量 每次卡密登录前需要调用退出登录, 没有开启 限制登录次数 这里不用管
  //从tokenPath路径 读取token
  if (files.isFile(tokenPath)) {
    token = files.read(tokenPath)
    if (token != "") {
      qcysdk.CardLogout(token)
    }
  } else {
    files.createWithDirs(tokenPath);
  }
  
  qcysdk.SetCard(ui.card.text());
  let login_ret = qcysdk.CardLogin();
  if (login_ret.code === 0) {
    toastLog("到期时间:" + login_ret.result.expires)
    files.write(tokenPath, login_ret.result.token);
    // 登录成功,后面写你的业务代码
    // 登录成功,后面写你的业务代码
    // 登录成功,后面写你的业务代码
  } else {
    // 登录失败提示
    toast(login_ret.message);
  }
})

1
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

# 用户登录例子

// 有问题请加群 675107742
"ui";
//=======================================界面============================================
ui.layout(
  <ScrollView>
    <vertical>
      <toolbar bg="#009688" gravity="center" marginBottom="3">
        <text w="*" text="7c云" gravity="center" textColor="#ffffff" textSize="25sp" />
      </toolbar>
      <horizontal marginTop="10sp">
        <text text="用户名:" textColor="black" textSize="15sp" marginLeft="10sp" />
        <input id="username" hint="" textSize="15sp" marginLeft="5sp" w="*" />
      </horizontal>
      <horizontal marginTop="10sp">
        <text text="密码:" textColor="black" textSize="15sp" marginLeft="10sp" />
        <input id="password" hint="" textSize="15sp" marginLeft="5sp" w="*" />
      </horizontal>
      <horizontal marginTop="10sp">
        <text text="新密码:" textColor="black" textSize="15sp" marginLeft="10sp" />
        <input id="newpassword" hint="" textSize="15sp" marginLeft="5sp" w="*" />
      </horizontal>
      <horizontal marginTop="10sp">
        <text text="注册使用的卡密:" textColor="black" textSize="15sp" marginLeft="10sp" />
        <input id="card" hint="" textSize="15sp" marginLeft="5sp" w="*" />
      </horizontal>
      <horizontal marginTop="10sp">
        <text text="充值使用的卡密:" textColor="black" textSize="15sp" marginLeft="10sp" />
        <input id="use_card" hint="" textSize="15sp" marginLeft="5sp" w="*" />
      </horizontal>
      <button id="register" text="注册账号" marginLeft="10" marginRight="10" marginBottom="20" />
      <button id="change_password" text="修改密码" marginLeft="10" marginRight="10" marginBottom="20" />
      <button id="unbind_card" text="解绑" marginLeft="10" marginRight="10" marginBottom="20" />
      <button id="recharge" text="充值用户" marginLeft="10" marginRight="10" marginBottom="20" />
      <button id="start" text="启动脚本" marginLeft="10" marginRight="10" />
    </vertical>
  </ScrollView>
);

let QCYSDK = require("./QCYSDK")
/*                          AppKey                    AppSecret*/
let qcysdk = new QCYSDK("", "");
qcysdk._protocol = "http"
qcysdk.debug = false; //关闭debug不会打印输出
// 开启断线重连
let isLoginAgain = true //false 关闭断线重连

qcysdk.SetUser(ui.username.text(), ui.password.text());

let tokenPath = "/sdcard/token.txt"//保存token的路径
let token = ""

//用户注册点击事件
ui.register.click(() => {
  if (!ui.username.text() || !ui.password.text() || !ui.card.text()) return toastLog("请输入注册的用户名,密码和注册使用的卡密")
  let ret = qcysdk.UserRegister(ui.username.text(), ui.password.text(), ui.card.text())
  if (ret.code === 0) {
    toastLog(ui.username.text() + "注册成功")
  } else {
    toastLog(ret.message)
  }
})

//用户修改密码
ui.change_password.click(() => {
  if (!ui.username.text() || !ui.password.text() || !ui.newpassword.text()) return toastLog("请输入用户名,密码和需要修改的新密码")
  let ret = qcysdk.UserChangePassword(ui.username.text(), ui.password.text(), ui.newpassword.text())
  if (ret.code === 0) {
    toastLog("新密码修改成功")
  } else {
    toastLog(ret.message)
  }
})

//充值用户点击事件
ui.recharge.click(() => {
  if (!ui.username.text() || !ui.use_card.text()) return toastLog("请输入用户名,和充值使用的卡密")
  let ret = qcysdk.UserRecharge(ui.username.text(), ui.use_card.text())
  if (ret.code === 0) {
    toastLog("用户充值成功")
  } else {
    toastLog(ret.message)
  }
})

//解绑用户点击事件
ui.unbind_card.click(() => {
  if (!ui.card.text()) return toastLog("请输入需要解绑的用户名")
  let ret = qcysdk.UserUnbindDevice()
  if (ret.code === 0) {
    toastLog("解绑成功")
  } else {
    toastLog(ret.message)
  }
})

// 监听心跳失败事件
qcysdk.event.on("heartbeat_failed", function (hret) {
  log("心跳失败,尝试重登...")
  sleep(2000);
  if (isLoginAgain) {
    let login_ret = qcysdk.UserLogin();
    if (login_ret.code == 0) {
      files.write(tokenPath, login_ret.result.token);
      log("重登成功");
    } else {
      toastLog(login_ret.message);  // 重登失败
      sleep(200);
      exit();  // 退出脚本
    }
  }
});

// 当脚本正常或者异常退出时会触发exit事件
events.on("exit", function () {
  qcysdk.UserLogout(token); // 调用退出登录
  log("结束运行");
});

//启动脚本点击事件
ui.start.click(() => {
  //如果开启 控制在线数量 每次卡密登录前需要调用退出登录, 没有开启 限制登录次数 这里不用管
  //从tokenPath路径 读取token
  if (files.isFile(tokenPath)) {
    token = files.read(tokenPath)
    if (token != "") {
      qcysdk.UserLogout(token)
    }
  } else {
    files.createWithDirs(tokenPath);
  }

  qcysdk.SetUser(ui.username.text(), ui.password.text());
  let login_ret = qcysdk.UserLogin();
  if (login_ret.code === 0) {
    toastLog("到期时间:" + login_ret.result.expires)
    files.write(tokenPath, login_ret.result.token);
    // 登录成功,后面写你的业务代码
    // 登录成功,后面写你的业务代码
    // 登录成功,后面写你的业务代码
  } else {
    // 登录失败提示
    toast(login_ret.message);
  }
})
1
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
133
134
135
136
137
138
139
140
141
142
143
144

# 试用登录例子

// 有问题请加群 675107742
"ui";
//=======================================界面============================================
ui.layout(
  <ScrollView>
    <vertical>
      <toolbar bg="#009688" gravity="center" marginBottom="3">
        <text w="*" text="七C云" gravity="center" textColor="#ffffff" textSize="25sp" />
      </toolbar>
      <button id="start" text="启动脚本" marginLeft="10" marginRight="10" />
    </vertical>
  </ScrollView>
);

let QCYSDK = require("./QCYSDK")
/*                          AppKey                    AppSecret*/
let qcysdk = new QCYSDK("", "");
qcysdk._protocol = "http"
qcysdk.debug = false; //关闭debug不会打印输出
// 开启断线重连
let isLoginAgain = true //false 关闭断线重连

// 监听心跳失败事件
qcysdk.event.on("heartbeat_failed", function (hret) {
  log("心跳失败,尝试重登...")
  sleep(2000);
  if (isLoginAgain) {
    let login_ret = qcysdk.TrialLogin();
    if (login_ret.code == 0) {
      files.write(tokenPath, login_ret.result.token);
      log("重登成功");
    } else {
      toastLog(login_ret.message);  // 重登失败
      sleep(200);
      exit();  // 退出脚本
    }
  }
});

// 当脚本正常或者异常退出时会触发exit事件
events.on("exit", function () {
  qcysdk.TrialLogout(); // 调用退出登录
  log("结束运行");
});

//启动脚本点击事件
ui.start.click(() => {
  let login_ret = qcysdk.TrialLogin();
  console.log("login_ret: ", login_ret);
  if (login_ret.code === 0) {
    toastLog("到期时间:" + login_ret.result.expires)
    // 登录成功,后面写你的业务代码
    // 登录成功,后面写你的业务代码
    // 登录成功,后面写你的业务代码
  } else {
    // 登录失败提示
    toast(login_ret.message);
  }
})
1
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

# 可更改变量

  • qcysdk.debug : bool型,默认为true,开启后会在控制台输出每次请求的详细信息,方便调试
  • qcysdk._device_id : string型,设备号默认会自动获取,不建议修改。如果你有更好的一机一码的生成方案,可在初始化后修改该值

# 初始化

# 初始化卡密

# 语法

qcysdk.SetCard(card)
1

# 参数

参数名 必传 类型 参数说明
card string 用户填写的卡密(长度不超过45位)

# 初始化用户账号

# 语法

qcysdk.SetUser(username, password)
1

# 参数

参数名 必传 类型 参数说明
username string 用户名(长度不能超过20位)
password string 用户密码(长度6-30位)

# 获取时间戳(网络时间)

# 语法

let ret = qcysdk.getTimestamp()
1

# 参数

# 返回值

数字类型,列如: 1624110613

# 获取心跳结果

# 语法

let ret = qcysdk.GetHeartbeatResult()
1

# 参数

# 返回值

Object类型,例:{"code": 0, "message": "ok"}

# 获取剩余时长

# 语法

let ret = qcysdk.GetTimeRemaining()
1

# 参数

# 返回值

数字类型,剩余多少秒,例:1024

# 卡密登录

注意

调用此接口前需调用 qcysdk.SetCard(card) 初始化卡密 登录成功后将自动启动一个线程发送心跳包,开发者就无需关注发送心跳包的细节。 开发者只需在自己的脚本中通过调用 qcysdk.GetHeartbeatResult() 获取当前心跳结果。

# 语法

let ret = qcysdk.CardLogin()
1

# 参数

# 返回值

Object类型,例:{ result: { cardType: '月卡', token: '8wr17hGcTs5lVVJ0liL97d6McNEaDTKk', expires: '2021-09-17 01:49:38', expires_ts: '1631814578', config: '', server_time: 1624110506 }, message: 'ok', code: 0 }

# 卡密退出登录

# 语法

let ret = qcysdk.CardLogout(token)
1

# 参数

参数名 必传 类型 参数说明
token string 登录成功获取的登录令牌

# 返回值

Object类型,例:{"code": 0, "message": "OK"}

# 卡密解绑设备

注意

请先进入开发者后台软件管理页面,配置软件开启设备绑定且可解除绑定。

# 语法

let ret = qcysdk.CardUnbindDevice()
1

# 参数

# 返回值

Object类型,例:{"code": 0, "message": "OK"}

# 卡密绑定设备上解绑

注意

请先进入开发者后台软件管理页面,配置软件开启设备绑定且可解除绑定。

# 语法

let ret = qcysdk.CardUnbindDeviceBybindDevice()
1

# 参数

# 返回值

Object类型,例:{"code": 0, "message": "OK"}

# 卡密设置解绑密码

说明

请先进入开发者后台软件管理页面,配置软件开启设备绑定且可解除绑定。 该密码用于绑定设备丢失或者其它原因导致无法在老设备登录时解绑设备。

# 语法

let ret = qcysdk.SetCardUnbindPassword(password)
1

# 参数

参数名 必传 类型 参数说明
password string 解绑密码(6-10位数字和字母组合的字符串)

# 返回值

Object类型,例:{"code": 0, "message": "OK"}

# 卡密通过密码解绑设备

说明

请先进入开发者后台软件管理页面,配置软件开启设备绑定且可解除绑定。 该接口用于绑定设备丢失或者其它原因导致无法在老设备登录时,通过解绑密码解绑设备。

# 语法

let ret = qcysdk.CardUnbindDeviceByPassword(password)
1
参数名 必传 类型 参数说明
password string 解绑密码(6-10位数字和字母组合的字符串)

# 返回值

Object类型,例:{"code": 0, "message": "OK"}

# 卡密充值(以卡充卡)

# 语法

let ret = qcysdk.CardRecharge(card, useCard)
1

# 参数

参数名 必传 类型 参数说明
card string 被充值的卡密(长度不超过45位)
useCard string 充值使用的卡密(长度不超过45位)

# 返回值

Object类型,例:{"code": 0, "message": "OK"}

# 用户注册(通过卡密)

# 语法

let ret = qcysdk.UserRegister(username, password, card)
1

# 参数

参数名 必传 类型 参数说明
username string 用户名(长度不能超过20位)
password string 用户密码(长度6-30位)
card string 注册使用的卡密(长度不超过45位)

# 返回值

Object类型,例:{"code": 0, "message": "ok"}

# 用户登录

注意

调用此接口前需调用 qcysdk.SetUser(username, password) 初始化用户账号密码 登录成功后将自动启动一个线程发送心跳包,开发者就无需关注发送心跳包的细节。 开发者只需在自己的脚本中通过调用 qcysdk.GetHeartbeatResult() 获取当前心跳结果。

# 语法

qcysdk.SetUser(username, password)
let ret = qcysdk.UserLogin()
1
2

# 参数

# 返回值

Object类型

# 用户退出登录

# 语法

let ret = qcysdk.UserLogout(token)
1

# 参数

参数名 必传 类型 参数说明
token string 卡密登录成功获取的登录凭证

# 返回值

Object类型,例:{"code": 0, "message": "OK"}

# 用户修改密码

# 语法

let ret = qcysdk.UserChangePassword(username, password, newPassword)
1

# 参数

参数名 必传 类型 参数说明
username string 用户名(长度不能超过20位)
password string 用户密码(长度6-30位)
newPassword string 新密码(长度6-30位)

# 返回值

Object类型,例:{"code": 0, "message": "OK"}

# 用户充值(通过卡密)

# 语法

let ret = qcysdk.UserRecharge(username, card)
1

# 参数

参数名 必传 类型 参数说明
username string 用户名(长度不能超过20位)
card string 充值使用的卡密(长度不超过45位)

# 返回值

Object类型,例:{"code": 0, "message": "OK"}

# 用户解绑设备

# 语法

let ret = qcysdk.UserUnbindDevice()
1

# 参数

# 返回值

Object类型,例:{"code": 0, "message": "OK"}

# 试用登录

注意

登录成功后将自动启动一个线程发送心跳包,开发者就无需关注发送心跳包的细节。 只需在自己的脚本中通过调用 qcysdk.GetHeartbeatResult() 获取当前心跳结果。

# 语法

let ret = qcysdk.TrialLogin()
1

# 参数

# 返回值

Object类型

# 试用退出登录

# 语法

let ret = qcysdk.TrialLogout()
1

# 参数

# 返回值

Object类型,例:{"code": 0, "message": "OK"}

# 获取卡密配置

# 语法

let ret = qcysdk.GetCardConfig()
1

# 参数

# 返回值

Object类型,例:{ result: { config: '', server_time: 1624120946 }, message: 'ok', code: 0 }

# 更改卡密配置

# 语法

let ret = qcysdk.UpdateCardConfig(config)
1

# 参数

参数名 必传 类型 参数说明
config string 自定义配置(长度不能超过512位)

# 返回值

Object类型,例:{"code": 0, "message": "OK"}

# 获取用户配置

# 语法

let ret = qcysdk.GetUserConfig()
1

# 参数

# 返回值

Object类型,例:{ result: { config: '迪迦', server_time: 1624121563 }, message: 'ok', code: 0 }

# 更改用户配置

# 语法

let ret = qcysdk.UpdateUserConfig(config)
1

# 参数

参数名 必传 类型 参数说明
config string 自定义配置(长度不能超过512位)

# 返回值

Object类型,例:{"code": 0, "message": "OK"}

# 获取软件配置

# 语法

let ret = qcysdk.GetSoftwareConfig()
1

# 参数

# 返回值

Object类型,例:{ result: { config: '迪迦', server_time: 1624121758 }, message: 'ok', code: 0 }

# 获取软件公告

# 语法

let ret = qcysdk.GetSoftwareNotice()
1

# 参数

# 返回值

Object类型,例:{ result: { server_time: 1624121862, notice: '泰罗' }, message: 'ok', code: 0 }

# 获取软件版本号和下载链接

# 语法

let ret = qcysdk.GetSoftwareVersion()
1

# 参数

# 返回值

Object类型,例:{ result: { server_time: 1624121862, version: '1.0.1', url:'www.baidu.com' }, message: 'ok', code: 0 }

# 获取远程变量

注意

调用此接口前 需要登录成功后才能调用。

# 语法

let ret = qcysdk.GetRemoteVar(key)
1

# 参数

参数名 必传 类型 参数说明
key string 远程变量名(长度不能超过64位)

# 返回值

Object类型,例:{ result: { server_time: 1624122124, varValue: '斯奥特曼' }, message: 'ok', code: 0 }

# 获取远程数据

注意

调用此接口前 需要登录成功后才能调用。

# 语法

let ret = qcysdk.GetRemoteData(key)
1

# 参数

参数名 必传 类型 参数说明
key string 远程数据key(长度不能超过64位)

# 返回值

Object类型,例:{ result: { server_time: 1624122295, value: '奥特曼' }, message: 'ok', code: 0 }

# 操作远程数据

# 新增远程数据

注意

调用此接口前 需要登录成功后才能调用。

# 语法

let ret = qcysdk.CreateRemoteData(key, value)
1

# 参数

参数名 必传 类型 参数说明
key string 远程数据key(长度不能超过64位)
value string 远程数据值(长度不能超过256位)

# 返回值

Object类型,例:{ result: { server_time: 1624122453 }, message: 'ok', code: 0 }

# 修改远程数据

注意

调用此接口前 需要登录成功后才能调用。

# 语法

let ret = qcysdk.UpdateRemoteData(key, value)
1

# 参数

参数名 必传 类型 参数说明
key string 远程数据key(长度不能超过64位)
value string 远程数据值(长度不能超过256位)

# 返回值

Object类型,例:{ result: { server_time: 1624122453 }, message: 'ok', code: 0 }

# 删除远程数据

注意

调用此接口前 需要登录成功后才能调用。

# 语法

let ret = qcysdk.DeleteRemoteData(key)
1

# 参数

参数名 必传 类型 参数说明
key string 远程数据key(长度不能超过64位)

# 返回值

Object类型,例:{ result: { server_time: 1624122453 }, message: 'ok', code: 0 }

# 云函数

注意

调用此接口前 需要登录成功后才能调用。

# 语法

let ret = qcysdk.CallRemoteFn(fnName, params);
1

# 参数

参数名 必传 类型 参数说明
fnName string 云函数名(长度不能超过64位)
params string 调用云函数时传入的参数

# 返回值

Object类型,例:{"result":{"return":"55","server_time":1689788200},"message":"ok","sign":"236cd75d551fb991ac88684761778a17","nonce":"vwWSKfwOgbLocFzg15OX","code":0}

例子:

let ret = qcysdk.CallRemoteFn("add", "21, 34");
if (ret.code == 0){
  console.log("云函数调用结果:", ret.result.return)
}else{
  console.log("云函数调用失败:", ret.message)
}
1
2
3
4
5
6