Cloud.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: Cloud.php 33755 2013-08-10 03:21:02Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. Cloud::loadFile('Service_Client_Restful');
  12. class Cloud_Service_Client_Cloud extends Cloud_Service_Client_Restful {
  13. protected static $_instance;
  14. public static function getInstance($debug = false) {
  15. if (!(self::$_instance instanceof self)) {
  16. self::$_instance = new self($debug);
  17. }
  18. return self::$_instance;
  19. }
  20. public function __construct($debug = false) {
  21. return parent::__construct($debug);
  22. }
  23. public function appOpen() {
  24. return $this->_callMethod('site.appOpen', array('sId' => $this->_sId, 'appIdentifier' => 'search'));
  25. }
  26. public function appOpenWithRegister($appIdentifier, $extra = array()) {
  27. $this->reloadId();
  28. return $this->_callMethod('site.appOpen', array(
  29. 'sId' => $this->_sId,
  30. 'appIdentifier' => $appIdentifier,
  31. 'sName' => $this->siteName,
  32. 'sSiteKey' => $this->uniqueId,
  33. 'sUrl' => $this->siteUrl,
  34. 'sCharset' => $this->charset,
  35. 'sTimeZone' => $this->timeZone,
  36. 'sUCenterUrl' => $this->UCenterUrl,
  37. 'sLanguage' => $this->language,
  38. 'sProductType' => $this->productType,
  39. 'sProductVersion' => $this->productVersion,
  40. 'sTimestamp' => $this->_ts,
  41. 'sApiVersion' => $this->apiVersion,
  42. 'sSiteUid' => $this->siteUid,
  43. 'sProductRelease' => $this->productRelease,
  44. 'extra' => $extra,
  45. ), false, true);
  46. }
  47. public function appOpenFormView($appIdentifier, $submitUrl, $fromUrl) {
  48. return $this->_callMethod('site.getAppOpenFormView', array(
  49. 'sId' => $this->_sId,
  50. 'sCharset' => $this->charset,
  51. 'appIdentifier' => $appIdentifier,
  52. 'submitUrl' => $submitUrl,
  53. 'fromUrl' => $fromUrl,
  54. 'type' => 'open',
  55. ));
  56. }
  57. public function appClose($appIdentifier) {
  58. return $this->_callMethod('site.appClose', array(
  59. 'sId' => $this->_sId,
  60. 'appIdentifier' => $appIdentifier,
  61. 'sSiteUid' => $this->siteUid,
  62. ), false, true);
  63. }
  64. public function appCloseReasonsView($appIdentifier, $submitUrl, $fromUrl) {
  65. return $this->_callMethod('site.getAppCloseReasonsView', array(
  66. 'sId' => $this->_sId,
  67. 'appIdentifier' => $appIdentifier,
  68. 'submitUrl' => $submitUrl,
  69. 'fromUrl' => $fromUrl,
  70. ));
  71. }
  72. private function reloadId() {
  73. global $_G;
  74. loadcache('setting', 1);
  75. $this->_sId = !empty($_G['setting']['my_siteid']) ? $_G['setting']['my_siteid'] : '';
  76. $this->_sKey = !empty($_G['setting']['my_sitekey']) ? $_G['setting']['my_sitekey'] : '';
  77. }
  78. public function bindQQ($appIdentifier, $fromUrl, $extra = array()) {
  79. $this->reloadId();
  80. $utilService = Cloud::loadClass('Service_Util');
  81. $fromUrl .= $extra ? '&'.$utilService->httpBuildQuery(array('extra' => $extra), '', '&') : '';
  82. $params = array(
  83. 's_id' => $this->_sId,
  84. 'app_identifier' => $appIdentifier,
  85. 's_site_uid' => $this->siteUid,
  86. 'from_url' => $fromUrl,
  87. 'ADTAG' => 'CP.CLOUD.BIND.INDEX',
  88. );
  89. ksort($params);
  90. $str = $utilService->httpBuildQuery($params, '', '&');
  91. $params['sig'] = md5(sprintf('%s|%s|%s', $str, $this->_sKey, $this->_ts));
  92. $params['ts'] = $this->_ts;
  93. return 'http://cp.discuz.qq.com/addon_bind/index?'.$utilService->httpBuildQuery($params, '', '&');
  94. }
  95. public function register() {
  96. return $this->_callMethod('site.register', array(
  97. 'sName' => $this->siteName,
  98. 'sSiteKey' => $this->uniqueId,
  99. 'sUrl' => $this->siteUrl,
  100. 'sCharset' => $this->charset,
  101. 'sTimeZone' => $this->timeZone,
  102. 'sUCenterUrl' => $this->UCenterUrl,
  103. 'sLanguage' => $this->language,
  104. 'sProductType' => $this->productType,
  105. 'sProductVersion' => $this->productVersion,
  106. 'sTimestamp' => $this->_ts,
  107. 'sApiVersion' => $this->apiVersion,
  108. 'sSiteUid' => $this->siteUid,
  109. 'sProductRelease' => $this->productRelease,
  110. )
  111. );
  112. }
  113. public function sync() {
  114. return $this->_callMethod('site.sync', array(
  115. 'sId' => $this->_sId,
  116. 'sName' => $this->siteName,
  117. 'sSiteKey' => $this->uniqueId,
  118. 'sUrl' => $this->siteUrl,
  119. 'sCharset' => $this->charset,
  120. 'sTimeZone' => $this->timeZone,
  121. 'sUCenterUrl' => $this->UCenterUrl,
  122. 'sLanguage' => $this->language,
  123. 'sProductType' => $this->productType,
  124. 'sProductVersion' => $this->productVersion,
  125. 'sTimestamp' => $this->_ts,
  126. 'sApiVersion' => $this->apiVersion,
  127. 'sSiteUid' => $this->siteUid,
  128. 'sProductRelease' => $this->productRelease
  129. )
  130. );
  131. }
  132. public function resetKey() {
  133. return $this->_callMethod('site.resetKey', array('sId' => $this->_sId));
  134. }
  135. public function resume() {
  136. return $this->_callMethod('site.resume', array(
  137. 'sUrl' => $this->siteUrl,
  138. 'sCharset' => 'UTF-8',
  139. 'sProductType' => $this->productType,
  140. 'sProductVersion' => $this->productVersion
  141. )
  142. );
  143. }
  144. public function registerCloud($cloudApiIp = '') {
  145. try {
  146. $returnData = $this->register();
  147. } catch (Cloud_Service_Client_RestfulException $e) {
  148. if ($e->getCode() == 1 && $cloudApiIp) {
  149. $this->setCloudApiIp($cloudApiIp);
  150. try {
  151. $returnData = $this->register();
  152. C::t('common_setting')->update('cloud_api_ip', $cloudApiIp);
  153. } catch (Cloud_Service_Client_RestfulException $e) {
  154. throw new Cloud_Service_Client_RestfulException($e);
  155. }
  156. } else {
  157. throw new Cloud_Service_Client_RestfulException($e);
  158. }
  159. }
  160. $sId = intval($returnData['sId']);
  161. $sKey = trim($returnData['sKey']);
  162. if ($sId && $sKey) {
  163. C::t('common_setting')->update_batch(array('my_siteid' => $sId, 'my_sitekey' =>$sKey ,'cloud_status' => '2'));
  164. updatecache('setting');
  165. } else {
  166. throw new Cloud_Service_Client_RestfulException('Error Response.', 2);
  167. }
  168. return true;
  169. }
  170. public function upgradeManyou($cloudApiIp = '') {
  171. try {
  172. $returnData = $this->sync();
  173. } catch (Cloud_Service_Client_RestfulException $e) {
  174. if ($e->getCode() == 1 && $cloudApiIp) {
  175. $this->setCloudApiIp($cloudApiIp);
  176. try {
  177. $returnData = $this->sync();
  178. C::t('common_setting')->update('cloud_api_ip', $cloudApiIp);
  179. } catch (Cloud_Service_Client_RestfulException $e) {
  180. throw new Cloud_Service_Client_RestfulException($e);
  181. }
  182. }
  183. }
  184. return true;
  185. }
  186. }