diff --git a/webapp/controller/GMController.class.php b/webapp/controller/GMController.class.php index 2b841af..17e114e 100644 --- a/webapp/controller/GMController.class.php +++ b/webapp/controller/GMController.class.php @@ -31,6 +31,12 @@ class GMController extends BaseAuthedController { }, '.additem' => function () use($params) { $this->addItem($params); + }, + '.getsystime' => function () use($params) { + $this->getSysTime($params); + }, + '.setsystime' => function () use($params) { + $this->setSysTime($params); } ); $func = getXVal($cmdHash, $cmd); @@ -46,7 +52,9 @@ class GMController extends BaseAuthedController { { $this->_rspData(array( 'text' => <<_rspData(array( + 'text' => $sysTime, + )); + } + + private function setSysTime($params) + { + if (!defined('GLOBAL_TIME_OFFSET_KEY')) { + die('不支持设置系统时间'); + return; + } + $newtime = strtotime($_REQUET['newtime']); + if ($newtime <= 0) { + die('时间格式错误'); + return; + } + $time_offset = $newtime - phpcommon\getRealTime(); + $r = new phpcommon\Redis(array( + 'host' => '127.0.0.1', + 'port' => 6379, + 'passwd' => '' + + )); + $r->set(GLOBAL_TIME_OFFSET_KEY, $time_offset); + } + } diff --git a/webapp/controller/ToolsController.class.php b/webapp/controller/ToolsController.class.php index abffda1..5ab0058 100644 --- a/webapp/controller/ToolsController.class.php +++ b/webapp/controller/ToolsController.class.php @@ -2,10 +2,11 @@ class ToolsController extends BaseController { - function __construct() + public function _handlePre() { + parent::_handlePre(); if (SERVER_ENV == _ONLINE) { - die("can't create GMController"); + die("can't create ToolsController"); return; } } @@ -30,30 +31,4 @@ class ToolsController extends BaseController { } } - public function getSysTime() - { - echo phpcommon\timestamp_to_datetime(phpcommon\getNowTime()); - } - - public function setSysTime() - { - if (!defined('GLOBAL_TIME_OFFSET_KEY')) { - die('不支持设置系统时间'); - return; - } - $newtime = strtotime($_REQUET['newtime']); - if ($newtime <= 0) { - die('时间格式错误'); - return; - } - $time_offset = $newtime - phpcommon\getRealTime(); - $r = new phpcommon\Redis(array( - 'host' => '127.0.0.1', - 'port' => 6379, - 'passwd' => '' - - )); - $r->set(GLOBAL_TIME_OFFSET_KEY, $time_offset); - } - }