diff --git a/app/BaseApp/BaseController.php b/app/BaseApp/BaseController.php index ab125527..7b7ea85e 100755 --- a/app/BaseApp/BaseController.php +++ b/app/BaseApp/BaseController.php @@ -2,7 +2,7 @@ namespace App\BaseApp; -use App\Service\UtilsService; +use App\Service\common\UtilsService; use Exception; use Illuminate\Http\JsonResponse; use Psr\Container\ContainerExceptionInterface; diff --git a/app/BaseApp/BaseService.php b/app/BaseApp/BaseService.php index 89818b36..8fbcd56b 100755 --- a/app/BaseApp/BaseService.php +++ b/app/BaseApp/BaseService.php @@ -3,7 +3,7 @@ namespace App\BaseApp; use App\Models\UserModel; -use App\Service\UtilsService; +use App\Service\common\UtilsService; class BaseService { diff --git a/app/Http/Controllers/LoginController.php b/app/Http/Controllers/LoginController.php new file mode 100644 index 00000000..5405c166 --- /dev/null +++ b/app/Http/Controllers/LoginController.php @@ -0,0 +1,37 @@ +service = LoginService::getInstance(); + } + + /** + * 登录 + * @Method POST + * @return \Illuminate\Http\JsonResponse + * @throws \Exception + */ + public function login() + { + $this->insertField = [ + 'account', 'password', 'is_remember' + ]; + $param = $this->checkRequiredFields(request()->post()); + + return jok( + $this->service->login($param['account'], $param['password']), + '登录成功' + ); + } + +} diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php new file mode 100644 index 00000000..f2ea61ee --- /dev/null +++ b/app/Http/Controllers/UserController.php @@ -0,0 +1,10 @@ +hasMany(ProjectModal::class, 'category_id', 'id'); + return $this->hasMany(ProjectModel::class, 'category_id', 'id'); } } diff --git a/app/Models/FeatureModal.php b/app/Models/FeatureModel.php similarity index 64% rename from app/Models/FeatureModal.php rename to app/Models/FeatureModel.php index be0aa280..240f8dce 100644 --- a/app/Models/FeatureModal.php +++ b/app/Models/FeatureModel.php @@ -2,12 +2,12 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; +use App\BaseApp\BaseModel; /** * 核心功能表 */ -class FeatureModal extends Model +class FeatureModel extends BaseModel { // protected $table = 'features'; diff --git a/app/Models/FrameworkModal.php b/app/Models/FrameworkModel.php similarity index 71% rename from app/Models/FrameworkModal.php rename to app/Models/FrameworkModel.php index 9fedc885..055dde96 100644 --- a/app/Models/FrameworkModal.php +++ b/app/Models/FrameworkModel.php @@ -2,13 +2,13 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; +use App\BaseApp\BaseModel; use Illuminate\Database\Eloquent\Relations\BelongsToMany; /** * 框架表 */ -class FrameworkModal extends Model +class FrameworkModel extends BaseModel { // protected $table = 'frameworks'; @@ -21,6 +21,6 @@ class FrameworkModal extends Model */ public function projects() { - return $this->belongsToMany(ProjectModal::class, 'project_frameworks_relations', 'framework_id', 'project_id'); + return $this->belongsToMany(ProjectModel::class, 'project_frameworks_relations', 'framework_id', 'project_id'); } } diff --git a/app/Models/LabelModal.php b/app/Models/LabelModel.php similarity index 65% rename from app/Models/LabelModal.php rename to app/Models/LabelModel.php index 23886959..9fb9ff87 100644 --- a/app/Models/LabelModal.php +++ b/app/Models/LabelModel.php @@ -2,14 +2,13 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; +use App\BaseApp\BaseModel; use Illuminate\Database\Eloquent\Relations\BelongsToMany; -use Illuminate\Database\Eloquent\Relations\HasMany; /** * 标签表 */ -class LabelModal extends Model +class LabelModel extends BaseModel { // protected $table = 'labels'; @@ -22,6 +21,6 @@ class LabelModal extends Model */ public function projects(): BelongsToMany { - return $this->belongsToMany(ProjectModal::class, 'project_labels_relations', 'label_id', 'project_id'); + return $this->belongsToMany(ProjectModel::class, 'project_labels_relations', 'label_id', 'project_id'); } } diff --git a/app/Models/OrderItemModal.php b/app/Models/OrderItemModel.php similarity index 64% rename from app/Models/OrderItemModal.php rename to app/Models/OrderItemModel.php index e2a88f6a..549c77f8 100644 --- a/app/Models/OrderItemModal.php +++ b/app/Models/OrderItemModel.php @@ -2,12 +2,12 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; +use App\BaseApp\BaseModel; /** * 订单详情表 */ -class OrderItemModal extends Model +class OrderItemModel extends BaseModel { // protected $table = 'order_items'; diff --git a/app/Models/OrderModal.php b/app/Models/OrderModel.php similarity index 69% rename from app/Models/OrderModal.php rename to app/Models/OrderModel.php index 4b3c62b9..a2b7eeb8 100644 --- a/app/Models/OrderModal.php +++ b/app/Models/OrderModel.php @@ -2,14 +2,14 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; +use App\BaseApp\BaseModel; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; /** * 订单表 */ -class OrderModal extends Model +class OrderModel extends BaseModel { // protected $table = 'orders'; @@ -22,7 +22,7 @@ class OrderModal extends Model */ public function user() { - return $this->hasOne(UserModal::class, 'id', 'user_id'); + return $this->hasOne(UserModel::class, 'id', 'user_id'); } /** @@ -31,6 +31,6 @@ class OrderModal extends Model */ public function items(): HasMany { - return $this->hasMany(OrderItemModal::class, 'order_id', 'id'); + return $this->hasMany(OrderItemModel::class, 'order_id', 'id'); } } diff --git a/app/Models/PartnerModal.php b/app/Models/PartnerModel.php similarity index 64% rename from app/Models/PartnerModal.php rename to app/Models/PartnerModel.php index 301d7966..a9c68d17 100644 --- a/app/Models/PartnerModal.php +++ b/app/Models/PartnerModel.php @@ -2,12 +2,12 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; +use App\BaseApp\BaseModel; /** * 合作伙伴表 */ -class PartnerModal extends Model +class PartnerModel extends BaseModel { // protected $table = 'partners'; diff --git a/app/Models/ProjectFrameworksRelationModal.php b/app/Models/ProjectFrameworksRelationModel.php similarity index 51% rename from app/Models/ProjectFrameworksRelationModal.php rename to app/Models/ProjectFrameworksRelationModel.php index 3151d80c..6ccd4260 100644 --- a/app/Models/ProjectFrameworksRelationModal.php +++ b/app/Models/ProjectFrameworksRelationModel.php @@ -2,13 +2,12 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use App\BaseApp\BaseModel; /** * 项目框架关联表 */ -class ProjectFrameworksRelationModal extends Model +class ProjectFrameworksRelationModel extends BaseModel { // protected $table = 'project_frameworks_relations'; diff --git a/app/Models/ProjectLabelRelationModal.php b/app/Models/ProjectLabelRelationModel.php similarity index 66% rename from app/Models/ProjectLabelRelationModal.php rename to app/Models/ProjectLabelRelationModel.php index 0f849a7e..a42b184d 100644 --- a/app/Models/ProjectLabelRelationModal.php +++ b/app/Models/ProjectLabelRelationModel.php @@ -2,13 +2,13 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; +use App\BaseApp\BaseModel; use Illuminate\Database\Eloquent\Relations\HasOne; /** * 项目标签关联表 */ -class ProjectLabelRelationModal extends Model +class ProjectLabelRelationModel extends BaseModel { // protected $table = 'project_label_relations'; @@ -21,7 +21,7 @@ class ProjectLabelRelationModal extends Model */ public function project(): HasOne { - return $this->hasOne(ProjectModal::class, 'id', 'project_id'); + return $this->hasOne(ProjectModel::class, 'id', 'project_id'); } /** @@ -30,6 +30,6 @@ class ProjectLabelRelationModal extends Model */ public function label(): HasOne { - return $this->hasOne(LabelModal::class, 'id', 'label_id'); + return $this->hasOne(LabelModel::class, 'id', 'label_id'); } } diff --git a/app/Models/ProjectModal.php b/app/Models/ProjectModel.php similarity index 71% rename from app/Models/ProjectModal.php rename to app/Models/ProjectModel.php index beb8d4f9..203497c4 100644 --- a/app/Models/ProjectModal.php +++ b/app/Models/ProjectModel.php @@ -2,7 +2,7 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; +use App\BaseApp\BaseModel; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; @@ -10,7 +10,7 @@ use Illuminate\Database\Eloquent\Relations\HasOne; /** * 项目表 */ -class ProjectModal extends Model +class ProjectModel extends BaseModel { // protected $table = 'projects'; @@ -23,7 +23,7 @@ class ProjectModal extends Model */ public function user(): HasOne { - return $this->hasOne(UserModal::class, 'id', 'user_id'); + return $this->hasOne(UserModel::class, 'id', 'user_id'); } /** @@ -32,7 +32,7 @@ class ProjectModal extends Model */ public function author(): HasOne { - return $this->hasOne(UserModal::class, 'id', 'author_id'); + return $this->hasOne(UserModel::class, 'id', 'author_id'); } /** @@ -41,7 +41,7 @@ class ProjectModal extends Model */ public function labels(): BelongsToMany { - return $this->belongsToMany(LabelModal::class, 'project_label_relations', 'project_id', 'label_id'); + return $this->belongsToMany(LabelModel::class, 'project_label_relations', 'project_id', 'label_id'); } /** @@ -50,7 +50,7 @@ class ProjectModal extends Model */ public function screenshots(): HasMany { - return $this->hasMany(ScreenshotModal::class, 'project_id', 'id'); + return $this->hasMany(ScreenshotModel::class, 'project_id', 'id'); } /** @@ -59,7 +59,7 @@ class ProjectModal extends Model */ public function frameworks(): BelongsToMany { - return $this->belongsToMany(FrameworkModal::class, 'project_frameworks_relations', 'project_id', 'framework_id'); + return $this->belongsToMany(FrameworkModel::class, 'project_frameworks_relations', 'project_id', 'framework_id'); } /** @@ -68,7 +68,7 @@ class ProjectModal extends Model */ public function technologyStacks(): BelongsToMany { - return $this->belongsToMany(TechnologyStackModal::class, 'project_technology_stacks_relations', 'project_id', 'technology_stacks_id'); + return $this->belongsToMany(TechnologyStackModel::class, 'project_technology_stacks_relations', 'project_id', 'technology_stacks_id'); } /** @@ -77,7 +77,7 @@ class ProjectModal extends Model */ public function features(): HasMany { - return $this->hasMany(FeatureModal::class, 'project_id', 'id'); + return $this->hasMany(FeatureModel::class, 'project_id', 'id'); } /** @@ -86,6 +86,6 @@ class ProjectModal extends Model */ public function category(): HasOne { - return $this->hasOne(CategoryModal::class, 'id', 'category_id'); + return $this->hasOne(CategoryModel::class, 'id', 'category_id'); } } diff --git a/app/Models/ProjectTechnologyStacksRelationModal.php b/app/Models/ProjectTechnologyStacksRelationModel.php similarity index 63% rename from app/Models/ProjectTechnologyStacksRelationModal.php rename to app/Models/ProjectTechnologyStacksRelationModel.php index f9ea8492..18ca3737 100644 --- a/app/Models/ProjectTechnologyStacksRelationModal.php +++ b/app/Models/ProjectTechnologyStacksRelationModel.php @@ -2,12 +2,12 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; +use App\BaseApp\BaseModel; /** * 项目技术栈关联表 */ -class ProjectTechnologyStacksRelationModal extends Model +class ProjectTechnologyStacksRelationModel extends BaseModel { // protected $table = 'project_technology_stacks_relations'; diff --git a/app/Models/RoleModal.php b/app/Models/RoleModel.php similarity index 64% rename from app/Models/RoleModal.php rename to app/Models/RoleModel.php index 7c533f82..6aaea64a 100644 --- a/app/Models/RoleModal.php +++ b/app/Models/RoleModel.php @@ -2,12 +2,12 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; +use App\BaseApp\BaseModel; /** * 角色表 */ -class RoleModal extends Model +class RoleModel extends BaseModel { // protected $table = 'roles'; diff --git a/app/Models/ScreenshotModal.php b/app/Models/ScreenshotModel.php similarity index 63% rename from app/Models/ScreenshotModal.php rename to app/Models/ScreenshotModel.php index 4c5459d7..a8a15bd4 100644 --- a/app/Models/ScreenshotModal.php +++ b/app/Models/ScreenshotModel.php @@ -2,12 +2,12 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; +use App\BaseApp\BaseModel; /** * 截图表 */ -class ScreenshotModal extends Model +class ScreenshotModel extends BaseModel { // protected $table = 'screenshots'; diff --git a/app/Models/TechnologyStackModal.php b/app/Models/TechnologyStackModel.php similarity index 72% rename from app/Models/TechnologyStackModal.php rename to app/Models/TechnologyStackModel.php index 8bcc4218..4af012d3 100644 --- a/app/Models/TechnologyStackModal.php +++ b/app/Models/TechnologyStackModel.php @@ -2,13 +2,13 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; +use App\BaseApp\BaseModel; use Illuminate\Database\Eloquent\Relations\BelongsToMany; /** * 技术栈表 */ -class TechnologyStackModal extends Model +class TechnologyStackModel extends BaseModel { // protected $table = 'technology_stacks'; @@ -21,6 +21,6 @@ class TechnologyStackModal extends Model */ public function projects(): BelongsToMany { - return $this->belongsToMany(ProjectModal::class, 'project_technology_stack_relations', 'technology_stack_id', 'project_id'); + return $this->belongsToMany(ProjectModel::class, 'project_technology_stack_relations', 'technology_stack_id', 'project_id'); } } diff --git a/app/Models/UserModal.php b/app/Models/UserModel.php similarity index 69% rename from app/Models/UserModal.php rename to app/Models/UserModel.php index 2959bb9c..c3dc4ab0 100644 --- a/app/Models/UserModal.php +++ b/app/Models/UserModel.php @@ -2,14 +2,14 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; +use App\BaseApp\BaseModel; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; /** * 用户表 */ -class UserModal extends Model +class UserModel extends BaseModel { // protected $table = 'users'; @@ -22,7 +22,7 @@ class UserModal extends Model */ public function projects(): HasMany { - return $this->hasMany(ProjectModal::class, 'user_id', 'id'); + return $this->hasMany(ProjectModel::class, 'user_id', 'id'); } /** @@ -31,7 +31,7 @@ class UserModal extends Model */ public function projectsAuthor(): HasMany { - return $this->hasMany(ProjectModal::class, 'author_id', 'id'); + return $this->hasMany(ProjectModel::class, 'author_id', 'id'); } /** @@ -40,6 +40,6 @@ class UserModal extends Model */ public function roles(): HasOne { - return $this->hasOne(RoleModal::class, 'id', 'role_id'); + return $this->hasOne(RoleModel::class, 'id', 'role_id'); } } diff --git a/app/Service/LoginService.php b/app/Service/LoginService.php new file mode 100644 index 00000000..1dd674fb --- /dev/null +++ b/app/Service/LoginService.php @@ -0,0 +1,107 @@ +first(); + if (empty($userModel)) { + return $this->register($account, $password); + } + + if (!password_verify($password, $userModel->password)) { + UtilsService::getInstance()->errorThrow('用户或密码错误!'); + } + + if ($userModel->ip !== get_ip()) { + $ipTable = json_decode($userModel->ip_table, true); + if (!in_array(get_ip(), $ipTable)) { + $ipTable[] = get_ip(); + } + $update = UserModel::where('id', $userModel->id)->update([ + 'ip' => get_ip(), + 'ip_table' => json_encode($ipTable), + 'updated_at' => get_time() + ]); + + if (!$update) { + UtilsService::getInstance()->errorThrow('更新失败!'); + } + + $userModel = UserModel::where('id', $userModel->id)->first(); + } + $result = [ + 'id' => $userModel->id, + 'account' => $userModel->account, + 'nick_name' => $userModel->nick_name, + 'avatar' => $userModel->avatar, + 'ip' => $userModel->ip, + 'ip_table' => $userModel->ip_table, + ]; + $token = JWTService::getInstance()->generateToken($result); + $result['token'] = $token; + return $result; + } + + public function register($account, $password) + { + $userModel = UserModel::where('account', $account)->first(); + if ($userModel) { + UtilsService::getInstance()->errorThrow('账号已被占用!'); + } + + $createModel = UserModel::create([ + 'account' => $account, + 'password' => password_hash($password, PASSWORD_DEFAULT), + 'nick_name' => '新用户'. Str::random(), + 'avatar' => 'https://pic.rmb.bdstatic.com/bjh/80852bfe7c321988191838517ba64e309354.jpeg@h_1280', + 'ip' => get_ip(), + 'ip_table' => json_encode([get_ip()]), + 'created_at' => get_time() + ]); + + if (!$createModel) { + UtilsService::getInstance()->errorThrow('注册失败!'); + } + + $result = [ + 'id' => $createModel->id, + 'account' => $createModel->account, + 'nick_name' => $createModel->nick_name, + 'avatar' => $createModel->avatar, + 'ip' => $createModel->ip, + 'ip_table' => $createModel->ip_table, + ]; + $token = JWTService::getInstance()->generateToken($result); + $result['token'] = $token; + + return $result; + } +} diff --git a/app/Service/UserService.php b/app/Service/UserService.php new file mode 100644 index 00000000..a4475ae8 --- /dev/null +++ b/app/Service/UserService.php @@ -0,0 +1,10 @@ +bearerToken(); + if (empty($token)) return UtilsService::getInstance()->notAuth('请先登录'); + $this->token = $token; + return $this; + } + + /** + * 生成 JWT Token + * @param array $data 要嵌入到 token 中的数据 + * @return string + */ + public function generateToken(array $data): string + { + $issuedAt = time(); + $expirationTime = $issuedAt + config('xk.redis.jwt_ttl'); + + $payload = [ + 'iat' => $issuedAt, + 'exp' => $expirationTime, + 'data' => $data + ]; + + return JWT::encode($payload, $this->secretKey, 'HS256'); + } + + /** + * 解析 JWT Token + * @return object|null 返回解码后的 payload 或者 null 如果验证失败 + * @throws Exception + */ + public function parseToken(): ?object + { + try { + if (empty($this->token)) return UtilsService::getInstance()->notAuth('请先登录'); + return JWT::decode($this->token, new Key($this->secretKey, 'HS256')); + } catch (Exception $e) { + return UtilsService::getInstance()->notAuth('【1】Token解析失败!请重新登录:'. $e->getMessage()); + } + } + + + /** + * 解析 JWT Token + * @return array|null 返回解码后的 payload 或者 null 如果验证失败 + * @throws Exception + */ + public function getUserInfo(): ?array + { + try { + $jwt = $this->parseToken(); + $user = RedisService::getInstance()->init(config('xk.redis.jwt'))->get($jwt->data->id); + if (empty($user)) return UtilsService::getInstance()->notAuth('登录状态过期'); + return json_decode($user, true); + } catch (Exception $e) { + return UtilsService::getInstance()->notAuth('【2】Token解析失败!请重新登录:'. $e->getMessage()); + } + } + + /** + * 续签 JWT Token + * @return string|null 新的 JWT 字符串或者 null 如果原 token 已过期或无效 + * @throws Exception + */ + public function refreshToken(): ?string + { + $decoded = $this->parseToken(); + if ($decoded === null || !property_exists($decoded, 'data')) { + return null; + } + + return $this->generateToken((array)$decoded->data); + } +} + + + diff --git a/app/Service/common/RedisService.php b/app/Service/common/RedisService.php new file mode 100755 index 00000000..29fa0fa6 --- /dev/null +++ b/app/Service/common/RedisService.php @@ -0,0 +1,94 @@ +redis = Redis::class; + $this->prefix = $prefix; + return $this; + } + + /** + * 设置缓存 + * @param $key + * @param $value + * @param int $expire + * @return true + */ + public function set($key, $value, int $expire = 0): true + { + $this->redis::set($this->prefix . $key, $value); + if ($expire > 0) { + $this->redis::expire($this->prefix . $key, $expire); + } + return true; + } + + /** + * 累加 + * @param $key + * @param int $value + * @param int $expire + * @return true + */ + public function incr($key, int $value = 1, int $expire = 0): true + { + $this->redis::incr($this->prefix . $key, $value); + if ($expire > 0) { + $this->redis::expire($this->prefix . $key, $expire); + } + return true; + } + + /** + * 获取缓存 + * + * @param $key + * @return mixed + */ + public function get($key): mixed + { + return $this->redis::get($this->prefix . $key); + } + + /** + * 删除缓存 + * @param $key + * @return bool + */ + public function del($key): bool + { + return $this->redis::del($this->prefix . $key); + } +} diff --git a/app/Service/UtilsService.php b/app/Service/common/UtilsService.php similarity index 98% rename from app/Service/UtilsService.php rename to app/Service/common/UtilsService.php index 643da8e2..167dbc2f 100755 --- a/app/Service/UtilsService.php +++ b/app/Service/common/UtilsService.php @@ -1,11 +1,11 @@ withRouting( @@ -15,5 +20,58 @@ return Application::configure(basePath: dirname(__DIR__)) // }) ->withExceptions(function (Exceptions $exceptions) { - // + $exceptions->render(function (Throwable $e) { + // 判断异常是否为Exception类型 + if ($e instanceof \Exception) { +// \App\Models\new\log\ErrorLogModel::create([ +// 'type' => 0, +// 'content' => json_encode([ +// 'message' => $e->getMessage(), +// 'line' => $e->getLine(), +// 'file' => $e->getFile(), +// 'trace' => $e->getTraceAsString(), +// ]), +// 'created_at' => time() +// ]); + // 使用switch语句判断异常类型 + switch (true) { // 注意这里使用了 'true' 因为 PHP 不允许在 case 中使用表达式 + // 如果异常是NotFoundHttpException类型 + case $e instanceof NotFoundHttpException: + // 返回一个自定义的JSON响应,状态码为404,错误信息为"路由未找到" + return jInstanceof(ErrorEnum::NOT_FOUND, '路由未找到', $e->getMessage()); + + // 如果异常是MethodNotAllowedHttpException类型 + case $e instanceof MethodNotAllowedHttpException: + Log::error($e->getMessage()); + // 返回一个自定义的JSON响应,状态码为405,错误信息为"请求方式错误" + return jInstanceof(405, '请求方式错误', $e->getMessage()); + + // 如果异常是UnprocessableEntityHttpException类型 + case $e instanceof UnprocessableEntityHttpException: + Log::warning($e->getMessage()); + // 返回一个自定义的JSON响应,状态码为422,错误信息为"服务器处理不过来啦" + return jInstanceof(422, '服务器处理不过来啦', $e->getMessage()); + + // 如果异常是HttpException类型 + case $e instanceof HttpException: + Log::error($e->getMessage()); + // 返回一个自定义的JSON响应,状态码为异常的状态码,错误信息为"服务器出错啦" + return jInstanceof($e->getCode(), ErrorEnum::FAIL->description(), 'ERROR:'. $e->getMessage()); + + // 对于所有其他类型的异常,默认返回500内部服务器错误 + default: + Log::critical($e->getMessage()); // 记录更严重的日志级别 + // 返回一个自定义的JSON响应,状态码为500,错误信息为"内部服务器错误" + return jInstanceof($e->getCode(), $e->getMessage(), $e->getCode()); + } + } + + return jInstanceof(ErrorEnum::FAIL, '服务器出错啦~', [ + 'message' => $e->getMessage(), + 'code' => $e->getCode(), + 'file' => $e->getFile(), + 'line' => $e->getLine(), + 'trace' => $e->getTrace(), + ]); + }); })->create(); diff --git a/composer.json b/composer.json index dfe9c82c..f3e69356 100644 --- a/composer.json +++ b/composer.json @@ -7,8 +7,10 @@ "license": "MIT", "require": { "php": "^8.2", + "firebase/php-jwt": "^6.11", "laravel/framework": "^12.0", - "laravel/tinker": "^2.10.1" + "laravel/tinker": "^2.10.1", + "ext-http": "*" }, "require-dev": { "fakerphp/faker": "^1.23", diff --git a/composer.lock b/composer.lock index 5c50b484..bcd60700 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "88970a0117c062eed55fa8728fc43833", + "content-hash": "bb43516eae1e73202940191fe341f64a", "packages": [ { "name": "brick/math", @@ -510,6 +510,69 @@ ], "time": "2025-03-06T22:45:56+00:00" }, + { + "name": "firebase/php-jwt", + "version": "v6.11.1", + "source": { + "type": "git", + "url": "https://github.com/firebase/php-jwt.git", + "reference": "d1e91ecf8c598d073d0995afa8cd5c75c6e19e66" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/firebase/php-jwt/zipball/d1e91ecf8c598d073d0995afa8cd5c75c6e19e66", + "reference": "d1e91ecf8c598d073d0995afa8cd5c75c6e19e66", + "shasum": "" + }, + "require": { + "php": "^8.0" + }, + "require-dev": { + "guzzlehttp/guzzle": "^7.4", + "phpspec/prophecy-phpunit": "^2.0", + "phpunit/phpunit": "^9.5", + "psr/cache": "^2.0||^3.0", + "psr/http-client": "^1.0", + "psr/http-factory": "^1.0" + }, + "suggest": { + "ext-sodium": "Support EdDSA (Ed25519) signatures", + "paragonie/sodium_compat": "Support EdDSA (Ed25519) signatures when libsodium is not present" + }, + "type": "library", + "autoload": { + "psr-4": { + "Firebase\\JWT\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Neuman Vong", + "email": "neuman+pear@twilio.com", + "role": "Developer" + }, + { + "name": "Anant Narayanan", + "email": "anant@php.net", + "role": "Developer" + } + ], + "description": "A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.", + "homepage": "https://github.com/firebase/php-jwt", + "keywords": [ + "jwt", + "php" + ], + "support": { + "issues": "https://github.com/firebase/php-jwt/issues", + "source": "https://github.com/firebase/php-jwt/tree/v6.11.1" + }, + "time": "2025-04-09T20:32:01+00:00" + }, { "name": "fruitcake/php-cors", "version": "v1.3.0", diff --git a/routes/api.php b/routes/api.php index e5301a0f..a40a8e10 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,6 +1,6 @@ autoRouteRegister([ + '' => \App\Http\Controllers\LoginController::class, // 登录控制器 ]); diff --git a/routes/web.php b/routes/web.php index 604a43cd..96708a99 100644 --- a/routes/web.php +++ b/routes/web.php @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Route; Route::get('/', function () { - $framework = \App\Models\ProjectModal::with([ + $framework = \App\Models\ProjectModel::with([ 'frameworks', 'labels', 'technologyStacks',