| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace App\Module\OpenAPI\Validations;
- use App\Module\OpenAPI\Validators\AppExistenceValidator;
- use App\Module\OpenAPI\Validators\AppStatusValidator;
- use UCore\ValidationCore;
- /**
- * JWT令牌请求验证类
- */
- class JwtRequestValidation extends ValidationCore
- {
- /** @var \App\Module\OpenAPI\Models\OpenApiApp|null 应用对象,由 AppExistenceValidator 设置 */
- public ?\App\Module\OpenAPI\Models\OpenApiApp $app = null;
- /**
- * 验证规则
- */
- public function rules($rules = []): array
- {
- return [
- // 基础验证
- ['app_id', 'required'],
- ['app_secret', 'required'],
- ['user_id', 'integer', 'min' => 0],
- // 业务验证(按顺序执行)
- [
- 'app_id', new AppExistenceValidator($this, ['app_secret', 'app']),
- 'msg' => '应用不存在或密钥错误'
- ],
- [
- 'app_id', new AppStatusValidator($this, ['app']),
- 'msg' => '应用状态异常'
- ],
- ];
- }
- /**
- * 默认值
- */
- public function default(): array
- {
- return [
- 'user_id' => 0,
- ];
- }
- }
|