开通或配置安全云脑订阅 - CreateSubscriptionOrder
功能介绍
安全云脑开通与配置接口
调用方法
请参见如何调用API。
授权信息
账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限,具体权限要求请参见权限和授权项。
URI
POST /v1/{project_id}/subscriptions/orders
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
project_id |
是 |
String |
租户项目ID |
请求参数
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
X-Auth-Token |
是 |
String |
用户Token。 通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。 |
|
X-Language |
是 |
String |
用户当前语言环境 zh-cn or en-us. |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
scene |
是 |
String |
场景描述,执行包年包月(PREPAID)、按需(POSTPAID)开通,或者配置资源(CONFIG)用量,缺省值:PREPAID,大小写不敏感 |
|
promotion_info |
否 |
String |
促销折扣信息 String,JSON格式 |
|
operate_type |
是 |
String |
操作类型,比如创建场景为:CREATE、订单用量预警配置为:ALERT_CONFIG,大小写不敏感 |
|
tag_list |
否 |
Array of SubscriptionTag objects |
计费标签 |
|
product_list |
否 |
Array of Product objects |
当scene=PREPAID 或者 POSTPAID时,当前字段必填 商品列表 |
|
config |
否 |
OrderConfig object |
配置列表,当scene为CONFIG时必填 |
|
period_type |
否 |
Integer |
当scene=PREPAID时需要填写,订阅周期类型: 2:月; 3:年; |
|
period_num |
否 |
Integer |
订阅周期数,当scene=PREPAID时需要填写该值 取值大于0;小于等于0会报错。 当period_type=2时,其可选范围为[1, 9],当period_type=3,其可选范围为[1, 3] |
|
is_auto_renew |
否 |
Integer |
当scene=PREPAID时,当前字段必填,是否自动续订,为空时表示不自动续订; 1:自动续订 0:不自动续订(默认) |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
key |
否 |
String |
键。 最大长度36个字符。 字符集:A-Z,a-z , 0-9,‘-’,‘_’,UNICODE字符(\u4E00-\u9FFF) |
|
value |
否 |
String |
值。 最大长度43个字符,可以为空字符串。 字符集:A-Z,a-z , 0-9,‘.’,‘-’,‘_’,UNICODE字符(\u4E00-\u9FFF) |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
resource_type |
是 |
String |
资源类型 |
|
resource_spec_code |
是 |
String |
资源规格编码 |
|
resource_size |
是 |
Integer |
订阅数量 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
threshold_list |
否 |
Array of UsageThreshold objects |
阈值列表 |
|
alert_config |
否 |
AlertConfig object |
开启或关闭当前告警配置 |
响应参数
状态码: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
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 := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := secmaster.NewSecMasterClient( secmaster.SecMasterClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) 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
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 := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := secmaster.NewSecMasterClient( secmaster.SecMasterClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) 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 |
权限不足 |
错误码
请参见错误码。