批量创建域名¶
1. 接口描述¶
接口请求路径:POST /prod-api/cdn/domain/batchCreateDomain
batchCreateDomain 用于批量创建安全加速域名,单次最多 100 个。
Token 获取方式见 密钥鉴权。
2. 输入参数¶
以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数。
| 参数名称 | 必选 | 类型 | 描述 |
|---|---|---|---|
| domainNames | 是 | Array of String | 待创建的域名列表,单次最多 100 个 示例值: ["demotest.com"] |
| oid | 是 | String | 所属套餐号 示例值: 202405232795134123456 |
| port | 否 | Integer | 端口。80、443 或小于 0 时按 0 处理示例值: 0 |
| customerRemark | 否 | String | 备注 |
| resouceHost | 否 | String | 回源 Host。使用默认 HOST 时传空字符串 |
| upstream | 否 | Integer | 负载均衡。取值:0(轮询)、2(会话保持)示例值: 2 |
| webSocket | 否 | Integer | WebSocket。取值:0(关闭)、1(开启)示例值: 1 |
| filterParameters | 否 | Integer | 是否开启过滤参数。取值:0(关闭)、1(开启)示例值: 0 |
| rangeSource | 否 | Integer | 是否开启分片回源。取值:0(关闭)、1(开启)示例值: 0 |
| locationList | 否 | [SaveDomainLocationVo] | 缓存过期设置列表 |
| origin | 是 | DomainOriginVO | 源站配置 |
| webFenceConfig | 否 | webFenceConfig | 安全策略关联配置 |
3. 示例¶
示例1 批量创建域名(源站组)¶
输入示例¶
{
"domainNames": ["demotest.com"],
"port": 0,
"oid": "202405232795134123456",
"customerRemark": "",
"resouceHost": "",
"upstream": 2,
"webSocket": 1,
"locationList": [
{
"locationValue": "/",
"locationType": 1,
"cacheTime": 0,
"cacheParameter": 0,
"cacheTimeUnit": "s"
},
{
"locationValue": "js;css;eot;svg;ttf;woff;otf",
"locationType": 2,
"cacheTime": 0,
"cacheParameter": 0,
"cacheTimeUnit": "s"
},
{
"locationValue": "png;jpg;jpeg;gif;ico;bmp",
"locationType": 2,
"cacheTime": 0,
"cacheParameter": 0,
"cacheTimeUnit": "s"
}
],
"filterParameters": 0,
"rangeSource": 0,
"origin": {
"httpOriginPort": 80,
"httpsOriginPort": 443,
"originGroupId": 1338,
"originRecord": "",
"originType": "originGroup",
"originProtocol": 0
},
"webFenceConfig": {
"wafId": "",
"httpDdosId": ""
}
}
代码调用¶
请将 {登录域名}、token 替换为实际值。
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class BatchCreateDomainTest {
public static void main(String[] args) throws Exception {
String url = "https://{登录域名}/prod-api/cdn/domain/batchCreateDomain";
String token = "eyJhbGciOiJIUzUxMiJ9.xxxxxx";
String requestBody = "{"
+ "\"domainNames\":[\"demotest.com\"],"
+ "\"port\":0,"
+ "\"oid\":\"202405232795134123456\","
+ "\"customerRemark\":\"\","
+ "\"resouceHost\":\"\","
+ "\"upstream\":2,"
+ "\"webSocket\":1,"
+ "\"locationList\":["
+ "{\"locationValue\":\"/\",\"locationType\":1,\"cacheTime\":0,\"cacheParameter\":0,\"cacheTimeUnit\":\"s\"},"
+ "{\"locationValue\":\"js;css;eot;svg;ttf;woff;otf\",\"locationType\":2,\"cacheTime\":0,\"cacheParameter\":0,\"cacheTimeUnit\":\"s\"},"
+ "{\"locationValue\":\"png;jpg;jpeg;gif;ico;bmp\",\"locationType\":2,\"cacheTime\":0,\"cacheParameter\":0,\"cacheTimeUnit\":\"s\"}"
+ "],"
+ "\"filterParameters\":0,"
+ "\"rangeSource\":0,"
+ "\"origin\":{"
+ "\"httpOriginPort\":80,"
+ "\"httpsOriginPort\":443,"
+ "\"originGroupId\":1338,"
+ "\"originRecord\":\"\","
+ "\"originType\":\"originGroup\","
+ "\"originProtocol\":0"
+ "},"
+ "\"webFenceConfig\":{\"wafId\":\"\",\"httpDdosId\":\"\"}"
+ "}";
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Authorization", "Bearer " + token);
httpPost.setEntity(new StringEntity(requestBody, ContentType.APPLICATION_JSON));
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
int statusCode = response.getStatusLine().getStatusCode();
String body = EntityUtils.toString(response.getEntity(), "UTF-8");
System.out.println("Status Code: " + statusCode);
System.out.println("Body: " + body);
}
}
}
}
package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
url := "https://{登录域名}/prod-api/cdn/domain/batchCreateDomain"
token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"
requestBody := []byte(`{
"domainNames": ["demotest.com"],
"port": 0,
"oid": "202405232795134123456",
"customerRemark": "",
"resouceHost": "",
"upstream": 2,
"webSocket": 1,
"locationList": [
{
"locationValue": "/",
"locationType": 1,
"cacheTime": 0,
"cacheParameter": 0,
"cacheTimeUnit": "s"
},
{
"locationValue": "js;css;eot;svg;ttf;woff;otf",
"locationType": 2,
"cacheTime": 0,
"cacheParameter": 0,
"cacheTimeUnit": "s"
},
{
"locationValue": "png;jpg;jpeg;gif;ico;bmp",
"locationType": 2,
"cacheTime": 0,
"cacheParameter": 0,
"cacheTimeUnit": "s"
}
],
"filterParameters": 0,
"rangeSource": 0,
"origin": {
"httpOriginPort": 80,
"httpsOriginPort": 443,
"originGroupId": 1338,
"originRecord": "",
"originType": "originGroup",
"originProtocol": 0
},
"webFenceConfig": {
"wafId": "",
"httpDdosId": ""
}
}`)
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(requestBody))
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println("Body:", string(body))
}
输出示例¶
{
"msg": "操作成功",
"code": 200,
"data": [
{
"domainName": "demotest.com",
"port": 0,
"error": null
}
]
}
4. 输出参数¶
| 参数名称 | 类型 | 描述 |
|---|---|---|
| code | Integer | 状态码。示例值:200 |
| msg | String | 提示信息。示例值:操作成功 |
| data | Array | 各域名创建结果列表 |
| data[].domainName | String | 域名。示例值:demotest.com |
| data[].port | Integer | 端口。示例值:0 |
| data[].error | String | 失败原因;成功时为 null |
5. 错误码¶
| HTTP 状态码 / 业务提示 | 描述 |
|---|---|
| 200 | 成功 |
| 401 | 未鉴权或 Token 无效 |
| 403 | 无权限 |
| 缺少必填字段:请填写域名。 | 未传 domainNames 或域名为空 |
| 缺少必填来源:请填写必填来源。 | 未传 origin |
| 超过最大域名限制:您一次最多只能上传100个域名。 | 单次域名数量超过 100 |
| 无效的套餐ID:请输入有效的套餐ID。 | 套餐不存在或不属于当前账号 |
| 套餐已过期,无法继续添加域名。 | 所属套餐已过期 |
| 该套餐可使用域名不足。 | 套餐剩余域名配额不足 |
| 输入的域名中存在重复的域名。 | domainNames 中有重复项 |
| 域名格式无效:请填写有效的域名,错误域名:{0}。 | 域名格式非法 |
| 域名无法重复添加:域名[{0}],无法添加到该套餐中。 | 同项目下域名+端口已存在 |
| 回源端口无效:特殊域名端口情况下,回源端口需一致。 | HTTP/HTTPS 回源端口不一致 |
| 回源类型只能为ipDomain或originGroup | originType 不合法 |
| 回源类型为ipDomain时,回源地址不能为空且只能为IP | originRecord 无效 |
| 回源类型为originGroup时,回源组不能为空 | 未传 originGroupId |
| 源站组不存在,请确认源站组ID是否正确 | originGroupId 无效 |
| 回源端口不能为空且范围在1-65535之间 | 回源端口越界 |
6. 数据模型¶
SaveDomainLocationVo¶
缓存过期设置项。
| 参数名称 | 必选 | 类型 | 描述 |
|---|---|---|---|
| locationValue | 是 | String | 匹配内容,长度不超过 150。目录如 /,文件类型如 js;css示例值: / |
| locationType | 否 | Integer | 类型。取值:1(全部)、2(文件类型)、3(文件夹)、4(全路径)示例值: 1 |
| cacheTime | 否 | Integer | 缓存时间 示例值: 0 |
| cacheTimeUnit | 否 | String | 缓存时间单位,如 s示例值: s |
| cacheParameter | 否 | Integer | 过滤参数 示例值: 0 |
DomainOriginVO¶
源站配置。
| 参数名称 | 必选 | 类型 | 描述 |
|---|---|---|---|
| originType | 是 | String | 源站类型。取值:ipDomain(IP)、originGroup(源站组)示例值: originGroup |
| originRecord | 否 | String | 源站 IP。originType 为 ipDomain 时必填 |
| originGroupId | 否 | Integer | 源站组 ID。originType 为 originGroup 时必填示例值: 1338 |
| originProtocol | 是 | Integer | 源协议。取值:0(HTTP)、1(协议跟随)、2(HTTPS)示例值: 0 |
| httpOriginPort | 是 | Integer | HTTP 回源端口,默认 80,范围 1–65535示例值: 80 |
| httpsOriginPort | 是 | Integer | HTTPS 回源端口,默认 443,范围 1–65535。特殊端口场景下需与 HTTP 回源端口一致示例值: 443 |
webFenceConfig¶
安全策略关联配置。
| 参数名称 | 必选 | 类型 | 描述 |
|---|---|---|---|
| wafId | 否 | Integer | Web 应用防火墙 3.0 策略 ID |
| httpDdosId | 否 | Integer | HTTP DDoS 策略 ID |