sso.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. #include "sso.h"
  2. SSO::SSO(QString host, QString port)
  3. {
  4. this->server_host = host;
  5. this->server_path = "/wsdl";
  6. this->server_url = "http://"+this->server_host+this->server_path;
  7. QRegExp exp("\\d{1,4}");
  8. if(exp.exactMatch(port))
  9. {
  10. //this->server_port = port.toInt();
  11. this->server_port = 86;
  12. }
  13. else
  14. {
  15. this->server_port = 80;
  16. }
  17. m_cancel = false;
  18. }
  19. void SSO::onCanceled()
  20. {
  21. m_cancel = true;
  22. emit responseProcessed();
  23. if(json.isEmpty())
  24. json = "ABORT";
  25. }
  26. QString SSO::userLogin(QString userCode, QString userPwd, QString src,QString mcode)
  27. {
  28. this->json = "";
  29. QObject::connect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  30. QObject::connect(this, SIGNAL(responseProcessed()),&loop, SLOT(quit()));
  31. QString md5;
  32. QByteArray ba;
  33. ba = QCryptographicHash::hash ( userPwd.toAscii(), QCryptographicHash::Md5 );
  34. md5.append(ba.toHex());
  35. setLoginRequest(userCode,md5, src,mcode);
  36. loop.exec();
  37. QObject::disconnect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  38. return json;
  39. }
  40. QString SSO::userLogout(QString userHash, QString src,QString mcode)
  41. {
  42. this->json = "";
  43. QObject::connect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  44. QObject::connect(this, SIGNAL(responseProcessed()),&loop, SLOT(quit()));
  45. setLogoutRequest(userHash,src,mcode);
  46. loop.exec();
  47. QObject::disconnect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  48. return json;
  49. }
  50. QString SSO::heartBeat(QString userHash,QString src,QString refreshStamp,QString mcode)
  51. {
  52. this->json = "";
  53. QObject::connect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  54. QObject::connect(this, SIGNAL(responseProcessed()),&loop, SLOT(quit()));
  55. setHeartBeatRequest(userHash,src,refreshStamp,mcode);
  56. loop.exec();
  57. QObject::disconnect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  58. return json;
  59. }
  60. QString SSO::regSysAccount(QString sysCode, QString userHash,QString regSrc)
  61. {
  62. this->json = "";
  63. QObject::connect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  64. QObject::connect(this, SIGNAL(responseProcessed()),&loop, SLOT(quit()));
  65. setRegSysAccountRequest(sysCode,userHash,regSrc);
  66. loop.exec();
  67. QObject::disconnect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  68. return json;
  69. }
  70. QString SSO::bindSysAccount(QString sysCode, QString bindUserCode, QString bindUserPwd, QString userHash)
  71. {
  72. this->json = "";
  73. QObject::connect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  74. QObject::connect(this, SIGNAL(responseProcessed()),&loop, SLOT(quit()));
  75. QString md5;
  76. QByteArray ba;
  77. ba = QCryptographicHash::hash ( bindUserPwd.toAscii(), QCryptographicHash::Md5 );
  78. md5.append(ba.toHex());
  79. setBindSysAccountRequest(sysCode,bindUserCode,md5,userHash);
  80. loop.exec();
  81. QObject::disconnect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  82. return json;
  83. }
  84. QString SSO::getSysAccount(QString sysCode, QString userHash)
  85. {
  86. this->json = "";
  87. QObject::connect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  88. QObject::connect(this, SIGNAL(responseProcessed()),&loop, SLOT(quit()));
  89. setGetSysAccountRequest(sysCode,userHash);
  90. loop.exec();
  91. QObject::disconnect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  92. return json;
  93. }
  94. QString SSO::getUserSSO(QString userHash)
  95. {
  96. this->json = "";
  97. QObject::connect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  98. QObject::connect(this, SIGNAL(responseProcessed()),&loop, SLOT(quit()));
  99. setGetUserSSORequest(userHash);
  100. loop.exec();
  101. QObject::disconnect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  102. return json;
  103. }
  104. QString SSO::getMfPayInfo(QString dateStart, QString dateEnd, QString userHash)
  105. {
  106. this->json = "";
  107. QObject::connect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  108. QObject::connect(this, SIGNAL(responseProcessed()),&loop, SLOT(quit()));
  109. setGetMfPayInfoRequest(dateStart,dateEnd,userHash);
  110. loop.exec();
  111. QObject::disconnect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  112. return json;
  113. }
  114. QString SSO::getTransferInfo(QString dateStart, QString dateEnd, QString userHash)
  115. {
  116. this->json = "";
  117. QObject::connect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  118. QObject::connect(this, SIGNAL(responseProcessed()),&loop, SLOT(quit()));
  119. setGetTransferInfoRequest(dateStart,dateEnd,userHash);
  120. loop.exec();
  121. QObject::disconnect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  122. return json;
  123. }
  124. QString SSO::userTransfer(QString sndsyscode, QString rcvsyscode, QString trsfmoney, QString trsfmemo, QString userHash)
  125. {
  126. this->json = "";
  127. QObject::connect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  128. QObject::connect(this, SIGNAL(responseProcessed()),&loop, SLOT(quit()));
  129. setUserTransferRequest(sndsyscode,rcvsyscode,trsfmoney,trsfmemo,userHash);
  130. loop.exec();
  131. QObject::disconnect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  132. return json;
  133. }
  134. QString SSO::mfUserPay(QString func, QString userHash)
  135. {
  136. this->json = "";
  137. QObject::connect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  138. QObject::connect(this, SIGNAL(responseProcessed()),&loop, SLOT(quit()));
  139. setMfUserPay(func,userHash);
  140. loop.exec();
  141. QObject::disconnect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  142. return json;
  143. }
  144. QString SSO::userReg(QString userCode, QString userPwd, QString detailInfo, QString src,QString mcode,QString authCode,QString regType)
  145. {
  146. this->json = "";
  147. QObject::connect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  148. QObject::connect(this, SIGNAL(responseProcessed()),&loop, SLOT(quit()));
  149. setUserRegRequest(userCode, userPwd, detailInfo, src,mcode, authCode,regType);
  150. loop.exec();
  151. QObject::disconnect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  152. return json;
  153. }
  154. QString SSO::editUserInfo(QString detailInfo, QString userHash)
  155. {
  156. this->json = "";
  157. QObject::connect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  158. QObject::connect(this, SIGNAL(responseProcessed()),&loop, SLOT(quit()));
  159. setEditUserInfoRequest(detailInfo, userHash);
  160. loop.exec();
  161. QObject::disconnect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  162. return json;
  163. }
  164. QString SSO::getMFUserInfo(QString userHash)
  165. {
  166. this->json = "";
  167. QObject::connect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  168. QObject::connect(this, SIGNAL(responseProcessed()),&loop, SLOT(quit()));
  169. setGetMFUserInfoRequest(userHash);
  170. loop.exec();
  171. QObject::disconnect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  172. return json;
  173. }
  174. QString SSO::getMFUserBalance(QString userHash)
  175. {
  176. this->json = "";
  177. QObject::connect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  178. QObject::connect(this, SIGNAL(responseProcessed()),&loop, SLOT(quit()));
  179. setGetMFUserBalanceRequest(userHash);
  180. loop.exec();
  181. QObject::disconnect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  182. return json;
  183. }
  184. QString SSO::changePass(QString oldPassword, QString newPassword, QString userHash)
  185. {
  186. this->json = "";
  187. QObject::connect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  188. QObject::connect(this, SIGNAL(responseProcessed()),&loop, SLOT(quit()));
  189. QString md51;
  190. QByteArray ba1;
  191. ba1 = QCryptographicHash::hash ( oldPassword.toAscii(), QCryptographicHash::Md5 );
  192. md51.append(ba1.toHex());
  193. QString md52;
  194. QByteArray ba2;
  195. ba2 = QCryptographicHash::hash ( newPassword.toAscii(), QCryptographicHash::Md5 );
  196. md52.append(ba2.toHex());
  197. setChangePassRequest(md51,md52,userHash);
  198. loop.exec();
  199. QObject::disconnect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  200. return json;
  201. }
  202. QString SSO::getSysParam(QString src,QString authCode)
  203. {
  204. this->json = "";
  205. QObject::connect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  206. QObject::connect(this, SIGNAL(responseProcessed()),&loop, SLOT(quit()));
  207. setGetSysParamsRequest(src,authCode);
  208. loop.exec();
  209. QObject::disconnect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  210. return json;
  211. }
  212. QString SSO::getServerTime(QString authCode)
  213. {
  214. this->json = "";
  215. QObject::connect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  216. QObject::connect(this, SIGNAL(responseProcessed()),&loop, SLOT(quit()));
  217. setGetServerTimeRequest(authCode);
  218. loop.exec();
  219. QObject::disconnect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  220. return json;
  221. }
  222. QString SSO::encrypt(QString data, QString authCode, QString key)
  223. {
  224. this->json = "";
  225. QObject::connect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  226. QObject::connect(this, SIGNAL(responseProcessed()),&loop, SLOT(quit()));
  227. setEncryptRequest(data,authCode,key);
  228. loop.exec();
  229. QObject::disconnect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  230. return json;
  231. }
  232. QString SSO::decrypt(QString data, QString authCode, QString key)
  233. {
  234. this->json = "";
  235. QObject::connect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  236. QObject::connect(this, SIGNAL(responseProcessed()),&loop, SLOT(quit()));
  237. setDecryptRequest(data,authCode,key);
  238. loop.exec();
  239. QObject::disconnect(&http, SIGNAL(responseReady()),this, SLOT(getResponse()));
  240. return json;
  241. }
  242. void SSO::setLoginRequest(QString userCode, QString userPwd, QString src,QString mcode)
  243. {
  244. QtSoapMessage request;
  245. request.setMethod("UserLogin", this->server_url);
  246. request.addMethodArgument("userCode","",userCode);
  247. request.addMethodArgument("userPwd", "",userPwd);
  248. request.addMethodArgument("src","",src);
  249. request.addMethodArgument("mcode","",mcode);
  250. http.setHost(this->server_host,this->server_port);
  251. http.submitRequest(request,this->server_path);
  252. }
  253. void SSO::setLogoutRequest(QString userHash, QString src,QString mcode)
  254. {
  255. QtSoapMessage request;
  256. request.setMethod("UserLogout", this->server_url);
  257. request.addMethodArgument("userHash","",userHash);
  258. request.addMethodArgument("src","",src);
  259. request.addMethodArgument("mcode","",mcode);
  260. http.setHost(this->server_host,this->server_port);
  261. http.submitRequest(request,this->server_path);
  262. }
  263. void SSO::setHeartBeatRequest(QString userHash,QString src,QString refreshStamp,QString mcode)
  264. {
  265. QtSoapMessage request;
  266. request.setMethod("HeartBeat", this->server_url);
  267. request.addMethodArgument("userHash","",userHash);
  268. request.addMethodArgument("src","",src);
  269. request.addMethodArgument("refreshStamp","",refreshStamp);
  270. request.addMethodArgument("mcode","",mcode);
  271. http.setHost(this->server_host,this->server_port);
  272. http.submitRequest(request,this->server_path);
  273. }
  274. void SSO::setEncryptRequest(QString data, QString authCode, QString key)
  275. {
  276. QtSoapMessage request;
  277. request.setMethod("Encrypt", this->server_url);
  278. request.addMethodArgument("data","",data);
  279. request.addMethodArgument("authCode","",authCode);
  280. request.addMethodArgument("key","",key);
  281. http.setHost(this->server_host,this->server_port);
  282. http.submitRequest(request,this->server_path);
  283. }
  284. void SSO::setDecryptRequest(QString data, QString authCode, QString key)
  285. {
  286. QtSoapMessage request;
  287. request.setMethod("Decrypt", this->server_url);
  288. request.addMethodArgument("data","",data);
  289. request.addMethodArgument("authCode","",authCode);
  290. request.addMethodArgument("key","",key);
  291. http.setHost(this->server_host,this->server_port);
  292. http.submitRequest(request,this->server_path);
  293. }
  294. void SSO::setRegSysAccountRequest(QString sysCode, QString userHash,QString regSrc)
  295. {
  296. QtSoapMessage request;
  297. request.setMethod("RegSysAccount", this->server_url);
  298. request.addMethodArgument("sysCode","",sysCode);
  299. request.addMethodArgument("userHash","",userHash);
  300. request.addMethodArgument("regsrc","",regSrc);
  301. http.setHost(this->server_host,this->server_port);
  302. http.submitRequest(request,this->server_path);
  303. }
  304. void SSO::setBindSysAccountRequest(QString sysCode, QString bindUserCode, QString bindUserPwd, QString userHash)
  305. {
  306. QtSoapMessage request;
  307. request.setMethod("BindSysAccount", this->server_url);
  308. request.addMethodArgument("sysCode","",sysCode);
  309. request.addMethodArgument("bindUserCode","",bindUserCode);
  310. request.addMethodArgument("bindUserPwd","",bindUserPwd);
  311. request.addMethodArgument("userHash","",userHash);
  312. http.setHost(this->server_host,this->server_port);
  313. http.submitRequest(request,this->server_path);
  314. }
  315. void SSO::setGetSysAccountRequest(QString sysCode, QString userHash)
  316. {
  317. QtSoapMessage request;
  318. request.setMethod("GetSysAccount", this->server_url);
  319. request.addMethodArgument("sysCode","",sysCode);
  320. request.addMethodArgument("userHash","",userHash);
  321. http.setHost(this->server_host,this->server_port);
  322. http.submitRequest(request,this->server_path);
  323. }
  324. void SSO::setGetUserSSORequest(QString userHash)
  325. {
  326. QtSoapMessage request;
  327. request.setMethod("GetUserSSO", this->server_url);
  328. request.addMethodArgument("userHash","",userHash);
  329. http.setHost(this->server_host,this->server_port);
  330. http.submitRequest(request,this->server_path);
  331. }
  332. void SSO::setGetMfPayInfoRequest(QString dateStart, QString dateEnd, QString userHash)
  333. {
  334. QtSoapMessage request;
  335. request.setMethod("GetMfPayInfo", this->server_url);
  336. request.addMethodArgument("dateStart","",dateStart);
  337. request.addMethodArgument("dateEnd","",dateEnd);
  338. request.addMethodArgument("userHash","",userHash);
  339. http.setHost(this->server_host,this->server_port);
  340. http.submitRequest(request,this->server_path);
  341. }
  342. void SSO::setGetTransferInfoRequest(QString dateStart, QString dateEnd, QString userHash)
  343. {
  344. QtSoapMessage request;
  345. request.setMethod("GetTransferInfo", this->server_url);
  346. request.addMethodArgument("dateStart","",dateStart);
  347. request.addMethodArgument("dateEnd","",dateEnd);
  348. request.addMethodArgument("userHash","",userHash);
  349. http.setHost(this->server_host,this->server_port);
  350. http.submitRequest(request,this->server_path);
  351. }
  352. void SSO::setUserTransferRequest(QString sndsyscode, QString rcvsyscode, QString trsfmoney, QString trsfmemo, QString userHash)
  353. {
  354. QtSoapMessage request;
  355. request.setMethod("UserTransfer", this->server_url);
  356. request.addMethodArgument("sndsyscode","",sndsyscode);
  357. request.addMethodArgument("rcvsyscode","",rcvsyscode);
  358. request.addMethodArgument("trsfmoney","",trsfmoney);
  359. request.addMethodArgument("trsfmemo","",trsfmemo);
  360. request.addMethodArgument("userHash","",userHash);
  361. http.setHost(this->server_host,this->server_port);
  362. http.submitRequest(request,this->server_path);
  363. }
  364. void SSO::setMfUserPay(QString func, QString userHash)
  365. {
  366. QtSoapMessage request;
  367. request.setMethod("MfUserPay", this->server_url);
  368. request.addMethodArgument("func","",func);
  369. request.addMethodArgument("userHash","",userHash);
  370. http.setHost(this->server_host,this->server_port);
  371. http.submitRequest(request,this->server_path);
  372. }
  373. void SSO::setUserRegRequest(QString userCode, QString userPwd, QString detailInfo, QString src,QString mcode, QString authCode,QString regType)
  374. {
  375. QtSoapMessage request;
  376. request.setMethod("UserReg", this->server_url);
  377. request.addMethodArgument("userCode","",userCode);
  378. request.addMethodArgument("userPwd","",userPwd);
  379. request.addMethodArgument("detailInfo","",detailInfo);
  380. request.addMethodArgument("src","",src);
  381. request.addMethodArgument("mcode","",mcode);
  382. request.addMethodArgument("authCode","",authCode);
  383. request.addMethodArgument("regType","",regType);
  384. http.setHost(this->server_host,this->server_port);
  385. http.submitRequest(request,this->server_path);
  386. }
  387. void SSO::setEditUserInfoRequest(QString detailInfo, QString userHash)
  388. {
  389. QtSoapMessage request;
  390. request.setMethod("EditUserInfo", this->server_url);
  391. request.addMethodArgument("detailInfo","",detailInfo);
  392. request.addMethodArgument("userHash","",userHash);
  393. http.setHost(this->server_host,this->server_port);
  394. http.submitRequest(request,this->server_path);
  395. }
  396. void SSO::setGetMFUserInfoRequest(QString userHash)
  397. {
  398. QtSoapMessage request;
  399. request.setMethod("GetMfUserInfo", this->server_url);
  400. request.addMethodArgument("userHash","",userHash);
  401. http.setHost(this->server_host,this->server_port);
  402. http.submitRequest(request,this->server_path);
  403. }
  404. void SSO::setGetMFUserBalanceRequest(QString userHash)
  405. {
  406. QtSoapMessage request;
  407. request.setMethod("GetMfUserBalance", this->server_url);
  408. request.addMethodArgument("userHash","",userHash);
  409. http.setHost(this->server_host,this->server_port);
  410. http.submitRequest(request,this->server_path);
  411. }
  412. void SSO::setChangePassRequest(QString oldPassword, QString newPassword, QString userHash)
  413. {
  414. QtSoapMessage request;
  415. request.setMethod("ChgUserPwd", this->server_url);
  416. request.addMethodArgument("oldPwd","",oldPassword);
  417. request.addMethodArgument("newPwd", "",newPassword);
  418. request.addMethodArgument("userHash","",userHash);
  419. http.setHost(this->server_host,this->server_port);
  420. http.submitRequest(request,this->server_path);
  421. }
  422. void SSO::setGetSysParamsRequest(QString src, QString authCode)
  423. {
  424. QtSoapMessage request;
  425. request.setMethod("GetSysParam", this->server_url);
  426. request.addMethodArgument("src","",src);
  427. request.addMethodArgument("authCode", "",authCode);
  428. http.setHost(this->server_host,this->server_port);
  429. http.submitRequest(request,this->server_path);
  430. }
  431. void SSO::setGetServerTimeRequest(QString authCode)
  432. {
  433. QtSoapMessage request;
  434. request.setMethod("GetServerTime", this->server_url);
  435. request.addMethodArgument("authCode", "",authCode);
  436. http.setHost(this->server_host,this->server_port);
  437. http.submitRequest(request,this->server_path);
  438. }
  439. void SSO::getResponse()
  440. {
  441. // Get the response, check for error.
  442. const QtSoapMessage &message = http.getResponse();
  443. if (message.isFault()) {
  444. qDebug()<<message.faultString().value().toString();
  445. json = "";
  446. emit responseProcessed();
  447. return;
  448. }
  449. const QtSoapType &response = message.returnValue();
  450. json = response.value().toString();
  451. // qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  452. // <<json;
  453. emit responseProcessed();
  454. return;
  455. }