formaccountinfo.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. #include "formaccountinfo.h"
  2. #include "ui_formaccountinfo.h"
  3. #include "respgetuserjsjcserviceinfo.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 WSCube();
  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","txt-green");
  61. ui->pushButtonLogin->setProperty("class","txt-green");
  62. ui->pushButtonRefreshUserState->setProperty("class","txt-green");
  63. setAccountAreaUI(NotLogin);
  64. }
  65. void FormAccountInfo::setAccountAreaUI(AccountLoginState state)
  66. {
  67. switch(state)
  68. {
  69. case LoginOk:
  70. ui->labelTip->setText("您可以使用号码推荐服务");
  71. ui->labelTip2->setText("");
  72. ui->pushButtonLogin->setVisible(false);
  73. ui->widgetAccountInfo->setVisible(false);
  74. ui->widgetDefault->setVisible(true);
  75. refreshAccountInfo();
  76. break;
  77. case NotLogin:
  78. ui->labelTip->setText("您需要");
  79. ui->labelTip2->setText("才可以使用该功能!");
  80. ui->pushButtonLogin->setVisible(true);
  81. ui->widgetAccountInfo->setVisible(false);
  82. ui->widgetDefault->setVisible(true);
  83. break;
  84. case NotBind:
  85. ui->labelTip->setText("号码推荐服务尚未开通!");
  86. ui->pushButtonLogin->setVisible(false);
  87. ui->widgetAccountInfo->setVisible(false);
  88. ui->widgetDefault->setVisible(true);
  89. break;
  90. case LoginError:
  91. ui->labelTip->setText("号码推荐服务无法连接!");
  92. ui->pushButtonLogin->setVisible(false);
  93. ui->widgetAccountInfo->setVisible(false);
  94. ui->widgetDefault->setVisible(true);
  95. break;
  96. }
  97. changeImage(state);
  98. }
  99. void FormAccountInfo::changeImage(AccountLoginState state)
  100. {
  101. m_state = state;
  102. QPixmap pixamp(":/service_state.png");
  103. int nHeight = pixamp.height();
  104. int nWidth = pixamp.width()/4;
  105. ui->labelStateImage->setPixmap(pixamp.copy(QRect(state * nWidth , 0, nWidth, nHeight)));
  106. }
  107. void FormAccountInfo::refreshAccountInfo()
  108. {
  109. QString ssoHash = m_account.value("ssohash");
  110. ui->labelStateImage->setMovie(m_movie);
  111. QString json = m_cubews->getUserJSJCServiceInfo(ssoHash);
  112. changeImage(m_state);
  113. bool succeed = false;
  114. RespGetUserJSJCServiceInfo resp(json);
  115. if(resp.getRtnCode()==1)
  116. {
  117. int downloads = resp.getMonthDownHmzs().toInt();
  118. int maxdownloads = resp.getMonthMaxDownHmzs().toInt();
  119. int downloadslimit = maxdownloads-downloads;
  120. int checks = resp.getDaySubmitHmzs().toInt();
  121. int maxchecks = resp.getDayMaxSubmitHmzs().toInt();
  122. int checkslimit = maxchecks-checks;
  123. ui->labelChecked->setText(QString("%1/%2").arg(checks).arg(checkslimit));
  124. ui->labelDownloaded->setText(QString("%1/%2").arg(downloads).arg(downloadslimit));
  125. succeed = true;
  126. }
  127. if(!succeed)
  128. {
  129. ui->labelChecked->setText("N/A");
  130. ui->labelDownloaded->setText("N/A");
  131. }
  132. }
  133. void FormAccountInfo::on_pushButtonLogin_clicked()
  134. {
  135. emit buttonLoginClick();
  136. }
  137. void FormAccountInfo::on_pushButtonCharge_clicked()
  138. {
  139. QString ssoHash = m_account.value("ssohash");
  140. if(ssoHash.isEmpty())
  141. {
  142. QMessageBox::critical(this,"提示","您现在还没有登录系统,请登录后再操作!",QMessageBox::Ok);
  143. return;
  144. }
  145. if(!checkLastClickTime(sender()))
  146. return ;
  147. QString json = m_ssows->encrypt(ssoHash);
  148. RespEncrypt resp1(json);
  149. QString data = resp1.getEncryptData();
  150. json = m_ssows->getServerTime();
  151. RespGetServerTime resp2(json);
  152. QString authCode;
  153. QByteArray ba;
  154. QString str = SNCDataBase::getAuthCodeUrl().arg(resp2.getServerTime().mid(0,16));
  155. ba = QCryptographicHash::hash ( str.toAscii(), QCryptographicHash::Md5 );
  156. authCode.append(ba.toHex());
  157. QString url = SNCDataBase::getSSOPayUrl() + "?s=mf&r="+authCode+"&u="+data+"&p=zxcz_shkj";
  158. QDesktopServices::openUrl(QUrl(url));
  159. }
  160. void FormAccountInfo::on_pushButtonRefreshUserState_clicked()
  161. {
  162. QString ssoHash = m_account.value("ssohash");
  163. if(ssoHash.isEmpty())
  164. {
  165. QMessageBox::critical(this,"提示","您现在还没有登录系统,请登录后再操作!",QMessageBox::Ok);
  166. return;
  167. }
  168. if(!checkLastClickTime(sender()))
  169. return ;
  170. setCursor(Qt::WaitCursor);
  171. refreshAccountInfo();
  172. setCursor(Qt::ArrowCursor);
  173. }
  174. void FormAccountInfo::onDataUpdated()
  175. {
  176. refreshAccountInfo();
  177. }
  178. bool FormAccountInfo::checkLastClickTime(QObject *button)
  179. {
  180. QPushButton *btn = qobject_cast<QPushButton*>(button);
  181. QDateTime lasttime = m_clickTime.value(btn->objectName());
  182. if(!lasttime.isNull())
  183. {
  184. if(lasttime.addSecs(30)>QDateTime::currentDateTime())
  185. {
  186. QMessageBox::critical(this,"提示","您不可以频繁点击!",QMessageBox::Ok);
  187. return false;
  188. }
  189. }
  190. m_clickTime.insert(btn->objectName(),QDateTime::currentDateTime());
  191. return true;
  192. }