itecdn 5.x用户文档
itecdn 5.x / 用户 API

更新当前用户的消息订阅开关

PUT/v1/messages/sub

更新当前登录用户已有消息类型订阅记录的邮件或短信开关。接口要求登录,请求可为单个对象或对象数组。每一项都必须提供 msg_type;phone、email 可任选或同时提供。服务端仅执行 UPDATE:若当前用户没有对应订阅记录,请求仍成功但不会新增记录。

身份认证

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

oneOf

oneOf · 1 · object
字段类型必填说明与约束
msg_typestring必填

要更新的消息类型;服务端不限制枚举值,必须与已有订阅记录的类型匹配才会实际更新。

约束 / 默认值 / 示例
{
  "example": "announcement"
}
phoneinteger可选

可选。短信订阅开关:1 开启,0 关闭。

约束 / 默认值 / 示例
{
  "enum": [
    0,
    1
  ]
}
emailinteger可选

可选。邮件订阅开关:1 开启,0 关闭。

约束 / 默认值 / 示例
{
  "enum": [
    0,
    1
  ]
}
oneOf · 2 · array <object>

批量更新对象数组。服务端允许空数组并返回成功;实际调用应至少提交一项。

数组元素 · object
字段类型必填说明与约束
msg_typestring必填

消息类型。

phoneinteger可选

短信订阅开关。

约束 / 默认值 / 示例
{
  "enum": [
    0,
    1
  ]
}
emailinteger可选

邮件订阅开关。

约束 / 默认值 / 示例
{
  "enum": [
    0,
    1
  ]
}
完整 Schema
{
  "oneOf": [
    {
      "type": "object",
      "required": [
        "msg_type"
      ],
      "properties": {
        "msg_type": {
          "type": "string",
          "description": "要更新的消息类型;服务端不限制枚举值,必须与已有订阅记录的类型匹配才会实际更新。",
          "example": "announcement"
        },
        "phone": {
          "type": "integer",
          "enum": [
            0,
            1
          ],
          "description": "可选。短信订阅开关:1 开启,0 关闭。"
        },
        "email": {
          "type": "integer",
          "enum": [
            0,
            1
          ],
          "description": "可选。邮件订阅开关:1 开启,0 关闭。"
        }
      },
      "additionalProperties": false
    },
    {
      "type": "array",
      "description": "批量更新对象数组。服务端允许空数组并返回成功;实际调用应至少提交一项。",
      "items": {
        "type": "object",
        "required": [
          "msg_type"
        ],
        "properties": {
          "msg_type": {
            "type": "string",
            "description": "消息类型。"
          },
          "phone": {
            "type": "integer",
            "enum": [
              0,
              1
            ],
            "description": "短信订阅开关。"
          },
          "email": {
            "type": "integer",
            "enum": [
              0,
              1
            ],
            "description": "邮件订阅开关。"
          }
        },
        "additionalProperties": false
      }
    }
  ]
}

开启公告邮件订阅

{
  "msg_type": "announcement",
  "email": 1
}

批量更新

[
  {
    "msg_type": "announcement",
    "phone": 0,
    "email": 1
  }
]

请求体示例

{
  "msg_type": "announcement",
  "phone": 0,
  "email": 0
}

响应

HTTP 200

成功及业务错误均返回 HTTP 200。注意:当前服务端中三个 client_error 调用的参数顺序与通用约定相反,缺少 msg_type 或开关值非法时,中文原因出现在 code,错误标识出现在 msg。

application/json

oneOf

oneOf · 1 · object
字段类型必填说明与约束
codeinteger必填

0 表示处理完成。

约束 / 默认值 / 示例
{
  "enum": [
    0
  ]
}
msgstring必填

成功提示。

约束 / 默认值 / 示例
{
  "enum": [
    "订阅已更新"
  ]
}
dataobject必填

成功时为 null,不返回更新后的订阅记录。

约束 / 默认值 / 示例
{
  "nullable": true
}
oneOf · 2 · object
字段类型必填说明与约束
codestring必填

缺少消息类型、phone/email 值非法或认证失败的实际错误标识;前三种来自服务端的参数顺序。

约束 / 默认值 / 示例
{
  "enum": [
    "请提供msg_type",
    "phone值错误",
    "email值错误",
    "login_required"
  ]
}
msgstring必填

实际错误消息;前三种为服务端写入的错误标识。

约束 / 默认值 / 示例
{
  "enum": [
    "message_sub-2",
    "message_sub-4",
    "message_sub-6",
    "需要登录"
  ]
}
datastring必填

业务错误时为空字符串。

约束 / 默认值 / 示例
{
  "enum": [
    ""
  ]
}
完整 Schema
{
  "oneOf": [
    {
      "type": "object",
      "required": [
        "code",
        "msg",
        "data"
      ],
      "properties": {
        "code": {
          "type": "integer",
          "enum": [
            0
          ],
          "description": "0 表示处理完成。"
        },
        "msg": {
          "type": "string",
          "enum": [
            "订阅已更新"
          ],
          "description": "成功提示。"
        },
        "data": {
          "type": "object",
          "nullable": true,
          "description": "成功时为 null,不返回更新后的订阅记录。"
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "code",
        "msg",
        "data"
      ],
      "properties": {
        "code": {
          "type": "string",
          "enum": [
            "请提供msg_type",
            "phone值错误",
            "email值错误",
            "login_required"
          ],
          "description": "缺少消息类型、phone/email 值非法或认证失败的实际错误标识;前三种来自服务端的参数顺序。"
        },
        "msg": {
          "type": "string",
          "enum": [
            "message_sub-2",
            "message_sub-4",
            "message_sub-6",
            "需要登录"
          ],
          "description": "实际错误消息;前三种为服务端写入的错误标识。"
        },
        "data": {
          "type": "string",
          "enum": [
            ""
          ],
          "description": "业务错误时为空字符串。"
        }
      },
      "additionalProperties": false
    }
  ]
}

示例

{
  "code": 0,
  "msg": "订阅已更新",
  "data": null
}

更新成功

{
  "code": 0,
  "msg": "订阅已更新",
  "data": null
}

短信开关错误(实际字段顺序)

{
  "code": "phone值错误",
  "msg": "message_sub-4",
  "data": ""
}

cURL 示例

根据文档生成;请替换主控地址、路径参数和凭证,并按上表补充查询参数。

curl --request PUT \
  "https://master.example.invalid/v1/messages/sub" \
  --header "access-token: YOUR_ACCESS_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{"msg_type": "announcement", "phone": 0, "email": 0}'

查看完整接口 JSON