fix(core): harden settlement and wallet integration
This commit is contained in:
@@ -3,9 +3,9 @@
|
||||
namespace App\Services\Wallet;
|
||||
|
||||
use App\Models\Player;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Services\Integration\PartnerSiteConfig;
|
||||
use App\Support\Integration\WalletApiRequestGuard;
|
||||
use App\Services\Integration\PartnerSiteConfigResolver;
|
||||
use App\Support\Integration\WalletApiUrlSanitizer;
|
||||
|
||||
/**
|
||||
* 查询主站钱包余额(供玩家端余额接口填充 main_balance)。
|
||||
@@ -14,6 +14,7 @@ final class HttpMainSiteWalletBalanceClient
|
||||
{
|
||||
public function __construct(
|
||||
private readonly PartnerSiteConfigResolver $partnerSiteConfigResolver,
|
||||
private readonly WalletApiRequestGuard $walletApiRequestGuard,
|
||||
) {}
|
||||
|
||||
public function fetch(Player $player, string $currencyCode): ?int
|
||||
@@ -52,8 +53,11 @@ final class HttpMainSiteWalletBalanceClient
|
||||
);
|
||||
}
|
||||
|
||||
$base = WalletApiUrlSanitizer::normalizeAndValidate($config->walletApiUrl);
|
||||
if ($base === null) {
|
||||
$endpoint = $this->walletApiRequestGuard->guard(
|
||||
$config->walletApiUrl,
|
||||
$config->walletTimeoutSeconds,
|
||||
);
|
||||
if ($endpoint === null) {
|
||||
return new MainSiteWalletBalanceProbeResult(
|
||||
success: false,
|
||||
mainBalanceMinor: null,
|
||||
@@ -66,12 +70,11 @@ final class HttpMainSiteWalletBalanceClient
|
||||
}
|
||||
|
||||
$path = $config->walletBalancePath;
|
||||
$url = $base.'/'.ltrim($path, '/');
|
||||
$timeout = $config->walletTimeoutSeconds;
|
||||
$url = $endpoint->baseUrl.'/'.ltrim($path, '/');
|
||||
$apiKey = $config->walletApiKey;
|
||||
|
||||
if (app()->environment(['production'])
|
||||
&& $config->source === \App\Services\Integration\PartnerSiteConfig::SOURCE_LEGACY_ENV
|
||||
&& $config->source === PartnerSiteConfig::SOURCE_LEGACY_ENV
|
||||
&& (! is_string($apiKey) || trim($apiKey) === '')
|
||||
) {
|
||||
return new MainSiteWalletBalanceProbeResult(
|
||||
@@ -97,8 +100,7 @@ final class HttpMainSiteWalletBalanceClient
|
||||
];
|
||||
|
||||
try {
|
||||
$response = Http::withHeaders($headers)
|
||||
->timeout($timeout)
|
||||
$response = $endpoint->request($headers)
|
||||
->acceptJson()
|
||||
->get($url, $query);
|
||||
} catch (\Throwable $e) {
|
||||
|
||||
Reference in New Issue
Block a user