Files
lotteryLaravel/app/Http/Controllers/Api/V1/E2E/E2ECaptchaPeekController.php
kang 6ec9634704
Some checks failed
lotterLaravel CI / test (push) Has been cancelled
feat: 添加E2E测试环境配置支持
添加LOTTERY_E2E环境变量来控制E2E测试相关功能,
包括绕过验证码、登录限制和钱包API URL验证,
同时更新composer.json以包含E2E专用的提供者和服务。
2026-06-18 14:42:22 +08:00

47 lines
1.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Http\Controllers\Api\V1\E2E;
use App\Services\AdminCaptchaService;
use App\Support\ApiResponse;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
/**
* E2E 辅助peek captcha bypass 码。
*
* digest 是 HMAC(app.key) 单向,存进 cache 的就是 digest无法反查明文。
* 改用 e2e 约定captcha_code == "LOTTERY_E2E_BYPASS" 在 LOTTERY_E2E=true 时视为通过。
* 本端点不返回任何"答案",仅返回约定码提示。
*/
final class E2ECaptchaPeekController extends \App\Http\Controllers\Controller
{
public function player(Request $request): JsonResponse
{
$key = (string) $request->input('captcha_key', '');
if ($key === '') {
return ApiResponse::error('captcha_key required', 'e2e_invalid_input', null, 422);
}
return $this->peek($key, AdminCaptchaService::SCOPE_PLAYER);
}
public function admin(Request $request): JsonResponse
{
$key = (string) $request->input('captcha_key', '');
if ($key === '') {
return ApiResponse::error('captcha_key required', 'e2e_invalid_input', null, 422);
}
return $this->peek($key, AdminCaptchaService::SCOPE_ADMIN);
}
private function peek(string $key, string $scope): JsonResponse
{
return ApiResponse::success([
'bypass_code' => 'LOTTERY_E2E_BYPASS',
'scope' => $scope,
'key' => $key,
'hint' => 'POST captcha_code=LOTTERY_E2E_BYPASS to login when LOTTERY_E2E=true',
]);
}
}