giftcon_dev/app/Providers/Danal/DanalConfig.php
2026-02-24 13:07:23 +09:00

67 lines
2.1 KiB
PHP

<?php
namespace App\Providers\Danal;
final class DanalConfig
{
public function card(string $kind): array
{
$cfg = config("danal.card.$kind");
if (!$cfg || !$cfg['cpid'] || !$cfg['key'] || !$cfg['iv'] || !$cfg['url']) {
throw new \RuntimeException("Danal card config missing: {$kind}");
}
return $cfg;
}
public function vact(): array
{
$cfg = config('danal.vact');
if (!$cfg || !$cfg['cpid'] || !$cfg['key'] || !$cfg['iv'] || !$cfg['url']) {
throw new \RuntimeException('Danal vact config missing');
}
return $cfg;
}
public function wiretransfer(): array
{
$cfg = config('danal.wiretransfer');
if (empty($cfg['cpid'])) throw new \RuntimeException('DANAL_AUTHVACT_CPID empty');
if (!is_string($cfg['key']) || !preg_match('/^[0-9a-fA-F]{64}$/', $cfg['key'])) {
throw new \RuntimeException('DANAL_AUTHVACT_KEY must be 64 hex chars');
}
if (!is_string($cfg['iv']) || !preg_match('/^[0-9a-fA-F]{32}$/', $cfg['iv'])) {
throw new \RuntimeException('DANAL_AUTHVACT_IV must be 32 hex chars');
}
return $cfg;
}
public function phone(string $mode): array
{
$base = config('danal.phone');
if (!$base || empty($base['bin_path']) || empty($base['item_code'])) {
throw new \RuntimeException('Danal phone base config missing (BIN_PATH/ITEMCODE)');
}
$m = $base[$mode] ?? null;
if (!$m || empty($m['cpid']) || empty($m['pwd'])) {
throw new \RuntimeException("Danal phone config missing: {$mode}");
}
return [
'bin_path' => $base['bin_path'],
'item_code' => $base['item_code'],
'start_url_web' => $base['start_url_web'],
'start_url_mobile' => $base['start_url_mobile'],
'cpid' => $m['cpid'],
'pwd' => $m['pwd'],
'iv' => $m['iv'] ?? '',
'mode' => $mode,
];
}
public function http(): array
{
return config('danal.http');
}
}