formad.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_riddle");
  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::getRiddleUrl(),QCoreApplication::applicationDirPath()+"/../cache");
  32. }
  33. else
  34. {
  35. QString url = getUserCenterUrl();
  36. m_webview->setPageUrl(url,QCoreApplication::applicationDirPath()+"/../cache");
  37. }
  38. }
  39. FormAd::~FormAd()
  40. {
  41. if(m_ssows)
  42. {
  43. m_ssows->abort();
  44. delete m_ssows;
  45. }
  46. delete m_webview;
  47. delete ui;
  48. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  49. <<"FormRiddle.FormAd Destroyed.";
  50. }
  51. QString FormAd::getUserCenterUrl()
  52. {
  53. QString ssoHash = m_account.value("ssohash");
  54. QString json = m_ssows->encrypt(ssoHash);
  55. RespEncrypt resp1(json);
  56. QString data = resp1.getEncryptData();
  57. json = m_ssows->getServerTime();
  58. RespGetServerTime resp2(json);
  59. QString authCode;
  60. QByteArray ba;
  61. QString str = SNCDataBase::getAuthCodeUrl().arg(resp2.getServerTime().mid(0,16));
  62. ba = QCryptographicHash::hash ( str.toAscii(), QCryptographicHash::Md5 );
  63. authCode.append(ba.toHex());
  64. QString url = SNCDataBase::getSSOAccountUrl() + "?s=mf&r="+authCode+"&u="+data+"&p=ad_shkj";
  65. return url;
  66. }
  67. void FormAd::onTitleChanged(QString title)
  68. {
  69. if(title=="ÉêÇë³É¹¦")
  70. emit userStateChanged();
  71. }