54 lines
1.5 KiB
PHP
54 lines
1.5 KiB
PHP
<?php
|
|
|
|
class VoiceController{
|
|
|
|
protected function getMysql($account_id)
|
|
{
|
|
$mysql_conf = getMysqlConfig(crc32($account_id));
|
|
$conn = new phpcommon\Mysql(array(
|
|
'host' => $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($accountid)
|
|
{
|
|
$redis_conf = getRedisConfig(crc32($accountid));
|
|
$r = new phpcommon\Redis(array(
|
|
'host' => $redis_conf['host'],
|
|
'port' => $redis_conf['port'],
|
|
'passwd' => $redis_conf['passwd']
|
|
));
|
|
return $r;
|
|
}
|
|
|
|
public function upload()
|
|
{
|
|
$raw_data = file_get_contents('php://input');
|
|
$data = base64_encode($raw_data);
|
|
$md5 = md5($data);
|
|
$r = $this->getRedis($md5);
|
|
$r->set('game2002:voice:' . $md5, $data);
|
|
$r -> pexpire('game2002:voice:' . $md5, 1000 * 600);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'download_url' => "https://game2002api.kingsome.cn/webapp/index.php?c=Voice&a=download&res_id=" . $md5
|
|
));
|
|
}
|
|
|
|
public function download()
|
|
{
|
|
$r = $this->getRedis($_REQUEST['res_id']);
|
|
$data = $r->get('game2002:voice:' . $_REQUEST['res_id']);
|
|
echo base64_decode($data);
|
|
}
|
|
|
|
}
|
|
|
|
|