| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- #include "formaccountinfo.h"
- #include "ui_formaccountinfo.h"
- #include "respgetservertime.h"
- #include "respencrypt.h"
- #include "respgetuserblance.h"
- #include "sncdatabase.h"
- //#include "dialogbindsystem.h"
- FormAccountInfo::FormAccountInfo(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::FormAccountInfo)
- {
- ui->setupUi(this);
- initVariables();
- initUI();
- }
- FormAccountInfo::~FormAccountInfo()
- {
- m_wool->abort();
- m_ssows->abort();
- m_movie->stop();
- delete m_movie;
- delete m_ssows;
- delete m_wool;
- delete ui;
- qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
- <<"FormWool.FormAccountInfo Destroyed.";
- }
- 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);
- }
- }
- }
- void FormAccountInfo::initVariables()
- {
- m_wool = new WSWool();
- m_ssows = new WSSSO();
- m_movie = new QMovie(":/working.gif");
- m_movie->start();
- }
- void FormAccountInfo::initUI()
- {
- //初始化背景效果
- ui->widgetBackground->setProperty("class","silverbg");
- //初始化登录后显示的账户相关信息区域的样式
- ui->pushButtonCharge->setProperty("class","small-red-bg");
- ui->pushButtonLogin->setProperty("class","txt-green");
- ui->pushButtonBind->setProperty("class","txt-green-bold");
- ui->pushButtonRefreshUserState->setProperty("class","txt-green");
- ui->pushButtonPay->setProperty("class","txt-green-bold");
- ui->labelToPay->setStyleSheet("color:red");
- setAccountAreaUI(NotLogin);
- }
- void FormAccountInfo::setAccountAreaUI(AccountLoginState state)
- {
- switch(state)
- {
- case LoginOk:
- ui->labelTip->setText("");
- ui->widgetAccountInfo->setVisible(true);
- ui->pushButtonLogin->setVisible(false);
- ui->labelTip2->setText("");
- ui->labelTip3->setText("");
- ui->widgetDefault->setVisible(false);
- refreshAccountInfo();
- break;
- case NotLogin:
- ui->labelTip->setText("您需要");
- ui->widgetAccountInfo->setVisible(false);
- ui->pushButtonLogin->setVisible(true);
- ui->pushButtonBind->setVisible(false);
- ui->labelTip2->setText("才可以使用该功能!");
- ui->widgetDefault->setVisible(true);
- ui->labelTip3->setText("");
- break;
- case NotBind:
- ui->labelTip->setText("尚未开通");
- ui->widgetAccountInfo->setVisible(false);
- ui->pushButtonLogin->setVisible(false);
- ui->pushButtonBind->setVisible(true);
- ui->labelTip2->setText("防薅羊毛检测服务!请点击此处[ ");
- ui->widgetDefault->setVisible(true);
- ui->labelTip3->setText(" ]");
- break;
- case LoginError:
- ui->labelTip->setText("防薅羊毛检测服务无法连接!");
- ui->widgetAccountInfo->setVisible(false);
- ui->pushButtonLogin->setVisible(false);
- ui->pushButtonBind->setVisible(false);
- ui->widgetDefault->setVisible(true);
- ui->labelTip2->setText("");
- ui->labelTip3->setText("");
- 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()
- {
- bool succeed =false;
- QString userHash = m_account.value("ssohash");
- ui->labelStateImage->setMovie(m_movie);
- QString json = m_wool->GetUserBalance(userHash);
- changeImage(m_state);
- RespGetUserBlance response (json);
- if(response.getRtnCode()==1){
- ui->labelGiftBalance->setText("¥" + response.getGiftMoney());
- ui->labelUserBlance->setText("¥" + response.getBlance());
- ui->labelValidNum->setText(response.getValidNum());
- ui->labelToPay->setText("待付金额:¥" + response.getToPayMoney());
- if(response.getToPayMoney()>response.getBlance())
- emit blanceOut();
- else
- emit blanceIn();
- // if(response.getToPayMoney().toDouble()==0)
- // {
- // ui->labelToPay->setVisible(false);
- // ui->pushButtonPay->setVisible(false);
- // }
- // else
- // {
- // ui->labelToPay->setVisible(true);
- // ui->pushButtonPay->setVisible(true);
- // }
- succeed = true;
- }
- if(!succeed)
- {
- ui->labelGiftBalance->setText("N/A");
- ui->labelUserBlance->setText("N/A");
- ui->labelValidNum->setText("N/A");
- ui->labelToPay->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_wool";
- QDesktopServices::openUrl(QUrl(url));
- }
- void FormAccountInfo::on_pushButtonRefreshUserState_clicked()
- {
- QString userHash = m_account.value("ssohash");
- if(userHash.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_pushButtonPay_clicked()
- {
- QString userHash = m_account.value("ssohash");
- if(userHash.isEmpty())
- {
- QMessageBox::critical(this,"提示","您现在还没有登录系统,请登录后再操作!",QMessageBox::Ok);
- return;
- }
- if(!checkLastClickTime(sender()))
- return ;
- QString json = m_ssows->encrypt(userHash);
- 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=fk_wool";
- QDesktopServices::openUrl(QUrl(url));
- }
- void FormAccountInfo::on_pushButtonBind_clicked()
- {
- /*
- DialogBindSystem dialog(this);
- QString ssoHash = m_account.value("ssohash");
- QString syscode = "";
- if(m_clientID=="sskh")
- {
- syscode = "1";
- }
- else if(m_clientID=="mykh")
- {
- syscode = "2";
- }
- dialog.setSysRegInfo(syscode,ssoHash);
- dialog.exec();
- if(dialog.serviceIsOpen())
- {
- // refreshSrvInfo();
- // WSSSO sso2;
- // QString json = sso2.getSysAccount(syscode,this->userHash);
- // RespGetSysAccount response2(json);
- // if(response2.getRtnCode() == 1)
- // {
- // QMap<QString,QString> shunshiInfo,mingyuanInfo;
- // if(syscode=="1")
- // {
- // shunshiInfo.insert("usercode",response2.getUserCode());
- // shunshiInfo.insert("userpwd",response2.getUserPwd());
- // emit updateShunShiAccount(shunshiInfo);
- // }
- // else if(syscode=="2")
- // {
- // mingyuanInfo.insert("usercode",response2.getUserCode());
- // mingyuanInfo.insert("userpwd",response2.getUserPwd());
- // emit updateMingYuanAccount(mingyuanInfo);
- // }
- // }
- }
- */
- }
|