更新时间:2024-12-13 GMT+08:00
分享

安全云脑按需订购

功能介绍

开通安全云脑按需服务

调用方法

请参见如何调用API

URI

POST /v1/{project_id}/subscriptions/orders

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

租户项目ID

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token。

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

X-Language

String

用户当前语言环境 zh-cn or en-us.

表3 请求Body参数

参数

是否必选

参数类型

描述

region_id

String

区域ID,如cn-north-4

domain_id

String

domainId

tag_list

Array of TagInfo objects

计费标签

product_list

Array of ProductPostPaid objects

商品列表

operate_type

String

操作类型:create新购, addition增加配额

表4 TagInfo

参数

是否必选

参数类型

描述

key

String

标识

中文、字母、数字、_或者-,且长度范围[2, 36]

value

String

内容

中文、字母、数字、_或者-,且长度范围[2, 36]

表5 ProductPostPaid

参数

是否必选

参数类型

描述

id

String

ID标识,同一次询价中不能重复,用于标识返回询价结果和请求的映射关系

product_id

String

产品Id,通过向CBC询价获取该商品的标识

cloud_service_type

String

云服务类型,固定值为hws.service.type.sa

resource_type

String

用户购买云服务产品的资源类型,例如SecMaster中的典型场景配置,资源类型为hws.resource.type.secmaster.typical

resource_spec_code

String

用户购买云服务产品的资源规格,例如安全云脑中的的基础版,资源规格为secmaster.basic

usage_measure_id

Integer

使用量单位标识,按需询价必填,例如按小时询价,使用量值为1,使用量单位为小时,枚举值如下:

4:小时

10:GB(带宽按流量询价使用)

11:MB(带宽按流量询价使用)

usage_value

Number

使用量值,按需询价必填,例如按小时询价,使用量值为1,使用量单位为小时

resource_size

Integer

配额个数

usage_factor

String

使用量因子,按需计费必填,取值和话单中的使用量因子一致,云服务和使用量因子对应关系如下:

典型场景配置:Duration

态势管理:duration

安全编排:count

智能分析:flow

resource_id

String

资源id,仅在增加配额的时候传入

响应参数

请求示例

https://{endpoint}/v1/{projectId}/subscriptions/orders

{
  "domain_id" : "abcdef8a41164a2280ec65f1f4c4mlnyz",
  "region_id" : "cn-north-4",
  "product_list" : [ {
    "product_id" : "OFFI908269345109094402",
    "cloud_service_type" : "hws.service.type.sa",
    "id" : "E52E1A22-9408-459A-9F67-7B5C11B1E71A",
    "resource_spec_code" : "secmaster.professional",
    "resource_type" : "hws.resource.type.secmaster.typical",
    "usage_factor" : "duration",
    "usage_value" : 1,
    "usage_measure_id" : 4,
    "resource_size" : 1
  } ]
}

响应示例

状态码: 400

参数异常

{
  "error_msg" : "云脑已包含【标准版】,如有需要请升级版本或增加配额",
  "error_code" : "SecMaster.00010201"
}

SDK代码示例

SDK代码示例如下。

Java

 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
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.v2.region.SecMasterRegion;
import com.huaweicloud.sdk.secmaster.v2.*;
import com.huaweicloud.sdk.secmaster.v2.model.*;

import java.util.List;
import java.util.ArrayList;

public class CreatePostPaidOrderSolution {

    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();
        CreatePostPaidOrderRequest request = new CreatePostPaidOrderRequest();
        PostPaidParam body = new PostPaidParam();
        List<ProductPostPaid> listbodyProductList = new ArrayList<>();
        listbodyProductList.add(
            new ProductPostPaid()
                .withId("E52E1A22-9408-459A-9F67-7B5C11B1E71A")
                .withProductId("OFFI908269345109094402")
                .withCloudServiceType("hws.service.type.sa")
                .withResourceType("hws.resource.type.secmaster.typical")
                .withResourceSpecCode("secmaster.professional")
                .withUsageMeasureId(ProductPostPaid.UsageMeasureIdEnum.NUMBER_4)
                .withUsageValue(java.math.BigDecimal.valueOf(1))
                .withResourceSize(1)
                .withUsageFactor("duration")
        );
        body.withProductList(listbodyProductList);
        body.withDomainId("abcdef8a41164a2280ec65f1f4c4mlnyz");
        body.withRegionId("cn-north-4");
        request.withBody(body);
        try {
            CreatePostPaidOrderResponse response = client.createPostPaidOrder(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());
        }
    }
}

Python

 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 BasicCredentials
from huaweicloudsdksecmaster.v2.region.secmaster_region import SecMasterRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdksecmaster.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"]
    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 = CreatePostPaidOrderRequest()
        listProductListbody = [
            ProductPostPaid(
                id="E52E1A22-9408-459A-9F67-7B5C11B1E71A",
                product_id="OFFI908269345109094402",
                cloud_service_type="hws.service.type.sa",
                resource_type="hws.resource.type.secmaster.typical",
                resource_spec_code="secmaster.professional",
                usage_measure_id=4,
                usage_value=1,
                resource_size=1,
                usage_factor="duration"
            )
        ]
        request.body = PostPaidParam(
            product_list=listProductListbody,
            domain_id="abcdef8a41164a2280ec65f1f4c4mlnyz",
            region_id="cn-north-4"
        )
        response = client.create_post_paid_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)

Go

 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
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    secmaster "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v2"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v2/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/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")
    projectId := "{project_id}"

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        Build()

    client := secmaster.NewSecMasterClient(
        secmaster.SecMasterClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.CreatePostPaidOrderRequest{}
	var listProductListbody = []model.ProductPostPaid{
        {
            Id: "E52E1A22-9408-459A-9F67-7B5C11B1E71A",
            ProductId: "OFFI908269345109094402",
            CloudServiceType: "hws.service.type.sa",
            ResourceType: "hws.resource.type.secmaster.typical",
            ResourceSpecCode: "secmaster.professional",
            UsageMeasureId: model.GetProductPostPaidUsageMeasureIdEnum().E_4,
            UsageValue: float32(1),
            ResourceSize: int32(1),
            UsageFactor: "duration",
        },
    }
	request.Body = &model.PostPaidParam{
		ProductList: &listProductListbody,
		DomainId: "abcdef8a41164a2280ec65f1f4c4mlnyz",
		RegionId: "cn-north-4",
	}
	response, err := client.CreatePostPaidOrder(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多

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

状态码

状态码

描述

200

请求成功

400

参数异常

403

权限不足

错误码

请参见错误码

相关文档