编辑自定义证书¶
1. 接口描述¶
接口请求路径:POST /prod-api/acdn/ccdn/certificateRest/modifyCustomCertificate
modifyCustomCertificate 用于为指定主域名上传或编辑自定义 SSL 证书。不传 customCertificateId 时为新增上传,传入时为编辑已有证书。账号需具备 ccdn:domain:edit 权限。
Token 获取方式见 密钥鉴权。
注意:
zoneId必须为当前账号下的域名,取自 查询域名列表 返回的rows[].zoneId。- 编辑已有证书时,证书内容与私钥需完整重新提交。
2. 输入参数¶
以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数。
| 参数名称 | 必选 | 类型 | 描述 |
|---|---|---|---|
| zoneId | 是 | String | 域名 Zone ID。示例值:551290393816e70c5e9765ca020e30a4 |
| customCertificateId | 否 | String | 证书 ID。不传为新增上传,传入为编辑该证书,取自 查询自定义证书列表 返回的 data.result[].id |
| customCertificate | 是 | Object | 证书信息 |
| customCertificate.certificate | 是 | String | SSL 证书,PEM 格式内容,换行以 \n 表示 |
| customCertificate.private_key | 是 | String | 私钥,PEM 格式内容,换行以 \n 表示 |
| customCertificate.bundle_method | 是 | String | 捆绑方法。取值:ubiquitous 兼容(推荐)、optimal 现代、force 用户定义 |
| customCertificate.type | 是 | String | 旧客户端支持。取值:legacy_custom 新版(推荐)、sni_custom 旧版 |
3. 输出参数¶
data 为上游返回的证书对象。
| 参数名称 | 类型 | 描述 |
|---|---|---|
| code | Integer | 状态码。示例值:200 |
| msg | String | 提示信息。示例值:成功 |
| data | Object | 上游返回的证书对象 |
4. 示例¶
示例1 上传自定义证书¶
输入示例¶
{
"zoneId": "551290393816e70c5e9765ca020e30a4",
"customCertificate": {
"certificate": "-----BEGIN CERTIFICATE-----\nMIIFJDCCBAygAwIBAgIQD0ifmj/Yi5NP...\n-----END CERTIFICATE-----\n",
"private_key": "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAwQHoetcl9+5ikGzV...\n-----END RSA PRIVATE KEY-----\n",
"bundle_method": "ubiquitous",
"type": "legacy_custom"
}
}
代码调用¶
请将 {登录域名}、token 替换为实际值。
curl -X POST 'https://{登录域名}/prod-api/acdn/ccdn/certificateRest/modifyCustomCertificate' \
-H 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.xxxxxx' \
-H 'Content-Type: application/json' \
-d '{
"zoneId": "551290393816e70c5e9765ca020e30a4",
"customCertificate": {
"certificate": "-----BEGIN CERTIFICATE-----\nMIIFJDCCBAygAwIBAgIQD0ifmj/Yi5NP...\n-----END CERTIFICATE-----\n",
"private_key": "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAwQHoetcl9+5ikGzV...\n-----END RSA PRIVATE KEY-----\n",
"bundle_method": "ubiquitous",
"type": "legacy_custom"
}
}'
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class ModifyCustomCertificateTest {
public static void main(String[] args) throws Exception {
String url = "https://{登录域名}/prod-api/acdn/ccdn/certificateRest/modifyCustomCertificate";
String token = "eyJhbGciOiJIUzUxMiJ9.xxxxxx";
String requestBody = "{"
+ "\"zoneId\":\"551290393816e70c5e9765ca020e30a4\","
+ "\"customCertificate\":{"
+ "\"certificate\":\"-----BEGIN CERTIFICATE-----\\nMIIFJDCCBAygAwIBAgIQD0ifmj/Yi5NP...\\n-----END CERTIFICATE-----\\n\","
+ "\"private_key\":\"-----BEGIN RSA PRIVATE KEY-----\\nMIIEowIBAAKCAQEAwQHoetcl9+5ikGzV...\\n-----END RSA PRIVATE KEY-----\\n\","
+ "\"bundle_method\":\"ubiquitous\","
+ "\"type\":\"legacy_custom\""
+ "}"
+ "}";
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Authorization", "Bearer " + token);
httpPost.setEntity(new StringEntity(requestBody, ContentType.APPLICATION_JSON));
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
int statusCode = response.getStatusLine().getStatusCode();
String body = EntityUtils.toString(response.getEntity(), "UTF-8");
System.out.println("Status Code: " + statusCode);
System.out.println("Body: " + body);
}
}
}
}
package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
url := "https://{登录域名}/prod-api/acdn/ccdn/certificateRest/modifyCustomCertificate"
token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"
requestBody := []byte(`{
"zoneId": "551290393816e70c5e9765ca020e30a4",
"customCertificate": {
"certificate": "-----BEGIN CERTIFICATE-----\nMIIFJDCCBAygAwIBAgIQD0ifmj/Yi5NP...\n-----END CERTIFICATE-----\n",
"private_key": "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAwQHoetcl9+5ikGzV...\n-----END RSA PRIVATE KEY-----\n",
"bundle_method": "ubiquitous",
"type": "legacy_custom"
}
}`)
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(requestBody))
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println("Body:", string(body))
}
输出示例¶
{
"msg": "成功",
"code": 200,
"data": {
"id": "8b0d6d0c72c14b21a7e39d4f5b1a2c3e",
"hosts": ["example.com", "*.example.com"],
"issuer": "Let's Encrypt",
"signature": "SHA256WithRSA",
"status": "pending",
"bundle_method": "ubiquitous",
"type": "legacy_custom",
"zone_id": "551290393816e70c5e9765ca020e30a4",
"uploaded_on": "2025-09-03T14:34:46.000000Z",
"modified_on": "2025-09-03T14:34:46.000000Z",
"expires_on": "2026-09-03T14:34:46.000000Z",
"priority": 0
}
}
5. 错误码¶
操作失败时,code 为 500,原因在 msg,没有 data。
| HTTP 状态码 / 业务提示 | 描述 |
|---|---|
| 200 | 成功 |
| 401 | 未鉴权或 Token 无效 |
| 403 | 无权限,需具备 ccdn:domain:edit |
| 无效的zoneId | zoneId 不存在或不属于当前账号 |