|
|
6 ay önce | |
|---|---|---|
| .. | ||
| AdminControllers | 7 ay önce | |
| Commands | 7 ay önce | |
| Config | 7 ay önce | |
| Contracts | 7 ay önce | |
| Controllers | 6 ay önce | |
| Databases | 7 ay önce | |
| Docs | 7 ay önce | |
| Enums | 6 ay önce | |
| Events | 7 ay önce | |
| Handlers | 6 ay önce | |
| Listeners | 7 ay önce | |
| Middleware | 7 ay önce | |
| Models | 7 ay önce | |
| Providers | 7 ay önce | |
| Repositorys | 7 ay önce | |
| Routes | 6 ay önce | |
| Services | 7 ay önce | |
| Tests | 7 ay önce | |
| Validations | 7 ay önce | |
| Validators | 7 ay önce | |
| README.md | 7 ay önce | |
OpenAPI模块提供了完整的API管理平台,支持应用管理、多种认证方式、权限控制、频率限制、Webhook回调、统计分析等功能。
确保模块已在 config/app.php 中注册:
'providers' => [
// ...
App\Module\OpenAPI\Providers\OpenAPIServiceProvider::class,
],
运行SQL文件创建相关表:
# 执行数据库SQL文件
mysql -u username -p database_name < app/Module/OpenAPI/Databases/GenerateSql/openapi_tables.sql
在 .env 文件中添加配置:
# OpenAPI基础配置
OPENAPI_LOGGING_ENABLED=true
OPENAPI_STATS_ENABLED=true
# 频率限制配置
OPENAPI_RATE_LIMIT_PER_MINUTE=60
OPENAPI_RATE_LIMIT_PER_HOUR=1000
OPENAPI_RATE_LIMIT_PER_DAY=10000
# Webhook配置
OPENAPI_WEBHOOK_TIMEOUT=30
OPENAPI_WEBHOOK_RETRY_COUNT=3
# 缓存配置
OPENAPI_CACHE_DRIVER=redis
OPENAPI_CACHE_TTL=3600
php artisan vendor:publish --provider="App\Module\OpenAPI\Providers\OpenAPIServiceProvider"
Controller结尾Service结尾Middleware结尾OpenApi开头use App\Module\OpenAPI\Services\OpenApiService;
$apiService = new OpenApiService();
$app = $apiService->createApp([
'name' => '第三方应用',
'description' => '应用描述',
'callback_url' => 'https://example.com/callback',
'scopes' => ['FUND_READ', 'FUND_RECHARGE', 'FUND_WITHDRAW']
]);
// POST /api/openapi/diamond/recharge
$response = $client->post('/api/openapi/diamond/recharge', [
'user_id' => 12345,
'amount' => 100.5,
'order_id' => 'ORDER_20250614_001',
'remark' => '游戏内购买道具'
]);
// POST /api/openapi/diamond/withdraw
$response = $client->post('/api/openapi/diamond/withdraw', [
'user_id' => 12345,
'amount' => 50.25,
'order_id' => 'WITHDRAW_20250614_001',
'remark' => '用户提现'
]);
// GET /api/openapi/diamond/recharge-balance
$rechargeBalance = $client->get('/api/openapi/diamond/recharge-balance');
// GET /api/openapi/diamond/withdraw-balance
$withdrawBalance = $client->get('/api/openapi/diamond/withdraw-balance');