CWeixinzhifuShoukuanWnd.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  1. #include "../pch/pch.h"
  2. #include "CWeixinzhifuShoukuanWnd.h"
  3. #include "CMessageboxWnd.h"
  4. #include "../helper/CSpeech.h"
  5. #define WM_TIMER_WND_CLOSE 200001
  6. void CWeixinzhifuShoukuanWnd::Init()
  7. {
  8. //::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
  9. }
  10. void CWeixinzhifuShoukuanWnd::Notify(TNotifyUI& msg)
  11. {
  12. if (msg.sType == _T("click"))
  13. {
  14. if (msg.pSender->GetName() == _T("closebtn"))
  15. {
  16. if (m_shoukuan_status == 0)
  17. {
  18. //还没开始支付,直接退出
  19. Close(IDCANCEL);
  20. }
  21. else if (m_shoukuan_status == 1 || m_shoukuan_status == 5)
  22. {
  23. //不能做任何处理
  24. }
  25. else if (m_shoukuan_status == 2)
  26. {
  27. //查询密码的过程中,取消付款
  28. CancelShoukuanPassword();
  29. }
  30. else if (m_shoukuan_status == 3)
  31. {
  32. Sleep(100);
  33. Close(IDOK);
  34. }
  35. else if (m_shoukuan_status == 4)
  36. {
  37. Sleep(100);
  38. Close(IDCANCEL);
  39. }
  40. }
  41. }
  42. }
  43. LRESULT CWeixinzhifuShoukuanWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  44. {
  45. LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);
  46. styleValue &= ~WS_CAPTION;
  47. ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
  48. // 把自己的窗口句柄与窗口绘制管理器挂接在一起
  49. m_pm.Init(m_hWnd);
  50. m_pm.AddPreMessageFilter(this);
  51. CDialogBuilder builder;
  52. CControlUI* pRoot = builder.Create(_T("weixinzhifu_shoukuan_wnd.xml"), (UINT)0, NULL, &m_pm);
  53. ASSERT(pRoot && "Failed to parse XML");
  54. // 把这些控件绘制到本窗口上
  55. m_pm.AttachDialog(pRoot);
  56. // 把自己加入到CPaintManagerUI的m_aNotifiers数组中,用于处理Notify函数
  57. m_pm.AddNotifier(this);
  58. Init();
  59. return 0;
  60. }
  61. LRESULT CWeixinzhifuShoukuanWnd::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  62. {
  63. //销毁定时器
  64. KillTimer(m_hWnd, WM_TIMER_WND_CLOSE);
  65. bHandled = FALSE;
  66. return 0;
  67. }
  68. /*
  69. *这个是窗口被销毁的时候调用的
  70. **/
  71. LRESULT CWeixinzhifuShoukuanWnd::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  72. {
  73. bHandled = FALSE;
  74. return 0;
  75. }
  76. LRESULT CWeixinzhifuShoukuanWnd::OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  77. {
  78. if (::IsIconic(*this))
  79. {
  80. bHandled = FALSE;
  81. }
  82. return (wParam == 0) ? TRUE : FALSE;
  83. }
  84. LRESULT CWeixinzhifuShoukuanWnd::OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  85. {
  86. return 0;
  87. }
  88. LRESULT CWeixinzhifuShoukuanWnd::OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  89. {
  90. UpdateFocus();
  91. return 0;
  92. }
  93. LRESULT CWeixinzhifuShoukuanWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  94. {
  95. POINT pt;
  96. pt.x = GET_X_LPARAM(lParam);
  97. pt.y = GET_Y_LPARAM(lParam);
  98. ::ScreenToClient(*this, &pt);
  99. RECT rcClient;
  100. ::GetClientRect(*this, &rcClient);
  101. RECT rcCaption = m_pm.GetCaptionRect();
  102. if (pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
  103. && pt.y >= rcCaption.top && pt.y < rcCaption.bottom)
  104. {
  105. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(pt));
  106. if (pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0)
  107. {
  108. return HTCAPTION;
  109. }
  110. }
  111. return HTCLIENT;
  112. }
  113. LRESULT CWeixinzhifuShoukuanWnd::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  114. {
  115. SIZE szRoundCorner = m_pm.GetRoundCorner();
  116. if (!::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0))
  117. {
  118. CDuiRect rcWnd;
  119. ::GetWindowRect(*this, &rcWnd);
  120. rcWnd.Offset(-rcWnd.left, -rcWnd.top);
  121. rcWnd.right++;
  122. rcWnd.bottom++;
  123. HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);
  124. ::SetWindowRgn(*this, hRgn, TRUE);
  125. ::DeleteObject(hRgn);
  126. }
  127. bHandled = FALSE;
  128. return 0;
  129. }
  130. LRESULT CWeixinzhifuShoukuanWnd::OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  131. {
  132. bHandled = TRUE;
  133. return 0;
  134. }
  135. LRESULT CWeixinzhifuShoukuanWnd::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  136. {
  137. if (wParam != WM_TIMER_WND_CLOSE)
  138. {
  139. bHandled = FALSE;
  140. return 0;
  141. }
  142. if (m_shoukuan_status == 0 || m_shoukuan_status == 1)
  143. {
  144. }
  145. else if (m_shoukuan_status == 2)
  146. {
  147. }
  148. else if (m_shoukuan_status == 3)
  149. {
  150. m_timer_now--;
  151. if (m_timer_now > 0)
  152. {
  153. CLabelUI* attention = static_cast<CLabelUI*>(m_pm.FindControl(_T("shouyin_pay_success_attention")));
  154. std::wstring ws_attention = L"按任意键关闭窗口," + to_wstring(m_timer_now) + L" 秒后自动关闭";
  155. attention->SetText(ws_attention.c_str());
  156. }
  157. else
  158. {
  159. Close(IDOK);
  160. }
  161. }
  162. else if (m_shoukuan_status == 4)
  163. {
  164. m_timer_now--;
  165. if (m_timer_now > 0)
  166. {
  167. CLabelUI* pFailMessage = static_cast<CLabelUI*>(m_pm.FindControl(_T("shouyin_pay_fail_attention")));
  168. std::wstring ws_fail_message = L"失败信息:" + m_fail_message + L",按任意键关闭窗口,";
  169. std::wstring ws_attention = ws_fail_message + to_wstring(m_timer_now) + L" 秒后自动关闭";
  170. pFailMessage->SetText(ws_attention.c_str());
  171. }
  172. else
  173. {
  174. Close(IDCANCEL);
  175. }
  176. }
  177. bHandled = TRUE;
  178. return 0;
  179. }
  180. LRESULT CWeixinzhifuShoukuanWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  181. {
  182. LRESULT lRes = 0;
  183. BOOL bHandled = TRUE;
  184. switch (uMsg)
  185. {
  186. case WM_CREATE:
  187. lRes = OnCreate(uMsg, wParam, lParam, bHandled);
  188. break;
  189. case WM_CLOSE:
  190. lRes = OnClose(uMsg, wParam, lParam, bHandled);
  191. break;
  192. case WM_DESTROY:
  193. lRes = OnDestroy(uMsg, wParam, lParam, bHandled);
  194. break;
  195. case WM_NCACTIVATE:
  196. lRes = OnNcActivate(uMsg, wParam, lParam, bHandled);
  197. break;
  198. case WM_NCCALCSIZE:
  199. lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled);
  200. break;
  201. case WM_NCPAINT:
  202. lRes = OnNcPaint(uMsg, wParam, lParam, bHandled);
  203. break;
  204. case WM_NCHITTEST:
  205. lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled);
  206. break;
  207. case WM_SIZE:
  208. lRes = OnSize(uMsg, wParam, lParam, bHandled);
  209. break;
  210. case WM_MOUSEHOVER:
  211. lRes = OnMouseMove(uMsg, wParam, lParam, bHandled);
  212. break;
  213. case WM_SHOUKUAN_STATUS_NEEDPASSWORD:
  214. lRes = OnShoukuanNeedPassword(uMsg, wParam, lParam, bHandled);
  215. break;
  216. case WM_SHOUKUAN_STATUS_SUCCESS:
  217. lRes = OnShoukuanSuccess(uMsg, wParam, lParam, bHandled);
  218. break;
  219. case WM_SHOUKUAN_STATUS_FAIL:
  220. lRes = OnShoukuanFail(uMsg, wParam, lParam, bHandled);
  221. break;
  222. case WM_TIMER:
  223. lRes = OnTimer(uMsg, wParam, lParam, bHandled);
  224. break;
  225. default:
  226. bHandled = FALSE;
  227. }
  228. if (bHandled)
  229. {
  230. return lRes;
  231. }
  232. if (m_pm.MessageHandler(uMsg, wParam, lParam, lRes))
  233. {
  234. return lRes;
  235. }
  236. return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
  237. }
  238. LRESULT CWeixinzhifuShoukuanWnd::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
  239. {
  240. if (uMsg == WM_KEYDOWN)
  241. {
  242. if (wParam == VK_RETURN)
  243. {
  244. if (m_shoukuan_status == 0)
  245. {
  246. }
  247. else if (m_shoukuan_status == 1 || m_shoukuan_status == 2 || m_shoukuan_status == 5)
  248. {
  249. //正在支付的过程中,这个时候按Enter键,不做任何处理
  250. }
  251. else if (m_shoukuan_status == 3)
  252. {
  253. //已经明确成功或者失败了,那么久直接关闭就可以了
  254. Close(IDOK);
  255. }
  256. else if (m_shoukuan_status == 4)
  257. {
  258. Close(IDCANCEL);
  259. }
  260. return true;
  261. }
  262. else if (wParam == VK_ESCAPE)
  263. {
  264. if (m_shoukuan_status == 0)
  265. {
  266. //还没开始支付,按Esc直接退出
  267. Close(IDCANCEL);
  268. }
  269. else if (m_shoukuan_status == 1 || m_shoukuan_status == 5)
  270. {
  271. //不能做任何处理
  272. }
  273. else if (m_shoukuan_status == 2)
  274. {
  275. //查询密码的过程中,取消付款
  276. CancelShoukuanPassword();
  277. }
  278. else if (m_shoukuan_status == 3)
  279. {
  280. Close(IDOK);
  281. }
  282. else if (m_shoukuan_status == 4)
  283. {
  284. Close(IDCANCEL);
  285. }
  286. return true;
  287. }
  288. if (m_shoukuan_status == 3)
  289. {
  290. Close(IDOK);
  291. return true;
  292. }
  293. else if (m_shoukuan_status == 4)
  294. {
  295. Close(IDCANCEL);
  296. return true;
  297. }
  298. }
  299. return false;
  300. }
  301. void CWeixinzhifuShoukuanWnd::InitMoney(std::wstring value)
  302. {
  303. CLabelUI* pMoneyLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("shoukuan_money_show_money")));
  304. if (pMoneyLabel)
  305. {
  306. pMoneyLabel->SetText(value.c_str());
  307. }
  308. m_money = value;
  309. }
  310. void CWeixinzhifuShoukuanWnd::InitFukuanma(std::string fukuanma)
  311. {
  312. m_fukuanma = fukuanma;
  313. this->StartShoukuan();
  314. }
  315. void CWeixinzhifuShoukuanWnd::SetCommonParams(std::map<string, string> params)
  316. {
  317. m_commonParams = params;
  318. }
  319. void CWeixinzhifuShoukuanWnd::UpdateFocus()
  320. {
  321. }
  322. LRESULT CWeixinzhifuShoukuanWnd::OnShoukuanNeedPassword(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  323. {
  324. wstring path = CSystem::GetProgramDir() + L"\\music\\pay_password.wav";
  325. if (CSetting::GetInstance()->GetParam("setting_is_new_diannei_voice") == "1")
  326. {
  327. PlaySound(path.c_str(), NULL, SND_FILENAME | SND_ASYNC);
  328. }
  329. CLabelUI* pFukuanEdit = static_cast<CLabelUI*>(m_pm.FindControl(_T("shoukuan_paying_status")));
  330. pFukuanEdit->SetText(L"用户支付中,需要输入密码");
  331. //需要用户输入密码,开始查询状态
  332. std::thread(&CWeixinzhifuShoukuanWnd::HandleShoukuanPassword, this).detach();
  333. bHandled = TRUE;
  334. return 0;
  335. }
  336. LRESULT CWeixinzhifuShoukuanWnd::OnShoukuanSuccess(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  337. {
  338. //播放收款成功的金额
  339. if (CSetting::GetInstance()->GetParam("setting_is_new_diannei_voice") == "1")
  340. {
  341. std::thread(&CWeixinzhifuShoukuanWnd::ReadShoukuanValue, this).detach();
  342. }
  343. Close(IDOK);
  344. bHandled = TRUE;
  345. return 0;
  346. /*
  347. CVerticalLayoutUI* paying_layout = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("shoukuan_paying_layout")));
  348. paying_layout->SetVisible(false);
  349. CVerticalLayoutUI* pay_success_layout = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("shoukuan_pay_success_layout")));
  350. pay_success_layout->SetVisible(true);
  351. CLabelUI* pMoneyPaySuccess = static_cast<CLabelUI*>(m_pm.FindControl(_T("shoukuan_pay_success_money")));
  352. std::wstring valueInfo = L"成功收款:¥" + m_money;
  353. pMoneyPaySuccess->SetText(valueInfo.c_str());
  354. CHorizontalLayoutUI* wx_logo = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("shoukuan_pay_success_logo_wx")));
  355. CHorizontalLayoutUI* zhifubao_logo = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("shoukuan_pay_success_logo_zhifubao")));
  356. CHorizontalLayoutUI* yunshanfu_logo = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("shoukuan_pay_success_logo_yunshanfu")));
  357. if (m_fukuanma_type == 1)
  358. {
  359. wx_logo->SetVisible(true);
  360. zhifubao_logo->SetVisible(false);
  361. yunshanfu_logo->SetVisible(false);
  362. }
  363. else if (m_fukuanma_type == 2)
  364. {
  365. wx_logo->SetVisible(false);
  366. zhifubao_logo->SetVisible(true);
  367. yunshanfu_logo->SetVisible(false);
  368. }
  369. else if (m_fukuanma_type == 3)
  370. {
  371. wx_logo->SetVisible(false);
  372. zhifubao_logo->SetVisible(false);
  373. yunshanfu_logo->SetVisible(true);
  374. }
  375. CLabelUI* attention = static_cast<CLabelUI*>(m_pm.FindControl(_T("shouyin_pay_success_attention")));
  376. std::wstring ws_attention = L"按任意键关闭窗口," + to_wstring(m_timer_now) + L" 秒后自动关闭";
  377. attention->SetText(ws_attention.c_str());
  378. SetTimer(m_hWnd, WM_TIMER_WND_CLOSE, 1000, NULL);
  379. SetFocus(m_hWnd);
  380. bHandled = TRUE;
  381. return 0;
  382. */
  383. }
  384. LRESULT CWeixinzhifuShoukuanWnd::OnShoukuanFail(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  385. {
  386. wstring path = CSystem::GetProgramDir() + L"\\music\\pay_fail.wav";
  387. if (CSetting::GetInstance()->GetParam("setting_is_new_diannei_voice") == "1")
  388. {
  389. PlaySound(path.c_str(), NULL, SND_FILENAME | SND_ASYNC);
  390. }
  391. CVerticalLayoutUI* paying_layout = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("shoukuan_paying_layout")));
  392. paying_layout->SetVisible(false);
  393. CVerticalLayoutUI* pay_fail_layout = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("shoukuan_pay_fail_layout")));
  394. pay_fail_layout->SetVisible(true);
  395. CHorizontalLayoutUI* title_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("shoukuan_title_bkg")));
  396. title_layout->SetBkColor(0xFFD33E3A);
  397. CLabelUI* pFailMessage = static_cast<CLabelUI*>(m_pm.FindControl(_T("shouyin_pay_fail_attention")));
  398. std::wstring ws_fail_message = L"失败信息:" + m_fail_message + L",按任意键关闭窗口,";
  399. std::wstring ws_attention = ws_fail_message + to_wstring(m_timer_now) + L" 秒后自动关闭";
  400. pFailMessage->SetText(ws_attention.c_str());
  401. SetTimer(m_hWnd, WM_TIMER_WND_CLOSE, 1000, NULL);
  402. SetFocus(m_hWnd);
  403. bHandled = TRUE;
  404. return 0;
  405. }
  406. void CWeixinzhifuShoukuanWnd::StartShoukuan()
  407. {
  408. CLabelUI* pLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("shoukuanresult")));
  409. //检查收款金额
  410. if (m_money == L"")
  411. {
  412. pLabel->SetText(L"收款金额不能为空,请重新输入!");
  413. pLabel->SetVisible(true);
  414. return;
  415. }
  416. if (m_money == L"0.00")
  417. {
  418. pLabel->SetText(L"收款金额不能为 0 元,请重新输入!");
  419. pLabel->SetVisible(true);
  420. return;
  421. }
  422. double money_value = atof(CLewaimaiString::UnicodeToUTF8(m_money).c_str());
  423. if (!money_value || money_value < 0.01)
  424. {
  425. pLabel->SetText(L"收款金额错误,请重新输入!");
  426. pLabel->SetVisible(true);
  427. return;
  428. }
  429. if (money_value > 50000)
  430. {
  431. pLabel->SetText(L"单笔收款金额不能大于5万,请重新输入!");
  432. pLabel->SetVisible(true);
  433. return;
  434. }
  435. //先判断收款码的格式是否正确
  436. std::string s_Fukuanma = m_fukuanma;
  437. int length = s_Fukuanma.size();
  438. if (length != 18 && length != 19)
  439. {
  440. pLabel->SetText(L"收款码格式不对,请检查后重新输入!");
  441. pLabel->SetVisible(true);
  442. return;
  443. }
  444. for (int i = 0; i < length; i++)
  445. {
  446. char c = *(s_Fukuanma.c_str() + i);
  447. if (isdigit(c) == 0)
  448. {
  449. //不是数字
  450. pLabel->SetText(L"收款码格式不对,请检查后重新输入!");
  451. pLabel->SetVisible(true);
  452. return;
  453. }
  454. }
  455. if (s_Fukuanma.find("10") == 0 \
  456. || s_Fukuanma.find("11") == 0 \
  457. || s_Fukuanma.find("12") == 0 \
  458. || s_Fukuanma.find("13") == 0 \
  459. || s_Fukuanma.find("14") == 0 \
  460. || s_Fukuanma.find("15") == 0)
  461. {
  462. //微信付款码
  463. m_fukuanma_type = 1;
  464. }
  465. else if (s_Fukuanma.find("25") == 0 \
  466. || s_Fukuanma.find("26") == 0 \
  467. || s_Fukuanma.find("27") == 0 \
  468. || s_Fukuanma.find("28") == 0 \
  469. || s_Fukuanma.find("29") == 0 \
  470. || s_Fukuanma.find("30") == 0)
  471. {
  472. //支付宝付款码
  473. m_fukuanma_type = 2;
  474. }
  475. else if (s_Fukuanma.find("62") == 0)
  476. {
  477. //云闪付付款码
  478. m_fukuanma_type = 3;
  479. }
  480. else
  481. {
  482. pLabel->SetText(L"收款码格式不对,请检查后重新输入!");
  483. pLabel->SetVisible(true);
  484. return;
  485. }
  486. //全部验证通过,就可以开始修改状态了
  487. m_shoukuan_status = 1;
  488. //不加这个的话,edit按回车之后样式有问题
  489. SetFocus(m_hWnd);
  490. CVerticalLayoutUI* before_pay_layout = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("shoukuan_before_pay_layout")));
  491. before_pay_layout->SetVisible(false);
  492. CVerticalLayoutUI* paying_layout = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("shoukuan_paying_layout")));
  493. paying_layout->SetVisible(true);
  494. CLabelUI* pMoneyPaying = static_cast<CLabelUI*>(m_pm.FindControl(_T("shoukuan_paying_money")));
  495. std::wstring valueInfo = L"付款金额:¥" + m_money;
  496. pMoneyPaying->SetText(valueInfo.c_str());
  497. //开启一个线程,开始处理收款
  498. std::thread(&CWeixinzhifuShoukuanWnd::HandleShoukuan, this).detach();
  499. }
  500. void CWeixinzhifuShoukuanWnd::HandleShoukuan()
  501. {
  502. //生成随机的order_no
  503. m_commonParams["zhifu_type"] = to_string(7);
  504. m_commonParams["zhifu_code"] = m_fukuanma;
  505. std::string response;
  506. std::string url;
  507. if (m_nType == 1)
  508. {
  509. url = "/diancan/sendorder";
  510. }
  511. else if (m_nType == 2)
  512. {
  513. url = "/dinnercash/pay";
  514. }
  515. else if (m_nType == 4)
  516. {
  517. url = "/shouyin/sendorder";
  518. }
  519. bool ret = CZhipuziHttpClient::GetInstance()->Request(url.c_str(), m_commonParams, response);
  520. if (ret == false)
  521. {
  522. m_shoukuan_status = 4;
  523. m_fail_message = L"请求服务器失败,请检查网络设置!";
  524. SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  525. return;
  526. }
  527. rapidjson::Document document;
  528. document.Parse(response.c_str());
  529. if (document.HasParseError())
  530. {
  531. LOG_INFO("parse response error!");
  532. m_shoukuan_status = 4;
  533. m_fail_message = L"服务器错误";
  534. SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  535. return;
  536. }
  537. if (!document.HasMember("errcode") || !document.HasMember("errmsg"))
  538. {
  539. LOG_INFO("json error!");
  540. m_shoukuan_status = 4;
  541. m_fail_message = L"服务器错误";
  542. SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  543. return;
  544. }
  545. rapidjson::Value& v_errcode = document["errcode"];
  546. int errcode = v_errcode.GetInt();
  547. if (errcode != 0)
  548. {
  549. LOG_INFO("response failed! message:" << document["errmsg"].GetString());
  550. m_shoukuan_status = 4;
  551. std::string errmsg = document["errmsg"].GetString();
  552. m_fail_message = CLewaimaiString::UTF8ToUnicode(errmsg);
  553. SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  554. return;
  555. }
  556. if (!document.HasMember("data"))
  557. {
  558. LOG_INFO("json error!");
  559. m_shoukuan_status = 4;
  560. m_fail_message = L"服务器错误";
  561. SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  562. return;
  563. }
  564. rapidjson::Value& data = document["data"];
  565. rapidjson::Value& status = data["status"];
  566. std::string s_status = status.GetString();
  567. if (s_status == "success")
  568. {
  569. //支付成功
  570. m_shoukuan_status = 3;
  571. if (m_nType == 1)
  572. {
  573. //快餐才有取餐号
  574. m_take_food_code = data["take_food_code"].GetString();
  575. m_trade_no = data["trade_no"].GetString();
  576. Value& stock = data["stock"];
  577. m_kucun_string = CLewaimaiJson::JsonToString(stock);
  578. m_show_trade_no = data["show_trade_no"].GetString();
  579. }
  580. else if (m_nType == 2)
  581. {
  582. Value& stock = data["stock"];
  583. m_kucun_string = CLewaimaiJson::JsonToString(stock);
  584. m_show_trade_no = data["show_trade_no"].GetString();
  585. }
  586. else if (m_nType == 4)
  587. {
  588. m_show_trade_no = data["trade_no"].GetString();
  589. }
  590. SendMessage(WM_SHOUKUAN_STATUS_SUCCESS, 0, 0);
  591. }
  592. else if (s_status == "fail")
  593. {
  594. //支付失败
  595. m_shoukuan_status = 4;
  596. m_fail_message = CLewaimaiString::UTF8ToUnicode(data["message"].GetString());
  597. SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  598. }
  599. else if (s_status == "password")
  600. {
  601. m_shoukuan_status = 2;
  602. m_trade_no = data["trade_no"].GetString();
  603. m_show_trade_no = data["trade_no"].GetString();
  604. //需要查询支付状态
  605. SendMessage(WM_SHOUKUAN_STATUS_NEEDPASSWORD, 0, 0);
  606. }
  607. else
  608. {
  609. m_shoukuan_status = 4;
  610. m_fail_message = L"服务器错误";
  611. SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  612. }
  613. }
  614. void CWeixinzhifuShoukuanWnd::HandleShoukuanPassword()
  615. {
  616. std::map<string, string> params;
  617. params["trade_no"] = m_trade_no;
  618. while (m_shoukuan_status == 2)
  619. {
  620. std::string response;
  621. std::string url;
  622. if (m_nType == 1)
  623. {
  624. url = "/diancan/queryorderstatus";
  625. }
  626. else if (m_nType == 2)
  627. {
  628. url = "/dinnercash/queryorderstatus";
  629. params["is_clear"] = "1";
  630. }
  631. else if (m_nType == 4)
  632. {
  633. url = "/shouyin/queryorderstatus";
  634. }
  635. bool ret = CZhipuziHttpClient::GetInstance()->Request(url.c_str(), params, response);
  636. if (ret == false)
  637. {
  638. m_shoukuan_status = 4;
  639. m_fail_message = L"请求服务器失败,请检查网络设置!";
  640. SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  641. return;
  642. }
  643. rapidjson::Document document;
  644. document.Parse(response.c_str());
  645. if (document.HasParseError())
  646. {
  647. LOG_INFO("parse response error!");
  648. m_shoukuan_status = 4;
  649. m_fail_message = L"服务器错误";
  650. SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  651. return;
  652. }
  653. if (!document.HasMember("errcode") || !document.HasMember("errmsg") || !document.HasMember("data"))
  654. {
  655. LOG_INFO("json error!");
  656. m_shoukuan_status = 4;
  657. m_fail_message = L"服务器错误";
  658. SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  659. return;
  660. }
  661. rapidjson::Value& v_errcode = document["errcode"];
  662. int errcode = v_errcode.GetInt();
  663. if (errcode != 0)
  664. {
  665. LOG_INFO("response failed! message:" << document["errmsg"].GetString());
  666. m_shoukuan_status = 4;
  667. m_fail_message = L"服务器错误";
  668. SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  669. return;
  670. }
  671. rapidjson::Value& data = document["data"];
  672. rapidjson::Value& status = data["status"];
  673. std::string s_status = status.GetString();
  674. if (s_status == "success")
  675. {
  676. //支付成功
  677. m_shoukuan_status = 3;
  678. if (m_nType == 1)
  679. {
  680. //快餐才有取餐号
  681. m_take_food_code = data["take_food_code"].GetString();
  682. Value& stock = data["stock"];
  683. m_kucun_string = CLewaimaiJson::JsonToString(stock);
  684. m_show_trade_no = data["show_trade_no"].GetString();
  685. }
  686. else if (m_nType == 2)
  687. {
  688. Value& stock = data["stock"];
  689. m_kucun_string = CLewaimaiJson::JsonToString(stock);
  690. m_show_trade_no = data["show_trade_no"].GetString();
  691. }
  692. else if (m_nType == 4)
  693. {
  694. }
  695. SendMessage(WM_SHOUKUAN_STATUS_SUCCESS, 0, 0);
  696. break;
  697. }
  698. else if (s_status == "fail")
  699. {
  700. if (data.HasMember("message") && CLewaimaiJson::ToString(data["message"]).length() > 0)
  701. {
  702. //返回了message,表示顾客主动关闭了支付
  703. //表示顾客那边出问题,已经失败了
  704. m_shoukuan_status = 4;
  705. m_fail_message = L"顾客取消支付,请重新扫码收款";
  706. SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  707. break;
  708. }
  709. else
  710. {
  711. //这个只是表示状态未知
  712. Sleep(1000);
  713. }
  714. }
  715. else
  716. {
  717. m_shoukuan_status = 4;
  718. m_fail_message = L"服务器错误";
  719. SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  720. break;
  721. }
  722. }
  723. }
  724. void CWeixinzhifuShoukuanWnd::CancelShoukuanPassword()
  725. {
  726. m_shoukuan_status = 5;
  727. std::thread(&CWeixinzhifuShoukuanWnd::HandleCancelShoukuan, this).detach();
  728. }
  729. void CWeixinzhifuShoukuanWnd::HandleCancelShoukuan()
  730. {
  731. std::map<string, string> params;
  732. params["trade_no"] = m_trade_no;
  733. std::string response;
  734. std::string url;
  735. if (m_nType == 1)
  736. {
  737. url = "/diancan/closeorder";
  738. }
  739. else if (m_nType == 2)
  740. {
  741. url = "/dinnercash/closeorder";
  742. }
  743. else if (m_nType == 4)
  744. {
  745. url = "/shouyin/closeorder";
  746. }
  747. bool ret = CZhipuziHttpClient::GetInstance()->Request(url.c_str(), params, response);
  748. if (ret == false)
  749. {
  750. m_shoukuan_status = 4;
  751. m_fail_message = L"请求服务器失败,请检查网络设置!";
  752. SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  753. return;
  754. }
  755. rapidjson::Document document;
  756. document.Parse(response.c_str());
  757. if (document.HasParseError())
  758. {
  759. LOG_INFO("parse response error!");
  760. m_shoukuan_status = 4;
  761. m_fail_message = L"服务器错误";
  762. SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  763. return;
  764. }
  765. if (!document.HasMember("errcode") || !document.HasMember("errmsg") || !document.HasMember("data"))
  766. {
  767. LOG_INFO("json error!");
  768. m_shoukuan_status = 4;
  769. m_fail_message = L"服务器错误";
  770. SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  771. return;
  772. }
  773. rapidjson::Value& v_errcode = document["errcode"];
  774. int errcode = v_errcode.GetInt();
  775. if (errcode != 0)
  776. {
  777. LOG_INFO("response failed! message:" << document["errmsg"].GetString());
  778. m_shoukuan_status = 4;
  779. m_fail_message = L"服务器错误";
  780. SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  781. return;
  782. }
  783. rapidjson::Value& data = document["data"];
  784. rapidjson::Value& status = data["status"];
  785. std::string s_status = status.GetString();
  786. if (s_status == "success")
  787. {
  788. //取消成功,订单变为失败状态
  789. m_shoukuan_status = 4;
  790. m_fail_message = L"商家取消收款";
  791. SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  792. }
  793. m_shoukuan_status = 4;
  794. m_fail_message = L"服务器错误";
  795. SendMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  796. }
  797. bool CWeixinzhifuShoukuanWnd::IsCanClose()
  798. {
  799. if (m_shoukuan_status == 0 || m_shoukuan_status == 3 || m_shoukuan_status == 4)
  800. {
  801. return true;
  802. }
  803. return false;
  804. }
  805. void CWeixinzhifuShoukuanWnd::ReadShoukuanValue()
  806. {
  807. CSpeech::SpeakNum(1, CLewaimaiString::UnicodeToUTF8(m_money));
  808. }
  809. //处理键盘捕捉结果
  810. void CWeixinzhifuShoukuanWnd::HandleTextCapture(std::string content)
  811. {
  812. m_fukuanma = content;
  813. if (m_shoukuan_status == 0)
  814. {
  815. StartShoukuan();
  816. }
  817. }