Commit 770e09ae authored by 郭勇志's avatar 郭勇志

格式化rediskey方法

parent c849bc30
......@@ -11,4 +11,16 @@ class Func
}
return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
}
/**
* 格式化redis key
* @return string
*/
public function formatKey($key)
{
$preFix = REDIS_PREFIX;
if (substr($key,0,strlen($preFix))==$preFix) {
return $key;
}
return $preFix.$key;
}
}
......@@ -28,16 +28,4 @@ class BaseModel extends ActiveRecord
}
return Yii::$app->$db;
}
/**
* 格式化redis key
* @return string
*/
public function formatKey($key)
{
$preFix = REDIS_PREFIX;
if (substr($key,0,strlen($preFix))==$preFix) {
return $key;
}
return $preFix.$key;
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ use Yii;
use app\models\v1\rbacuser\ShopRbacUser;
use app\models\v1\BaseModel;
use yii\web\HttpException;
use backend\helpers\Func;
/**
* Login form
*/
......@@ -56,9 +57,10 @@ class LoginForm extends BaseModel
if ($this->validate()) {
$accessToken=$this->_shopRbacUser->generateAccessToken();
// 生成access_token=>array(用户GUID,ORG_GUID)保存到redis
$func= new Func;
$redis = Yii::$app->redis;
$rtnSet=$redis->set($this->formatKey($accessToken), json_encode(array('USER_GUID'=>$this->_shopRbacUser->GUID,'ORG_GUID'=>$this->_shopRbacUser->ORG_GUID)));
$rtnExpire=$redis->expire($this->formatKey($accessToken), 10800);
$rtnSet=$redis->set($func->formatKey($accessToken), json_encode(array('USER_GUID'=>$this->_shopRbacUser->GUID,'ORG_GUID'=>$this->_shopRbacUser->ORG_GUID)));
$rtnExpire=$redis->expire($func->formatKey($accessToken), 10800);
if ($rtnSet&&$rtnExpire) {
return $accessToken;
}
......
......@@ -6,6 +6,7 @@ use Yii;
use yii\web\IdentityInterface;
use app\models\v1\BaseModel;
use yii\web\HttpException;
use backend\helpers\Func;
/**
* This is the model class for table "shop_rbac_user".
*
......@@ -135,7 +136,8 @@ class ShopRbacUser extends BaseModel implements IdentityInterface
// 取得reids中用户信息
$redis = Yii::$app->redis;
$model = new ShopRbacUser;
$rtnGet=$redis->get($model->formatKey($token));
$func= new Func;
$rtnGet=$redis->get($func->formatKey($token));
if ($rtnGet) {
$userInfo=json_decode($rtnGet,true);
$db=DB_PREFIX.$userInfo['ORG_GUID'];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment