|
@@ -26,6 +26,8 @@
|
26
|
26
|
clock_t start;
|
27
|
27
|
clock_t endtime;
|
28
|
28
|
|
|
29
|
+//#define VERSION_V2
|
|
30
|
+
|
29
|
31
|
PostClient* PostClient::getInstance()
|
30
|
32
|
{
|
31
|
33
|
static PostClient value;
|
|
@@ -48,7 +50,12 @@ void PostClient::ClientInit(QString account, QString password)
|
48
|
50
|
connect(manager, &QNetworkAccessManager::finished, this, &PostClient::PostBack);//通信完成后,自动执行getBack
|
49
|
51
|
task = SIGNIN;
|
50
|
52
|
QString str = "{\"type\":\"1\",\"account\":\"" + account + "\",\"password\":\"" + password + "\"}";
|
|
53
|
+
|
|
54
|
+#ifdef VERSION_V2
|
|
55
|
+ SendPost(str, "/login");
|
|
56
|
+#else
|
51
|
57
|
SendPost(str);
|
|
58
|
+#endif
|
52
|
59
|
LOG_DEBUG("登录信息发送成功!!");
|
53
|
60
|
}
|
54
|
61
|
/*
|
|
@@ -247,19 +254,24 @@ void PostClient::PostImgToServer(std::string data1, std::string data2)
|
247
|
254
|
{
|
248
|
255
|
task = JIER;
|
249
|
256
|
QString str = "{\"type\":\"2\",\"key\":\"" + key + "\",\"img1\":\"" + QString::fromStdString(data1) + "\",\"img2\":\"" + QString::fromStdString(data2) + "\"}";
|
|
257
|
+
|
|
258
|
+#ifdef VERSION_V2
|
|
259
|
+ SendPost(str, "/measure/process");
|
|
260
|
+#else
|
250
|
261
|
SendPost(str);
|
|
262
|
+#endif
|
251
|
263
|
}
|
252
|
264
|
/*
|
253
|
265
|
* @brief 向服务器发送请求
|
254
|
266
|
* @param QString sendString 所要发送的json字符串
|
255
|
267
|
* @return void
|
256
|
268
|
*/
|
257
|
|
-void PostClient::SendPost(QString sendString)
|
|
269
|
+void PostClient::SendPost(QString sendString, QString path)
|
258
|
270
|
{
|
259
|
271
|
QByteArray dataArray = sendString.toUtf8();
|
260
|
272
|
// 构造请求
|
261
|
273
|
static QNetworkRequest request;
|
262
|
|
- request.setUrl(QUrl("https://api.chanivision.com/api/"));
|
|
274
|
+ request.setUrl(QUrl("https://api.chanivision.com/api/" + path));
|
263
|
275
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json;charset=utf-8");
|
264
|
276
|
// 发送请求
|
265
|
277
|
start = clock();
|
|
@@ -311,7 +323,11 @@ void PostClient::PostBack(QNetworkReply* reply)
|
311
|
323
|
QJsonObject jsonObject = doucment.object();
|
312
|
324
|
if (task == SIGNIN) //登录任务解析数据
|
313
|
325
|
{
|
|
326
|
+#ifdef VERSION_V2
|
|
327
|
+ if (jsonObject.value("code").toInt() == 0)
|
|
328
|
+#else
|
314
|
329
|
if (jsonObject.value("code").toInt() == 1)
|
|
330
|
+#endif
|
315
|
331
|
{
|
316
|
332
|
qDebug() << "Sign in finished!";
|
317
|
333
|
key = jsonObject.value("key").toString();
|
|
@@ -357,8 +373,18 @@ void PostClient::ParseJson(QJsonObject jsonObject)
|
357
|
373
|
{
|
358
|
374
|
std::multimap<int, QRect> errorsRect;
|
359
|
375
|
|
|
376
|
+#ifdef VERSION_V2
|
|
377
|
+ if (jsonObject.contains("code") && jsonObject.value("code").toInt() != 0)
|
|
378
|
+ {
|
|
379
|
+ // TODO 处理错误
|
|
380
|
+ }
|
|
381
|
+
|
|
382
|
+ // TODO
|
|
383
|
+
|
|
384
|
+#else
|
360
|
385
|
if (jsonObject.contains("code"))
|
361
|
386
|
{
|
|
387
|
+
|
362
|
388
|
if (jsonObject.value("code").toInt() == 3)
|
363
|
389
|
{
|
364
|
390
|
emit(sendInformation(QStringLiteral("执行失败!(code:3)")));
|
|
@@ -415,6 +441,7 @@ void PostClient::ParseJson(QJsonObject jsonObject)
|
415
|
441
|
}
|
416
|
442
|
LOG_INFO(rltStr.toStdString().c_str());
|
417
|
443
|
emit(sendParseResult(errorsRect)); //emit检测框的类别以及对应的位置信息
|
|
444
|
+#endif
|
418
|
445
|
}
|
419
|
446
|
|
420
|
447
|
|