feat: 开放API授权相关

This commit is contained in:
2025-05-20 14:40:39 +08:00
parent a7b752636d
commit 1d723b31a5
16 changed files with 577 additions and 1 deletions

35
app/openapi/route/v1.php Normal file
View File

@@ -0,0 +1,35 @@
<?php
use think\facade\Route;
Route::group('v1', function() {
// 接口授权
Route::post('authorize', 'v1.Authorize/token');
// 接口授权后才能访问
Route::group(function(){
// 获取产品列表
Route::get('products', 'v1.Product/list');
Route::group('product', function() {
// 获取产品信息
Route::get(':id', 'v1.Product/detail');
// 获取产品分类
Route::get('categories', 'v1.Product/categories');
});
// 获取新闻动态
Route::get('news', 'v1.News/list');
Route::group('news', function() {
// 获取新闻详情
Route::get(':id', 'v1.News/detail');
});
})
->middleware(\app\openapi\middleware\Auth::class);
})
->middleware(\think\middleware\Throttle::class, [
'visit_rate' => '5/m',
'visit_fail_response' => function (\think\middleware\Throttle $throttle, \think\Request $request, int $wait_seconds) {
return \think\Response::create('您的操作过于频繁, 请在 ' . $wait_seconds . ' 秒后再试。')->code(429);
},
]);