1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-26 12:23:06 +08:00

修正websocket连接地址

This commit is contained in:
koogua 2021-10-03 09:47:23 +08:00
parent b64168120a
commit 1d58446245
4 changed files with 33 additions and 2 deletions

View File

@ -11,6 +11,7 @@ use App\Models\User as UserModel;
use App\Services\Auth\Api as ApiAuth;
use App\Traits\Response as ResponseTrait;
use App\Traits\Security as SecurityTrait;
use App\Validators\Validator as AppValidator;
use Phalcon\Mvc\Dispatcher;
class Controller extends \Phalcon\Mvc\Controller
@ -30,6 +31,10 @@ class Controller extends \Phalcon\Mvc\Controller
$this->setCors();
}
$validator = new AppValidator();
$validator->checkSiteStatus();
$this->checkRateLimit();
return true;
@ -52,4 +57,16 @@ class Controller extends \Phalcon\Mvc\Controller
return $auth->getCurrentUser();
}
protected function getSiteInfo()
{
return $this->getSettings('site');
}
protected function getSettings($section)
{
$appService = new AppService();
return $appService->getSettings($section);
}
}

View File

@ -147,7 +147,7 @@ class Controller extends \Phalcon\Mvc\Controller
* ssl通过nginx转发实现
*/
if ($this->request->isSecure()) {
$websocket->connect_url = sprintf('wss://%s/wss', $this->request->getHttpHost());
$websocket->connect_url = sprintf('wss://%s/wss', $websocket->connect_address);
} else {
$websocket->connect_url = sprintf('ws://%s', $websocket->connect_address);
}

View File

@ -8,12 +8,26 @@
namespace App\Validators;
use App\Exceptions\Forbidden as ForbiddenException;
use App\Exceptions\ServiceUnavailable;
use App\Exceptions\ServiceUnavailable as ServiceUnavailableException;
use App\Exceptions\Unauthorized as UnauthorizedException;
use App\Services\Service as AppService;
use Phalcon\Di\Injectable;
class Validator extends Injectable
{
public function checkSiteStatus()
{
$service = new AppService();
$siteInfo = $service->getSettings('site');
if ($siteInfo['status'] == 'closed') {
throw new ServiceUnavailableException('sys.service_unavailable');
}
}
public function checkAuthUser($userId)
{
if (empty($userId)) {

View File

@ -150,7 +150,7 @@ $config['throttle']['rate_limit'] = 60;
/**
* 客户端ping服务端间隔
*/
$config['websocket']['ping_interval'] = 50;
$config['websocket']['ping_interval'] = 30;
/**
* 客户端连接地址外部可访问的域名或ip带端口号