scbc.tools.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. // scbc.tools.cpp : 定义 DLL 应用程序的导出函数。
  2. //
  3. #include "stdafx.h"
  4. #include "scbc.tools.h"
  5. #include "CurlClient.h"
  6. #include "DataImpl.h"
  7. #include "Global.h"
  8. #include "SDK.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #endif
  12. #ifdef TEST_MODE
  13. // 唯一的应用程序对象
  14. CWinApp theApp;
  15. using namespace std;
  16. void TEST_Download()
  17. {
  18. printf("开始压测下载……\n");
  19. TCHAR szDir[MAX_PATH] = {0};
  20. _stprintf_s(szDir, _T("%s%s.exe"), Global::g_szCurModuleDir, "SunloginClient");
  21. for (int i = 0; i < 300000; i++)
  22. {
  23. CCurlClient curl;
  24. curl.Initialize();
  25. curl.DownloadEx("http://download.oray.com/sunlogin/windows/SunloginClient10.1.exe", szDir);
  26. DeleteFile(szDir);
  27. printf("\n\t完成第%d次\n\n", i);
  28. }
  29. printf("结束压测下载……\n");
  30. }
  31. void TEST_GetMidInfo()
  32. {
  33. CSDK sdk;
  34. STMid mid;
  35. sdk.DownloadMidData("IDL144240G");
  36. Sleep(60000);
  37. }
  38. void TEST_InsertMidInfo()
  39. {
  40. CDataImpl db;
  41. if ( db.Open() )
  42. {
  43. STMid mid;
  44. char szdata[10] = {0};
  45. for ( int i = 0; i < 100; i++ )
  46. {
  47. _itoa_s(i, szdata, 10);
  48. mid.order = szdata;
  49. mid.ctype = szdata;
  50. mid.version = "V8-SCBC098-LV1096";
  51. mid.number = "1000";
  52. mid.pid = "102";
  53. mid.pmd5 = "dfeqadfadfer546489er4adf";
  54. mid.purl = "https://www.baidu.com";
  55. db.InsertMidInfo(mid);
  56. }
  57. for ( int i = 0; i < 100; i++)
  58. {
  59. _itoa_s(i, szdata, 10);
  60. if ( i%2 )
  61. db.UpdateKeyReportStatus(szdata);
  62. }
  63. }
  64. }
  65. void TEST_InertKeys()
  66. {
  67. CDataImpl db;
  68. if ( db.Open() )
  69. {
  70. STKeys keys;
  71. char szdata[10] = {0};
  72. db.TransactionBegin();
  73. for ( int i = 0; i < 50000; i++ )
  74. {
  75. _itoa_s(i, szdata, 10);
  76. keys.bid = "1";
  77. keys.pid = "102";
  78. keys.sn = szdata;
  79. keys.keys = "{\"did\":\"did\",\"mac\":\"mac\",\"cikey\":\"cikey\",\"hdcp\":\"hdcp\",\"hdcp22\":\"hdcp22\",\"widi\":\"widi\",\"esn\":\"esn\",\"widevine\":\"widevine\"}";
  80. db.InsertKeyInfo(keys);
  81. }
  82. db.TransactionCommit();
  83. }
  84. }
  85. void TEST_InertKeys2()
  86. {
  87. CDataImpl db;
  88. if ( db.Open() )
  89. {
  90. char szdata[10] = {0};
  91. printf("批量插入数据:%s\n",CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S\n").GetString());
  92. std::vector<STKeys> vtKeys;
  93. vtKeys.resize(200);
  94. std::vector<STKeys>::iterator it = vtKeys.begin();
  95. for ( int i = 0; it != vtKeys.end(); it++, i++ )
  96. {
  97. _itoa_s(i, szdata, 10);
  98. it->bid = "1";
  99. it->pid = "102";
  100. it->sn = szdata;
  101. it->keys = "{\"did\":\"did\",\"mac\":\"mac\",\"cikey\":\"cikey\",\"hdcp\":\"hdcp\",\"hdcp22\":\"hdcp22\",\"widi\":\"widi\",\"esn\":\"esn\",\"widevine\":\"widevine\"}";
  102. }
  103. printf("开始批量插入数据:%s\n",CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S\n").GetString());
  104. db.BatchInsertKeyInfo(vtKeys);
  105. printf("完成批量插入数据:%s\n",CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S\n").GetString());
  106. }
  107. }
  108. void TEST_InertLog()
  109. {
  110. CDataImpl db;
  111. if ( db.Open() )
  112. {
  113. STLog log;
  114. char szdata[10] = {0};
  115. db.TransactionBegin();
  116. for ( int i = 0; i < 200; i++ )
  117. {
  118. _itoa_s(i, szdata, 10);
  119. log.bid = "1";
  120. log.sn = szdata;
  121. log.type = "1";
  122. log.content = "测试内容:东方丽景散热地觚单位 加菲软糖加工厂饮用水";
  123. if ( i%2 )
  124. log.report_date = CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S").GetString();
  125. db.InsertLogInfo(log);
  126. }
  127. db.TransactionCommit();
  128. std::vector<STLog> vtLog;
  129. db.QueryUnReportLogInfo(vtLog);
  130. db.UpdateLogReportStatus("0", "1");
  131. }
  132. }
  133. void TEST_QueryMidInfo()
  134. {
  135. CDataImpl db;
  136. if ( db.Open() )
  137. {
  138. STMid mid;
  139. db.QueryMidInfo("1", mid);
  140. printf("查询MID=>order=%s,ctype=%s,ver=%s, pid=%s, psize=%s, purl=%s, pmd5=%s \n",
  141. 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());
  142. }
  143. }
  144. void TEST_QueryUnReportKey()
  145. {
  146. CDataImpl db;
  147. if ( db.Open() )
  148. {
  149. std::vector<STKeys> vtKeys;
  150. db.QueryUnReportKeyInfo(vtKeys);
  151. std::vector<STKeys>::iterator it = vtKeys.begin();
  152. for (; it != vtKeys.end(); it++ )
  153. {
  154. printf("sn:%s\n", it->sn.c_str());
  155. //printf("pid:%s\n", it->pid.c_str());
  156. //printf("keys:%s\n", it->keys.c_str());
  157. printf("copy_date:%s\n", it->copy_date.c_str());
  158. //printf("copy_status:%s\n", it->copy_status.c_str());
  159. //printf("report_date:%s\n", it->report_date.c_str());
  160. //printf("report_status:%s\n", it->report_status.c_str());
  161. }
  162. }
  163. }
  164. void TEST_QueryKeyInfo()
  165. {
  166. CDataImpl db;
  167. if ( db.Open() )
  168. {
  169. STKeys key;
  170. db.QueryKeyInfo("1", key);
  171. printf("查询SNKey=>bid=%s, sn=%s,pid=%s,keys=%s, copy_date=%s, report_date=%s \n", key.bid.c_str(),
  172. key.sn.c_str(), key.pid.c_str(), key.keys.c_str(), key.copy_date.c_str(), key.report_date.c_str());
  173. }
  174. }
  175. void TEST_QueryLogInfo()
  176. {
  177. CDataImpl db;
  178. if ( db.Open() )
  179. {
  180. STLog log;
  181. db.QueryLogInfo("1", log);
  182. printf("查询Log=>bid=%s, sn=%s,type=%s, content=%s, gdate=%s, report_date=%s \n", log.bid.c_str(),
  183. log.sn.c_str(), log.type.c_str(), log.content.c_str(), log.gdate.c_str(), log.report_date.c_str());
  184. }
  185. }
  186. void TEST_QueryUnReportLogInfo()
  187. {
  188. CDataImpl db;
  189. if ( db.Open() )
  190. {
  191. std::vector<STLog> vtlog;
  192. db.QueryUnReportLogInfo(vtlog);
  193. std::vector<STLog>::iterator it = vtlog.begin();
  194. for (; it != vtlog.end(); it++)
  195. {
  196. printf("查询Log=>bid=%s, sn=%s,type=%s, content=%s, gdate=%s, report_date=%s \n", it->bid.c_str(),
  197. it->sn.c_str(), it->type.c_str(), it->content.c_str(), it->gdate.c_str(), it->report_date.c_str());
  198. }
  199. }
  200. }
  201. int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
  202. {
  203. int nRetCode = 0;
  204. Global::Init();
  205. // 初始化 MFC 并在失败时显示错误
  206. if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
  207. {
  208. // TODO: 更改错误代码以符合您的需要
  209. _tprintf(_T("错误: MFC 初始化失败\n"));
  210. nRetCode = 1;
  211. }
  212. else
  213. {
  214. std::string md5 = GetFileMD5("D:\\bin\\scbc.tools\\scbc.tools.pdb");
  215. // TODO: 在此处为应用程序的行为编写代码。
  216. //Sleep(10000);
  217. //TEST_Download();
  218. //TEST_GetMidInfo();
  219. TEST_InsertMidInfo();
  220. TEST_QueryMidInfo();
  221. TEST_InertKeys();
  222. TEST_InertKeys2();
  223. TEST_InertLog();
  224. TEST_QueryKeyInfo();
  225. TEST_QueryUnReportKey();
  226. TEST_QueryLogInfo();
  227. TEST_QueryUnReportLogInfo();
  228. }
  229. system("pause");
  230. return nRetCode;
  231. }
  232. #else
  233. // 全局数据库对象;
  234. CDataImpl g_db;
  235. CSDK g_sdk;
  236. bool ScbcInit(const char* lpOrder)
  237. {
  238. Global::GetMacAddress();
  239. return g_sdk.GetBidInfo(lpOrder, Global::g_strMacs);
  240. }
  241. int QueryMidInfo(const char* lpOrder)
  242. {
  243. if ( lpOrder == NULL || lpOrder[0] == '\0' )
  244. return -1;
  245. return g_sdk.QueryMidInfo(lpOrder);
  246. }
  247. int DownloadMidData(const char* lpOrder)
  248. {
  249. if ( lpOrder == NULL || lpOrder[0] == '\0' )
  250. return -1;
  251. return g_sdk.DownloadMidData(lpOrder);
  252. }
  253. int QueryKeyInfo(const char* lpSN, SNKeys &snKeys)
  254. {
  255. if ( lpSN == NULL || lpSN[0] == '\0' )
  256. return -1;
  257. STKeys keys;
  258. int nRet = g_sdk.QueryKeyInfo(lpSN, keys);
  259. if ( nRet == 1 )
  260. {
  261. snKeys.pid = atoi(keys.pid.c_str());
  262. nRet = CSDK::ParserSNKey(keys.keys, snKeys);
  263. }
  264. return nRet;
  265. }
  266. int UpdateKeyCopyStatus(const char* lpSN)
  267. {
  268. if ( lpSN == NULL || lpSN[0] == '\0' )
  269. return -1;
  270. return g_sdk.UpdateKeyCopyStatus(lpSN);
  271. }
  272. int UpdateKeyReportStatus(const char* lpSN)
  273. {
  274. if ( lpSN == NULL || lpSN[0] == '\0' )
  275. return -1;
  276. return g_sdk.UpdateKeyReportStatus(lpSN);
  277. }
  278. int ReportKeyCopyResults(const char* lpSN)
  279. {
  280. if ( lpSN == NULL || lpSN[0] == '\0' )
  281. return -1;
  282. return g_sdk.ReportKeyCopyResults(lpSN);
  283. }
  284. int BatchReportKeyCopyResults()
  285. {
  286. return g_sdk.BatchReportKeyCopyResults();
  287. }
  288. int QueryBidInfo(const char* lpOrder, BidInfo& binfo)
  289. {
  290. if ( lpOrder == NULL || lpOrder[0] == '\0' )
  291. return -1;
  292. CDataImpl db;
  293. if ( db.Open() )
  294. {
  295. int nRet = db.QueryBidInfo(lpOrder, binfo);
  296. if ( nRet == 0 )
  297. return 0;
  298. else if ( nRet == -1 )
  299. return -3;
  300. else if ( nRet == 1 )
  301. return 1;
  302. else if ( nRet > 1 )
  303. return -4;
  304. }
  305. return -2;
  306. }
  307. int RemoveBidData(const char* lpOrder)
  308. {
  309. if ( lpOrder == NULL || lpOrder[0] == '\0' )
  310. return -1;
  311. CDataImpl db;
  312. if ( db.Open() )
  313. {
  314. if( db.RemoveBidData(lpOrder) == FALSE)
  315. return 0;
  316. return 1;
  317. }
  318. return -2;
  319. }
  320. #endif