request->module(); $controllername = strtolower($this->request->controller()); $actionname = strtolower($this->request->action()); $path = '/' . $modulename . '/' . str_replace('.', '/', $controllername) . '/' . $actionname; $this->user = Auth::instance(); // 设置当前请求的URI $this->user->setRequestUri($path); // 检测当前是否登录并进行初始化 //$this->user->init(); // //加载UC函数库 //加载UC XML类库 Loader::import('fast.ucenter.common.Functions'); Loader::import('fast.ucenter.common.XML'); $this->initConfig(); //初始化UC应用配置 $this->initRequest(); //初始化请求 } function initConfig() { if (!defined('UC_API')) { $this->error('未发现uc常量配置信息'); } } function _serialize($arr, $htmlon = 0) { return xml_serialize($arr, $htmlon); } /** * 解析请求 * @return boolean */ public function initRequest() { $code = $this->request->get('code'); parse_str(_uc_authcode($code, 'DECODE', UC_KEY), $get); if (get_magic_quotes_gpc()) { $get = _uc_stripslashes($get); } if (empty($get) || !isset($get['time']) || !isset($get['action'])) { $this->error = '非法请求'; return false; } $timestamp = time(); if ($timestamp - $get['time'] > 36001111) { $this->error = '请求有效期已过'; return false; } $requestdata = file_get_contents('php://input'); $this->code = $code; $this->action = strtolower(parse_name($get['action'], '1')); $this->get = $get; $this->post = @xml_unserialize($requestdata); $this->appdir = EXTEND_PATH . 'fast/ucenter/client/'; // 定义允许请求的接口 $allowaction = ['test', 'adduser', 'deleteuser', 'gettag', 'synregister', 'synlogin', 'synlogout', 'updateinfo', 'updatebadwords', 'updatehosts', 'updateapps', 'updateclient', 'updatecredit', 'getcreditsettings', 'updatecreditsettings']; if (!in_array($this->action, $allowaction)) { $this->error = '请求不允许'; return false; } } /** * 响应ucserver的通信请求,调用相应方法,输出最终结果并结束整个流程 */ public function response() { if ($this->_before_response()) { if ($this->error !== NULL) { exit($this->error); } $response = call_user_func(array($this, $this->action)); } if ($this->_after_response($response)) { exit($response); } exit('-1'); } protected function _before_response() { return true; } protected function _after_response($response = "") { return true; } public function test() { return API_RETURN_SUCCEED; } }