# c++ SDK接入

7c云网络验证提供了c++对接,方便 c++ 开发者接入。

# 接入须知

# 对接视频

c++对接视频 (opens new window)

# 获取方式

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

# 使用方式

先将下载到的c++ QCYSDK.rar文件解压出来,双击QCYSDK.sln选择VisualStudio 2022打开 压缩包中包含卡密登录例子,和用户登录例子。

# 卡密登录例子

#include "QCYSDK.h"

//appKey 在你的7c云开发后台软件管理里面获取
const string appKey = "";
//appSecret 在你的7c云开发后台软件管理里面获取
const string appSecret = "";
const bool isLoginAgain = true;//开启断线重连
const bool autoHeartbeat = true;//开启心跳
QCYSDK qcysdk(appKey, appSecret, isLoginAgain, autoHeartbeat);

//下载进度的回调
void printProgress(int percentage) {
	std::cout << "\rDownloading: [";
	int pos = percentage / 2;
	for (int i = 0; i < 50; ++i) {
		if (i < pos) std::cout << "=";
		else if (i == pos) std::cout << ">";
		else std::cout << " ";
	}
	std::cout << "] " << percentage << "%" << std::flush;
}


int main() {
	qcysdk.token_path = "token.txt";//设备保存登录凭证token的路径
	//热更新,需要热更新的,请将下面代码块取消注释
	/*
	string localVersion = "1.0.2";//本地版本号
	string savePathfileName = "qcysdk.exe"; //保存的路径和文件名,自己更改
	Resp resp = qcysdk.GetSoftwareVersion();//获取版本号和下载链接,网页后台->软件管理里面设置
	if (resp.code == 0)
	{
		cout << "网络版本号" << resp.result.version << "下载链接" << resp.result.url << endl;
		if (resp.result.version != localVersion)
		{
			cout << "发现新版本-进行下载" << endl;
			if (qcysdk.DownLoadFile(resp.result.url, savePathfileName, printProgress)) {
				cout << "\nDownload completed successfully!" << std::endl;
			}
			else {
				cerr << "\nDownload failed!" << std::endl;
			}
		}
	}
	*/
	char card[50];
	cout << "请输入卡密:";
	cin >> card;
	qcysdk.SetCard(card);//设置使用的卡密
	qcysdk.CardLogout();//退出上次的登录
	Resp resp = qcysdk.CardLogin();//卡密登录
	if (resp.code == 0) {
		cout << "登录成功" << endl;
		cout << "到期时间:" << resp.result.expires << endl;
		//**************下面开始你的代码*********************
		
	}
	else {
		cout << "登录失败:" << resp.message << endl;
		Sleep(15000);
	}
	return 0;
}
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

# 用户登录例子

#include "QCYSDK.h"

//appKey 在你的7c云开发后台软件管理里面获取
const string appKey = "";
//appSecret 在你的7c云开发后台软件管理里面获取
const string appSecret = "";
const bool isLoginAgain = true;//开启断线重连
const bool autoHeartbeat = true;//开启心跳
QCYSDK qcysdk(appKey, appSecret, isLoginAgain, autoHeartbeat);

//下载进度的回调
void printProgress(int percentage) {
	std::cout << "\rDownloading: [";
	int pos = percentage / 2;
	for (int i = 0; i < 50; ++i) {
		if (i < pos) std::cout << "=";
		else if (i == pos) std::cout << ">";
		else std::cout << " ";
	}
	std::cout << "] " << percentage << "%" << std::flush;
}

int main() {
	qcysdk.token_path = "token.txt";//设备保存登录凭证token的路径
	//热更新,需要热更新的,请将下面代码块取消注释
	/*
	string localVersion = "1.0.2";//本地版本号
	string savePathfileName = "qcysdk.exe"; //保存的路径和文件名,自己更改
	Resp resp = qcysdk.GetSoftwareVersion();//获取版本号和下载链接,网页后台->软件管理里面设置
	if (resp.code == 0)
	{
		cout << "网络版本号" << resp.result.version << "下载链接" << resp.result.url << endl;
		if (resp.result.version != localVersion)
		{
			cout << "发现新版本-进行下载" << endl;
			if (qcysdk.DownLoadFile(resp.result.url, savePathfileName, printProgress)) {
				cout << "\nDownload completed successfully!" << std::endl;
			}
			else {
				cerr << "\nDownload failed!" << std::endl;
			}
		}
	}
	*/
	char username[30];
	char password[20];
	cout << "请输入账号:";
	cin >> username;
	cout << "请输入密码:";
	cin >> password;
	qcysdk.SetUser(username, password);//填写用户名和密码
	qcysdk.UserLogout();//退出上次的登录
	Resp resp = qcysdk.UserLogin();//卡密登录
	if (resp.code == 0) {
		cout << "登录成功" << endl;
		cout << "到期时间:" << resp.result.expires << endl;
		//**************下面开始你的代码*********************
		
	}
	else {
		cout << "登录失败:" << resp.message << endl;
		Sleep(5000);
	}
	return 0;
}

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

# 初始化

# 初始化SDK

# 语法

QCYSDK qcysdk(appKey, appSecret, isLoginAgain, autoHeartbeat);
1

# 参数

参数名 必传 类型 参数说明
appKey string 软件的appKey
appSecret string 软件的appSecret
autoHeartbeat boolean true开启心跳,false关闭心跳
isLoginAgain boolean true开启断线重登,false关闭断线重登

# 卡密登录

注意

调用此接口前需调用 qcysdk.SetCard(card) 初始化卡密 登录成功后将自动启动一个线程发送心跳包,开发者就无需关注发送心跳包的细节。

# 语法

qcysdk.SetCard(card);
Resp resp = qcysdk.CardLogin();
cout << "code=" << resp.code << " message=" << resp.message << endl;
cout << "cardType=" << resp.result.cardType << endl;
cout << "token=" << resp.result.token << endl;
cout << "expires=" << resp.result.expires << endl;
cout << "expires_ts=" << resp.result.expires_ts << endl;
cout << "config=" << resp.result.config << endl;
cout << "server_time=" << resp.result.server_time << endl;
1
2
3
4
5
6
7
8
9

# 参数

# 返回值

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

# 卡密心跳

注意

调用此接口前需调用 qcysdk.CardLogin 卡密登录 卡密登录成功后,将自动启动一个线程发送心跳包,开发者就无需关注发送心跳包的细节 如若关闭心跳,请设置autoHeartbeat = false

# 语法

Resp resp = qcysdk.CardHeartbeat()
1

# 参数

# 返回值

Resp结构体类型,例:{ "code": 0, "message": "ok", "result": { "expires": "2020-10-16 00:47:58", "expires_ts": 1602780478, "server_time": 1574654207 } }

# 卡密退出登录

# 语法

Resp resp = qcysdk.CardLogout();
cout << "code=" << resp.code << " message=" << resp.message << endl;
1
2

# 参数

# 返回值

Resp结构体类型,例:{"code": 0, "message": "OK"}

# 卡密解绑设备

注意

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

# 语法

Resp resp = qcysdk.CardUnbindDevice();
cout << "code=" << resp.code << " message=" << resp.message << endl;
1
2

# 参数

# 返回值

Resp结构体类型,例:{"code": 0, "message": "OK"}

# 卡密绑定设备上解绑

注意

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

# 语法

Resp resp = qcysdk.CardUnbindDeviceBybindDevice();
cout << "code=" << resp.code << " message=" << resp.message << endl;
1
2

# 参数

# 返回值

Resp结构体类型,例:{"code": 0, "message": "OK"}

# 卡密设置解绑密码

说明

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

# 语法

Resp res = qcysdk.SetCardUnbindPassword(password);
1

# 参数

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

# 返回值

Resp结构体类型,例:{"code": 0, "message": "OK"}

# 卡密通过密码解绑设备

说明

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

# 语法

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

# 返回值

Resp结构体类型,例:{"code": 0, "message": "OK"}

# 卡密充值(以卡充卡)

# 语法

Resp resp = qcysdk.CardRecharge(card, useCard);
1

# 参数

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

# 返回值

Resp结构体类型,例:{"code": 0, "message": "OK"}

# 卡密充值(以卡充卡仅限新卡)

# 语法

Resp resp = qcysdk.CardNewRecharge(card, useCard);
1

# 参数

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

# 返回值

Resp结构体类型,例:{"code": 0, "message": "OK"}

# 获取卡密邀请码

# 语法

Resp resp = qcysdk.GetIc(card);
1

# 参数

参数名 必传 类型 参数说明
card string 获取邀请码的卡密(长度不超过45位)

# 返回值

Resp结构体类型,例:{result :{"ic": "60ff56305eafe963d1f0561e", server_time: 1624110506}, "code": 0, "message": "OK"}

# 卡密邀请充值(通过卡密)

接口说明

B用户使用A用户邀请码并充值成功,A用户会获得赠送时间 赠送时间在网页后台设置 软件管理 编辑 卡类配置

# 语法

Resp resp = qcysdk.CardIcRecharge(card, useCard, ic);
1

# 参数

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

# 返回值

Resp结构体类型,例:{"code": 0, "message": "OK"}

# 用户注册(通过卡密)

# 语法

Resp res = qcysdk.UserRegister(username, password, card);
1

# 参数

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

# 返回值

Resp结构体类型,例:{"code": 0, "message": "ok"}

# 用户登录

注意

调用此接口前需调用 qcysdk.SetUser(username, password) 初始化用户账号密码 登录成功后将自动启动一个线程发送心跳包,开发者就无需关注发送心跳包的细节。

# 语法

qcysdk.SetUser(username, password);
Resp resp = qcysdk.UserLogin();
cout << "code=" << resp.code << " message=" << resp.message << endl;
cout << "cardType=" << resp.result.cardType << endl;
cout << "token=" << resp.result.token << endl;
cout << "expires=" << resp.result.expires << endl;
cout << "expires_ts=" << resp.result.expires_ts << endl;
cout << "config=" << resp.result.config << endl;
cout << "server_time=" << resp.result.server_time << endl;
1
2
3
4
5
6
7
8
9

# 参数

# 返回值

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

# 用户心跳

注意

调用此接口前需调用 qcysdk.UserLogin 用户登录 用户登录成功后,将自动启动一个线程发送心跳包,开发者就无需关注发送心跳包的细节 如若关闭心跳,请设置autoHeartbeat = false

# 语法

Resp resp = qcysdk.UserHeartbeat()
1

# 参数

# 返回值

Resp结构体类型,例:{ "code": 0, "message": "ok", "result": { "expires": "2020-10-16 00:47:58", "expires_ts": 1602780478, "server_time": 1574654207 } }

# 用户退出登录

# 语法

Resp resp = qcysdk.UserLogout();
1

# 参数

# 返回值

Resp结构体类型,例:{"code": 0, "message": "OK"}

# 用户修改密码

# 语法

Resp resp = qcysdk.UserChangePassword(username, oldPassword, newPassword);
1

# 参数

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

# 返回值

Resp结构体类型,例:{"code": 0, "message": "OK"}

# 用户充值(通过卡密)

# 语法

Resp resp = qcysdk.UserRecharge(username, card);
1

# 参数

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

# 返回值

Resp结构体类型,例:{"code": 0, "message": "OK"}

# 用户邀请充值(通过卡密)

接口说明

B用户充值时填写邀请人A用户账号充值并充值成功,A用户会获得赠送时间 赠送时间在网页后台设置 软件管理 编辑 卡类配置

# 语法

Resp resp = qcysdk.UserIcRecharge(username, icusername, card);
1

# 参数

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

# 返回值

Resp结构体类型,例:{"code": 0, "message": "OK"}

# 用户解绑设备

# 语法

Resp resp = qcysdk.UserUnbindDevice();
1

# 参数

# 返回值

Resp结构体类型,例:{"code": 0, "message": "OK"}

# 试用登录

注意

登录成功后将自动启动一个线程发送心跳包,开发者就无需关注发送心跳包的细节。

# 语法

Resp resp = qcysdk.TrialLogin();
1

# 参数

# 返回值

Resp结构体类型,如:{"result":{"expires":"2025-08-21 01:18:54","expires_ts":1755710335,"server_time":1755709735},"message":"ok","sign":"b425171d29c97ab68872fca982fd5cca","nonce":"dkERQBBP8npatEkwRxFP","code":0}

# 试用心跳

注意

调用此接口前需调用 qcysdk.TrialLogin 试用登录 试用登录成功后,将自动启动一个线程发送心跳包,开发者就无需关注发送心跳包的细节

# 语法

Resp resp = qcysdk.TrialHeartbeat()
1

# 参数

# 返回值

Resp结构体类型,例:{ "code": 0, "message": "ok", "result": { "expires": "2020-10-16 00:47:58", "expires_ts": 1602780478, "server_time": 1574654207 } }

# 获取卡密配置

# 语法

Resp resp = qcysdk.GetCardConfig();
1

# 参数

# 返回值

Resp结构体类型,例:{ result: { config: '', server_time: 1624120946 }, message: 'ok', code: 0 }

# 更改卡密配置

# 语法

Resp resp = qcysdk.UpdateCardConfig(config);
1

# 参数

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

# 返回值

Resp结构体类型,例:{"code": 0, "message": "OK"}

# 获取用户配置

# 语法

Resp resp = qcysdk.GetUserConfig();
1

# 参数

# 返回值

Resp结构体类型,例:{ result: { config: '迪迦', server_time: 1624121563 }, message: 'ok', code: 0 }

# 更改用户配置

# 语法

Resp resp = qcysdk.UpdateUserConfig(config);
1

# 参数

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

# 返回值

Resp结构体类型,例:{"code": 0, "message": "OK"}

# 获取软件配置

# 语法

Resp resp = qcysdk.GetSoftwareConfig();
1

# 参数

# 返回值

Resp结构体类型,例:{ result: { config: '迪迦', server_time: 1624121758 }, message: 'ok', code: 0 }

# 获取软件公告

# 语法

Resp resp = qcysdk.GetSoftwareNotice();
1

# 参数

# 返回值

Resp结构体类型,例:{ result: { server_time: 1624121862, notice: '泰罗' }, message: 'ok', code: 0 }

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

# 语法

Resp resp = qcysdk.GetSoftwareVersion();
1

# 参数

# 返回值

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

# 获取远程变量

注意

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

# 语法

Resp resp = qcysdk.GetRemoteVar(key);
1

# 参数

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

# 返回值

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

# 获取远程数据

注意

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

# 语法

Resp resp = qcysdk.GetRemoteData(key);
1

# 参数

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

# 返回值

Resp结构体类型,例:{ result: { server_time: 1624122295, value: '奥特曼' }, message: 'ok', code: 0 }

# 操作远程数据

# 新增远程数据

注意

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

# 语法

Resp resp = qcysdk.CreateRemoteData(key, value);
1

# 参数

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

# 返回值

Resp结构体类型,例:{ result: { server_time: 1624122453 }, message: 'ok', code: 0 }

# 修改远程数据

注意

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

# 语法

Resp resp = qcysdk.UpdateRemoteData(key, value);
1

# 参数

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

# 返回值

Resp结构体类型,例:{ result: { server_time: 1624122453 }, message: 'ok', code: 0 }

# 删除远程数据

注意

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

# 语法

Resp resp = qcysdk.DeleteRemoteData(key);
1

# 参数

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

# 返回值

Resp结构体类型,例:{ result: { server_time: 1624122453 }, message: 'ok', code: 0 }

# 云函数

注意

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

# 语法

Resp resp = qcysdk.CallRemoteFn(fnName, params);
1

# 参数

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

# 返回值

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

例子:

Resp resp = qcysdk.CallRemoteFn("add", "21, 34");
if (resp.code == 0)
{
  cout << "云函数调用结果:" << resp.result.returnValue << endl;
}
else
{
  cout << "云函数调用失败:" << resp.message << endl;
}
1
2
3
4
5
6
7
8
9

# 热更新(下载软件)

注意

调用此接口前 需要初始化后才能调用。

# 语法

qcysdk.DownLoadFile(url, savePath, printProgress);
1

# 参数

参数名 必传 类型 参数说明
url string 下载链接
savePath string 下载后保存的路径
printProgress function 下载进度的回调函数

# 返回值 布尔值

例子:

//下载进度的回调
void printProgress(int percentage) {
	std::cout << "\rDownloading: [";
	int pos = percentage / 2;
	for (int i = 0; i < 50; ++i) {
		if (i < pos) std::cout << "=";
		else if (i == pos) std::cout << ">";
		else std::cout << " ";
	}
	std::cout << "] " << percentage << "%" << std::flush;
}

string localVersion = "1.0.0";//本地版本号
string savePathfileName = "qcysdk.exe"; //保存的路径和文件名,自己更改
Resp resp = qcysdk.GetSoftwareVersion();//获取版本号和下载链接,网页后台->软件管理里面设置
if (resp.code == 0)
{
	cout << "网络版本号" << resp.result.version << "下载链接" << resp.result.url << endl;
	if (resp.result.version != localVersion)
	{
		cout << "发现新版本-进行下载" << endl;
		if (qcysdk.DownLoadFile(resp.result.url, savePathfileName, printProgress)) {
			cout << "\nDownload completed successfully!" << std::endl;
		}
		else {
			cerr << "\nDownload failed!" << std::endl;
		}
	}
}
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