|
|
@@ -3,6 +3,7 @@
|
|
|
namespace SixShop\Lakala;
|
|
|
|
|
|
use SixShop\Lakala\Extension;
|
|
|
+use SixShop\Lakala\OpenAPISDK\V2\V2Configuration;
|
|
|
use SixShop\Lakala\OpenAPISDK\V3\Configuration;
|
|
|
use SixShop\System\Trait\ConfigTrait;
|
|
|
|
|
|
@@ -35,18 +36,55 @@ class Config
|
|
|
* 获取V3配置
|
|
|
* @return Configuration
|
|
|
*/
|
|
|
- public function getV3Config():Configuration
|
|
|
+ public function getV3Config(): Configuration
|
|
|
{
|
|
|
- return new 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' => public_path().$this->getConfig('sign_cert')[0],
|
|
|
- 'lkl_certificate_path' => public_path().$this->getConfig('verify_cert')[0],
|
|
|
- 'app_debug' => $this->getConfig('environment') === 'test',
|
|
|
- 'host_test' => $this->getConfig('gateway')['test'],
|
|
|
- 'host_pro' => $this->getConfig('gateway')['product'],
|
|
|
- ]);
|
|
|
+ '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);
|
|
|
}
|
|
|
}
|