创建用户套餐
/v1/user-packages购买并创建一个用户套餐。普通用户为自己购买时会校验套餐可购资格、购买次数、实名认证、套餐状态,并按 duration、可用折扣和优惠码计算价格后扣除余额、创建订单;管理员可为指定用户分配套餐,并可覆盖套餐资源额度与价格。
身份认证
access-token
api-key + api-secret
认证定义
{
"AccessToken": {
"type": "apiKey",
"in": "header",
"name": "access-token",
"description": "通过登录接口获得的短期访问令牌。"
},
"ApiKey": {
"type": "apiKey",
"in": "header",
"name": "api-key",
"description": "API Key;必须和 api-secret 同时发送。"
},
"ApiSecret": {
"type": "apiKey",
"in": "header",
"name": "api-secret",
"description": "API Secret;必须和 api-key 同时发送。"
}
}请求参数
未定义路径、查询或请求头参数。
请求体 · 必填
application/json
object
| 字段 | 类型 | 必填 | 说明与约束 |
|---|---|---|---|
package | integer | 必填 | 必填。要购买的基础套餐定义 ID,必须存在。 约束 / 默认值 / 示例 |
name | string | 必填 | 必填。用户套餐名称;会进行 XSS 过滤。 约束 / 默认值 / 示例 |
duration | string | 可选 | 购买期限;普通用户购买时用于计算价格。 约束 / 默认值 / 示例 |
coupon_code | string | 可选 | 可选。购买基础套餐时使用的优惠码。 约束 / 默认值 / 示例 |
enable_ipv6 | integer | 可选 | 是否启用 IPv6;未传时为 1。 约束 / 默认值 / 示例 |
uid | integer | 可选 | 管理员专用。指定套餐归属用户 ID。 约束 / 默认值 / 示例 |
cname_hostname | string | 可选 | 管理员专用。自定义套餐 CNAME 主机名;必须唯一且合法。 |
traffic | integer | 可选 | 管理员专用。流量额度;-1 表示不限。 约束 / 默认值 / 示例 |
bandwidth | string | 可选 | 管理员专用。带宽额度;-1 表示不限,其他值为数字加 Mbps 或 Gbps。 |
connection | integer | 可选 | 管理员专用。连接数额度;-1 表示不限。 约束 / 默认值 / 示例 |
domain | integer | 可选 | 管理员专用。域名数量额度;-1 表示不限。 约束 / 默认值 / 示例 |
main_domain | integer | 可选 | 管理员专用。主域名数量额度;-1 表示不限。 约束 / 默认值 / 示例 |
http_port | integer | 可选 | 管理员专用。HTTP 非标准端口额度;-1 表示不限。 约束 / 默认值 / 示例 |
stream_port | integer | 可选 | 管理员专用。四层转发端口额度;-1 表示不限。 约束 / 默认值 / 示例 |
custom_cc_rule | integer | 可选 | 管理员专用。是否允许自定义 CC 规则。 约束 / 默认值 / 示例 |
websocket | integer | 可选 | 管理员专用。是否允许 WebSocket。 约束 / 默认值 / 示例 |
http3 | integer | 可选 | 管理员专用。是否允许 HTTP/3。 约束 / 默认值 / 示例 |
month_price | integer | 可选 | 管理员专用。月付价格。 约束 / 默认值 / 示例 |
quarter_price | integer | 可选 | 管理员专用。季付价格。 约束 / 默认值 / 示例 |
year_price | integer | 可选 | 管理员专用。年付价格。 约束 / 默认值 / 示例 |
end_at | string | 可选 | 管理员专用。到期时间,格式 YYYY-MM-DD HH:mm:ss。 |
enable | integer | 可选 | 管理员专用。套餐启用状态。 约束 / 默认值 / 示例 |
reason | string | 可选 | 管理员禁用套餐时必填的禁用原因。 约束 / 默认值 / 示例 |
完整 Schema
{
"type": "object",
"additionalProperties": false,
"required": [
"package",
"name"
],
"properties": {
"package": {
"type": "integer",
"minimum": 1,
"description": "必填。要购买的基础套餐定义 ID,必须存在。",
"example": 2
},
"name": {
"type": "string",
"minLength": 1,
"description": "必填。用户套餐名称;会进行 XSS 过滤。",
"example": "我的标准套餐"
},
"duration": {
"type": "string",
"enum": [
"month",
"quarter",
"year"
],
"description": "购买期限;普通用户购买时用于计算价格。",
"example": "month"
},
"coupon_code": {
"type": "string",
"description": "可选。购买基础套餐时使用的优惠码。",
"example": "WELCOME10"
},
"enable_ipv6": {
"type": "integer",
"enum": [
0,
1
],
"default": 1,
"description": "是否启用 IPv6;未传时为 1。"
},
"uid": {
"type": "integer",
"minimum": 1,
"description": "管理员专用。指定套餐归属用户 ID。"
},
"cname_hostname": {
"type": "string",
"description": "管理员专用。自定义套餐 CNAME 主机名;必须唯一且合法。"
},
"traffic": {
"type": "integer",
"minimum": -1,
"description": "管理员专用。流量额度;-1 表示不限。"
},
"bandwidth": {
"type": "string",
"description": "管理员专用。带宽额度;-1 表示不限,其他值为数字加 Mbps 或 Gbps。"
},
"connection": {
"type": "integer",
"minimum": -1,
"description": "管理员专用。连接数额度;-1 表示不限。"
},
"domain": {
"type": "integer",
"minimum": -1,
"description": "管理员专用。域名数量额度;-1 表示不限。"
},
"main_domain": {
"type": "integer",
"minimum": -1,
"description": "管理员专用。主域名数量额度;-1 表示不限。"
},
"http_port": {
"type": "integer",
"minimum": -1,
"description": "管理员专用。HTTP 非标准端口额度;-1 表示不限。"
},
"stream_port": {
"type": "integer",
"minimum": -1,
"description": "管理员专用。四层转发端口额度;-1 表示不限。"
},
"custom_cc_rule": {
"type": "integer",
"enum": [
0,
1
],
"description": "管理员专用。是否允许自定义 CC 规则。"
},
"websocket": {
"type": "integer",
"enum": [
0,
1
],
"description": "管理员专用。是否允许 WebSocket。"
},
"http3": {
"type": "integer",
"enum": [
0,
1
],
"description": "管理员专用。是否允许 HTTP/3。"
},
"month_price": {
"type": "integer",
"minimum": 0,
"description": "管理员专用。月付价格。"
},
"quarter_price": {
"type": "integer",
"minimum": 0,
"description": "管理员专用。季付价格。"
},
"year_price": {
"type": "integer",
"minimum": 0,
"description": "管理员专用。年付价格。"
},
"end_at": {
"type": "string",
"description": "管理员专用。到期时间,格式 YYYY-MM-DD HH:mm:ss。"
},
"enable": {
"type": "integer",
"enum": [
0,
1
],
"description": "管理员专用。套餐启用状态。"
},
"reason": {
"type": "string",
"enum": [
"到期",
"流量用完",
"锁定"
],
"description": "管理员禁用套餐时必填的禁用原因。"
}
},
"example": {
"package": 2,
"name": "我的标准套餐",
"duration": "month",
"coupon_code": "WELCOME10",
"enable_ipv6": 1
}
}请求体示例
{
"package": 2,
"name": "我的标准套餐",
"duration": "month",
"coupon_code": "WELCOME10",
"enable_ipv6": 1
}响应
HTTP 200
请求已被处理。成功时 code 为 0、msg 为“套餐添加成功”、data 为新建用户套餐 ID;套餐不存在、无购买权限、实名不足、余额不足或参数不合法时仍返回 HTTP 200。
application/json
object
| 字段 | 类型 | 必填 | 说明与约束 |
|---|---|---|---|
code | integer | 必填 | 业务状态码;成功为 0。 约束 / 默认值 / 示例 |
msg | string | 必填 | 处理结果说明。 约束 / 默认值 / 示例 |
data | integer | 必填 | 成功时的新建用户套餐 ID;失败时为空字符串。 约束 / 默认值 / 示例 |
完整 Schema
{
"type": "object",
"required": [
"code",
"msg",
"data"
],
"properties": {
"code": {
"type": "integer",
"description": "业务状态码;成功为 0。",
"example": 0
},
"msg": {
"type": "string",
"description": "处理结果说明。",
"example": "套餐添加成功"
},
"data": {
"type": "integer",
"description": "成功时的新建用户套餐 ID;失败时为空字符串。",
"example": 8
}
}
}示例
{
"code": 0,
"msg": "套餐添加成功",
"data": 8
}购买成功
{
"code": 0,
"msg": "套餐添加成功",
"data": 8
}余额不足
{
"code": "user_package-14",
"msg": "余额不足",
"data": ""
}需要实名认证
{
"code": "user_package-27",
"msg": "此套餐需要实名认证才能购买",
"data": ""
}cURL 示例
根据文档生成;请替换主控地址、路径参数和凭证,并按上表补充查询参数。
curl --request POST \
"https://master.example.invalid/v1/user-packages" \
--header "access-token: YOUR_ACCESS_TOKEN" \
--header "Content-Type: application/json" \
--data '{"package": 2, "name": "我的标准套餐", "duration": "month", "coupon_code": "WELCOME10", "enable_ipv6": 1}'