safeLoad(); } catch (\Throwable $exception) { // The validation error below identifies the missing setting. } $raw = self::environmentKey(); } if ($raw === '') { throw new \RuntimeException('未配置环境变量 PAYTARO_CREDENTIAL_KEY'); } $decoded = base64_decode($raw, true); if ($decoded !== false && strlen($decoded) === SODIUM_CRYPTO_SECRETBOX_KEYBYTES) { return $decoded; } if (preg_match('/^[a-f0-9]{64}$/i', $raw)) { return hex2bin($raw); } throw new \RuntimeException('PAYTARO_CREDENTIAL_KEY 必须是 32 字节 Base64 或 64 位十六进制字符串'); } private static function environmentKey() { $raw = trim((string) getenv(self::ENV_KEY)); if ($raw === '' && isset($_ENV[self::ENV_KEY])) { $raw = trim((string) $_ENV[self::ENV_KEY]); } return $raw; } }