This commit is contained in:
2025-06-25 16:12:51 +08:00
parent dbcc89b8fb
commit 28aec960e2
15 changed files with 2013 additions and 45 deletions

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Services\Base;
class BaseService
{
protected $userId;
protected static $instance;
public function __construct()
{
$token = request()->header('token');
$this->userId = $token;
}
// 单例
public static function getInstance()
{
if (!self::$instance instanceof self) {
self::$instance = new self();
}
return self::$instance;
}
}

View File

@@ -2,7 +2,19 @@
namespace App\Services\GatewayWorker;
class ImService
use App\Services\Base\BaseService;
class ImService extends BaseService
{
public function bindClientIdByUserId($clientId)
{
if (empty($clientId)) {
throw new \Exception('clientId不能为空');
}
GatewayClientService::getInstance()->init()->bindUser($clientId, $this->userId);
return ['绑定成功'];
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Services\GatewayWorker;
use App\Models\UserModel;
class UserService
{
public function login($username, $password)
{
$userModel = UserModel::where('username', $username)->first();
if ($userModel) {
if ($userModel->password == md5($password)) {
return [
'token' => $userModel->id,
'user_info' => $userModel
];
} else {
return false;
}
} else {
return false;
}
}
public function register($username, $password, $nickName)
{
$userModel = UserModel::create([
'username' => $username,
'password' => md5($password),
'nick_name' => $nickName,
'created_at' => time()
]);
return [
'token' => $userModel->id,
'user_info' => $userModel
];
}
}