-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAliyunThingManager.cpp
More file actions
94 lines (83 loc) · 4.55 KB
/
AliyunThingManager.cpp
File metadata and controls
94 lines (83 loc) · 4.55 KB
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
/**
******************************************************************************
* @file AliyunThingManager.cpp
* @author Junxin Zheng
* @version V1.0.0
* @date 5-January-2019
* @brief ...
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "AliyunThingManager.h"
/* Variables -----------------------------------------------------------------*/
/* Function ------------------------------------------------------------------*/
/*******************************************************************************
* @brief Construct function.
* @param QString key - The AppKey of Aliyun API Platform.
* QString secret - The AppSecret of Aliyun API Platform.
* QString host - The host of Aliyun API Platform.
* QString parent - Pointer of parent object
* @retval None.
*****************************************************************************/
AliyunThingManager::AliyunThingManager(const QString &key, const QString &secret, const QString &host, QObject *parent) :
AliyunIoTClient(key, secret, host, parent)
{
// Do Nothing.
}
/*******************************************************************************
* @brief Send Requset to Aliyun API Platform.
* @param ThingManageAPI api - The Url of Api.
* AliyunThingJson json - The Data (json file) to send.
* qint32 timeout - Timeout.
* @retval None.
*****************************************************************************/
void AliyunThingManager::sendRequest(ThingManageAPI api, const AliyunThingJson &json, qint32 timeout)
{
QString url;
switch(api)
{
case getThingDetail: url = "/thing/device/detail/get"; break; // getThingDetail - Get detail information for the object.
case getThingExtendInfo: url = "/thing/device/extendinfo/get"; break; // getThingExtendInfo - Get extended information for the object.
case getThingInfo: url = "/thing/device/info/get"; break; // getThingInfo - Get basal information for the object.
case getThingProperties: url = "/thing/device/properties/query"; break; // getThingProperties - Get all the attribute snapshot data for the object.
case getThingProperty: url = "/thing/device/property/query"; break; // getThingProperty - Get one attribute snapshot data for the object.
case getThingPropertyTimeline: url = "/thing/device/property/timeline/get"; break; // getThingPropertyTimeline - Get all the attribute data for the object.
case queryThingCount: url = "/thing/device/count"; break; // queryThingCount - Get the number of object.
case queryPropertyByProductKey:url = "/thing/product/properties/get"; break; // queryPropertyByProductKey - Get the properities of product.
}
AliyunIoTClient::sendRequest(url, getContent(json), timeout);
}
/*******************************************************************************
* @brief Get Content adapting to format of Aliyun API Platform.
* @param AliyunThingJson json.
* @retval None.
*****************************************************************************/
QString AliyunThingManager::getContent(const AliyunThingJson &json)
{
QJsonObject params
{
{"productKey", QJsonValue(json.productKey)},
{"deviceName", QJsonValue(json.deviceName)},
{"propertyIdentifier", QJsonValue(json.propertyIdentifier)},
{"start", QJsonValue(json.start)},
{"end", QJsonValue(json.end)},
{"pageSize", QJsonValue(json.pageSize)},
{"ordered", QJsonValue(json.ordered)}
};
QJsonObject request
{
{"iotToken", QJsonValue("xxxx")},
{"apiVer", QJsonValue(json.apiVer)}
};
QJsonObject body
{
{"id", QJsonValue(getUuid())},
{"version", QJsonValue(json.version)},
{"request", request},
{"params", params}
};
qDebug() << endl << "--------- Content ---------";
printFormattedJson(body);
return QString(QJsonDocument(body).toJson(QJsonDocument::Compact));
}
/**************** (C) COPYRIGHT 2019 Junxin Zheng ******** END OF FILE ********/