| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- #include "formaccountinfo.h"
- #include "ui_formaccountinfo.h"
- #include "respgetuserzxshserviceinfo.h"
- #include "respgetservertime.h"
- #include "respencrypt.h"
- #include "sncdatabase.h"
- FormAccountInfo::FormAccountInfo(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::FormAccountInfo)
- {
- ui->setupUi(this);
- initVariables();
- initUI();
- }
- void FormAccountInfo::setAccountInfo(QMap<QString, QString> info)
- {
- m_account = info;
- QString ssoHash = info.value("ssohash");
- QString userCode = info.value("usercode");
- if(!ssoHash.isEmpty())
- {
- setAccountAreaUI(LoginOk);
- }
- else
- {
- if(userCode.isEmpty())
- {
- setAccountAreaUI(NotLogin);
- }
- else
- {
- setAccountAreaUI(LoginError);
- }
- }
- }
- FormAccountInfo::~FormAccountInfo()
- {
- m_cubews->abort();
- m_ssows->abort();
- m_movie->stop();
- delete m_movie;
- delete m_ssows;
- delete m_cubews;
- delete ui;
- qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
- <<"FormRiddle.FormAccountInfo Destroyed.";
- }
- void FormAccountInfo::initVariables()
- {
- m_cubews = new WSCube2();
- m_ssows = new WSSSO();
- m_movie = new QMovie(":/working.gif");
- m_movie->start();
- }
- void FormAccountInfo::initUI()
- {
- //初始化背景效果
- ui->widgetBackgournd->setProperty("class","silverbg");
- //初始化登录后显示的账户相关信息区域的样式
- ui->pushButtonCharge->setProperty("class","small-red-bg");
- ui->pushButtonLogin->setProperty("class","txt-green");
- ui->pushButtonRefreshUserState->setProperty("class","txt-green");
- ui->pushButtonDetail->setProperty("class","txt-green");
- setAccountAreaUI(NotLogin);
- }
- void FormAccountInfo::setAccountAreaUI(AccountLoginState state)
- {
- switch(state)
- {
- case LoginOk:
- ui->labelTip->setText("");
- ui->labelTip2->setText("");
- ui->pushButtonLogin->setVisible(false);
- ui->widgetAccountInfo->setVisible(true);
- ui->widgetDefault->setVisible(false);
- refreshAccountInfo();
- break;
- case NotLogin:
- ui->labelTip->setText("您需要");
- ui->labelTip2->setText("才可以使用该功能!");
- ui->pushButtonLogin->setVisible(true);
- ui->widgetAccountInfo->setVisible(false);
- ui->widgetDefault->setVisible(true);
- break;
- case NotBind:
- ui->labelTip->setText("实号快检服务尚未开通!");
- ui->pushButtonLogin->setVisible(false);
- ui->widgetAccountInfo->setVisible(false);
- ui->widgetDefault->setVisible(true);
- break;
- case LoginError:
- ui->labelTip->setText("实号快检服务无法连接!");
- ui->pushButtonLogin->setVisible(false);
- ui->widgetAccountInfo->setVisible(false);
- ui->widgetDefault->setVisible(true);
- break;
- }
- changeImage(state);
- }
- void FormAccountInfo::changeImage(AccountLoginState state)
- {
- m_state = state;
- QPixmap pixamp(":/service_state.png");
- int nHeight = pixamp.height();
- int nWidth = pixamp.width()/4;
- ui->labelStateImage->setPixmap(pixamp.copy(QRect(state * nWidth , 0, nWidth, nHeight)));
- }
- void FormAccountInfo::refreshAccountInfo()
- {
- QString ssoHash = m_account.value("ssohash");
- ui->labelStateImage->setMovie(m_movie);
- m_cubews->abort();
- QString json = m_cubews->getUserZXSHServiceInfo(ssoHash);
- changeImage(m_state);
- bool succeed = false;
- RespGetUserZXSHServiceInfo resp(json);
- if(resp.getRtnCode()==1)
- {
- int downloads = resp.getMonthDownShzs().toInt();
- int maxdownloads = resp.getMonthMaxDownShzs().toInt();
- int downloadslimit = maxdownloads-downloads;
- int checks = resp.getZxshMonthDownShzs().toInt();
- int maxchecks = resp.getZxshMonthMaxDownShzs().toInt();
- int checkslimit = maxchecks-checks;
- QDateTime dt1=QDateTime::fromString(resp.getMonthStartTime(),"yyyy-MM-dd hh:mm:ss");
- QDateTime dt2=QDateTime::fromString(resp.getMonthEndTime(),"yyyy-MM-dd hh:mm:ss");
- QString startTime = dt1.toString("yy年MM月dd日");
- QString endTime = dt2.toString("yy年MM月dd日");
- ui->labelChecked->setText(QString("%1-%2").arg(startTime).arg(endTime));
- ui->labelDownloaded->setText(QString("%1/%2").arg(downloads).arg(downloadslimit));
- succeed = true;
- }
- if(!succeed)
- {
- ui->labelChecked->setText("N/A");
- ui->labelDownloaded->setText("N/A");
- }
- }
- void FormAccountInfo::on_pushButtonLogin_clicked()
- {
- emit buttonLoginClick();
- }
- void FormAccountInfo::on_pushButtonCharge_clicked()
- {
- QString ssoHash = m_account.value("ssohash");
- if(ssoHash.isEmpty())
- {
- QMessageBox::critical(this,"提示","您现在还没有登录系统,请登录后再操作!",QMessageBox::Ok);
- return;
- }
- if(!checkLastClickTime(sender()))
- return ;
- QString json = m_ssows->encrypt(ssoHash);
- RespEncrypt resp1(json);
- QString data = resp1.getEncryptData();
- json = m_ssows->getServerTime();
- RespGetServerTime resp2(json);
- QString authCode;
- QByteArray ba;
- QString str = SNCDataBase::getAuthCodeUrl().arg(resp2.getServerTime().mid(0,16));
- ba = QCryptographicHash::hash ( str.toAscii(), QCryptographicHash::Md5 );
- authCode.append(ba.toHex());
- QString url = SNCDataBase::getSSOPayUrl() + "?s=mf&r="+authCode+"&u="+data+"&p=zxcz_zxsh";
- QDesktopServices::openUrl(QUrl(url));
- }
- void FormAccountInfo::on_pushButtonRefreshUserState_clicked()
- {
- QString ssoHash = m_account.value("ssohash");
- if(ssoHash.isEmpty())
- {
- QMessageBox::critical(this,"提示","您现在还没有登录系统,请登录后再操作!",QMessageBox::Ok);
- return;
- }
- if(!checkLastClickTime(sender()))
- return ;
- setCursor(Qt::WaitCursor);
- refreshAccountInfo();
- setCursor(Qt::ArrowCursor);
- }
- void FormAccountInfo::onDataUpdated()
- {
- refreshAccountInfo();
- }
- bool FormAccountInfo::checkLastClickTime(QObject *button)
- {
- QPushButton *btn = qobject_cast<QPushButton*>(button);
- QDateTime lasttime = m_clickTime.value(btn->objectName());
- if(!lasttime.isNull())
- {
- if(lasttime.addSecs(30)>QDateTime::currentDateTime())
- {
- QMessageBox::critical(this,"提示","您不可以频繁点击!",QMessageBox::Ok);
- return false;
- }
- }
- m_clickTime.insert(btn->objectName(),QDateTime::currentDateTime());
- return true;
- }
- void FormAccountInfo::on_pushButtonDetail_clicked()
- {
- QString ssoHash = m_account.value("ssohash");
- if(ssoHash.isEmpty())
- {
- QMessageBox::critical(this,"提示","您现在还没有登录系统,请登录后再操作!",QMessageBox::Ok);
- return;
- }
- if(!checkLastClickTime(sender()))
- return ;
- QString json = m_ssows->encrypt(ssoHash);
- RespEncrypt resp1(json);
- QString data = resp1.getEncryptData();
- json = m_ssows->getServerTime();
- RespGetServerTime resp2(json);
- QString authCode;
- QByteArray ba;
- QString str = SNCDataBase::getAuthCodeUrl().arg(resp2.getServerTime().mid(0,16));
- ba = QCryptographicHash::hash ( str.toAscii(), QCryptographicHash::Md5 );
- authCode.append(ba.toHex());
- QString url = SNCDataBase::getSSOPayUrl() + "?s=mf&r="+authCode+"&u="+data+"&p=xq_zxsh";
- QDesktopServices::openUrl(QUrl(url));
- }
|