formad.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "formad.h"
  2. #include "ui_formad.h"
  3. #include "sncdatabase.h"
  4. #include "respencrypt.h"
  5. #include "respgetservertime.h"
  6. FormAd::FormAd(QWidget *parent) :
  7. QWidget(parent),
  8. ui(new Ui::FormAd)
  9. {
  10. ui->setupUi(this);
  11. page_ads = SNCDataBase::getLocalPageAds();
  12. m_webview = new CacheWebView(this);
  13. m_webview->setMinimumWidth(280);
  14. m_webview->setMaximumWidth(280);
  15. QString url = "";
  16. if(page_ads.count()>0)
  17. {
  18. url = page_ads.value("ad_app2_zxsh");
  19. }
  20. m_webview->setPageUrl(url,QCoreApplication::applicationDirPath()+"/../cache");
  21. connect(m_webview,SIGNAL(titleChanged(QString)),this,SLOT(onTitleChanged(QString)));
  22. ui->verticalLayout->addWidget(m_webview);
  23. m_ssows = new WSSSO();
  24. }
  25. void FormAd::setAccountInfo(QMap<QString, QString> info)
  26. {
  27. m_account = info;
  28. QString ssoHash = info.value("ssohash");
  29. if(ssoHash.isEmpty())
  30. {
  31. m_webview->setPageUrl(SNCDataBase::getZxshUrl(),QCoreApplication::applicationDirPath()+"/../cache");
  32. }
  33. else
  34. {
  35. QString url = getUserCenterUrl();
  36. //QString url = SNCDataBase::getZxshUrl();
  37. m_webview->setPageUrl(url,QCoreApplication::applicationDirPath()+"/../cache");
  38. }
  39. }
  40. FormAd::~FormAd()
  41. {
  42. if(m_ssows)
  43. {
  44. m_ssows->abort();
  45. delete m_ssows;
  46. }
  47. delete m_webview;
  48. delete ui;
  49. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  50. <<"FormRiddle.FormAd Destroyed.";
  51. }
  52. QString FormAd::getUserCenterUrl()
  53. {
  54. QString ssoHash = m_account.value("ssohash");
  55. QString json = m_ssows->encrypt(ssoHash);
  56. RespEncrypt resp1(json);
  57. QString data = resp1.getEncryptData();
  58. json = m_ssows->getServerTime();
  59. RespGetServerTime resp2(json);
  60. QString authCode;
  61. QByteArray ba;
  62. QString str = SNCDataBase::getAuthCodeUrl().arg(resp2.getServerTime().mid(0,16));
  63. ba = QCryptographicHash::hash ( str.toAscii(), QCryptographicHash::Md5 );
  64. authCode.append(ba.toHex());
  65. QString url = SNCDataBase::getSSOAccountUrl() + "?s=mf&r="+authCode+"&u="+data+"&p=ad_zxsh";
  66. return url;
  67. }
  68. void FormAd::onTitleChanged(QString title)
  69. {
  70. if(title=="ÉêÇë³É¹¦")
  71. emit userStateChanged();
  72. }