$mysql_conf['host'], 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], 'dbname' => 'gamedb2002_' . $mysql_conf['instance_id'] )); return $conn; } protected function getRedis() { $key = 'game2002api'; $redis_conf = getRedisConfig($key); $r = new phpcommon\Redis(array( 'host' => $redis_conf['host'], 'port' => $redis_conf['port'], 'passwd' => $redis_conf['passwd'], )); return $r; } public function rankInfo() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $conn = $this->getMysql($account_id); if (!$conn) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $score_list = array(); $score_rank = 0; $user_list = array(); //个人信息 $row = $conn->execQueryOne('SELECT user_name, avatar_url, score FROM user ' . ' WHERE accountid=:accountid;', array( ':accountid' => $account_id )); if ($row) { array_push($user_list, array( 'account_id' => $account_id, 'name' => $row['user_name'], 'avatar_url' => $row['avatar_url'], 'score' => $row['score'] )); } //积分榜 $r = $this->getRedis(); $score_rank_db = $r->get("game2002api: score_rank"); $score_db = json_decode($score_rank_db); $i = 0; foreach ($score_db as $score) { if ($i > 49) { break; } if ($score_db[$i][0] == $account_id) { $score_rank = $i + 1; } array_push($score_list, array( 'account_id' => $score_db[$i][0], 'name' => $score_db[$i][1], 'avatar_url' => $score_db[$i][2], 'score' => $score_db[$i][3], )); $i++; } echo json_encode(array( 'errcode' => 0, 'errmsg' => "", 'user_list' => $user_list, 'score_rank' => $score_rank, 'score_list' => $score_list, )); } } ?>