From 2fedee1e932c0aea8a78d81f8a7386ee11fb57ec Mon Sep 17 00:00:00 2001 From: Hanada Date: Tue, 8 Jul 2025 23:12:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BD=BF=E7=94=A8guzzle?= =?UTF-8?q?=E5=BA=93=E5=90=8E=E9=83=A8=E7=BD=B2=E8=AF=81=E4=B9=A6=E5=88=B0?= =?UTF-8?q?=E7=BE=A4=E6=99=96=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common.php | 30 ++++++++++++++++++------------ app/lib/deploy/synology.php | 35 +++++++++++++++++++++++------------ 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/app/common.php b/app/common.php index 06befa5..f573bae 100644 --- a/app/common.php +++ b/app/common.php @@ -450,19 +450,25 @@ function http_request($url, $data = null, $referer = null, $cookie = null, $head } } } else if (is_array($data) || is_object($data)) { - if (!isset($options['headers']['Content-Type'])) { - // 默认为表单 - $options['headers']['Content-Type'] = 'application/x-www-form-urlencoded'; - } - if ($options['headers']['Content-Type'] == 'application/x-www-form-urlencoded') { - // 表单 - $options['form_params'] = $data; - } else if ($options['headers']['Content-Type'] == 'application/json') { - // json - $options['json'] = $data; + if ($options['headers']['X-Content-Type'] == 'multipart/form-data') { + // 表单文件 + unset($options['headers']['X-Content-Type']) + $options['multipart'] = $data; } else { - // 其他 - $options['body'] = http_build_query($data); + if (!isset($options['headers']['Content-Type'])) { + // 默认为表单 + $options['headers']['Content-Type'] = 'application/x-www-form-urlencoded'; + } + if ($options['headers']['Content-Type'] == 'application/x-www-form-urlencoded') { + // 表单 + $options['form_params'] = $data; + } else if ($options['headers']['Content-Type'] == 'application/json') { + // json + $options['json'] = $data; + } else { + // 其他 + $options['body'] = http_build_query($data); + } } } else { $options['body'] = $data; diff --git a/app/lib/deploy/synology.php b/app/lib/deploy/synology.php index 2d2ee63..f9b3f5c 100644 --- a/app/lib/deploy/synology.php +++ b/app/lib/deploy/synology.php @@ -109,19 +109,30 @@ class synology implements DeployInterface '_sid' => $this->token['sid'], 'SynoToken' => $this->token['synotoken'], ]; - $privatekey_file = tempnam(sys_get_temp_dir(), 'privatekey'); - file_put_contents($privatekey_file, $privatekey); - $fullchain_file = tempnam(sys_get_temp_dir(), 'fullchain'); - file_put_contents($fullchain_file, $fullchain); - $post = [ - 'key' => new \CURLFile($privatekey_file), - 'cert' => new \CURLFile($fullchain_file), - 'id' => $id, - 'desc' => $config['desc'], + $headers = [ + 'X-Content-Type' => 'multipart/form-data' ]; - $response = http_request($url . '?' . http_build_query($params), $post, null, null, null, $this->proxy, null, 15); - unlink($privatekey_file); - unlink($fullchain_file); + $post = [ + [ + 'name' => 'key', + 'filename' => 'key.pem', + 'contents' => $privatekey + ], + [ + 'name' => 'cert', + 'filename' => 'cert.pem', + 'contents' => $fullchain + ], + [ + 'name' => 'id', + 'contents' => $id + ], + [ + 'name' => 'desc', + 'contents' => $config['desc'] + ] + ]; + $response = http_request($url . '?' . http_build_query($params), $post, null, null, $headers, $this->proxy, null, 15); $result = json_decode($response['body'], true); if ($id) { if (isset($result['success']) && $result['success']) {