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']) {