lyfzLoadLibrary.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. #include "StdAfx.h"
  2. #include "lyfzLoadLibrary.h"
  3. namespace lyfzLibrary
  4. {
  5. CString g_strCloundHost = _T("http://121.42.170.207"); // 云服务器主机地址;
  6. HMODULE g_hCloudSelectionLib = NULL;
  7. API_uploadorder g_uploadorder = NULL;
  8. API_uploadgoodinfo g_uploadgoodinfo = NULL;
  9. API_uploadimg g_uploadimg = NULL;
  10. API_getcloundresult g_getcloundresult = NULL;
  11. BOOL LoadCloudSelectionLib()
  12. {
  13. if ( g_hCloudSelectionLib == NULL )
  14. g_hCloudSelectionLib = LoadLibrary(_T("lyfzCloudSelection.dll"));
  15. if ( !g_hCloudSelectionLib )
  16. {
  17. //AfxMessageBox(_T("打开云链接库失败"));
  18. WriteTextLog(_T("加载云选片模块失败:%d"), GetLastError());
  19. return FALSE;
  20. }
  21. g_uploadorder = (API_uploadorder)GetProcAddress(g_hCloudSelectionLib, "uploadorder");
  22. if ( g_uploadorder == NULL )
  23. {
  24. //AfxMessageBox(_T("获取生成云接口失败"));
  25. return FALSE;
  26. }
  27. g_uploadgoodinfo = (API_uploadgoodinfo)GetProcAddress(g_hCloudSelectionLib, "uploadgoodinfo");
  28. if ( g_uploadgoodinfo == NULL )
  29. {
  30. //AfxMessageBox(_T("获取生成云接口失败"));
  31. return FALSE;
  32. }
  33. g_uploadimg = (API_uploadimg)GetProcAddress(g_hCloudSelectionLib, "uploadImg");
  34. if ( g_uploadimg == NULL )
  35. {
  36. //AfxMessageBox(_T("获取生成云接口失败"));
  37. return FALSE;
  38. }
  39. g_getcloundresult = (API_getcloundresult)GetProcAddress(g_hCloudSelectionLib, "getresult");
  40. if ( g_getcloundresult == NULL )
  41. {
  42. return FALSE;
  43. }
  44. return TRUE;
  45. }
  46. void FreeCloudSelectionLib()
  47. {
  48. if ( g_hCloudSelectionLib )
  49. {
  50. if ( FreeLibrary(g_hCloudSelectionLib) )
  51. {
  52. g_hCloudSelectionLib = NULL;
  53. g_uploadorder = NULL;
  54. g_uploadgoodinfo = NULL;
  55. g_uploadimg = NULL;
  56. g_getcloundresult = NULL;
  57. }
  58. }
  59. }
  60. void getXPJsonresult(IN CString strJson, IN CArray<CStringArray,CStringArray>& AryResult)
  61. {
  62. INT i = 0;
  63. INT nIndex = 0;
  64. INT nCount = 0;
  65. CString strTemp = _T("");
  66. CString strTemp2 = _T("");
  67. CString strMark = _T("{\"photo_list\": ");
  68. nCount = strJson.Replace(strMark, strMark);
  69. strJson += _T(", {\"photo_list\": ");
  70. AryResult.SetSize(nCount,1);
  71. strJson = strJson.Mid(strMark.GetLength());
  72. while ( strJson.Find(strMark) != -1 )
  73. {
  74. nIndex = strJson.Find(strMark);
  75. strTemp = strJson.Left(nIndex - 3);
  76. strJson = strJson.Mid(nIndex + strMark.GetLength());
  77. // 解析出Json内容;
  78. AryResult.ElementAt(i).RemoveAll();
  79. // 相片串;
  80. nIndex = strTemp.Find(_T(", "));
  81. if ( nIndex != -1)
  82. {
  83. strTemp2 = strTemp.Left(nIndex);
  84. strTemp2.TrimLeft(_T("\""));
  85. strTemp2.TrimRight(_T("\""));
  86. AryResult.ElementAt(i).Add(strTemp2);
  87. strTemp = strTemp.Mid(nIndex + 2);
  88. }
  89. // 商品数量;
  90. nIndex = strTemp.Find(_T("\"num\": "));
  91. if ( nIndex != -1)
  92. {
  93. strTemp = strTemp.Mid(nIndex + 7);
  94. nIndex = strTemp.Find(_T(", \"product_id\": "));
  95. if ( nIndex != -1)
  96. {
  97. strTemp2 = strTemp.Left(nIndex);
  98. AryResult.ElementAt(i).Add(strTemp2);
  99. strTemp = strTemp.Mid(nIndex + strlen(_T(", \"product_id\": ")));
  100. }
  101. }
  102. // 商品ID;
  103. nIndex = strTemp.Find(_T(", \"name\": "));
  104. if ( nIndex != -1)
  105. {
  106. strTemp2 = strTemp.Left(nIndex);
  107. strTemp2.TrimLeft(_T("\""));
  108. strTemp2.TrimRight(_T("\""));
  109. AryResult.ElementAt(i).Add(strTemp2);
  110. strTemp = strTemp.Mid(nIndex + _tcslen(_T(", \"name\": ")));
  111. }
  112. // 商品名称;
  113. if ( strTemp.GetLength() )
  114. {
  115. strTemp.TrimLeft(_T("\""));
  116. strTemp.TrimRight(_T("\""));
  117. AryResult.ElementAt(i).Add(strTemp);
  118. }
  119. i++;
  120. }
  121. }
  122. void getXPJsonresult(IN CString strJson, IN vector<STSpJson>& vtSpJson)
  123. {
  124. INT i = 0;
  125. INT nIndex = 0;
  126. INT nCount = 0;
  127. CString strTemp = _T("");
  128. CString strTemp2 = _T("");
  129. CString strMark = _T("{\"photo_list\": ");
  130. nCount = strJson.Replace(strMark, strMark);
  131. strJson += _T(", {\"photo_list\": ");
  132. strJson = strJson.Mid(strMark.GetLength());
  133. while ( strJson.Find(strMark) != -1 )
  134. {
  135. STSpJson tagJson;
  136. nIndex = strJson.Find(strMark);
  137. strTemp = strJson.Left(nIndex - 3);
  138. strJson = strJson.Mid(nIndex + strMark.GetLength());
  139. // 解析出Json内容;
  140. // 相片串;
  141. nIndex = strTemp.Find(_T(", "));
  142. if ( nIndex != -1)
  143. {
  144. strTemp2 = strTemp.Left(nIndex);
  145. strTemp2.TrimLeft(_T("\""));
  146. strTemp2.TrimRight(_T("\""));
  147. //AryResult.ElementAt(i).Add(strTemp2);
  148. tagJson.strImgs = strTemp2;
  149. strTemp = strTemp.Mid(nIndex + 2);
  150. }
  151. // 商品数量;
  152. nIndex = strTemp.Find(_T("\"num\": "));
  153. if ( nIndex != -1)
  154. {
  155. strTemp = strTemp.Mid(nIndex + 7);
  156. nIndex = strTemp.Find(_T(", \"product_id\": "));
  157. if ( nIndex != -1)
  158. {
  159. strTemp2 = strTemp.Left(nIndex);
  160. //AryResult.ElementAt(i).Add(strTemp2);
  161. tagJson.strSpCount = strTemp2;
  162. strTemp = strTemp.Mid(nIndex + strlen(_T(", \"product_id\": ")));
  163. }
  164. }
  165. // 商品ID;
  166. nIndex = strTemp.Find(_T(", \"name\": "));
  167. if ( nIndex != -1)
  168. {
  169. strTemp2 = strTemp.Left(nIndex);
  170. strTemp2.TrimLeft(_T("\""));
  171. strTemp2.TrimRight(_T("\""));
  172. //AryResult.ElementAt(i).Add(strTemp2);
  173. tagJson.strSpId = strTemp2;
  174. strTemp = strTemp.Mid(nIndex + _tcslen(_T(", \"name\": ")));
  175. }
  176. // 商品名称;
  177. if ( strTemp.GetLength() )
  178. {
  179. strTemp.TrimLeft(_T("\""));
  180. strTemp.TrimRight(_T("\""));
  181. //AryResult.ElementAt(i).Add(strTemp);
  182. tagJson.strSpName = strTemp;
  183. }
  184. vtSpJson.push_back(tagJson);
  185. i++;
  186. }
  187. }
  188. void getXYJsonresult(IN CString strJson, OUT CString& strResult)
  189. {
  190. //CString strResult = _T("");
  191. CString strTemp = _T("");
  192. CString strSubJson = _T("");
  193. CString strMark = _T("\"general_require\": ");
  194. CString strMark2 = _T("");
  195. CString strImgName = _T(""); // 相片名;
  196. CString strImgctx = _T(""); // 相片修改要求;
  197. INT nIndex = strJson.Find(strMark);
  198. if ( nIndex != -1 )
  199. strJson = strJson.Mid(nIndex + strMark.GetLength());
  200. strMark = _T(", \"sample_list\": [{");
  201. nIndex = strJson.Find(strMark);
  202. if ( nIndex != -1 )
  203. {
  204. // 总的要求;
  205. strTemp = strJson.Left(nIndex);
  206. strTemp.TrimLeft(_T("\""));
  207. strTemp.TrimRight(_T("\""));
  208. if ( !strTemp.IsEmpty() )
  209. strResult += strTemp + _T(";");
  210. strJson = strJson.Mid(nIndex + strMark.GetLength());
  211. }
  212. strMark = _T("\"modify\": ");
  213. strJson += strMark;
  214. nIndex = strJson.Find(strMark) ;
  215. if ( nIndex != -1 )
  216. {
  217. strJson = strJson.Mid(nIndex + strMark.GetLength());
  218. while( strJson.Find(strMark) != -1 )
  219. {
  220. nIndex = strJson.Find(strMark);
  221. strSubJson = strJson.Left(nIndex);
  222. strJson = strJson.Mid(nIndex+ strMark.GetLength());
  223. if ( nIndex != -1 )
  224. {
  225. strMark2 = _T(", \"modify_note\": ");
  226. nIndex = strSubJson.Find(strMark2);
  227. if ( nIndex != -1)
  228. {
  229. // 相片选样类型 2 = 修改, 1 = 确认;
  230. strTemp = strSubJson.Left(nIndex);
  231. if ( strTemp == _T("2") )
  232. {
  233. strSubJson = strSubJson.Mid(nIndex + strMark2.GetLength() );
  234. strMark2 = _T("\", \"photo_name\": ");
  235. nIndex = strSubJson.Find(strMark2);
  236. if ( nIndex != -1 )
  237. {
  238. strImgctx = strSubJson.Left(nIndex);
  239. strImgctx.TrimLeft(_T("\""));
  240. strImgName = strSubJson.Mid(nIndex + strMark2.GetLength()+1);
  241. strImgName = strImgName.Left(strImgName.Find(_T("\"")));
  242. strResult += strImgName + _T(":") + strImgctx + _T(";");
  243. }
  244. }
  245. }
  246. }
  247. }
  248. }
  249. OutputDebugString(strResult + _T("\n"));
  250. }
  251. //////////////////////////////////////////////////////////////////////////
  252. HMODULE g_hQRCodeLibrary = NULL;
  253. API_GetQRCodeImg g_GetQRCodeImg = NULL;
  254. API_ShowQRCodeBitmap g_ShowQRCodeBitmap = NULL;
  255. API_ShowQRCodeOnDC g_ShowQRCodeOnDC = NULL;
  256. BOOL LoadQRCodeLibrary()
  257. {
  258. if ( g_hQRCodeLibrary == NULL )
  259. {
  260. g_hQRCodeLibrary = ( HMODULE )LoadLibrary(_T("QRCode.dll"));
  261. DWORD dwError = GetLastError();
  262. if ( g_hQRCodeLibrary == NULL )
  263. {
  264. WriteTextLog(_T("加载二维码模块失败:%d"), dwError);
  265. return FALSE;
  266. }
  267. }
  268. g_GetQRCodeImg = (API_GetQRCodeImg)GetProcAddress(g_hQRCodeLibrary, "GetQRCodeBitmap");
  269. if ( g_GetQRCodeImg == NULL )
  270. {
  271. FreeLibrary(g_hQRCodeLibrary);
  272. return FALSE;
  273. }
  274. g_ShowQRCodeBitmap = (API_ShowQRCodeBitmap)GetProcAddress(g_hQRCodeLibrary, "ShowQRCodeBitmap");
  275. if ( g_ShowQRCodeBitmap == NULL )
  276. {
  277. FreeLibrary(g_hQRCodeLibrary);
  278. return FALSE;
  279. }
  280. g_ShowQRCodeOnDC = (API_ShowQRCodeOnDC)GetProcAddress(g_hQRCodeLibrary, "ShowQRCodeOnDC");
  281. if ( g_ShowQRCodeOnDC == NULL )
  282. {
  283. FreeLibrary(g_hQRCodeLibrary);
  284. return FALSE;
  285. }
  286. return TRUE;
  287. }
  288. void FreeQRCodeLibrary()
  289. {
  290. if ( g_hQRCodeLibrary )
  291. {
  292. if ( FreeLibrary(g_hQRCodeLibrary) )
  293. {
  294. g_hQRCodeLibrary = NULL;
  295. g_GetQRCodeImg = NULL;
  296. g_ShowQRCodeBitmap = NULL;
  297. }
  298. }
  299. }
  300. //////////////////////////////////////////////////////////////////////////
  301. // 微信模块;
  302. HMODULE g_hWeiXinLibaray = NULL;
  303. API_ShowWeiXingDialog g_PtrShowWeiXinDialog = NULL;
  304. API_ShowWeiXingDialog g_PtrShowWXMsgconfigDialog = NULL;
  305. API_ShowWeiXingDialog g_PtrShowWXMsgRcordDialog = NULL;
  306. API_ShowSoftRunTimeDialog g_PtrShowSoftRunTimeDialog = NULL;
  307. BOOL LoadWeiXinLibaray()
  308. {
  309. if ( g_hWeiXinLibaray == NULL )
  310. {
  311. g_hWeiXinLibaray = (HMODULE)LoadLibrary(_T("lyfzWeiXin"));
  312. DWORD dwError = GetLastError();
  313. if (!g_hWeiXinLibaray)
  314. {
  315. WriteTextLog(_T("加载微信模块失败:%d"), dwError);
  316. return FALSE;
  317. }
  318. }
  319. g_PtrShowWeiXinDialog = (API_ShowWeiXingDialog) GetProcAddress(g_hWeiXinLibaray, "ShowWeiXinDialog");
  320. if ( !g_PtrShowWeiXinDialog )
  321. {
  322. FreeLibrary(g_hWeiXinLibaray);
  323. return FALSE;
  324. }
  325. g_PtrShowWXMsgconfigDialog = (API_ShowWeiXingDialog) GetProcAddress(g_hWeiXinLibaray, "ShowWXMsgConfigDialog");
  326. if ( !g_PtrShowWXMsgconfigDialog )
  327. {
  328. FreeLibrary(g_hWeiXinLibaray);
  329. return FALSE;
  330. }
  331. g_PtrShowWXMsgRcordDialog = (API_ShowWeiXingDialog) GetProcAddress(g_hWeiXinLibaray, "ShowWXMsgRecordDialog");
  332. if ( !g_PtrShowWXMsgRcordDialog )
  333. {
  334. FreeLibrary(g_hWeiXinLibaray);
  335. return FALSE;
  336. }
  337. g_PtrShowSoftRunTimeDialog = (API_ShowSoftRunTimeDialog) GetProcAddress(g_hWeiXinLibaray, "ShowSoftRunTimeDialog");
  338. if ( !g_PtrShowSoftRunTimeDialog )
  339. {
  340. FreeLibrary(g_hWeiXinLibaray);
  341. return FALSE;
  342. }
  343. return TRUE;
  344. }
  345. void FreeWeiXinLibaray()
  346. {
  347. if ( g_hWeiXinLibaray )
  348. {
  349. if ( FreeLibrary(g_hWeiXinLibaray) )
  350. {
  351. g_hWeiXinLibaray = NULL;
  352. g_PtrShowWeiXinDialog = NULL;
  353. g_PtrShowWXMsgconfigDialog = NULL;
  354. g_PtrShowWXMsgRcordDialog = NULL;
  355. g_PtrShowSoftRunTimeDialog = NULL;
  356. }
  357. }
  358. }
  359. };