文档首页/ 安全云脑 SecMaster/ API参考/ 安全云脑 API V1/ 计量计费管理/ 开通或配置安全云脑订阅 - CreateSubscriptionOrder
更新时间:2026-09-30 GMT+08:00
分享

开通或配置安全云脑订阅 - CreateSubscriptionOrder

功能介绍

安全云脑开通与配置接口

调用方法

请参见如何调用API。

授权信息

账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限,具体权限要求请参见权限和授权项。

URI

POST /v1/{project_id}/subscriptions/orders

表1 路径参数

参数

是否必选

参数类型

描述

project_id

是

String

参数解释:

项目ID,用于明确项目归属,配置后可通过该ID查询项目下资产,可以通过调用API获取,也可以从控制台获取。

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

是

String

参数解释:

用户Token。

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

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

X-Language

否

String

参数解释:

语言

约束限制:

不涉及

取值范围:

  • zh-cn:中文

  • en-us:英文

默认取值:

不涉及

表3 请求Body参数

参数

是否必选

参数类型

描述

scene

是

String

参数解释:

场景描述,执行包年包月(PREPAID)、按需(POSTPAID)开通,或者配置资源(CONFIG)用量,大小写不敏感

约束限制:

不涉及

取值范围:

PREPAID:包年包月开通,POSTPAID:按需开通,CONFIG:配置资源用量

默认取值:

POSTPAID

promotion_info

否

String

参数解释:

促销折扣信息,用于传递促销活动相关的折扣信息。

约束限制:

不涉及

取值范围:

String类型,JSON格式

默认取值:

不涉及

operate_type

是

String

参数解释:

订单接口操作类型,大小写不敏感

约束限制:

不涉及

取值范围:

如创建场景为:CREATE,订单用量预警配置为:ALERT_CONFIG,大小写不敏感

默认取值:

CREATE

tag_list

否

Array of SubscriptionTag objects

参数解释:

计费标签

约束限制:

标签个数范围:[0, 20]

product_list

否

Array of Product objects

参数解释:

商品列表

约束限制:

商品列表最大支持20个

当scene=PREPAID 或者 POSTPAID时,当前字段必填

config

否

OrderConfig object

参数解释:

配置列表

约束限制:

当scene为CONFIG时必填

period_type

否

Integer

参数解释:

订阅周期类型,包年或者包月

约束限制:

当scene=PREPAID时需要填写

取值范围:

2:月,3:年;

默认取值:

2

period_num

否

Integer

参数解释:

订阅周期数,当scene=PREPAID时需要填写该值

约束限制:

当scene=PREPAID时需要填写

取值范围:

[1, 9]

取值大于9小于等于0会报错。

当period_type=2时,其可选范围为[1, 9],当period_type=3,其可选范围为[1, 3]

默认取值:

1

is_auto_renew

否

Integer

参数解释:

当scene=PREPAID时,是否自动续订

约束限制:

当scene=PREPAID时需要填写

取值范围:

0:不自动续订, 1:自动续订

默认取值:

0,即不自动续订

表4 SubscriptionTag

参数

是否必选

参数类型

描述

key

否

String

参数解释:

标签键。

约束限制:

字符集:A-Z,a-z , 0-9,‘-’,‘_’,UNICODE字符(\u4E00-\u9FFF)

取值范围:

最小标签长度为1,最大长度128个字符。

默认取值:

不涉及

value

否

String

参数解释:

标签值。

约束限制:

字符集:A-Z,a-z , 0-9,‘-’,‘_’,UNICODE字符(\u4E00-\u9FFF)

取值范围:

最小标签长度为0,最大长度255个字符。

默认取值:

空

表5 Product

参数

是否必选

参数类型

描述

resource_type

是

String

参数解释:

用户购买安全云脑产品的资源类型,用于区分不同种类的安全云脑资源,清单列表参见云脑商品规格列表接口

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

resource_spec_code

是

String

参数解释:

用户购买安全云脑产品的资源规格编码,用于区分统一资源类型下的不同商品规格,清单列表参见云脑商品规格列表接口

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

resource_size

是

Integer

参数解释:

订阅资源的数量,单位为个

约束限制:

不涉及

取值范围:

[1, 10000]

默认取值:

不涉及

表6 OrderConfig

参数

是否必选

参数类型

描述

threshold_list

否

Array of UsageThreshold objects

参数解释:

阈值列表,每个元素为UsageThreshold对象,包含资源规格编码、源资源规格编码、阈值、单位和启用状态等信息

约束限制:

配置项个数最大为20

alert_config

否

AlertConfig object

参数解释:

开启或关闭当前告警配置,空,即为关闭

约束限制:

不涉及

表7 UsageThreshold

参数

是否必选

参数类型

描述

resource_spec_code

否

String

参数解释:

资源规格编码

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

source_resource_spec_code

否

String

参数解释:

源资源规格编码

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

threshold

是

Double

参数解释:

资源用量的告警阈值,当资源使用量达到该值时触发告警

约束限制:

不涉及

取值范围:

最小值为0

默认取值:

不涉及

unit

是

String

参数解释:

阈值对应的单位

约束限制:

不涉及

取值范围:

  • OPS:操作次数

  • MB:兆字节

  • GB:吉字节

默认取值:

不涉及

enable

否

Boolean

参数解释:

开启或关闭当前资源类型的告警设置

约束限制:

不涉及

取值范围:

true:开启告警配置,false:关闭告警配置

默认取值:

false

表8 AlertConfig

参数

是否必选

参数类型

描述

topic_urn

否

String

参数解释:

关联SMN消息主题的URN,用于接收告警通知

约束限制:

当type=smn时,可以填写当前参数

取值范围:

不涉及

默认取值:

不涉及

type

否

String

参数解释:

支持的订单告警类型,SMN为消息协议

约束限制:

当前仅支持SMN

取值范围:

SMN

默认取值:

SMN

enable

否

Boolean

参数解释:

开启或关闭当前告警配置

约束限制:

不涉及

取值范围:

true:开启告警配置,false:关闭告警配置

默认取值:

不涉及

响应参数

状态码:200

表9 响应Body参数

参数

参数类型

描述

order_id

String

参数解释:

创建的订单ID,只有scene为PREPAID时返回有此数据

取值范围:

不涉及

order_status

Integer

参数解释:

订单创建状态

取值范围:

1:创建成功,5:创建失败

状态码:400

表10 响应Body参数

参数

参数类型

描述

error_code

String

参数解释:

错误码

取值范围:

不涉及

error_msg

String

参数解释:

错误描述

取值范围:

不涉及

状态码:403

表11 响应Body参数

参数

参数类型

描述

error_code

String

参数解释:

错误码

取值范围:

不涉及

error_msg

String

参数解释:

错误描述

取值范围:

不涉及

请求示例

  • 开通包周期资源

    POST https://{endpoint}/v1/{projectId}/subscriptions/orders
    
    {
      "period_num" : 1,
      "period_type" : 2,
      "is_auto_renew" : 1,
      "scene" : "PREPAID",
      "operate_type" : "CREATE",
      "product_list" : [ {
        "resource_type" : "xxx.resource.type.secmaster.typical",
        "resource_spec_code" : "secmaster.professional",
        "resource_size" : 3
      } ],
      "tag_list" : [ {
        "key" : "testKey1",
        "value" : "testVal1"
      } ]
    }
  • 开通按需资源

    {
      "scene" : "POSTPAID",
      "operate_type" : "CREATE",
      "product_list" : [ {
        "resource_type" : "xxx.resource.type.secmaster.typical",
        "resource_spec_code" : "secmaster.basic",
        "resource_size" : 3
      } ],
      "tag_list" : [ {
        "key" : "testKey2",
        "value" : "testVal2"
      } ]
    }

响应示例

状态码:200

{
  "order_id" : "CS2510212051NLDL4",
  "order_status" : 1
}

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
    63
    64
    65
    66
    67
    68
    69
    70
    71
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    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.secmaster.v1.region.SecMasterRegion;
    import com.huaweicloud.sdk.secmaster.v1.*;
    import com.huaweicloud.sdk.secmaster.v1.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class CreateSubscriptionOrderSolution {
    
        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");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            SecMasterClient client = SecMasterClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(SecMasterRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateSubscriptionOrderRequest request = new CreateSubscriptionOrderRequest();
            OrderInfoReq body = new OrderInfoReq();
            List<Product> listbodyProductList = new ArrayList<>();
            listbodyProductList.add(
                new Product()
                    .withResourceType("xxx.resource.type.secmaster.typical")
                    .withResourceSpecCode("secmaster.professional")
                    .withResourceSize(3)
            );
            List<SubscriptionTag> listbodyTagList = new ArrayList<>();
            listbodyTagList.add(
                new SubscriptionTag()
                    .withKey("testKey1")
                    .withValue("testVal1")
            );
            body.withIsAutoRenew(OrderInfoReq.IsAutoRenewEnum.NUMBER_1);
            body.withPeriodNum(OrderInfoReq.PeriodNumEnum.NUMBER_1);
            body.withPeriodType(OrderInfoReq.PeriodTypeEnum.NUMBER_2);
            body.withProductList(listbodyProductList);
            body.withTagList(listbodyTagList);
            body.withOperateType(OrderInfoReq.OrderInfoReq.fromValue("CREATE"));
            body.withScene(OrderInfoReq.OrderInfoReq.fromValue("PREPAID"));
            request.withBody(body);
            try {
                CreateSubscriptionOrderResponse response = client.createSubscriptionOrder(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
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    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.secmaster.v1.region.SecMasterRegion;
    import com.huaweicloud.sdk.secmaster.v1.*;
    import com.huaweicloud.sdk.secmaster.v1.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class CreateSubscriptionOrderSolution {
    
        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");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            SecMasterClient client = SecMasterClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(SecMasterRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateSubscriptionOrderRequest request = new CreateSubscriptionOrderRequest();
            OrderInfoReq body = new OrderInfoReq();
            List<Product> listbodyProductList = new ArrayList<>();
            listbodyProductList.add(
                new Product()
                    .withResourceType("xxx.resource.type.secmaster.typical")
                    .withResourceSpecCode("secmaster.basic")
                    .withResourceSize(3)
            );
            List<SubscriptionTag> listbodyTagList = new ArrayList<>();
            listbodyTagList.add(
                new SubscriptionTag()
                    .withKey("testKey2")
                    .withValue("testVal2")
            );
            body.withProductList(listbodyProductList);
            body.withTagList(listbodyTagList);
            body.withOperateType(OrderInfoReq.OrderInfoReq.fromValue("CREATE"));
            body.withScene(OrderInfoReq.OrderInfoReq.fromValue("POSTPAID"));
            request.withBody(body);
            try {
                CreateSubscriptionOrderResponse response = client.createSubscriptionOrder(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
    50
    51
    52
    53
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdksecmaster.v1.region.secmaster_region import SecMasterRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdksecmaster.v1 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"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = SecMasterClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(SecMasterRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateSubscriptionOrderRequest()
            listProductListbody = [
                Product(
                    resource_type="xxx.resource.type.secmaster.typical",
                    resource_spec_code="secmaster.professional",
                    resource_size=3
                )
            ]
            listTagListbody = [
                SubscriptionTag(
                    key="testKey1",
                    value="testVal1"
                )
            ]
            request.body = OrderInfoReq(
                is_auto_renew=1,
                period_num=1,
                period_type=2,
                product_list=listProductListbody,
                tag_list=listTagListbody,
                operate_type="CREATE",
                scene="PREPAID"
            )
            response = client.create_subscription_order(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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdksecmaster.v1.region.secmaster_region import SecMasterRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdksecmaster.v1 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"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = SecMasterClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(SecMasterRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateSubscriptionOrderRequest()
            listProductListbody = [
                Product(
                    resource_type="xxx.resource.type.secmaster.typical",
                    resource_spec_code="secmaster.basic",
                    resource_size=3
                )
            ]
            listTagListbody = [
                SubscriptionTag(
                    key="testKey2",
                    value="testVal2"
                )
            ]
            request.body = OrderInfoReq(
                product_list=listProductListbody,
                tag_list=listTagListbody,
                operate_type="CREATE",
                scene="POSTPAID"
            )
            response = client.create_subscription_order(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
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        secmaster "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v1/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")
        projectId := "{project_id}"
    
        auth, err := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            SafeBuild()
    
        if err != nil {
            fmt.Println(err)
            return
        }
    
        hcClient, err := secmaster.SecMasterClientBuilder().
             WithRegion(region.ValueOf("<YOUR REGION>")).
             WithCredential(auth).
             SafeBuild()
    
    
        if err != nil {
            fmt.Println(err)
            return
        }
    
        client := secmaster.NewSecMasterClient(hcClient)
    
        request := &model.CreateSubscriptionOrderRequest{}
    	var listProductListbody = []model.Product{
            {
                ResourceType: "xxx.resource.type.secmaster.typical",
                ResourceSpecCode: "secmaster.professional",
                ResourceSize: int32(3),
            },
        }
    	keyTagList:= "testKey1"
    	valueTagList:= "testVal1"
    	var listTagListbody = []model.SubscriptionTag{
            {
                Key: &keyTagList,
                Value: &valueTagList,
            },
        }
    	isAutoRenewOrderInfoReq:= model.GetOrderInfoReqIsAutoRenewEnum().E_1
    	periodNumOrderInfoReq:= model.GetOrderInfoReqPeriodNumEnum().E_1
    	periodTypeOrderInfoReq:= model.GetOrderInfoReqPeriodTypeEnum().E_2
    	request.Body = &model.OrderInfoReq{
    		IsAutoRenew: &isAutoRenewOrderInfoReq,
    		PeriodNum: &periodNumOrderInfoReq,
    		PeriodType: &periodTypeOrderInfoReq,
    		ProductList: &listProductListbody,
    		TagList: &listTagListbody,
    		OperateType: model.GetOrderInfoReqOperateTypeEnum().CREATE,
    		Scene: model.GetOrderInfoReqSceneEnum().PREPAID,
    	}
    	response, err := client.CreateSubscriptionOrder(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 开通按需资源

     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
    63
    64
    65
    66
    67
    68
    69
    70
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        secmaster "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v1/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")
        projectId := "{project_id}"
    
        auth, err := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            SafeBuild()
    
        if err != nil {
            fmt.Println(err)
            return
        }
    
        hcClient, err := secmaster.SecMasterClientBuilder().
             WithRegion(region.ValueOf("<YOUR REGION>")).
             WithCredential(auth).
             SafeBuild()
    
    
        if err != nil {
            fmt.Println(err)
            return
        }
    
        client := secmaster.NewSecMasterClient(hcClient)
    
        request := &model.CreateSubscriptionOrderRequest{}
    	var listProductListbody = []model.Product{
            {
                ResourceType: "xxx.resource.type.secmaster.typical",
                ResourceSpecCode: "secmaster.basic",
                ResourceSize: int32(3),
            },
        }
    	keyTagList:= "testKey2"
    	valueTagList:= "testVal2"
    	var listTagListbody = []model.SubscriptionTag{
            {
                Key: &keyTagList,
                Value: &valueTagList,
            },
        }
    	request.Body = &model.OrderInfoReq{
    		ProductList: &listProductListbody,
    		TagList: &listTagListbody,
    		OperateType: model.GetOrderInfoReqOperateTypeEnum().CREATE,
    		Scene: model.GetOrderInfoReqSceneEnum().POSTPAID,
    	}
    	response, err := client.CreateSubscriptionOrder(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

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

状态码

状态码

描述

200

请求成功

400

请求参数异常

403

权限不足

错误码

请参见错误码。

相关文档