formaccountinfo.cpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. #include "formaccountinfo.h"
  2. #include "ui_formaccountinfo.h"
  3. #include "respgetuserzxshserviceinfo.h"
  4. #include "respgetservertime.h"
  5. #include "respencrypt.h"
  6. #include "sncdatabase.h"
  7. FormAccountInfo::FormAccountInfo(QWidget *parent) :
  8. QWidget(parent),
  9. ui(new Ui::FormAccountInfo)
  10. {
  11. ui->setupUi(this);
  12. initVariables();
  13. initUI();
  14. }
  15. void FormAccountInfo::setAccountInfo(QMap<QString, QString> info)
  16. {
  17. m_account = info;
  18. QString ssoHash = info.value("ssohash");
  19. QString userCode = info.value("usercode");
  20. if(!ssoHash.isEmpty())
  21. {
  22. setAccountAreaUI(LoginOk);
  23. }
  24. else
  25. {
  26. if(userCode.isEmpty())
  27. {
  28. setAccountAreaUI(NotLogin);
  29. }
  30. else
  31. {
  32. setAccountAreaUI(LoginError);
  33. }
  34. }
  35. }
  36. FormAccountInfo::~FormAccountInfo()
  37. {
  38. m_cubews->abort();
  39. m_ssows->abort();
  40. m_movie->stop();
  41. delete m_movie;
  42. delete m_ssows;
  43. delete m_cubews;
  44. delete ui;
  45. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  46. <<"FormRiddle.FormAccountInfo Destroyed.";
  47. }
  48. void FormAccountInfo::initVariables()
  49. {
  50. m_cubews = new WSCube2();
  51. m_ssows = new WSSSO();
  52. m_movie = new QMovie(":/working.gif");
  53. m_movie->start();
  54. }
  55. void FormAccountInfo::initUI()
  56. {
  57. //初始化背景效果
  58. ui->widgetBackgournd->setProperty("class","silverbg");
  59. //初始化登录后显示的账户相关信息区域的样式
  60. ui->pushButtonCharge->setProperty("class","small-red-bg");
  61. ui->pushButtonLogin->setProperty("class","txt-green");
  62. ui->pushButtonRefreshUserState->setProperty("class","txt-green");
  63. ui->pushButtonDetail->setProperty("class","txt-green");
  64. setAccountAreaUI(NotLogin);
  65. }
  66. void FormAccountInfo::setAccountAreaUI(AccountLoginState state)
  67. {
  68. switch(state)
  69. {
  70. case LoginOk:
  71. ui->labelTip->setText("");
  72. ui->labelTip2->setText("");
  73. ui->pushButtonLogin->setVisible(false);
  74. ui->widgetAccountInfo->setVisible(true);
  75. ui->widgetDefault->setVisible(false);
  76. refreshAccountInfo();
  77. break;
  78. case NotLogin:
  79. ui->labelTip->setText("您需要");
  80. ui->labelTip2->setText("才可以使用该功能!");
  81. ui->pushButtonLogin->setVisible(true);
  82. ui->widgetAccountInfo->setVisible(false);
  83. ui->widgetDefault->setVisible(true);
  84. break;
  85. case NotBind:
  86. ui->labelTip->setText("实号快检服务尚未开通!");
  87. ui->pushButtonLogin->setVisible(false);
  88. ui->widgetAccountInfo->setVisible(false);
  89. ui->widgetDefault->setVisible(true);
  90. break;
  91. case LoginError:
  92. ui->labelTip->setText("实号快检服务无法连接!");
  93. ui->pushButtonLogin->setVisible(false);
  94. ui->widgetAccountInfo->setVisible(false);
  95. ui->widgetDefault->setVisible(true);
  96. break;
  97. }
  98. changeImage(state);
  99. }
  100. void FormAccountInfo::changeImage(AccountLoginState state)
  101. {
  102. m_state = state;
  103. QPixmap pixamp(":/service_state.png");
  104. int nHeight = pixamp.height();
  105. int nWidth = pixamp.width()/4;
  106. ui->labelStateImage->setPixmap(pixamp.copy(QRect(state * nWidth , 0, nWidth, nHeight)));
  107. }
  108. void FormAccountInfo::refreshAccountInfo()
  109. {
  110. QString ssoHash = m_account.value("ssohash");
  111. ui->labelStateImage->setMovie(m_movie);
  112. m_cubews->abort();
  113. QString json = m_cubews->getUserZXSHServiceInfo(ssoHash);
  114. changeImage(m_state);
  115. bool succeed = false;
  116. RespGetUserZXSHServiceInfo resp(json);
  117. if(resp.getRtnCode()==1)
  118. {
  119. int downloads = resp.getMonthDownShzs().toInt();
  120. int maxdownloads = resp.getMonthMaxDownShzs().toInt();
  121. int downloadslimit = maxdownloads-downloads;
  122. int checks = resp.getZxshMonthDownShzs().toInt();
  123. int maxchecks = resp.getZxshMonthMaxDownShzs().toInt();
  124. int checkslimit = maxchecks-checks;
  125. QDateTime dt1=QDateTime::fromString(resp.getMonthStartTime(),"yyyy-MM-dd hh:mm:ss");
  126. QDateTime dt2=QDateTime::fromString(resp.getMonthEndTime(),"yyyy-MM-dd hh:mm:ss");
  127. QString startTime = dt1.toString("yy年MM月dd日");
  128. QString endTime = dt2.toString("yy年MM月dd日");
  129. ui->labelChecked->setText(QString("%1-%2").arg(startTime).arg(endTime));
  130. ui->labelDownloaded->setText(QString("%1/%2").arg(downloads).arg(downloadslimit));
  131. succeed = true;
  132. }
  133. if(!succeed)
  134. {
  135. ui->labelChecked->setText("N/A");
  136. ui->labelDownloaded->setText("N/A");
  137. }
  138. }
  139. void FormAccountInfo::on_pushButtonLogin_clicked()
  140. {
  141. emit buttonLoginClick();
  142. }
  143. void FormAccountInfo::on_pushButtonCharge_clicked()
  144. {
  145. QString ssoHash = m_account.value("ssohash");
  146. if(ssoHash.isEmpty())
  147. {
  148. QMessageBox::critical(this,"提示","您现在还没有登录系统,请登录后再操作!",QMessageBox::Ok);
  149. return;
  150. }
  151. if(!checkLastClickTime(sender()))
  152. return ;
  153. QString json = m_ssows->encrypt(ssoHash);
  154. RespEncrypt resp1(json);
  155. QString data = resp1.getEncryptData();
  156. json = m_ssows->getServerTime();
  157. RespGetServerTime resp2(json);
  158. QString authCode;
  159. QByteArray ba;
  160. QString str = SNCDataBase::getAuthCodeUrl().arg(resp2.getServerTime().mid(0,16));
  161. ba = QCryptographicHash::hash ( str.toAscii(), QCryptographicHash::Md5 );
  162. authCode.append(ba.toHex());
  163. QString url = SNCDataBase::getSSOPayUrl() + "?s=mf&r="+authCode+"&u="+data+"&p=zxcz_zxsh";
  164. QDesktopServices::openUrl(QUrl(url));
  165. }
  166. void FormAccountInfo::on_pushButtonRefreshUserState_clicked()
  167. {
  168. QString ssoHash = m_account.value("ssohash");
  169. if(ssoHash.isEmpty())
  170. {
  171. QMessageBox::critical(this,"提示","您现在还没有登录系统,请登录后再操作!",QMessageBox::Ok);
  172. return;
  173. }
  174. if(!checkLastClickTime(sender()))
  175. return ;
  176. setCursor(Qt::WaitCursor);
  177. refreshAccountInfo();
  178. setCursor(Qt::ArrowCursor);
  179. }
  180. void FormAccountInfo::onDataUpdated()
  181. {
  182. refreshAccountInfo();
  183. }
  184. bool FormAccountInfo::checkLastClickTime(QObject *button)
  185. {
  186. QPushButton *btn = qobject_cast<QPushButton*>(button);
  187. QDateTime lasttime = m_clickTime.value(btn->objectName());
  188. if(!lasttime.isNull())
  189. {
  190. if(lasttime.addSecs(30)>QDateTime::currentDateTime())
  191. {
  192. QMessageBox::critical(this,"提示","您不可以频繁点击!",QMessageBox::Ok);
  193. return false;
  194. }
  195. }
  196. m_clickTime.insert(btn->objectName(),QDateTime::currentDateTime());
  197. return true;
  198. }
  199. void FormAccountInfo::on_pushButtonDetail_clicked()
  200. {
  201. QString ssoHash = m_account.value("ssohash");
  202. if(ssoHash.isEmpty())
  203. {
  204. QMessageBox::critical(this,"提示","您现在还没有登录系统,请登录后再操作!",QMessageBox::Ok);
  205. return;
  206. }
  207. if(!checkLastClickTime(sender()))
  208. return ;
  209. QString json = m_ssows->encrypt(ssoHash);
  210. RespEncrypt resp1(json);
  211. QString data = resp1.getEncryptData();
  212. json = m_ssows->getServerTime();
  213. RespGetServerTime resp2(json);
  214. QString authCode;
  215. QByteArray ba;
  216. QString str = SNCDataBase::getAuthCodeUrl().arg(resp2.getServerTime().mid(0,16));
  217. ba = QCryptographicHash::hash ( str.toAscii(), QCryptographicHash::Md5 );
  218. authCode.append(ba.toHex());
  219. QString url = SNCDataBase::getSSOPayUrl() + "?s=mf&r="+authCode+"&u="+data+"&p=xq_zxsh";
  220. QDesktopServices::openUrl(QUrl(url));
  221. }