Browse Source

1、reportToolsLog返回值是json格式;
2、删除\n \t 两字符;

scbc.sat2 5 năm trước cách đây
mục cha
commit
ef71013f01

+ 23 - 1
TCL Copy Tool/TCL Copy Tool/Global.cpp

@@ -99,6 +99,19 @@ namespace Global
 		free(old_locale); //»¹Ô­ÇøÓòÉ趨;
 	}
 
+
+	void replace_str(std::string& str, const std::string& before, const std::string& after)
+	{
+		for (std::string::size_type pos(0); pos != std::string::npos; pos += after.length())
+		{
+			pos = str.find(before, pos);
+			if (pos != std::string::npos)
+				str.replace(pos, before.length(), after);
+			else
+				break;
+		}
+	}
+
 	void WriteReportLog(int type, std::string des, const TCHAR* format, ...)
 	{
 		if (Global::g_tConfig.com.size() == 0)
@@ -122,8 +135,17 @@ namespace Global
 		}
 		_vstprintf_s(buffer, len, format, args);
 
+		std::string content = buffer;
+		content.erase(std::remove(content.begin(), content.end(), '\n'), content.end());
+		content.erase(std::remove(content.begin(), content.end(), '\t'), content.end());
 		std::map<std::string, std::string> report_data;
-		report_data.insert(std::pair<std::string, std::string>(des, buffer));
+		report_data.insert(std::pair<std::string, std::string>(des, content));
+		report_data.insert(std::pair<std::string, std::string>("PC-MAC", g_strMacs));
+		report_data.insert(std::pair<std::string, std::string>("TV-VER", g_midInfo.version));
+		report_data.insert(std::pair<std::string, std::string>("TV-CLIENTTYPE", g_midInfo.clienttype));
+		report_data.insert(std::pair<std::string, std::string>("FAC-IP", g_midInfo.factoryip));
+		report_data.insert(std::pair<std::string, std::string>("FAC-NAME", g_midInfo.factoryname));
+		report_data.insert(std::pair<std::string, std::string>("HOST", g_midInfo.host));
 		if ( type == 0 )
 			g_db.InsertReportInfo("NetWork", report_data);
 		else if ( type == 1 )

+ 36 - 3
TCL Copy Tool/TCL Copy Tool/OTA.cpp

@@ -1730,7 +1730,7 @@ BOOL COTA::GetKeyInfo(std::string host, std::string context, std::string keyname
 {
 	AUTOTIMING;
 	std::string result;
-	if (!HttpPost(host, context, result))
+	if (!HttpPost(host, context, result, DATA_JSON))
 	{
 		return FALSE;
 	}
@@ -1832,10 +1832,12 @@ BOOL COTA::GetKeyInfo(std::string host, std::string context, std::string keyname
 
 				return FALSE;
 			}
+
+			return TRUE;
 		}
 	}
 
-	return TRUE;
+	return FALSE;
 }
 
 void COTA::UpgradeCheck(std::string factoryNum)
@@ -2085,7 +2087,7 @@ BOOL COTA::ReportLog(TReportData& repdata)
 	// post请求;
 	std::string strHttpUrl, strResHttp, strContext;
 	strContext = pJsonText;
-	strHttpUrl = _T("https://cn.ota.qhmoka.com/ota-services/report/reportToolsLog.do");
+	strHttpUrl = _T("https://cn.ota.qhmoka.com/ota-services/report/reportToolsLog");
 	HttpPost(strHttpUrl.c_str(), strContext.c_str(), strResHttp, DATA_JSON);
 
 	// 释放Json;
@@ -2117,6 +2119,37 @@ BOOL COTA::ReportLog(TReportData& repdata)
 	return FALSE;
 }
 
+BOOL COTA::ReportLog(std::string url, std::string content)
+{
+	AUTOTIMING;
+	// post请求;
+	std::string result;
+	if (!HttpPost(url, content, result, DATA_JSON))
+		return FALSE;
+
+	// 释放Json;
+	cJSON *pJson = cJSON_Parse(result.c_str());
+	if (pJson == NULL)
+	{
+		LOG4C((LOG_WARN, "解析JSON失败:post=%s;return=%s", content.c_str(), result.c_str()));
+		Global::WriteReportLog(0, __FUNCTION__, "JSON Parsing Error: host=%s, content=%s, result=%s", url.c_str(), content.c_str(), result.c_str());
+
+		return FALSE;
+	}
+
+	std::string code = cJSON_GetObjectItem(pJson, "code") ? cJSON_GetObjectItem(pJson, "code")->valuestring : "";
+	cJSON_Delete(pJson);
+	pJson = NULL;
+	if (_tcsicmp(code.c_str(), _T("1000")) == 0)
+	{
+		return TRUE;
+	}
+
+	Global::WriteReportLog(0, __FUNCTION__, "http Code is not equal to 1000: host=%s, content=%s, result=%s", url.c_str(), content.c_str(), result.c_str());
+
+	return FALSE;
+}
+
 BOOL COTA::GetVCode(std::string mac, std::string& vcode)
 {
 	std::string result;

+ 1 - 0
TCL Copy Tool/TCL Copy Tool/OTA.h

@@ -237,6 +237,7 @@ public:
 	void ReportUpgrade(BOOL bUpgrade, std::string ver, std::string num);
 	BOOL DownloadFile(std::string url, std::string savePath);
 	BOOL ReportLog(TReportData &repdata);
+	BOOL ReportLog(std::string url, std::string content);
 	BOOL GetVCode(std::string mac, std::string &vcode);
 };
 

+ 11 - 1
TCL Copy Tool/TCL Copy Tool/TCL Copy Tool.cpp

@@ -111,6 +111,7 @@ BOOL CTCLToolsApp::InitInstance()
 	// 启动线程上报;
 	std::thread t([]() {
 		COTA ota;
+		BOOL bRet;
 		std::string xml;
 		std::vector<STReport> vt;
 		while (true)
@@ -119,7 +120,16 @@ BOOL CTCLToolsApp::InitInstance()
 			g_db.QueryUnReportInfo(vt);
 			for (auto it : vt)
 			{
-				if (ota.GetKeyInfo(it.url, it.content, "", "", xml))
+				if ( _tcsicmp("https://cn.ota.qhmoka.com/ota-services/report/reportToolsLog", it.url.c_str()) == 0 )
+				{
+					bRet = ota.ReportLog(it.url, it.content);
+				}
+				else
+				{
+					bRet = ota.GetKeyInfo(it.url, it.content, "", "", xml);
+				}
+
+				if (bRet)
 				{
 					// 上报成功;
 					g_db.UpdateKeyReportStatus(it);

+ 41 - 41
TCL Copy Tool/TCL Copy Tool/db.cpp

@@ -195,27 +195,27 @@ INT CDataImpl::QueryUnReportInfo(std::vector<STReport>& vtdata)
 	return nRow;
 }
 
-INT CDataImpl::InsertReportInfo(STReport& data)
-{
-	if(m_psqlite3 == NULL)
-		return -1;
-
-	std::string strInsert = "INSERT INTO report(url, content)VALUES ('";
-	strInsert.append(data.url);
-	strInsert.append("','");
-	strInsert.append(data.content);
-	strInsert.append("');");
-
-	char* psqlite_error = NULL;
-	int sqlite_error = sqlite3_exec(m_psqlite3, strInsert.c_str(), NULL, 0, &psqlite_error);
-	if(SQLITE_OK != sqlite_error)
-	{
-		//Global::WriteTextLog(_T("InsertContactsType:%s"), psqlite_error);
-		FREE_MSG;
-	}
-
-	return sqlite_error;
-}
+// INT CDataImpl::InsertReportInfo(STReport& data)
+// {
+// 	if(m_psqlite3 == NULL)
+// 		return -1;
+// 
+// 	std::string strInsert = "INSERT INTO report(url, content)VALUES ('";
+// 	strInsert.append(data.url);
+// 	strInsert.append("','");
+// 	strInsert.append(data.content);
+// 	strInsert.append("');");
+// 
+// 	char* psqlite_error = NULL;
+// 	int sqlite_error = sqlite3_exec(m_psqlite3, strInsert.c_str(), NULL, 0, &psqlite_error);
+// 	if(SQLITE_OK != sqlite_error)
+// 	{
+// 		//Global::WriteTextLog(_T("InsertContactsType:%s"), psqlite_error);
+// 		FREE_MSG;
+// 	}
+// 
+// 	return sqlite_error;
+// }
 
 INT CDataImpl::InsertReportInfo(std::string url, std::string content, bool report_status)
 {
@@ -249,26 +249,26 @@ INT CDataImpl::InsertReportInfo(std::string url, std::string content, bool repor
 	return sqlite_error;
 }
 
-INT CDataImpl::InsertReportInfo(std::string content)
-{
-	if (m_psqlite3 == NULL)
-		return -1;
-
-	std::string strInsert = "INSERT INTO report(url, content)VALUES ('";
-	strInsert.append("https://cn.ota.qhmoka.com/ota-services/report/reportToolsLog.do");
-	strInsert.append("','");
-	strInsert.append(content);
-	strInsert.append("');");
-	char* psqlite_error = NULL;
-	int sqlite_error = sqlite3_exec(m_psqlite3, strInsert.c_str(), NULL, 0, &psqlite_error);
-	if (SQLITE_OK != sqlite_error)
-	{
-		//Global::WriteTextLog(_T("InsertContactsType:%s"), psqlite_error);
-		FREE_MSG;
-	}
-
-	return sqlite_error;
-}
+// INT CDataImpl::InsertReportInfo(std::string content)
+// {
+// 	if (m_psqlite3 == NULL)
+// 		return -1;
+// 
+// 	std::string strInsert = "INSERT INTO report(url, content)VALUES ('";
+// 	strInsert.append("https://cn.ota.qhmoka.com/ota-services/report/reportToolsLog.do");
+// 	strInsert.append("','");
+// 	strInsert.append(content);
+// 	strInsert.append("');");
+// 	char* psqlite_error = NULL;
+// 	int sqlite_error = sqlite3_exec(m_psqlite3, strInsert.c_str(), NULL, 0, &psqlite_error);
+// 	if (SQLITE_OK != sqlite_error)
+// 	{
+// 		//Global::WriteTextLog(_T("InsertContactsType:%s"), psqlite_error);
+// 		FREE_MSG;
+// 	}
+// 
+// 	return sqlite_error;
+// }
 
 INT CDataImpl::InsertReportInfo(std::string report_type, std::map<std::string, std::string> report_data)
 {

+ 2 - 2
TCL Copy Tool/TCL Copy Tool/db.h

@@ -99,9 +99,9 @@ public:
 	// 根据订单号查询订单信息;//返回查询数量;
 	INT QueryUnReportInfo(std::vector<STReport> &vtdata);
 	// 插入mid信息;
-	INT InsertReportInfo(STReport& data);
+	//INT InsertReportInfo(STReport& data);
 	INT InsertReportInfo(std::string url, std::string content, bool report_status =  false);
-	INT InsertReportInfo(std::string content);
+	//INT InsertReportInfo(std::string content);
 	INT InsertReportInfo(std::string report_type, std::map<std::string, std::string> report_data);
 	// 删除已上报成功的记录(1个月前的);
 	INT RemoveReportInfo();