objDUserInfo = new UserInfo (); } /** * 页面中调用获取 当前用户信息的方法 */ public function getRunTimeUserData() { $JsonUserData = Cookie::get ( 'CAS_USER_DATA' ); $objDUser = new User (); if (empty ( $JsonUserData )) { $info = array (); $uid = $objDUser->initUser ( $info ); } else { $userData = json_decode ( $userData ); if ($userData ['key'] != Math::md5_16 ( $userData ['id'] )) { return false; } $uid = $userData ['id']; } $userData = $objDUser->get ( $uid ); $userData ['key'] = Math::md5_16 ( $uid ); $userData = json_decode ( $userData ); Cooke::set ( 'CAS_USER_DATA', $userData, 60 * 60 * 24 * 20 ,'.'.$_SERVER['HTTP_HOST']); return $userData; } /** * 通过$passport_uid 获取用户信息 */ public function getUserDataPasspord($passport_uid){ $condition = array( 'passport_uid' => $passport_uid ); $ids = $this->objDUserInfo -> findIdsBy($condition,1); $userData = $this->objDUserInfo -> gets($ids); $userData = array_pop($userData); return $userData; } /** * 获取一个随机头像 */ public function getAvatar() { $num = 16; $config = Config::getInstance ()->get ( 'web_cfg' ); $file = $config['cdn'] . '/public/avatar/'.rand(1,$num).'.jpg'; return $file; } /** * 为当前用户分配一个头像 */ public function setAvatar() { $ids = $this->objDUserInfo -> findIdsBy(array()); $userData = $this->objDUserInfo -> gets($ids); if ($userData) { foreach ($userData as $k => $v) { if (empty($v['headimgurl']) || (isset($v['headimgurl']) && !strstr($v['headimgurl'], 'https://'))) { $result['headimgurl'] = $this->getAvatar(); $this->objDUserInfo->modify (array('headimgurl' => $result['headimgurl']) , array ( 'id' => $v['id'] ) ); } } } } /** * 初始化一个新用户 返回ID */ public function initUser() { $info = array ( 'is_new' => UserInfo::NEW_USER , 'passport_uid' => '-1', 'headimgurl' => $this->getAvatar(), ); return $this->objDUserInfo->add ( $info ); } /** * 绑定一个新用户 */ public function bindingUser($info, $uid) { $info ['is_new'] = UserInfo::OLD_USER; return $this->objDUserInfo->modify ( $info, array ( 'id' => $uid ) ); } /** * 通过本平台的UID 获取用户信息 */ public function get($uid) { $result = array (); if (! Verify::unsignedInt ( $uid )) { return $result; } $result = $this->objDUserInfo->gets ( array ( $uid ) ); if (! $result) { return array (); } $result = array_pop ( $result ); if (empty($result['headimgurl'])) { $result['headimgurl'] = $this->getAvatar(); $this->objDUserInfo->modify (array('headimgurl' => $result['headimgurl']) , array ( 'id' => $result['id'] )); } return $result; } /** * 通过本平台的UIDS 批量获取用户信息 */ public function gets(array $uids) { $result = array (); if (! $uids) { return $result; } $result = $this->objDUserInfo->gets ( $uids ); return $result; } }