接口说明
更新时间:2025-03-07 15:58:55
接口集合,包括:用户登录、登出,设备列表,直播等功能。开发可先阅读用户账号开发指南
接口集
#pragma once
#include <stdint.h>
#include <functional>
#include <string>
#include <memory>
#include "AccountDevice.h"
namespace rtx
{
namespace pcsdk
{
// 错误码
enum RtcxPcCode {
RTCX_PC_SUCCESS = 0,
RTCX_PC_FAIL = -1
};
// 初始化参数
struct InitParam
{
std::string cfgFileName = "config.ini"; // 配置文件名
std::string appKey;
std::string appSecret;
};
// 事件回调接口
class IRtcxPcEvtHandler
{
public:
typedef std::shared_ptr<IRtcxPcEvtHandler> Ptr;
IRtcxPcEvtHandler() {}
virtual ~IRtcxPcEvtHandler() {}
// 上线回调
virtual void OnConnection(int errCode, const std::string &message) = 0;
};
// 接口
class IRtcxPcApi
{
public:
typedef std::shared_ptr<IRtcxPcApi> Ptr;
IRtcxPcApi() {}
virtual ~IRtcxPcApi() {}
// 初始化
static int32_t Initialize(const InitParam ¶m);
// 反初始化
static int32_t Uninitialize();
// 创建PC API智能指针
static IRtcxPcApi::Ptr CreateRtcxPcApi(const std::shared_ptr<IRtcxPcEvtHandler> handler);
// 登入
virtual int32_t Login(const std::string &userName, const std::string &password) = 0;
// 登出
virtual int32_t Logout() = 0;
// 获取设备列表
virtual std::shared_ptr<rtx::account::DeviceList> GetDeviceList(const rtx::account::DeviceListReq &deviceListReq) = 0;
// 获取设备分组列表
virtual std::shared_ptr<rtx::account::DeviceGroupList> GetDeviceGroupList(const rtx::account::DeviceGroupListReq &deviceGroupListReq) = 0;
// 开始播放
virtual void StartPlay(const std::string &deviceName, const std::string &productKey, void *hWnd) = 0;
// 结束播放
virtual void StopPlay() = 0;
};
}
}
用户登录与登出
InitParam param;
param.appKey = "aaaaaaaa";
param.appSecret = "bbbbbbbbbbbbbbb";
IRtcxPcApi::Initialize(param);
std::shared_ptr<TestPcEvtHandler> handler = std::make_shared<TestPcEvtHandler>();
IRtcxPcApi::Ptr pcapi = IRtcxPcApi::CreateRtcxPcApi(handler);
// 用户登录
pcapi->Login("xxxx", "yyyyy");
// ....
// 用户登出
pcapi->Logout();
获取设备列表
// 获取设备列表,默认只获取第一页,所有列表需要自行遍历获取
rtx::account::DeviceListReq req;
std::shared_ptr<rtx::account::DeviceList> resp = pcapi->GetDeviceList(req);
if (resp && resp->total > 0)
{
std::cout << "total:" << resp->total << ", pageNo:" << resp->pageNo << ", pageSize:" << resp->pageSize << std::endl;
for (size_t i = 0; i < resp->data.size(); i++)
{
const rtx::account::DeviceInfo &deviceInfo = resp->data[i];
iotIdDeviceMap[deviceInfo.iotId] = deviceInfo;
std::cout << deviceInfo.toJsonString() << std::endl;
}
}
// 请求参数结构
struct DeviceListReq
{
/**
* 该参数仅调用客户端API时生效,主要用于确认请求发起者的系统参数,使用生活物联网平台提供的账号SDK时该值会自动生成。
*/
std::string iotToken;
/**
* 当前页码,从1开始。
*/
uint32_t pageNo = 1;
/**
* 分页大小,大于等于1,小于等于100。
*/
uint32_t pageSize = 100;
/**
* 绑定类型。取值为:0(表示被分享的设备);1(表示拥有的设备);null(表示所有的设备)。
*/
OwnedType owned = OwnedType::ALL;
/**
* 分组id,可按照分组id过滤列表
*/
uint64_t groupId = 0;
/**
* 是否为子设备,true(表示获取子设备列表),false(表示获取直连设备列表)
*/
bool isSubDevice = false;
};
// 响应参数结构
enum class OwnedType : uint32_t
{
/**
* 分享者
*/
SHARED = 0,
/**
* 拥有者
*/
OWNED = 1
};
enum class DeviceStatus : uint32_t
{
/**
* 未激活
*/
INACTIVE = 0,
/**
* 在线
*/
ONLINE = 1,
/**
* 离线
*/
OFFLINE = 3,
/**
* 禁用
*/
DISABLE = 8
};
enum class NodeType : uint32_t
{
/**
* 普通节点
*/
DEVICE = 0,
/**
* 网关节点
*/
GATEWAY = 1,
UNKNOWN = 10000
};
enum class NetType : uint32_t
{
/**
* 表示LoRa
*/
NET_LORA = 0,
/**
* 表示2G/3G/4G/5G蜂窝网
*/
NET_CELLULAR = 1,
/**
* 表示Wi-Fi
*/
NET_WIFI = 2,
/**
* 表示ZigBee
*/
NET_ZIGBEE = 3,
/**
* 表示以太网
*/
NET_ETHERNET = 4,
/**
* 表示其他 网络类型
*/
NET_OTHER = 5,
/**
* 未知
*/
NET_UNKNOWN = 10000
};
struct DeviceInfo
{
/**
* 用户的身份ID。
*/
uint64_t identityId;
/**
* 平台为设备颁发的ID,设备的唯一标识符。
*/
std::string iotId;
std::string deviceName;
std::string productKey;
std::string productName;
/**
* 设备所属产品的型号。
*/
std::string productModel;
/**
* 设备的昵称
*/
std::string nickName;
/**
* 产品下设备的联网方式,可取值: NET_LORA(表示LoRa);NET_CELLULAR(表示2G/3G/4G/5G蜂窝网);NET_WIFI(表示Wi-Fi);NET_ZIGBEE(表示ZigBee);NET_ETHERNET(表示以太网);NET_OTHER(表示其他网络类型)。
*/
NetType netType = NetType::NET_UNKNOWN;
/**
* DEVICE:普通设备
*/
std::string thingType;
/**
* 设备状态。0(表示未激活);1(表示在线);3(表示离线);8(表示禁用)。
*/
DeviceStatus status = DeviceStatus::OFFLINE;
/**
* 设备和用户的关系,可取值:0(表示分享者),1(表示拥有者)。
*/
OwnedType owned = OwnedType::ALL;
/**
* 设备的节点类型,可取值包括:DEVICE,GATEWAY。
*/
NodeType nodeType = NodeType::DEVICE;
/**
* gmtModified
*/
uint64_t gmtModified;
/**
* 设备当前所在的机房
*/
std::string region;
/**
* 只有owned=0有值,分享权限列表,live:直播,control:设备控制,record:录像回看,ptz:云台控制,voiceIntercom:语音对讲,setting:高级设置,notification:消息通知
*/
std::vector<std::string> sharePermissionList;
/**
* 分组id
*/
uint64_t groupId = 0;
};
struct DeviceList
{
/**
* 列表总数
*/
uint32_t total;
/**
* 当前页码
*/
uint32_t pageNo;
/**
* 分页大小
*/
uint32_t pageSize;
/**
* 设备列表详细信息
*/
std::vector<DeviceInfo> data;
};
获取设备分组列表
std::map<uint64_t, std::string> groupMap;
bool bHasMore = false;
int pageNo = 1;
do {
DeviceGroupListReq deviceGroupListReq;
deviceGroupListReq.pageNo = pageNo;
deviceGroupListReq.pageSize = 100;
std::shared_ptr<DeviceGroupList> deviceGroupList = pcapi->GetDeviceGroupList(deviceGroupListReq);
if (deviceGroupList && deviceGroupList->total > 0) {
bHasMore = deviceGroupList->total > deviceGroupList->pageNo * deviceGroupList->pageSize;
}
pageNo++;
for (size_t i = 0; i < deviceGroupList->items.size(); i++)
{
DevicGroupInfo& groupInfo = deviceGroupList->items[i];
groupMap[groupInfo.groupId] = groupInfo.name;
}
} while (bHasMore);
// 请求参数结构
struct DeviceGroupListReq
{
/**
* 该参数仅调用客户端API时生效,主要用于确认请求发起者的系统参数,使用生活物联网平台提供的账号SDK时该值会自动填充。
*/
std::string iotToken;
/**
* 当前页码,从1开始。
*/
uint32_t pageNo = 1;
/**
* 分页大小,大于等于1,小于等于100。
*/
uint32_t pageSize = 100;
};
// 响应参数结构
struct DevicGroupInfo
/**
* 分组id
*/
uint64_t groupId;
/**
* 设备组的名称
*/
std::string name;
};
struct DeviceGroupList
{
/**
* 列表总数
*/
uint32_t total;
/**
* 当前页码
*/
uint32_t pageNo;
/**
* 分页大小
*/
uint32_t pageSize;
/**
* 设备分组列表详细信息
*/
std::vector<DevicGroupInfo> items;
};
开始播放和停止播放
// 开始播放
pcapi->StartPlay(deviceInfoPtr->deviceName, deviceInfoPtr->productKey, renderHwnd);
// 停止播放
pcapi->StopPlay();