feat: 增强管理员 API 鉴权,新增 token 有效天数配置,更新相关异常处理与错误码引用
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
// 币种码:字母数字,长度 1–16,与 migrations 字段一致
|
||||
if (! preg_match('/^[A-Z0-9]{1,16}$/', $code)) {
|
||||
// 业务码占用 1000–1999 钱包段;1003 已在 PRD 保留为「金额超出限制」,币种非法单用 1005
|
||||
return ApiResponse::error(
|
||||
__('wallet.invalid_currency'),
|
||||
1005,
|
||||
ErrorCode::WalletInvalidCurrency->value,
|
||||
null,
|
||||
400,
|
||||
);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Exceptions\PlayerAuthenticationException;
|
||||
use App\Lottery\ErrorCode;
|
||||
use App\Services\PlayerTokenResolver;
|
||||
use App\Support\ApiResponse;
|
||||
use App\Support\LotteryMessage;
|
||||
@@ -15,7 +16,7 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
*
|
||||
* - 成功:解析 Bearer → Player,写入 request attribute `lottery_player`。
|
||||
* - 失败:直接 JSON 返回,不进入控制器;其中 msg 经由 LotteryMessage::sso() 按请求语言翻译
|
||||
* (依赖前置的 NegotiateLotteryLocale),code 仍为文档约定业务码(如 8001)。
|
||||
* (依赖前置的 NegotiateLotteryLocale),code 为 {@see ErrorCode} 中玩家鉴权段。
|
||||
*
|
||||
* PlayerAuthenticationException 的 getMessage() 仅作开发与日志用语,可与 API msg 语种不一致。
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user