['alipay', 'private_key'], 'alipay_public_key.pem' => ['alipay', 'public_key'], 'wechat_mch_private_key.pem' => ['wechat', 'mch_private_key'], 'wechat_api_v3_key.pem' => ['wechat', 'api_v3_key'], 'wechat_platform_cert.pem' => ['wechat', 'platform_cert'], ]; foreach ($map as $file => [$section, $key]) { $path = $dir . '/' . $file; if (!is_file($path)) { continue; } $content = trim((string)file_get_contents($path)); if ($content === '') { continue; } if (!isset($config[$section]) || !is_array($config[$section])) { $config[$section] = []; } $config[$section][$key] = $content; } } }