99 lines
2.4 KiB
PHP
99 lines
2.4 KiB
PHP
<?php
|
|
|
|
class BaseAuthedController extends BaseController {
|
|
|
|
private $accountId = '';
|
|
private $sessionId = '';
|
|
private $mysqlConn = null;
|
|
|
|
public function handlePre()
|
|
{
|
|
$this->accountId = $_REQUEST['account_id'];
|
|
$this->sessionId = $_REQUEST['session_id'];
|
|
if (!phpcommon\isValidSessionId($this->accountId,
|
|
$this->sessionId)) {
|
|
phpcommon\sendError(500, '无效的session_id');
|
|
die();
|
|
}
|
|
}
|
|
|
|
protected function getAccountId()
|
|
{
|
|
return $this->accountId;
|
|
}
|
|
|
|
protected function getChannel()
|
|
{
|
|
return phpcommon\extractChannel($this->getAccountId());
|
|
}
|
|
|
|
protected function getSessionId()
|
|
{
|
|
return $this->sessionId;
|
|
}
|
|
|
|
protected function getRegisterTime()
|
|
{
|
|
$registertime = phpcommon\extractRegisterTimeFromSessionId($this->sessionId);
|
|
return $registertime;
|
|
}
|
|
|
|
|
|
protected function getMysql($data)
|
|
{
|
|
$mysql_conf = getMysqlConfig(crc32($data));
|
|
$conn = new phpcommon\Mysql(array(
|
|
'host' => $mysql_conf['host'],
|
|
'port' => $mysql_conf['port'],
|
|
'user' => $mysql_conf['user'],
|
|
'passwd' => $mysql_conf['passwd'],
|
|
'dbname' => DBNAME_PREFIX . $mysql_conf['instance_id']
|
|
));
|
|
return $conn;
|
|
}
|
|
|
|
protected function getSelfMysql()
|
|
{
|
|
if (!$this->mysqlConn) {
|
|
$this->mysqlConn = $this->getMysql($this->getAccountId());
|
|
}
|
|
return $this->mysqlConn;
|
|
}
|
|
|
|
protected function getRedis($data)
|
|
{
|
|
$redis_conf = getRedisConfig(crc32($data));
|
|
$r = new phpcommon\Redis(array(
|
|
'host' => $redis_conf['host'],
|
|
'port' => $redis_conf['port'],
|
|
'passwd' => $redis_conf['passwd']
|
|
|
|
));
|
|
return $r;
|
|
}
|
|
|
|
protected function isValidSex($sex)
|
|
{
|
|
return in_array($sex, array(0, 1, 2));
|
|
}
|
|
|
|
protected function getUserInfo($fields)
|
|
{
|
|
$row = phpcommon\SqlHelper::selectOne
|
|
($this->getSelfMysql(),
|
|
'user',
|
|
$fields,
|
|
array(
|
|
'accountid' => $this->getAccountId()
|
|
)
|
|
);
|
|
if (empty($row)) {
|
|
phpcommon\sendError(500, '服务器内部错误');
|
|
error_log('getUserInfo error '. $this->getAccountId());
|
|
die();
|
|
}
|
|
return $row;
|
|
}
|
|
|
|
}
|