From 19a3ae1e720cc0b66a9dd2244fd41715a1ccace3 Mon Sep 17 00:00:00 2001 From: Donny Date: Sun, 8 Apr 2018 11:22:19 +0800 Subject: [PATCH] =?UTF-8?q?AbStractAPI=E5=A2=9E=E5=8A=A0version=E7=9A=84ge?= =?UTF-8?q?t=E5=92=8Cset=E6=96=B9=E6=B3=95;=E4=BF=AE=E6=AD=A3accessToken?= =?UTF-8?q?=E8=BF=87=E6=9C=9F=E6=97=B6=E9=97=B4=E4=B8=BAlifeTime=E7=9A=842?= =?UTF-8?q?=E5=80=8Dbug=EF=BC=9Bsession=E7=9A=84=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E6=8C=89=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=BA=A6=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Core/Api/AbstractApi.php | 9 ++++++- src/Core/Api/ApiService.php | 4 +-- src/Core/Api/Request.php | 7 +++++- src/Init.php | 48 +++++++++++++++++++++++------------- 4 files changed, 47 insertions(+), 21 deletions(-) diff --git a/src/Core/Api/AbstractApi.php b/src/Core/Api/AbstractApi.php index 1265318..e0af24e 100644 --- a/src/Core/Api/AbstractApi.php +++ b/src/Core/Api/AbstractApi.php @@ -56,6 +56,7 @@ abstract class AbstractApi extends AbstractService protected $_blackProps = []; protected $_accessToken; + protected $_version; /** * 对accessToken的等级要求 @@ -92,6 +93,12 @@ public function getAppKey() { return $this->_appKey; } + public function getVersion(){ + return $this->_version; + } + public function setVersion($v){ + $this->_version = $v; + } /** * 设置AccessToken @@ -309,4 +316,4 @@ protected function isDevMember() return false; } -} \ No newline at end of file +} diff --git a/src/Core/Api/ApiService.php b/src/Core/Api/ApiService.php index 3bf4852..9012bad 100644 --- a/src/Core/Api/ApiService.php +++ b/src/Core/Api/ApiService.php @@ -351,7 +351,7 @@ static private function _filterValidParams($apiConfigData, $params) * 4.接口对应的实际类与方法要存在,不存在报错 * 5.调用接口,并返回 * - * @param \Kuga\Service\ApiV3\Request $req + * @param \Kuga\Core\Api\Request $req * * @return multitype */ @@ -467,7 +467,7 @@ static public function decryptData($data, $time = 0) $time || $time = time(); $txt = $crypt->decryptBase64($data, md5(self::$_appKey)); $data = @unserialize($txt); - if ($time - $data['time'] <= self::$_lifetime) { + if ($time <= $data['time']) { return $data['data']; } else { return null; diff --git a/src/Core/Api/Request.php b/src/Core/Api/Request.php index 94cafd5..4372c54 100644 --- a/src/Core/Api/Request.php +++ b/src/Core/Api/Request.php @@ -32,6 +32,10 @@ public function getAppKey() { return $this->_get('appkey'); } + public function getVersion() + { + return $this->_get('version'); + } public function getSign() { @@ -57,6 +61,7 @@ public function getParams() $data = $this->_unset('format', $data); $data = $this->_unset('sign', $data); $data = $this->_unset('locale', $data); + $data = $this->_unset('version', $data); return $data; } @@ -151,4 +156,4 @@ public function getData() { return $this->_data; } -} \ No newline at end of file +} diff --git a/src/Init.php b/src/Init.php index af20d56..494b216 100644 --- a/src/Init.php +++ b/src/Init.php @@ -72,7 +72,7 @@ public static function setup($config = [],$di = null) self::injectSimpleStorageService(); self::injectFileStorageService(); self::injectQueueService(); - //self::injectSessionService(); + self::injectSessionService(); //增加插件 @@ -263,22 +263,36 @@ private static function injectCryptService(){ */ private static function injectSessionService(){ $config = self::$config; - self::$di->setShared('session', function() use($config){ - if (isset($_POST['sessid'])){ - session_id($_POST['sessid']); + if(file_exists($config->session)){ + //读取配置 + $sessionConfigContent = file_get_contents($config->session); + $sessonConfig = \json_decode($sessionConfigContent,true); + if($sessonConfig && $sessonConfig['enabled']){ + $adapter = $sessonConfig['adapter']; + $sessionOption = is_array($sessonConfig['option'])?$sessonConfig['option']:[]; + if($sessionOption){ + if($adapter=='redis'){ + $session = new \Phalcon\Session\Adapter\Redis($sessionOption); + $option = $config->redis; + $option = \Qing\Lib\utils::arrayExtend($option,$sessionOption); + }else{ + $session = new \Phalcon\Session\Adapter\Files($sessionOption); + $option = $sessionOption; + } + self::$di->setShared('session', function() use($option){ + if (isset($_POST['sessid'])){ + session_id($_POST['sessid']); + } + $session = new \Phalcon\Session\Adapter\Redis($option); + ini_set('session.cookie_domain', \Qing\Lib\Application::getCookieDomain()); + ini_set('session.cookie_path', '/'); + ini_set('session.cookie_lifetime', 86400); + $session->start(); + return $session; + }); + } } - $option = $config->redis; - $option['uniqueId'] = 'LA-SESS'; - $option['persistent'] = false; - $option['prefix'] = 'se_'; - $option['index'] = 2; - $session = new \Phalcon\Session\Adapter\Redis($option); - ini_set('session.cookie_domain', \Qing\Lib\Application::getCookieDomain()); - ini_set('session.cookie_path', '/'); - ini_set('session.cookie_lifetime', 86400); - $session->start(); - return $session; - }); + } } /** @@ -323,4 +337,4 @@ private static function injectQueueService(){ return $queue; }); } -} \ No newline at end of file +}