formaccountinfo.cpp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. #include "formaccountinfo.h"
  2. #include "ui_formaccountinfo.h"
  3. #include "respgetservertime.h"
  4. #include "respencrypt.h"
  5. #include "respgetuserblance.h"
  6. #include "sncdatabase.h"
  7. #include "dialogbindsystem.h"
  8. FormAccountInfo::FormAccountInfo(QWidget *parent) :
  9. QWidget(parent),
  10. ui(new Ui::FormAccountInfo)
  11. {
  12. ui->setupUi(this);
  13. initVariables();
  14. initUI();
  15. }
  16. void FormAccountInfo::setClientID(QString clientID)
  17. {
  18. m_clientID = clientID;
  19. }
  20. void FormAccountInfo::setHost(QString host, QString port)
  21. {
  22. m_host = host;
  23. m_port = port;
  24. m_numchk->setHost(host,port);
  25. }
  26. FormAccountInfo::~FormAccountInfo()
  27. {
  28. m_numchk->abort();
  29. m_ssows->abort();
  30. m_movie->stop();
  31. delete m_movie;
  32. delete m_ssows;
  33. delete m_numchk;
  34. delete ui;
  35. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  36. <<"FormRiddle.FormAccountInfo Destroyed.";
  37. }
  38. void FormAccountInfo::setAccountInfo(QMap<QString, QString> info)
  39. {
  40. m_account = info;
  41. QString ssoHash = info.value("ssohash");
  42. QString userCode = info.value("usercode");
  43. QString userHash = info.value("userhash");
  44. if(!ssoHash.isEmpty())
  45. {
  46. if(!userHash.isEmpty())
  47. {
  48. setAccountAreaUI(LoginOk);
  49. }
  50. else
  51. {
  52. if(!userCode.isEmpty())
  53. {
  54. setAccountAreaUI(LoginError);
  55. }
  56. else
  57. {
  58. setAccountAreaUI(NotBind);
  59. }
  60. }
  61. }
  62. else
  63. {
  64. setAccountAreaUI(NotLogin);
  65. }
  66. }
  67. void FormAccountInfo::initVariables()
  68. {
  69. m_numchk = new WSNumChk();
  70. m_ssows = new WSSSO();
  71. m_movie = new QMovie(":/working.gif");
  72. m_movie->start();
  73. }
  74. void FormAccountInfo::initUI()
  75. {
  76. //初始化背景效果
  77. ui->widgetBackground->setProperty("class","silverbg");
  78. //初始化登录后显示的账户相关信息区域的样式
  79. ui->pushButtonCharge->setProperty("class","small-red-bg");
  80. ui->pushButtonLogin->setProperty("class","txt-green");
  81. ui->pushButtonBind->setProperty("class","txt-green-bold");
  82. ui->pushButtonRefreshUserState->setProperty("class","txt-green");
  83. ui->pushButtonPay->setProperty("class","txt-green-bold");
  84. ui->labelToPay->setStyleSheet("color:red");
  85. setAccountAreaUI(NotLogin);
  86. }
  87. void FormAccountInfo::setAccountAreaUI(AccountLoginState state)
  88. {
  89. switch(state)
  90. {
  91. case LoginOk:
  92. ui->labelTip->setText("");
  93. ui->widgetAccountInfo->setVisible(true);
  94. ui->pushButtonLogin->setVisible(false);
  95. ui->labelTip2->setText("");
  96. ui->labelTip3->setText("");
  97. ui->widgetDefault->setVisible(false);
  98. refreshAccountInfo();
  99. break;
  100. case NotLogin:
  101. ui->labelTip->setText("您需要");
  102. ui->widgetAccountInfo->setVisible(false);
  103. ui->pushButtonLogin->setVisible(true);
  104. ui->pushButtonBind->setVisible(false);
  105. ui->labelTip2->setText("才可以使用该功能!");
  106. ui->widgetDefault->setVisible(true);
  107. ui->labelTip3->setText("");
  108. break;
  109. case NotBind:
  110. ui->labelTip->setText("尚未开通");
  111. ui->widgetAccountInfo->setVisible(false);
  112. ui->pushButtonLogin->setVisible(false);
  113. ui->pushButtonBind->setVisible(true);
  114. ui->labelTip2->setText("空号检测服务!请点击此处[ ");
  115. ui->widgetDefault->setVisible(true);
  116. ui->labelTip3->setText(" ]");
  117. break;
  118. case LoginError:
  119. ui->labelTip->setText("空号检测服务无法连接!");
  120. ui->widgetAccountInfo->setVisible(false);
  121. ui->pushButtonLogin->setVisible(false);
  122. ui->pushButtonBind->setVisible(false);
  123. ui->widgetDefault->setVisible(true);
  124. ui->labelTip2->setText("");
  125. ui->labelTip3->setText("");
  126. break;
  127. }
  128. changeImage(state);
  129. }
  130. void FormAccountInfo::changeImage(AccountLoginState state)
  131. {
  132. m_state = state;
  133. QPixmap pixamp(":/service_state.png");
  134. int nHeight = pixamp.height();
  135. int nWidth = pixamp.width()/4;
  136. ui->labelStateImage->setPixmap(pixamp.copy(QRect(state * nWidth , 0, nWidth, nHeight)));
  137. }
  138. void FormAccountInfo::refreshAccountInfo()
  139. {
  140. bool succeed =false;
  141. QString userHash = m_account.value("userhash");
  142. ui->labelStateImage->setMovie(m_movie);
  143. QString json = m_numchk->getUserBalance(userHash);
  144. changeImage(m_state);
  145. RespGetUserBlance response (json);
  146. if(response.getRtnCode()==1){
  147. ui->labelGiftBalance->setText("¥" + response.getGiftMoney());
  148. ui->labelUserBlance->setText("¥" + response.getBlance());
  149. ui->labelValidNum->setText(response.getValidNum());
  150. ui->labelToPay->setText("待付金额:¥" + response.getToPayMoney());
  151. if(response.getToPayMoney()>response.getBlance())
  152. emit blanceOut();
  153. else
  154. emit blanceIn();
  155. // if(response.getToPayMoney().toDouble()==0)
  156. // {
  157. // ui->labelToPay->setVisible(false);
  158. // ui->pushButtonPay->setVisible(false);
  159. // }
  160. // else
  161. // {
  162. // ui->labelToPay->setVisible(true);
  163. // ui->pushButtonPay->setVisible(true);
  164. // }
  165. succeed = true;
  166. }
  167. if(!succeed)
  168. {
  169. ui->labelGiftBalance->setText("N/A");
  170. ui->labelUserBlance->setText("N/A");
  171. ui->labelValidNum->setText("N/A");
  172. ui->labelToPay->setText("待付金额:N/A");
  173. }
  174. }
  175. void FormAccountInfo::on_pushButtonLogin_clicked()
  176. {
  177. emit buttonLoginClick();
  178. }
  179. void FormAccountInfo::on_pushButtonCharge_clicked()
  180. {
  181. QString ssoHash = m_account.value("ssohash");
  182. if(ssoHash.isEmpty())
  183. {
  184. QMessageBox::critical(this,"提示","您现在还没有登录系统,请登录后再操作!",QMessageBox::Ok);
  185. return;
  186. }
  187. if(!checkLastClickTime(sender()))
  188. return ;
  189. QString json = m_ssows->encrypt(ssoHash);
  190. RespEncrypt resp1(json);
  191. QString data = resp1.getEncryptData();
  192. json = m_ssows->getServerTime();
  193. RespGetServerTime resp2(json);
  194. QString authCode;
  195. QByteArray ba;
  196. QString str = SNCDataBase::getAuthCodeUrl().arg(resp2.getServerTime().mid(0,16));
  197. ba = QCryptographicHash::hash ( str.toAscii(), QCryptographicHash::Md5 );
  198. authCode.append(ba.toHex());
  199. QString url = SNCDataBase::getSSOPayUrl() + "?s=mf&r="+authCode+"&u="+data+"&p=zxcz_"+m_clientID;
  200. QDesktopServices::openUrl(QUrl(url));
  201. }
  202. void FormAccountInfo::on_pushButtonRefreshUserState_clicked()
  203. {
  204. QString userHash = m_account.value("userhash");
  205. if(userHash.isEmpty())
  206. {
  207. QMessageBox::critical(this,"提示","您现在还没有登录系统,请登录后再操作!",QMessageBox::Ok);
  208. return;
  209. }
  210. if(!checkLastClickTime(sender()))
  211. return ;
  212. setCursor(Qt::WaitCursor);
  213. refreshAccountInfo();
  214. setCursor(Qt::ArrowCursor);
  215. }
  216. void FormAccountInfo::onDataUpdated()
  217. {
  218. refreshAccountInfo();
  219. }
  220. bool FormAccountInfo::checkLastClickTime(QObject *button)
  221. {
  222. QPushButton *btn = qobject_cast<QPushButton*>(button);
  223. QDateTime lasttime = m_clickTime.value(btn->objectName());
  224. if(!lasttime.isNull())
  225. {
  226. if(lasttime.addSecs(30)>QDateTime::currentDateTime())
  227. {
  228. QMessageBox::critical(this,"提示","您不可以频繁点击!",QMessageBox::Ok);
  229. return false;
  230. }
  231. }
  232. m_clickTime.insert(btn->objectName(),QDateTime::currentDateTime());
  233. return true;
  234. }
  235. void FormAccountInfo::on_pushButtonPay_clicked()
  236. {
  237. QString userHash = m_account.value("userhash");
  238. if(userHash.isEmpty())
  239. {
  240. QMessageBox::critical(this,"提示","您现在还没有登录系统,请登录后再操作!",QMessageBox::Ok);
  241. return;
  242. }
  243. if(!checkLastClickTime(sender()))
  244. return ;
  245. QString json = m_ssows->encrypt(userHash);
  246. RespEncrypt resp1(json);
  247. QString data = resp1.getEncryptData();
  248. json = m_ssows->getServerTime();
  249. RespGetServerTime resp2(json);
  250. QString authCode;
  251. QByteArray ba;
  252. QString str = SNCDataBase::getAuthCodeUrl().arg(resp2.getServerTime().mid(0,16));
  253. ba = QCryptographicHash::hash ( str.toAscii(), QCryptographicHash::Md5 );
  254. authCode.append(ba.toHex());
  255. QString url = SNCDataBase::getSSOPayUrl() + "?s=mf&r="+authCode+"&u="+data+"&p=fk_"+m_clientID;
  256. QDesktopServices::openUrl(QUrl(url));
  257. }
  258. void FormAccountInfo::on_pushButtonBind_clicked()
  259. {
  260. DialogBindSystem dialog(this);
  261. QString ssoHash = m_account.value("ssohash");
  262. QString syscode = "";
  263. if(m_clientID=="sskh")
  264. {
  265. syscode = "1";
  266. }
  267. else if(m_clientID=="mykh")
  268. {
  269. syscode = "2";
  270. }
  271. dialog.setSysRegInfo(syscode,ssoHash);
  272. dialog.exec();
  273. if(dialog.serviceIsOpen())
  274. {
  275. // refreshSrvInfo();
  276. // WSSSO sso2;
  277. // QString json = sso2.getSysAccount(syscode,this->userHash);
  278. // RespGetSysAccount response2(json);
  279. // if(response2.getRtnCode() == 1)
  280. // {
  281. // QMap<QString,QString> shunshiInfo,mingyuanInfo;
  282. // if(syscode=="1")
  283. // {
  284. // shunshiInfo.insert("usercode",response2.getUserCode());
  285. // shunshiInfo.insert("userpwd",response2.getUserPwd());
  286. // emit updateShunShiAccount(shunshiInfo);
  287. // }
  288. // else if(syscode=="2")
  289. // {
  290. // mingyuanInfo.insert("usercode",response2.getUserCode());
  291. // mingyuanInfo.insert("userpwd",response2.getUserPwd());
  292. // emit updateMingYuanAccount(mingyuanInfo);
  293. // }
  294. // }
  295. }
  296. }