diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php new file mode 100644 index 00000000..ec1687e4 --- /dev/null +++ b/app/Http/Controllers/AuthController.php @@ -0,0 +1,48 @@ +service = new UserService(); + } + + /** + * @Method POST + * @return JsonResponse + */ + public function login(): JsonResponse + { + $username = request()->input('username'); + $password = request()->input('password'); + + return jok( + $this->service->login($username, $password), + '登录成功' + ); + } + /** + * @Method POST + * @return JsonResponse + */ + public function register(): JsonResponse + { + $username = request()->input('username'); + $password = request()->input('password'); + $nickName = request()->input('nickname'); + + return jok( + $this->service->register($username, $password, $nickName), + '注册成功' + ); + } +} diff --git a/app/Http/Controllers/ImController.php b/app/Http/Controllers/ImController.php new file mode 100644 index 00000000..cb5a963c --- /dev/null +++ b/app/Http/Controllers/ImController.php @@ -0,0 +1,28 @@ +service = ImService::getInstance(); + } + public function bind() + { + $clientId = request()->input('client_id'); + + try { + return jok($this->service->bindClientIdByUserId($clientId)); + } catch (\Exception $e) { + return jerr($e->getMessage()); + } + } +} diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php new file mode 100644 index 00000000..b754608e --- /dev/null +++ b/app/Http/Controllers/UserController.php @@ -0,0 +1,10 @@ +header('token'); + $this->userId = $token; + } + + // 单例 + + public static function getInstance() + { + if (!self::$instance instanceof self) { + self::$instance = new self(); + } + return self::$instance; + } +} diff --git a/app/Services/GatewayWorker/ImService.php b/app/Services/GatewayWorker/ImService.php index 77c5bf98..8b80e4a8 100644 --- a/app/Services/GatewayWorker/ImService.php +++ b/app/Services/GatewayWorker/ImService.php @@ -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 ['绑定成功']; + } } diff --git a/app/Services/GatewayWorker/UserService.php b/app/Services/GatewayWorker/UserService.php new file mode 100644 index 00000000..ff04f36f --- /dev/null +++ b/app/Services/GatewayWorker/UserService.php @@ -0,0 +1,40 @@ +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 + ]; + } +} diff --git a/bootstrap/app.php b/bootstrap/app.php index c1832766..c3928c57 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -7,6 +7,7 @@ use Illuminate\Foundation\Configuration\Middleware; return Application::configure(basePath: dirname(__DIR__)) ->withRouting( web: __DIR__.'/../routes/web.php', + api: __DIR__.'/../routes/api.php', commands: __DIR__.'/../routes/console.php', health: '/up', ) diff --git a/config/gateway.php b/config/gateway.php index e14b6165..aff0910b 100644 --- a/config/gateway.php +++ b/config/gateway.php @@ -4,8 +4,8 @@ return [ /* * -----------服务地址----------- */ -// 'register_address' => 'http://t-ws.nailaoyun.cn/register/' -// 'register_address' => 't-ws.nailaoyun.cn/register/', +// 'register_address' => 'http://t-ws.奶酪yun.cn/register/' +// 'register_address' => 't-ws.奶酪yun.cn/register/', 'register_address' => '10.0.12.17:11238', // 'register_address' => '101.43.12.11:11238', // 'register_address' => '172.22.240.1:11238', diff --git a/config/helpers.php b/config/helpers.php new file mode 100644 index 00000000..112c9323 --- /dev/null +++ b/config/helpers.php @@ -0,0 +1,80 @@ + $value) { + + // 获取控制器$value的所有方法 + $methods = (new ReflectionClass($value))->getMethods(); + + // 注册路由 + foreach ($methods as $method) { + // 获取方法注释 @Method + $docComment = $method->getDocComment(); + if ($method->name === '__construct' || preg_match('/@Method\s+(NO)\b/', $docComment, $matches)) { + continue; + } + + $httpMethod = 'any'; + // 查询 @Method GET 或者 @Method POST + if (preg_match('/@Method\s+(GET|POST|PUT|DELETE|PATCH|OPTIONS|HEAD|ANY)\b/', $docComment, $matches)) { + $httpMethod = $matches[1]; + } + Illuminate\Support\Facades\Route::$httpMethod( $key. '/'. cc_camel_case_to_dash($method->getName()), [$value, conjunction_symbol_processing($method->name)] ); + } + } + } +} + +/** + * 连赐福转换小驼峰 + * @param $string + * @return string + */ +if(!function_exists('conjunction_symbol_processing')) { + function conjunction_symbol_processing($string): string + { + $string = str_replace('-', ' ', $string); // 将连字符替换为空格 + $string = ucwords($string); // 将每个单词的首字母大写 + $string = str_replace(' ', '', $string); // 空格删除 + $string[0] = lcfirst($string)[0]; // 首字母小写 + + return $string; + } + +} + + + +// 小驼峰转换- +if ( !function_exists('cc_camel_case_to_dash') ) { + function cc_camel_case_to_dash($str): string + { + return strtolower(preg_replace('/([a-z])([A-Z])/', '$1-$2', $str)); + } +} diff --git a/resources/views/chat.blade.php b/resources/views/chat.blade.php new file mode 100644 index 00000000..ced7281e --- /dev/null +++ b/resources/views/chat.blade.php @@ -0,0 +1,899 @@ + + +
+ + +安全通讯 · 暗色主题 · 极致体验
+ +安全通讯 · 暗色主题 · 极致体验