/** * 获得用户web socket fd * * @param Request $request */ public function postSocketFd(Request $request) { $user_id = $request->get('id'); //加载函数库 load_func('instanceof,image'); //获得发送对象$fb $user_info = unserialize(get_redis()->hGet(config('config.user_list_hash_table'), $user_id)); if (!empty($user_info)) { $this->response(200, 'success', ['fd' => $user_info->web_socket_fd, 'name' => $user_info->user_name, 'face' => get_user_info_face($user_info->face)]); } else { $this->response(400, trans('response.save_user_socket_to_redis_error')); } }
/** * 获得在线好友 * * @param $params array 用户登录名和密码参数 * @return int * @author yangyifan <*****@*****.**> */ public static function onlineUser() { load_func('instanceof,image,common'); $online_user = get_redis()->hGetAll(config('config.user_list_hash_table')); $item = []; //获得全部我的好友 $my_friends = FriendsModel::getMyFriends(); foreach ($online_user as $user) { $user = unserialize($user); //如果是自己,则跳过 || 如果不是自己好友,则跳过 if ($user->id == is_user_login() || !in_array($user->id, $my_friends)) { continue; } $item[] = ['id' => $user->id, 'name' => $user->user_name, 'face' => get_user_info_face($user->face), 'url' => action("User\\UserController@getIndex", ['id' => $user->id])]; } $data = [['name' => '在线好友', 'nums' => count($item), 'id' => 1, 'item' => $item]]; return $data; }
/** * 组合用户信息 * * @param $user_info * @author yangyifan <*****@*****.**> */ private static function mergeUserInfo($user_info) { if (!empty($user_info)) { load_func('image'); $user_info->face = get_user_info_face($user_info->face); $user_info->url = action("User\\UserController@getIndex", ['id' => $user_info->id]); $user_info->user_name = !empty($user_info->user_name) ? $user_info->user_name : $user_info->email; return $user_info; } }
" <?php } else { ?> var user_name = "<?php echo Session::get('user_info.email'); ?> " <?php } ?> <?php $face = Session::get('user_info.face'); ?> var user_face = "<?php echo get_user_info_face($face); ?> " </script> @show </head> <body> <!-- top --> <div class="top"> @section('header') @include('user.block.header') @show </div>