Skip to content

Commit

Permalink
AbStractAPI增加version的get和set方法;修正accessToken过期时间为lifeTime的2倍bug;sessi…
Browse files Browse the repository at this point in the history
…on的启动改为按配置文件约定
  • Loading branch information
Donny committed Apr 8, 2018
1 parent 8305540 commit 19a3ae1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 21 deletions.
9 changes: 8 additions & 1 deletion src/Core/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ abstract class AbstractApi extends AbstractService
protected $_blackProps = [];

protected $_accessToken;
protected $_version;

/**
* 对accessToken的等级要求
Expand Down Expand Up @@ -92,6 +93,12 @@ public function getAppKey()
{
return $this->_appKey;
}
public function getVersion(){
return $this->_version;
}
public function setVersion($v){
$this->_version = $v;
}

/**
* 设置AccessToken
Expand Down Expand Up @@ -309,4 +316,4 @@ protected function isDevMember()

return false;
}
}
}
4 changes: 2 additions & 2 deletions src/Core/Api/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion src/Core/Api/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public function getAppKey()
{
return $this->_get('appkey');
}
public function getVersion()
{
return $this->_get('version');
}

public function getSign()
{
Expand All @@ -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;
}
Expand Down Expand Up @@ -151,4 +156,4 @@ public function getData()
{
return $this->_data;
}
}
}
48 changes: 31 additions & 17 deletions src/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static function setup($config = [],$di = null)
self::injectSimpleStorageService();
self::injectFileStorageService();
self::injectQueueService();
//self::injectSessionService();
self::injectSessionService();


//增加插件
Expand Down Expand Up @@ -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;
});
}
}

/**
Expand Down Expand Up @@ -323,4 +337,4 @@ private static function injectQueueService(){
return $queue;
});
}
}
}

0 comments on commit 19a3ae1

Please sign in to comment.