开通或配置安全云脑订阅 - CreateSubscriptionOrder
功能介绍
安全云脑开通与配置接口
调用方法
请参见如何调用API。
授权信息
账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限,具体权限要求请参见权限和授权项。
URI
POST /v1/{project_id}/subscriptions/orders
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| project_id | 是 | String | 参数解释: 项目ID,用于明确项目归属,配置后可通过该ID查询项目下资产,可以通过调用API获取,也可以从控制台获取。 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
请求参数
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| X-Auth-Token | 是 | String | 参数解释: 用户Token。 通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
| X-Language | 否 | String | 参数解释: 语言 约束限制: 不涉及 取值范围: 默认取值: 不涉及 |
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| scene | 是 | String | 参数解释: 场景描述,执行包年包月(PREPAID)、按需(POSTPAID)开通,或者配置资源(CONFIG)用量,缺省值:POSTPAID,大小写不敏感 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
| promotion_info | 否 | String | 参数解释: 促销折扣信息。 约束限制: String类型,JSON格式 取值范围: 不涉及 默认取值: 不涉及 |
| operate_type | 是 | String | 参数解释: 操作类型,比如创建场景为:CREATE、订单用量预警配置为:ALERT_CONFIG,大小写不敏感 约束限制: 不涉及 取值范围: CREATE、ALERT_CONFIG 默认取值: CREATE |
| tag_list | 否 | Array of SubscriptionTag objects | 参数解释: 计费标签 约束限制: 不涉及 取值范围: 标签个数范围:[0, 20] 默认取值: 不涉及 |
| product_list | 否 | Array of Product objects | 参数解释: 商品列表,当scene=PREPAID 或者 POSTPAID时,当前字段必填 约束限制: 商品列表最大支持20个 取值范围: 不涉及 默认取值: 不涉及 |
| config | 否 | OrderConfig object | 参数解释: 配置列表 约束限制: 当scene为CONFIG时必填 取值范围: 不涉及 默认取值: 不涉及 |
| period_type | 否 | Integer | 参数解释: 订阅周期类型,当scene=PREPAID时需要填写 约束限制: 当scene=PREPAID时需要填写 取值范围: 2:月,3:年; 默认取值: 2 |
| period_num | 否 | Integer | 参数解释: 订阅周期数,当scene=PREPAID时需要填写该值 取值大于0;小于等于0会报错。 当period_type=2时,其可选范围为[1, 9],当period_type=3,其可选范围为[1, 3] 约束限制: 当scene=PREPAID时需要填写 取值范围: [1, 9] 默认取值: 1 |
| is_auto_renew | 否 | Integer | 参数解释: 当scene=PREPAID时,当前字段必填,是否自动续订,为空时表示不自动续订; 约束限制: 当scene=PREPAID时需要填写 取值范围: 0:不自动续订(默认), 1:自动续订 默认取值: 0 |
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| 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个字符。 默认取值: 空 |
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| resource_type | 是 | String | 参数解释: 资源类型 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
| resource_spec_code | 是 | String | 参数解释: 资源规格编码 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
| resource_size | 是 | Integer | 参数解释: 订阅数量 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| threshold_list | 否 | Array of UsageThreshold objects | 参数解释: 阈值列表 约束限制: 不涉及 取值范围: 配置项个数最大为20 默认取值: 不涉及 |
| alert_config | 否 | AlertConfig object | 参数解释: 开启或关闭当前告警配置 约束限制: 不涉及 取值范围: 不涉及 默认取值: 空,即为关闭 |
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| resource_spec_code | 否 | String | 参数解释: 资源规格编码 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
| source_resource_spec_code | 否 | String | 参数解释: 源资源规格编码 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
| threshold | 是 | Double | 参数解释: 阈值 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
| unit | 是 | String | 参数解释: 阈值对应的单位 约束限制: 目前仅支持 OPS(操作次数)、MB、GB 取值范围: 默认取值: 不涉及 |
| enable | 否 | Boolean | 参数解释: 开启或关闭当前资源类型的告警设置 约束限制: 不涉及 取值范围: true,false 默认取值: false |
响应参数
状态码:200
| 参数 | 参数类型 | 描述 |
|---|---|---|
| order_id | String | 参数解释: 创建的订单ID 约束限制: 只有scene为PREPAID时返回有此数据 取值范围: 不涉及 默认取值: 不涉及 |
| order_status | Integer | 参数解释: 订单创建状态 约束限制: 不涉及 取值范围: 1:创建成功,5,创建失败 默认取值: 不涉及 |
状态码:400
| 参数 | 参数类型 | 描述 |
|---|---|---|
| error_code | String | 参数解释: 错误码 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
| error_msg | String | 参数解释: 错误描述 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
状态码:403
| 参数 | 参数类型 | 描述 |
|---|---|---|
| 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.OperateTypeEnum.fromValue("CREATE")); body.withScene(OrderInfoReq.SceneEnum.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.OperateTypeEnum.fromValue("CREATE")); body.withScene(OrderInfoReq.SceneEnum.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 | 权限不足 |
错误码
请参见错误码。