通过调用API购买公网权威解析实例

描述:通过 CreateInstance 进行公网权威解析实例创建。

调用接口名称:CreateInstance

接口参考文档实例创建服务

参数说明

名称

类型

是否必填

说明

描述

ProductCode

String

产品代码

产品code,取值:dns

ProductType

String

产品类型

商品code,取值:

  • alidns_pre:适用于中国站用户

  • dns_dns_public_intl:适用于国际站用户

SubscriptionType

String

付费类型

付费类型,取值:

  • Subscription:预付费,当前只支持预付费模式。

Period

Integer

预付费周期

当创建预付费实例时,必须设置,单位为月,按年付费产品请输入12的整数倍。举例:

  • 1:购买周期为1个月;

  • 6:购买周期为半年;

  • 12:购买周期为1年;

  • 36:购买周期为3年;

RenewalStatus

String

自动续费状态

  • AutoRenewal:自动续费。

  • ManualRenewal:手动续费(默认值)。

    重要

    为了避免实例到期释放而影响您的业务,建议您设置自动续费并保证账号余额充足。

RenewPeriod

Integer

自动续费周期, 单位为月。

当设置RenewalStatusAutoRenewal时,必须设置。举例:

  • 1:自动续费周期为1个月;

  • 6:自动续费周期为半年;

  • 12:自动续费周期为1年;

Parameter.1.Value

String

订购的实例类型

  • HostedPublicZone:权威托管域名

  • CachedPublicZone: 权威代理域名

Parameter.1.Code

String

实例类型

InstanceType

Parameter.2.Value

String

实例版本值

权威托管域名实例版本:

  • version_personal:个人版

  • version_enterprise_basic:企业标准版

  • version_enterprise_advanced:企业旗舰版

权威代理域名实例版本:

  • version_cached_basic:标准版

Parameter.2.Code

String

实例版本

Version

Parameter.3.Value

String

DNS安全防御版本

  • no:无防御

  • basic:DNS攻击基础防御

  • advanced:DNS攻击全力防御

Parameter.3.Code

String

DNS安全防御

DNSSecurity

Parameter.4.Value

String

实例可绑定的域名数量

默认值为1,最大支持10万个。

Parameter.4.Code

String

实例可绑定的域名数量

DomainNumbers

Parameter.5.Value

String

首次绑定的域名明细

可以为空,若需要绑定多个域名,域名之间请用英文逗号字符隔开。

Parameter.5.Code

String

首次绑定域名

Domain

代码Demo

// This file is auto-generated, don't edit it. Thanks.
package com.aliyun.sample;

import com.aliyun.tea.*;

public class Sample {

    /**
     * <b>description</b> :
     * <p>使用AK&amp;SK初始化账号Client</p>
     * @return Client
     * 
     * @throws Exception
     */
    public static com.aliyun.bssopenapi20171214.Client createClient() throws Exception {
        // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
        // 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html。
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        // Endpoint 请参考 https://api.aliyun.com/product/BssOpenApi
        config.endpoint = "business.aliyuncs.com";
        return new com.aliyun.bssopenapi20171214.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.bssopenapi20171214.Client client = Sample.createClient();
        com.aliyun.bssopenapi20171214.models.CreateInstanceRequest.CreateInstanceRequestParameter parameter0 = new com.aliyun.bssopenapi20171214.models.CreateInstanceRequest.CreateInstanceRequestParameter()
                .setCode("InstanceType")
                .setValue("HostedPublicZone");
        com.aliyun.bssopenapi20171214.models.CreateInstanceRequest.CreateInstanceRequestParameter parameter1 = new com.aliyun.bssopenapi20171214.models.CreateInstanceRequest.CreateInstanceRequestParameter()
                .setValue("version_personal")
                .setCode("Version");
        com.aliyun.bssopenapi20171214.models.CreateInstanceRequest.CreateInstanceRequestParameter parameter2 = new com.aliyun.bssopenapi20171214.models.CreateInstanceRequest.CreateInstanceRequestParameter()
                .setValue("basic")
                .setCode("DNSSecurity");
        com.aliyun.bssopenapi20171214.models.CreateInstanceRequest.CreateInstanceRequestParameter parameter3 = new com.aliyun.bssopenapi20171214.models.CreateInstanceRequest.CreateInstanceRequestParameter()
                .setValue("1")
                .setCode("DomainNumbers");
        com.aliyun.bssopenapi20171214.models.CreateInstanceRequest.CreateInstanceRequestParameter parameter4 = new com.aliyun.bssopenapi20171214.models.CreateInstanceRequest.CreateInstanceRequestParameter()
                .setValue("db3.com")
                .setCode("Domain");
        com.aliyun.bssopenapi20171214.models.CreateInstanceRequest createInstanceRequest = new com.aliyun.bssopenapi20171214.models.CreateInstanceRequest()
                .setProductCode("dns")
                .setSubscriptionType("Subscription")
                .setProductType("alidns_pre")
                .setPeriod(1)
                .setRenewalStatus("ManualRenewal")
                .setParameter(java.util.Arrays.asList(
                    parameter0,
                    parameter1,
                    parameter2,
                    parameter3,
                    parameter4
                ));
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // 复制代码运行请自行打印 API 的返回值
            client.createInstanceWithOptions(createInstanceRequest, runtime);
        } catch (TeaException error) {
            // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            // 错误 message
            System.out.println(error.getMessage());
            // 诊断地址
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            // 错误 message
            System.out.println(error.getMessage());
            // 诊断地址
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }        
    }
}
# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import os
import sys

from typing import List

from alibabacloud_bssopenapi20171214.client import Client as BssOpenApi20171214Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_bssopenapi20171214 import models as bss_open_api_20171214_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client() -> BssOpenApi20171214Client:
        """
        使用AK&SK初始化账号Client
        @return: Client
        @throws Exception
        """
        # 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
        # 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378659.html。
        config = open_api_models.Config(
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
            access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
            access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
        )
        # Endpoint 请参考 https://api.aliyun.com/product/BssOpenApi
        config.endpoint = f'business.aliyuncs.com'
        return BssOpenApi20171214Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        parameter_0 = bss_open_api_20171214_models.CreateInstanceRequestParameter(
            code='InstanceType',
            value='HostedPublicZone'
        )
        parameter_1 = bss_open_api_20171214_models.CreateInstanceRequestParameter(
            value='version_personal',
            code='Version'
        )
        parameter_2 = bss_open_api_20171214_models.CreateInstanceRequestParameter(
            value='basic',
            code='DNSSecurity'
        )
        parameter_3 = bss_open_api_20171214_models.CreateInstanceRequestParameter(
            value='1',
            code='DomainNumbers'
        )
        parameter_4 = bss_open_api_20171214_models.CreateInstanceRequestParameter(
            value='db3.com',
            code='Domain'
        )
        create_instance_request = bss_open_api_20171214_models.CreateInstanceRequest(
            product_code='dns',
            subscription_type='Subscription',
            product_type='alidns_pre',
            period=1,
            renewal_status='ManualRenewal',
            parameter=[
                parameter_0,
                parameter_1,
                parameter_2,
                parameter_3,
                parameter_4
            ]
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            client.create_instance_with_options(create_instance_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        parameter_0 = bss_open_api_20171214_models.CreateInstanceRequestParameter(
            code='InstanceType',
            value='HostedPublicZone'
        )
        parameter_1 = bss_open_api_20171214_models.CreateInstanceRequestParameter(
            value='version_personal',
            code='Version'
        )
        parameter_2 = bss_open_api_20171214_models.CreateInstanceRequestParameter(
            value='basic',
            code='DNSSecurity'
        )
        parameter_3 = bss_open_api_20171214_models.CreateInstanceRequestParameter(
            value='1',
            code='DomainNumbers'
        )
        parameter_4 = bss_open_api_20171214_models.CreateInstanceRequestParameter(
            value='db3.com',
            code='Domain'
        )
        create_instance_request = bss_open_api_20171214_models.CreateInstanceRequest(
            product_code='dns',
            subscription_type='Subscription',
            product_type='alidns_pre',
            period=1,
            renewal_status='ManualRenewal',
            parameter=[
                parameter_0,
                parameter_1,
                parameter_2,
                parameter_3,
                parameter_4
            ]
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            await client.create_instance_with_options_async(create_instance_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)


if __name__ == '__main__':
    Sample.main(sys.argv[1:])
// This file is auto-generated, don't edit it. Thanks.
package main

import (
  "encoding/json"
  "strings"
  "fmt"
  "os"
  bssopenapi20171214  "github.com/alibabacloud-go/bssopenapi-20171214/v5/client"
  openapi  "github.com/alibabacloud-go/darabonba-openapi/v2/client"
  util  "github.com/alibabacloud-go/tea-utils/v2/service"
  "github.com/alibabacloud-go/tea/tea"
)


// Description:
// 
// 使用AK&SK初始化账号Client
// 
// @return Client
// 
// @throws Exception
func CreateClient () (_result *bssopenapi20171214.Client, _err error) {
  // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
  // 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378661.html。
  config := &openapi.Config{
    // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
    AccessKeyId: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")),
    // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
    AccessKeySecret: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")),
  }
  // Endpoint 请参考 https://api.aliyun.com/product/BssOpenApi
  config.Endpoint = tea.String("business.aliyuncs.com")
  _result = &bssopenapi20171214.Client{}
  _result, _err = bssopenapi20171214.NewClient(config)
  return _result, _err
}

func _main (args []*string) (_err error) {
  client, _err := CreateClient()
  if _err != nil {
    return _err
  }

  parameter0 := &bssopenapi20171214.CreateInstanceRequestParameter{
    Code: tea.String("InstanceType"),
    Value: tea.String("HostedPublicZone"),
  }
  parameter1 := &bssopenapi20171214.CreateInstanceRequestParameter{
    Value: tea.String("version_personal"),
    Code: tea.String("Version"),
  }
  parameter2 := &bssopenapi20171214.CreateInstanceRequestParameter{
    Value: tea.String("basic"),
    Code: tea.String("DNSSecurity"),
  }
  parameter3 := &bssopenapi20171214.CreateInstanceRequestParameter{
    Value: tea.String("1"),
    Code: tea.String("DomainNumbers"),
  }
  parameter4 := &bssopenapi20171214.CreateInstanceRequestParameter{
    Value: tea.String("db3.com"),
    Code: tea.String("Domain"),
  }
  createInstanceRequest := &bssopenapi20171214.CreateInstanceRequest{
    ProductCode: tea.String("dns"),
    SubscriptionType: tea.String("Subscription"),
    ProductType: tea.String("alidns_pre"),
    Period: tea.Int32(1),
    RenewalStatus: tea.String("ManualRenewal"),
    Parameter: []*bssopenapi20171214.CreateInstanceRequestParameter{parameter0, parameter1, parameter2, parameter3, parameter4},
  }
  runtime := &util.RuntimeOptions{}
  tryErr := func()(_e error) {
    defer func() {
      if r := tea.Recover(recover()); r != nil {
        _e = r
      }
    }()
    // 复制代码运行请自行打印 API 的返回值
    _, _err = client.CreateInstanceWithOptions(createInstanceRequest, runtime)
    if _err != nil {
      return _err
    }

    return nil
  }()

  if tryErr != nil {
    var error = &tea.SDKError{}
    if _t, ok := tryErr.(*tea.SDKError); ok {
      error = _t
    } else {
      error.Message = tea.String(tryErr.Error())
    }
    // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
    // 错误 message
    fmt.Println(tea.StringValue(error.Message))
    // 诊断地址
    var data interface{}
    d := json.NewDecoder(strings.NewReader(tea.StringValue(error.Data)))
    d.Decode(&data)
    if m, ok := data.(map[string]interface{}); ok {
      recommend, _ := m["Recommend"]
      fmt.Println(recommend)
    }
    _, _err = util.AssertAsString(error.Message)
    if _err != nil {
      return _err
    }
  }
  return _err
}


func main() {
  err := _main(tea.StringSlice(os.Args[1:]))
  if err != nil {
    panic(err)
  }
}