formaccountinfo.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #include "formaccountinfo.h"
  2. #include "ui_formaccountinfo.h"
  3. #include "respgetusershkjserviceinfo.h"
  4. #include "respgetservertime.h"
  5. #include "respencrypt.h"
  6. #include "sncdatabase.h"
  7. #include "dialogviewfeedetail.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::setAccountInfo(QMap<QString, QString> info)
  17. {
  18. m_account = info;
  19. QString ssoHash = info.value("ssohash");
  20. QString userCode = info.value("usercode");
  21. if(!ssoHash.isEmpty())
  22. {
  23. setAccountAreaUI(LoginOk);
  24. }
  25. else
  26. {
  27. if(userCode.isEmpty())
  28. {
  29. setAccountAreaUI(NotLogin);
  30. }
  31. else
  32. {
  33. setAccountAreaUI(LoginError);
  34. }
  35. }
  36. }
  37. FormAccountInfo::~FormAccountInfo()
  38. {
  39. m_cubews->abort();
  40. m_ssows->abort();
  41. m_movie->stop();
  42. delete m_movie;
  43. delete m_ssows;
  44. delete m_cubews;
  45. delete ui;
  46. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  47. <<"FormRiddle.FormAccountInfo Destroyed.";
  48. }
  49. void FormAccountInfo::initVariables()
  50. {
  51. m_cubews = new WSCube2();
  52. m_ssows = new WSSSO();
  53. m_movie = new QMovie(":/working.gif");
  54. m_movie->start();
  55. }
  56. void FormAccountInfo::initUI()
  57. {
  58. //初始化背景效果
  59. ui->widgetBackgournd->setProperty("class","silverbg");
  60. //初始化登录后显示的账户相关信息区域的样式
  61. ui->pushButtonCharge->setProperty("class","small-red-bg");
  62. ui->pushButtonLogin->setProperty("class","txt-green");
  63. ui->pushButtonRefreshUserState->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->getUserSHKJServiceInfo(ssoHash);
  114. changeImage(m_state);
  115. bool succeed = false;
  116. RespGetUserSHKJServiceInfo 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.getShkjDaySubmitHmzs().toInt();
  123. int maxchecks = resp.getShkjDayMaxSubmitHmzs().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_shkj";
  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. }