文档首页> 内容分发网络 CDN> API参考> API> 域名配置> 一个证书批量设置多个域名
更新时间:2024-07-05 GMT+08:00

一个证书批量设置多个域名

功能介绍

一个证书配置多个域名,设置域名强制https回源参数。

调用方法

请参见如何调用API

URI

PUT /v1.0/cdn/domains/config-https-info

表1 Query参数

参数

是否必选

参数类型

描述

enterprise_project_id

String

当用户开启企业项目功能时,该参数生效,表示修改当前企业项目下加速域名的配置,"all"代表所有项目。注意:当使用子账号调用接口时,该参数必传。

您可以通过调用企业项目管理服务(EPS)的查询企业项目列表接口(ListEnterpriseProject)查询企业项目id。

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token。

通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。

表3 请求Body参数

参数

是否必选

参数类型

描述

https

UpdateDomainMultiCertificatesRequestBodyContent object

https配置。

表4 UpdateDomainMultiCertificatesRequestBodyContent

参数

是否必选

参数类型

描述

domain_name

String

域名列表,逗号分割,上限50个域名

https_switch

Integer

https开关(0:"关闭";1:"设置证书" https_switch为1时,证书参数不能为空)

access_origin_way

Integer

回源方式:1:"回源跟随";2:"http"(默认),3:"https" 为空值时默认设置为http

force_redirect_https

Integer

强制跳转HTTPS(0:不强制;1:强制) 为空值时默认设置为关闭。(此参数即将下线,建议使用force_redirect_config修改配置)

force_redirect_config

ForceRedirect object

强制跳转。

http2

Integer

http2.0(0:关闭;1:开启) 为空值时默认设置为关闭

cert_name

String

证书名称(设置证书必填)(长度限制为3-64字符)。

certificate

String

HTTPS协议使用的SSL证书内容,仅支持PEM编码格式。不启用证书则无需输入。初次配置证书时必传。

private_key

String

HTTPS协议使用的SSL证书私钥内容,仅支持PEM编码格式。不启用证书则无需输入。初次配置证书时必传。

certificate_type

Integer

证书类型(0为自有证书 ;1为托管证书,此时不必不传入证书内容和私钥,自动根据证书名称匹配;不传默认为自有证书)

表5 ForceRedirect

参数

是否必选

参数类型

描述

switch

Integer

强制跳转开关。1打开。0关闭。

redirect_type

String

强制跳转类型。http:强制跳转HTTP。https:强制跳转HTTPS。

响应参数

状态码: 200

表6 响应Body参数

参数

参数类型

描述

https

UpdateDomainMultiCertificatesResponseBodyContent object

https配置。

表7 UpdateDomainMultiCertificatesResponseBodyContent

参数

参数类型

描述

domain_name

String

域名列表。

https_switch

Integer

https开关(0:"关闭";1:"设置证书")。

access_origin_way

Integer

回源方式:1:"回源跟随";2:"HTTP"(默认),3:https(自建)。

force_redirect_https

Integer

强制跳转HTTPS(0:不强制;1:强制) 。

force_redirect_config

ForceRedirect object

强制跳转。

http2

Integer

http2.0(0:关闭;1:开启)

cert_name

String

证书名称。

certificate

String

证书内容。

certificate_type

Integer

证书类型(0为自有证书 , 1为托管证书)。

expiration_time

Long

证书过期时间。

表8 ForceRedirect

参数

参数类型

描述

switch

Integer

强制跳转开关。1打开。0关闭。

redirect_type

String

强制跳转类型。http:强制跳转HTTP。https:强制跳转HTTPS。

请求示例

{
  "https" : {
    "domain_name" : "example1.com",
    "access_origin_way" : 2,
    "http2" : 0,
    "certificate_type" : 0,
    "force_redirect_config" : {
      "redirect_type" : "https",
      "switch" : 1
    },
    "https_switch" : 1,
    "cert_name" : "cdn_test_cert",
    "certificate" : "-----BEGIN CERTIFICATE----------END CERTIFICATE-----",
    "private_key" : "-----BEGIN RSA PRIVATE KEY---------END RSA PRIVATE KEY-----"
  }
}

响应示例

状态码: 200

OK

{
  "https" : {
    "domain_name" : "example1.com",
    "https_switch" : 1,
    "access_origin_way" : 2,
    "force_redirect_https" : 1,
    "force_redirect_config" : {
      "redirect_type" : "https",
      "switch" : 1
    },
    "http2" : 0,
    "expiration_time" : 1925791912000,
    "cert_name" : "cdn_test_cert",
    "certificate" : "-----BEGIN CERTIFICATE----------END CERTIFICATE-----",
    "certificate_type" : 0
  }
}

SDK代码示例

SDK代码示例如下。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.GlobalCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.cdn.v2.region.CdnRegion;
import com.huaweicloud.sdk.cdn.v2.*;
import com.huaweicloud.sdk.cdn.v2.model.*;


public class UpdateDomainMultiCertificatesSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");

        ICredential auth = new GlobalCredentials()
                .withAk(ak)
                .withSk(sk);

        CdnClient client = CdnClient.newBuilder()
                .withCredential(auth)
                .withRegion(CdnRegion.valueOf("<YOUR REGION>"))
                .build();
        UpdateDomainMultiCertificatesRequest request = new UpdateDomainMultiCertificatesRequest();
        request.withEnterpriseProjectId("<enterprise_project_id>");
        UpdateDomainMultiCertificatesRequestBody body = new UpdateDomainMultiCertificatesRequestBody();
        ForceRedirect forceRedirectConfigHttps = new ForceRedirect();
        forceRedirectConfigHttps.withSwitch(1)
            .withRedirectType("https");
        UpdateDomainMultiCertificatesRequestBodyContent httpsbody = new UpdateDomainMultiCertificatesRequestBodyContent();
        httpsbody.withDomainName("example1.com")
            .withHttpsSwitch(1)
            .withAccessOriginWay(2)
            .withForceRedirectConfig(forceRedirectConfigHttps)
            .withHttp2(0)
            .withCertName("cdn_test_cert")
            .withCertificate("-----BEGIN CERTIFICATE----------END CERTIFICATE-----")
            .withPrivateKey("-----BEGIN RSA PRIVATE KEY---------END RSA PRIVATE KEY-----")
            .withCertificateType(0);
        body.withHttps(httpsbody);
        request.withBody(body);
        try {
            UpdateDomainMultiCertificatesResponse response = client.updateDomainMultiCertificates(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import GlobalCredentials
from huaweicloudsdkcdn.v2.region.cdn_region import CdnRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcdn.v2 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]

    credentials = GlobalCredentials(ak, sk)

    client = CdnClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(CdnRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = UpdateDomainMultiCertificatesRequest()
        request.enterprise_project_id = "<enterprise_project_id>"
        forceRedirectConfigHttps = ForceRedirect(
            switch=1,
            redirect_type="https"
        )
        httpsbody = UpdateDomainMultiCertificatesRequestBodyContent(
            domain_name="example1.com",
            https_switch=1,
            access_origin_way=2,
            force_redirect_config=forceRedirectConfigHttps,
            http2=0,
            cert_name="cdn_test_cert",
            certificate="-----BEGIN CERTIFICATE----------END CERTIFICATE-----",
            private_key="-----BEGIN RSA PRIVATE KEY---------END RSA PRIVATE KEY-----",
            certificate_type=0
        )
        request.body = UpdateDomainMultiCertificatesRequestBody(
            https=httpsbody
        )
        response = client.update_domain_multi_certificates(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global"
    cdn "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")

    auth := global.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := cdn.NewCdnClient(
        cdn.CdnClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.UpdateDomainMultiCertificatesRequest{}
	enterpriseProjectIdRequest:= "<enterprise_project_id>"
	request.EnterpriseProjectId = &enterpriseProjectIdRequest
	redirectTypeForceRedirectConfig:= "https"
	forceRedirectConfigHttps := &model.ForceRedirect{
		Switch: int32(1),
		RedirectType: &redirectTypeForceRedirectConfig,
	}
	accessOriginWayHttps:= int32(2)
	http2Https:= int32(0)
	certNameHttps:= "cdn_test_cert"
	certificateHttps:= "-----BEGIN CERTIFICATE----------END CERTIFICATE-----"
	privateKeyHttps:= "-----BEGIN RSA PRIVATE KEY---------END RSA PRIVATE KEY-----"
	certificateTypeHttps:= int32(0)
	httpsbody := &model.UpdateDomainMultiCertificatesRequestBodyContent{
		DomainName: "example1.com",
		HttpsSwitch: int32(1),
		AccessOriginWay: &accessOriginWayHttps,
		ForceRedirectConfig: forceRedirectConfigHttps,
		Http2: &http2Https,
		CertName: &certNameHttps,
		Certificate: &certificateHttps,
		PrivateKey: &privateKeyHttps,
		CertificateType: &certificateTypeHttps,
	}
	request.Body = &model.UpdateDomainMultiCertificatesRequestBody{
		Https: httpsbody,
	}
	response, err := client.UpdateDomainMultiCertificates(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

OK

错误码

请参见错误码