ソースを参照

1、完成上报功能;
2、测试用例完善;

Jeff 5 年 前
コミット
159091aeba

+ 29 - 28
scbc.tools/scbc.tools/DataImpl.cpp

@@ -48,10 +48,14 @@ PRIMARY KEY (type, sn));"
 #define _SELECT_LOG_TABLE_ "SELECT type, sn, content, gdate, report_status FROM log"
 
 
-#define FREE_MSG if ( m_pszErrmsg ) { sqlite3_free(m_pszErrmsg); m_pszErrmsg = NULL;}
-#define FREE_MSG2 if ( psqlite_error ) { sqlite3_free(psqlite_error); psqlite_error = NULL;}
+//#define FREE_MSG if ( m_pszErrmsg ) { printf(m_pszErrmsg);sqlite3_free(m_pszErrmsg); m_pszErrmsg = NULL;}
+#define FREE_MSG if ( psqlite_error )  \
+	printf("%s\n",psqlite_error),\
+	sqlite3_free(psqlite_error),\
+	psqlite_error = NULL
 
-CDataImpl::CDataImpl(void):m_psqlite3(NULL),m_pszErrmsg(NULL)
+
+CDataImpl::CDataImpl(void):m_psqlite3(NULL)
 {
 	//sqlite3_threadsafe();
 }
@@ -65,7 +69,7 @@ BOOL CDataImpl::Open()
 {
 	Close();
 	CHAR szpath[MAX_PATH] = {0};
-	_stprintf_s(szpath, _T("%sscbc.db"), Global::g_szCurModuleDir);
+	_stprintf_s(szpath, _T("%sdb\\scbc.db"), Global::g_szCurModuleDir);
 	std::string strPath;
 	if ( !CharEncoding::ASCII2UTF8(szpath,strPath))
 	{
@@ -81,19 +85,19 @@ BOOL CDataImpl::Open()
 	if ( !QueryTable("mid"))
 	{
 		sqlite3_exec(m_psqlite3, _CREATE_MID_TABLE_, NULL, NULL, &psqlite_error);
-		FREE_MSG2
+		FREE_MSG;
 	}
 
 	if ( !QueryTable("keys"))
 	{
 		sqlite3_exec(m_psqlite3, _CREATE_KEYS_TABLE_, NULL, NULL, &psqlite_error);
-		FREE_MSG2
+		FREE_MSG;
 	}
 
 	if ( !QueryTable("log"))
 	{
 		sqlite3_exec(m_psqlite3, _CREATE_LOG_TABLE_, NULL, NULL, &psqlite_error);
-		FREE_MSG2
+		FREE_MSG;
 	}
 
 	return TRUE;
@@ -105,9 +109,6 @@ void CDataImpl::Close()
 		sqlite3_close(m_psqlite3);
 
 	m_psqlite3 = NULL;
-	if ( m_pszErrmsg )
-		sqlite3_free(m_pszErrmsg);
-	m_pszErrmsg = NULL;
 }
 
 BOOL CDataImpl::ExecteSQL(IN LPCSTR lpSQL)
@@ -126,7 +127,7 @@ BOOL CDataImpl::ExecteSQL(IN LPCSTR lpSQL)
 	if(SQLITE_OK != sqlite_error)
 	{
 		//Global::WriteTextLog(_T("ExecteSQL:%s"), psqlite_error);
-		FREE_MSG2
+		FREE_MSG;
 		return FALSE;
 	}
 
@@ -155,7 +156,7 @@ BOOL CDataImpl::QueryTable(std::string table)
 	if ( sqlite_error != SQLITE_OK)
 	{
 		//Global::WriteTextLog(_T("QueryContactsType:%s"), m_pszErrmsg);
-		FREE_MSG2
+		FREE_MSG;
 		return FALSE;
 	}
 
@@ -183,7 +184,7 @@ INT CDataImpl::QueryMidInfo(std::string order, STMid &data)
 	if ( sqlite_error != SQLITE_OK)
 	{
 		//Global::WriteTextLog(_T("QueryContactsType:%s"), m_pszErrmsg);
-		FREE_MSG2
+		FREE_MSG;
 		return -1;
 	}
 
@@ -242,7 +243,7 @@ INT CDataImpl::QueryKeyInfo(std::string sn, STKeys &data)
 	if ( sqlite_error != SQLITE_OK)
 	{
 		//Global::WriteTextLog(_T("QueryContactsInfo:%s"), m_pszErrmsg);
-		FREE_MSG2
+		FREE_MSG;
 		return -1;
 	}
 
@@ -288,7 +289,7 @@ INT CDataImpl::QueryUnReportKeyInfo(std::vector<STKeys> &vtdata)
 	if ( sqlite_error != SQLITE_OK)
 	{
 		//Global::WriteTextLog(_T("QueryContactsInfo:%s"), m_pszErrmsg);
-		FREE_MSG2
+		FREE_MSG;
 		return -1;
 	}
 
@@ -319,7 +320,7 @@ INT CDataImpl::QueryLogInfo(std::string sn, STLog &data)
 	if ( sqlite_error != SQLITE_OK)
 	{
 		//Global::WriteTextLog(_T("QueryTaskInfo:%s"), m_pszErrmsg);
-		FREE_MSG2
+		FREE_MSG;
 		return -1;
 	}
 
@@ -361,7 +362,7 @@ INT CDataImpl::QueryUnReportLogInfo(std::vector<STLog> &vtdata)
 	if ( sqlite_error != SQLITE_OK)
 	{
 		//Global::WriteTextLog(_T("QueryContactsInfo:%s"), m_pszErrmsg);
-		FREE_MSG2
+		FREE_MSG;
 		return -1;
 	}
 
@@ -408,7 +409,7 @@ INT CDataImpl::InsertMidInfo(STMid &data)
 	if(SQLITE_OK != sqlite_error)
 	{
 		//Global::WriteTextLog(_T("InsertContactsType:%s"), psqlite_error);
-		FREE_MSG2
+		FREE_MSG;
 	}
 
 	return sqlite_error;
@@ -432,7 +433,7 @@ INT CDataImpl::InsertKeyInfo(STKeys &data)
 	if(SQLITE_OK != sqlite_error)
 	{
 		//Global::WriteTextLog(_T("InsertContactsInfo:%s"), psqlite_error);
-		FREE_MSG2
+		FREE_MSG;
 	}
 
 	return sqlite_error;
@@ -459,7 +460,7 @@ INT CDataImpl::InsertLogInfo(STLog &data)
 	if(SQLITE_OK != sqlite_error)
 	{
 		//Global::WriteTextLog(_T("InsertContactsInfo:%s"), psqlite_error);
-		FREE_MSG2
+		FREE_MSG;
 	}
 
 	return sqlite_error;
@@ -474,7 +475,7 @@ INT CDataImpl::BatchInsertKeyInfo(std::vector<STKeys> &vtdata)
 	INT nRet = sqlite3_exec(m_psqlite3, "begin;", 0, 0, &psqlite_error);
 	if ( nRet != SQLITE_OK )
 	{
-		FREE_MSG2
+		FREE_MSG;
 		return nRet;
 	}
 
@@ -497,14 +498,14 @@ INT CDataImpl::BatchInsertKeyInfo(std::vector<STKeys> &vtdata)
 	{
 		// »Ø¹öÊÂÎñ;
 		nRet = sqlite3_exec(m_psqlite3, "rollback;", 0, 0, &psqlite_error);
-		FREE_MSG2
+		FREE_MSG;
 		return nRet;
 	}
 
 	nRet = sqlite3_exec(m_psqlite3, "commit;", 0, 0, &psqlite_error);
 	if ( nRet != SQLITE_OK )
 	{
-		FREE_MSG2
+		FREE_MSG;
 		return nRet;
 	}
 
@@ -540,7 +541,7 @@ BOOL CDataImpl::UpdateMidInfo(STMid &data)
 	if(SQLITE_OK != sqlite_error)
 	{
 		//Global::WriteTextLog(_T("UpdateContactsType:%s"), psqlite_error);
-		FREE_MSG2
+		FREE_MSG;
 		return FALSE;
 	}
 
@@ -576,7 +577,7 @@ BOOL CDataImpl::UpdateDownloadStatus(std::string order, int status, std::string
 	if(SQLITE_OK != sqlite_error)
 	{
 		//Global::WriteTextLog(_T("UpdateContactsType:%s"), psqlite_error);
-		FREE_MSG2
+		FREE_MSG;
 		return FALSE;
 	}
 
@@ -606,7 +607,7 @@ BOOL CDataImpl::UpdateKeyCopyStatus(std::string sn, int status)
 	if(SQLITE_OK != sqlite_error)
 	{
 		//Global::WriteTextLog(_T("UpdateContactsInfo:%s"), psqlite_error);
-		FREE_MSG2
+		FREE_MSG;
 		return FALSE;
 	}
 
@@ -636,7 +637,7 @@ BOOL CDataImpl::UpdateKeyReportStatus(std::string sn, int status)
 	if(SQLITE_OK != sqlite_error)
 	{
 		//Global::WriteTextLog(_T("UpdateContactsInfo:%s"), psqlite_error);
-		FREE_MSG2
+		FREE_MSG;
 		return FALSE;
 	}
 
@@ -668,7 +669,7 @@ BOOL CDataImpl::UpdateLogReportStatus(std::string sn, std::string type, int stat
 	if(SQLITE_OK != sqlite_error)
 	{
 		//Global::WriteTextLog(_T("UpdateContactsInfo:%s"), psqlite_error);
-		FREE_MSG2
+		FREE_MSG;
 		return FALSE;
 	}
 

+ 0 - 14
scbc.tools/scbc.tools/DataImpl.h

@@ -25,27 +25,13 @@
 
 class CDataImpl
 {
-	//CDataImpl(void);
 public:
 	CDataImpl(void);
-// 	static CDataImpl* GetInstance()
-// 	{
-// 		static CDataImpl *pObj = NULL;
-// 		if ( pObj == NULL )
-// 		{
-// 			pObj = new CDataImpl;
-// 			pObj->Open();
-// 		}
-// 
-// 		return pObj;
-// 	}
-
 	virtual ~CDataImpl(void);
 
 	// ˽ÓбäÁ¿;
 private:
 	sqlite3		*m_psqlite3;
-	CHAR		*m_pszErrmsg;
 
 	// Óû§º¯Êý;
 public:

+ 1 - 1
scbc.tools/scbc.tools/Global.cpp

@@ -45,7 +45,7 @@ namespace Global
 		_stprintf_s(szPath, _T("%scache"), g_szCurModuleDir);
 		MKDIR(szPath);
 
-		_stprintf_s(szPath, _T("%slog"), g_szCurModuleDir);
+		_stprintf_s(szPath, _T("%sdb"), g_szCurModuleDir);
 		MKDIR(szPath);
 	}
 

+ 49 - 1
scbc.tools/scbc.tools/SDK.cpp

@@ -15,6 +15,7 @@ m_hReportEvent(NULL),
 m_hThreadReport(NULL)
 {
 	Global::Init();
+	Global::GetMacAddress();
 	m_curl.Initialize();
 }
 
@@ -225,7 +226,11 @@ bool CSDK::CheckDownload(std::string file, STMid& mid)
 				if ( db.BatchInsertKeyInfo(vtKeys) == 0 )
 				{
 					// 更新任务状态;
-					db.UpdateDownloadStatus(mid.order, 1);
+					if ( ReportDownloadStatus(mid.order) == 0 )
+					{
+						db.UpdateDownloadStatus(mid.order, 1);
+					}
+
 					return true;
 				}
 			}
@@ -242,6 +247,8 @@ int CSDK::GetMidInfo(std::string order, STMid &mid)
 	std::string url = "http://test.admin.ota.qhmoka.com/IDManage/getofflinelist.do?";
 	std::string content = "orderNumber=";
 	content.append(order);
+	//content.append("&mac=");
+	//content.append(Global::g_strMacs);
 	if ( m_curl.Posts(url, content, result) == CURLE_OK)
 	{
 		// 解析json字符串;
@@ -291,6 +298,46 @@ int CSDK::GetMidInfo(std::string order, STMid &mid)
 	// http请求异常;
 	return -1;
 }
+
+int CSDK::ReportDownloadStatus(std::string order)
+{
+	// http获取mid;
+	std::string result;
+	std::string url = "http://test.admin.ota.qhmoka.com/IDManage/getreportofflinesn.do?";
+	std::string content = "orderNumber=";
+	content.append(order);
+
+	CCurlClient curl;
+	curl.Initialize();
+	if ( curl.Posts(url, content, result) == CURLE_OK)
+	{
+		// 解析json字符串;
+		cJSON *pJson = cJSON_Parse(result.c_str());
+		if ( !pJson )
+		{
+			return -2;
+		}
+
+		std::string code, des;
+		code = cJSON_GetObjectItem(pJson, _T("code")) ? cJSON_GetObjectItem(pJson, _T("code"))->valuestring : "";
+		des = cJSON_GetObjectItem(pJson, _T("des")) ? cJSON_GetObjectItem(pJson, _T("des"))->valuestring : "";
+
+		if ( _tcsicmp(code.c_str(), "1000") && _tcsicmp(code.c_str(), "1006"))
+		{
+			cJSON_Delete(pJson);
+			return -3;
+		}
+
+		cJSON_Delete(pJson);
+		pJson = NULL;
+
+		return 0;
+	}
+
+	// http请求异常;
+	return -1;
+}
+
 void CSDK::ParserKey(std::string file, std::vector<STKeys> &vtKyes, std::string pid)
 {
 	// 读取文件;
@@ -399,6 +446,7 @@ DWORD CSDK::ThreadDownload(LPVOID lpParam)
 					{
 						m_vtMidTask.pop_front();
 					}
+
 					continue;
 				}
 

+ 1 - 0
scbc.tools/scbc.tools/SDK.h

@@ -21,6 +21,7 @@ public:
 	int ReportKeyCopyResults(std::string sn = "");
 
 	int GetMidInfo(std::string order, STMid &mid);
+	static int ReportDownloadStatus(std::string order);
 	static void ParserKey(std::string file, std::vector<STKeys> &vtKyes, std::string pid);
 	static bool ParserSNKey(std::string json, SNKeys &snKey);
 private:

+ 40 - 31
scbc.tools/scbc.tools/scbc.tools.cpp

@@ -73,6 +73,7 @@ void TEST_InertKeys()
 		for ( int i = 0; i < 50000; i++ )
 		{
 			_itoa_s(i, szdata, 10);
+			keys.pid = "102";
 			keys.sn = szdata;
 			keys.keys = "{\"did\":\"did\",\"mac\":\"mac\",\"cikey\":\"cikey\",\"hdcp\":\"hdcp\",\"hdcp22\":\"hdcp22\",\"widi\":\"widi\",\"esn\":\"esn\",\"widevine\":\"widevine\"}";
 			db.InsertKeyInfo(keys);
@@ -87,8 +88,7 @@ void TEST_InertKeys2()
 	if ( db.Open() )
 	{
 		char szdata[10] = {0};
-		OutputDebugString("批量插入数据\n");
-		OutputDebugString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S\n"));
+		printf("批量插入数据:%s\n",CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S\n").GetString());
 		
 		std::vector<STKeys> vtKeys;
 		vtKeys.resize(200);
@@ -96,16 +96,14 @@ void TEST_InertKeys2()
 		for ( int i = 0; it != vtKeys.end(); it++, i++ )
 		{
 			_itoa_s(i, szdata, 10);
-			it->pid = "1";
+			it->pid = "102";
 			it->sn = szdata;
 			it->keys = "{\"did\":\"did\",\"mac\":\"mac\",\"cikey\":\"cikey\",\"hdcp\":\"hdcp\",\"hdcp22\":\"hdcp22\",\"widi\":\"widi\",\"esn\":\"esn\",\"widevine\":\"widevine\"}";
 		}
 
-		OutputDebugString("开始批量插入数据\n");
-		OutputDebugString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S\n"));
+		printf("开始批量插入数据:%s\n",CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S\n").GetString());
 		db.BatchInsertKeyInfo(vtKeys);
-		OutputDebugString("完成批量插入数据\n");
-		OutputDebugString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S\n"));
+		printf("完成批量插入数据:%s\n",CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S\n").GetString());
 	}
 }
 
@@ -145,6 +143,9 @@ void TEST_QueryMidInfo()
 	{
 		STMid mid;
 		db.QueryMidInfo("1", mid);
+
+		printf("查询MID=>order=%s,ctype=%s,ver=%s, pid=%s, psize=%s, purl=%s, pmd5=%s \n", 
+			mid.order.c_str(), mid.ctype.c_str(), mid.version.c_str(), mid.pid.c_str(), mid.psize.c_str(), mid.purl.c_str(), mid.pmd5.c_str());
 	}
 }
 
@@ -158,25 +159,13 @@ void TEST_QueryUnReportKey()
 		std::vector<STKeys>::iterator it = vtKeys.begin();
 		for (; it != vtKeys.end(); it++ )
 		{
-			OutputDebugString("SN:");
-			OutputDebugString(it->sn.c_str());
-			OutputDebugString("\t");
-
-			OutputDebugString("copy_date:");
-			OutputDebugString(it->copy_date.c_str());
-			OutputDebugString("\t");
-
-			OutputDebugString("copy_status:");
-			OutputDebugString(it->copy_status.c_str());
-			OutputDebugString("\t");
-
-			OutputDebugString("report_date:");
-			OutputDebugString(it->report_date.c_str());
-			OutputDebugString("\t");
-
-			OutputDebugString("report_status:");
-			OutputDebugString(it->report_status.c_str());
-			OutputDebugString("\n");
+			printf("sn:%s\n", it->sn.c_str());
+			//printf("pid:%s\n", it->pid.c_str());
+			//printf("keys:%s\n", it->keys.c_str());
+			printf("copy_date:%s\n", it->copy_date.c_str());
+			//printf("copy_status:%s\n", it->copy_status.c_str());
+			//printf("report_date:%s\n", it->report_date.c_str());
+			//printf("report_status:%s\n", it->report_status.c_str());
 		}
 	}
 }
@@ -188,6 +177,8 @@ void TEST_QueryKeyInfo()
 	{
 		STKeys key;
 		db.QueryKeyInfo("1", key);
+		printf("查询SNKey=>sn=%s,pid=%s,keys=%s, copy_date=%s, report_date=%s \n", 
+			key.sn.c_str(), key.pid.c_str(), key.keys.c_str(), key.copy_date.c_str(), key.report_date.c_str());
 	}
 }
 
@@ -196,8 +187,11 @@ void TEST_QueryLogInfo()
 	CDataImpl db;
 	if ( db.Open() )
 	{
-		STKeys log;
-		db.QueryKeyInfo("1", log);
+		STLog log;
+		db.QueryLogInfo("1", log);
+		printf("查询Log=>sn=%s,type=%s, content=%s, gdate=%s, report_date=%s \n", 
+			log.sn.c_str(), log.type.c_str(), log.content.c_str(), log.gdate.c_str(), log.report_date.c_str());
+
 	}
 }
 
@@ -208,6 +202,12 @@ void TEST_QueryUnReportLogInfo()
 	{
 		std::vector<STLog> vtlog;
 		db.QueryUnReportLogInfo(vtlog);
+		std::vector<STLog>::iterator it = vtlog.begin();
+		for (; it != vtlog.end(); it++)
+		{
+			printf("查询Log=>sn=%s,type=%s, content=%s, gdate=%s, report_date=%s \n", 
+				it->sn.c_str(), it->type.c_str(), it->content.c_str(), it->gdate.c_str(), it->report_date.c_str());
+		}
 	}
 }
 
@@ -227,11 +227,20 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
 	{
 		std::string md5 = GetFileMD5("D:\\bin\\scbc.tools\\scbc.tools.pdb");
 		// TODO: 在此处为应用程序的行为编写代码。
-		TEST_GetMidInfo();
-
-		
+		//TEST_GetMidInfo();
+		TEST_InsertMidInfo();
+		TEST_QueryMidInfo();
+		TEST_InertKeys();
+		TEST_InertKeys2();
+		TEST_InertLog();
+		TEST_QueryKeyInfo();		
+		TEST_QueryUnReportKey();
+		TEST_QueryLogInfo();
+		TEST_QueryUnReportLogInfo();
 	}
 
+	system("pause");
+
 	return nRetCode;
 }