feat: 增强管理员 API 鉴权,新增 token 有效天数配置,更新相关异常处理与错误码引用

This commit is contained in:
2026-05-09 11:26:39 +08:00
parent 8a70c029f6
commit f1b38ef421
13 changed files with 124 additions and 42 deletions

View File

@@ -70,7 +70,12 @@ final class LoginController
);
}
$plainToken = $admin->createToken('admin-api')->plainTextToken;
$ttlDays = (int) config('lottery.admin_api.token_ttl_days', 7);
$plainToken = $admin->createToken(
'admin-api',
['*'],
now()->addDays(max(1, $ttlDays)),
)->plainTextToken;
$admin->forceFill(['last_login_at' => now()])->save();

View File

@@ -3,6 +3,7 @@
namespace App\Http\Controllers\Api\V1\Wallet;
use App\Http\Controllers\Controller;
use App\Lottery\ErrorCode;
use App\Models\Player;
use App\Models\PlayerWallet;
use App\Support\ApiResponse;
@@ -58,7 +59,7 @@ class WalletBalanceController extends Controller
}
/**
* @return string|JsonResponse 合法币种码或错误响应(code 1003:参数非法
* @return string|JsonResponse 合法币种码或错误响应({@see ErrorCode::WalletInvalidCurrency}
*/
private function resolveCurrencyCode(Request $request, Player $player): string|JsonResponse
{
@@ -72,10 +73,9 @@ class WalletBalanceController extends Controller
// 币种码:字母数字,长度 116与 migrations 字段一致
if (! preg_match('/^[A-Z0-9]{1,16}$/', $code)) {
// 业务码占用 10001999 钱包段1003 已在 PRD 保留为「金额超出限制」,币种非法单用 1005
return ApiResponse::error(
__('wallet.invalid_currency'),
1005,
ErrorCode::WalletInvalidCurrency->value,
null,
400,
);