<?php
|
|
class Common_Util{
|
|
/**
|
* 随机字符串
|
* @param int $length 长度
|
* @param int $numeric 类型(0:混合;1:纯数字)
|
* @return string
|
*/
|
public static function random($length, $numeric = 0) {
|
$seed = base_convert(md5(microtime().$_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
|
$seed = $numeric ? (str_replace('0', '', $seed).'012340567890') : ($seed.'zZ'.strtoupper($seed));
|
if($numeric) {
|
$hash = '';
|
} else {
|
$hash = chr(rand(1, 26) + rand(0, 1) * 32 + 64);
|
$length--;
|
}
|
$max = strlen($seed) - 1;
|
for($i = 0; $i < $length; $i++) {
|
$hash .= $seed{mt_rand(0, $max)};
|
}
|
return $hash;
|
}
|
|
/**
|
* 更新角色权限
|
* @return [type] [description]
|
*/
|
public function updateRoleAuth(){
|
$role_service = new Service_Role();
|
$roles = $role_service->getRoleList();
|
$role_auths = array();
|
foreach ($roles as $role) {
|
$role_auth[$role['_id']] = explode(',', $role['modules']);
|
}
|
//初始化redis
|
$redis = System_Service_Locator::getInstance()->get('redis');
|
$redis->set('role_auth', $role_auth);
|
}
|
|
|
}
|