formad.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. m_webview = new CacheWebView(this);
  12. m_webview->setMinimumWidth(280);
  13. m_webview->setMaximumWidth(280);
  14. ui->verticalLayout->addWidget(m_webview);
  15. m_ssows = new WSSSO();
  16. }
  17. FormAd::~FormAd()
  18. {
  19. if(m_ssows)
  20. {
  21. m_ssows->abort();
  22. delete m_ssows;
  23. }
  24. delete m_webview;
  25. delete ui;
  26. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  27. <<"FormNumchk.FormAd Destroyed.";
  28. }
  29. void FormAd::setDefaultUrl(QString pageUrl)
  30. {
  31. m_pageUrl = pageUrl;
  32. m_webview->setPageUrl(m_pageUrl,QCoreApplication::applicationDirPath()+"/cache");
  33. }
  34. void FormAd::setAccountInfo(QMap<QString, QString> info)
  35. {
  36. QString userHash = info.value("userhash");
  37. m_account = info;
  38. if(userHash.isEmpty())
  39. {
  40. m_webview->setPageUrl(m_pageUrl,QCoreApplication::applicationDirPath()+"/../cache");
  41. }
  42. else
  43. {
  44. QString url = getUserCenterUrl();
  45. m_webview->setPageUrl(url,QCoreApplication::applicationDirPath()+"/../cache");
  46. }
  47. }
  48. void FormAd::setClientID(QString clientID)
  49. {
  50. m_clientID = clientID;
  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_"+m_clientID;
  66. return url;
  67. }