From fa47ffb0808968b53b8a2e932904a420fdddb207 Mon Sep 17 00:00:00 2001 From: Hanada Date: Sun, 11 May 2025 23:16:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DAWS=E9=83=A8=E7=BD=B2?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/lib/client/AWS.php | 21 ++++++++++++++++++--- app/lib/deploy/aws.php | 7 +++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/lib/client/AWS.php b/app/lib/client/AWS.php index e0bfe63..36b841d 100644 --- a/app/lib/client/AWS.php +++ b/app/lib/client/AWS.php @@ -328,16 +328,31 @@ class AWS return json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA), JSON_UNESCAPED_UNICODE), true); } - private function array2xml($array, $xml = null) + private function array2xml($array, $xml = null, $parentTagName = 'root') { if ($xml === null) { $xml = new \SimpleXMLElement(''); } foreach ($array as $key => $value) { + // 确定当前标签名:如果是数字键名,使用父级标签名,否则使用当前键名 + $tagName = is_numeric($key) ? $parentTagName : $key; + if (is_array($value)) { - $subNode = $xml->addChild($key); - $this->array2xml($value, $subNode); + // 检查数组的第一个子节点的键是否为0 + $firstKey = array_key_first($value); + $isFirstKeyZero = ($firstKey === 0 || $firstKey === '0'); + + if ($isFirstKeyZero) { + // 如果第一个子节点的键是0,则不生成当前节点标签,直接递归子节点 + $this->array2xml($value, $xml, $tagName); + + } else { + // 否则生成当前节点标签,并递归子节点 + $subNode = $xml->addChild($tagName); + $this->array2xml($value, $subNode, $tagName); + } + } else { $xml->addChild($key, $value); } diff --git a/app/lib/deploy/aws.php b/app/lib/deploy/aws.php index 74773ff..9aa40c4 100644 --- a/app/lib/deploy/aws.php +++ b/app/lib/deploy/aws.php @@ -54,8 +54,11 @@ class aws implements DeployInterface } $data['ViewerCertificate']['ACMCertificateArn'] = $cert_id; - $data['ViewerCertificate']['CloudFrontDefaultCertificate'] = false; - $xml = new \SimpleXMLElement(''); + $data['ViewerCertificate']['CloudFrontDefaultCertificate'] = 'false'; + unset($data['ViewerCertificate']['Certificate']); + unset($data['ViewerCertificate']['CertificateSource']); + + $xml = new \SimpleXMLElement(''); $client->requestXmlN('PUT', '/distribution/' . $config['distribution_id'] . '/config', $data, $xml); $this->log('分配ID: ' . $config['distribution_id'] . ' 证书部署成功!'); }