Onex ecstore缓存的用法

/ 0评 / 0

class mapi_tools_accesstoken{

//使用缓存

static function _set_accesstoken($str_token,$member_id) {

$actoken=self::_check_accesstoken($str_token,$member_id);

if (!$actoken) {

$actokenkey='accesstoken-'.$member_id;

$actokenNew=array(

'member_id'=>$member_id,

'accesstoken'=>$str_token,

'expire_time'=>time()+6000

);

self::_save_atoken($actokenkey,$actokenNew);

}

}

 

static function _get_accesstoken($member_id){

$actokenkey='accesstoken-'.$member_id;

if (base_kvstore::instance('b2c_apiv')->fetch($actokenkey,$content)) {

$actokenArr=json_decode($content,true);

if ($actokenArr['expire_time'] > time()) {

$actoken=array(

'member_id'=>$member_id,

'accesstoken'=>$actokenArr['accesstoken'],

'expire_time'=>time()+6000

);

self::_save_atoken($actokenkey,$actoken);

return $actoken;

}else{

return false;

}

}else{

return false;

}

}

 

 

static function _check_accesstoken($str_token,$member_id){

$actoken=self::_get_accesstoken($member_id,$type);

if ($actoken) {

if($actoken['accesstoken'] == $str_token){

return $actoken;

}

return false;

}else{

return false;

}

}

 

private function _save_atoken($actokenkey,$aToken){

base_kvstore::instance('b2c_apiv')->store($actokenkey,json_encode($aToken));

}

 

static function _clear_atoken($actokenkey){

base_kvstore::instance('b2c_apiv')->store($actokenkey,'');

}

}

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注