[ 'product' => 'https://s2.lakala.com', // 生产网关地址 'test' => 'https://test.wsmsd.cn/sit', ], ]; } /** * 获取V3配置 * @return Configuration */ public function getV3Config(): Configuration { return new Configuration($this->getCommonConfig()); } /** * 获取V2配置 * @return V2Configuration */ public function getV2Config(): V2Configuration { return new V2Configuration($this->getCommonConfig()); } private function getCommonConfig(): array { $signCert = $this->getConfig('sign_cert'); $verifyCert = $this->getConfig('verify_cert'); $gateway = $this->getConfig('gateway'); // 校验必要字段 if (!is_array($signCert) || !isset($signCert[0])) { throw new \InvalidArgumentException("sign_cert must be an array and contain at least one element."); } if (!is_array($verifyCert) || !isset($verifyCert[0])) { throw new \InvalidArgumentException("verify_cert must be an array and contain at least one element."); } if (!is_array($gateway) || !isset($gateway['test'], $gateway['product'])) { throw new \InvalidArgumentException("gateway config must contain both 'test' and 'product' keys."); } $environment = $this->getConfig('environment'); return [ 'app_id' => $this->getConfig('appid'), 'serial_no' => $this->getConfig('serial_no'), 'sm4_key' => null, 'merchant_private_key_path' => $this->buildPath($signCert[0]), 'lkl_certificate_path' => $this->buildPath($verifyCert[0]), 'app_debug' => $environment === 'test', 'host_test' => $gateway['test'], 'host_pro' => $gateway['product'], ]; } private function buildPath(string $relativePath): string { return rtrim(public_path(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($relativePath, DIRECTORY_SEPARATOR); } }