huchao 2 年之前
父节点
当前提交
0a48780f6c
共有 2 个文件被更改,包括 30 次插入3 次删除
  1. 29 2
      src/client/client.cpp
  2. 1 1
      src/client/client.h

+ 29 - 2
src/client/client.cpp

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

+ 1 - 1
src/client/client.h

@@ -33,7 +33,7 @@ public:
33
 
33
 
34
 	void ClientInit(QString account, QString password);//客户端初始化,登录
34
 	void ClientInit(QString account, QString password);//客户端初始化,登录
35
 	void Register(QString account, QString password);//注册账户
35
 	void Register(QString account, QString password);//注册账户
36
-	void SendPost(QString sendString);//向服务器发送请求
36
+	void SendPost(QString sendString, QString path = "");//向服务器发送请求
37
 	void PostImgToServer(std::string data1, std::string data2);//发送参考图和检测图到服务器
37
 	void PostImgToServer(std::string data1, std::string data2);//发送参考图和检测图到服务器
38
 	void ParseJson(QJsonObject jsonObject);//解析服务器返回结果
38
 	void ParseJson(QJsonObject jsonObject);//解析服务器返回结果
39
 
39