{
  "tags": [
    "消息"
  ],
  "description": "更新当前登录用户已有消息类型订阅记录的邮件或短信开关。接口要求登录，请求可为单个对象或对象数组。每一项都必须提供 `msg_type`；`phone`、`email` 可任选或同时提供。服务端仅执行 UPDATE：若当前用户没有对应订阅记录，请求仍成功但不会新增记录。",
  "operationId": "user_put_v1_messages_sub",
  "security": [
    {
      "AccessToken": []
    },
    {
      "ApiKey": [],
      "ApiSecret": []
    }
  ],
  "responses": {
    "200": {
      "description": "成功及业务错误均返回 HTTP 200。注意：当前服务端中三个 `client_error` 调用的参数顺序与通用约定相反，缺少 `msg_type` 或开关值非法时，中文原因出现在 `code`，错误标识出现在 `msg`。",
      "content": {
        "application/json": {
          "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
              }
            ]
          },
          "examples": {
            "success": {
              "summary": "更新成功",
              "value": {
                "code": 0,
                "msg": "订阅已更新",
                "data": null
              }
            },
            "invalidPhone": {
              "summary": "短信开关错误（实际字段顺序）",
              "value": {
                "code": "phone值错误",
                "msg": "message_sub-4",
                "data": ""
              }
            }
          },
          "example": {
            "code": 0,
            "msg": "订阅已更新",
            "data": null
          }
        }
      }
    }
  },
  "x-python-handler": "system.MessageSubAPI",
  "x-python-route-line": 1036,
  "x-audience": "user",
  "x-auth": "user",
  "x-reviewed": true,
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "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
              }
            }
          ]
        },
        "examples": {
          "emailOnly": {
            "summary": "开启公告邮件订阅",
            "value": {
              "msg_type": "announcement",
              "email": 1
            }
          },
          "batch": {
            "summary": "批量更新",
            "value": [
              {
                "msg_type": "announcement",
                "phone": 0,
                "email": 1
              }
            ]
          }
        }
      }
    }
  },
  "parameters": [],
  "x-itecdn-source-reviewed": true,
  "extensions": [
    {
      "key": "x-python-handler",
      "value": "system.MessageSubAPI"
    },
    {
      "key": "x-python-route-line",
      "value": 1036
    },
    {
      "key": "x-audience",
      "value": "user"
    },
    {
      "key": "x-auth",
      "value": "user"
    },
    {
      "key": "x-reviewed",
      "value": true
    },
    {
      "key": "x-itecdn-source-reviewed",
      "value": true
    }
  ],
  "method": "put",
  "path": "/v1/messages/sub",
  "servers": [
    {
      "url": "https://master.example.invalid",
      "description": "不可调用的示例地址；复制示例后替换为自己的主控域名。"
    }
  ],
  "securitySchemes": {
    "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 同时发送。"
    }
  },
  "jsonRequestBodyExample": {
    "msg_type": "announcement",
    "phone": 0,
    "email": 0
  },
  "info": {
    "title": "itecdn v5 用户 API",
    "version": "5.x",
    "description": "itecdn v5.x Python 主控用户 API。本文档不适用于 v6 或其它实现。"
  },
  "postman": {
    "name": "更新当前用户的消息订阅开关",
    "description": {
      "content": "更新当前登录用户已有消息类型订阅记录的邮件或短信开关。接口要求登录，请求可为单个对象或对象数组。每一项都必须提供 `msg_type`；`phone`、`email` 可任选或同时提供。服务端仅执行 UPDATE：若当前用户没有对应订阅记录，请求仍成功但不会新增记录。",
      "type": "text/plain"
    },
    "url": {
      "path": [
        "v1",
        "messages",
        "sub"
      ],
      "host": [
        "{{baseUrl}}"
      ],
      "query": [],
      "variable": []
    },
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "method": "PUT",
    "body": {
      "mode": "raw",
      "raw": "",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "auth": {
      "type": "apikey",
      "apikey": [
        {
          "type": "any",
          "value": "access-token",
          "key": "key"
        },
        {
          "type": "any",
          "value": "{{apiKey}}",
          "key": "value"
        },
        {
          "type": "any",
          "value": "header",
          "key": "in"
        }
      ]
    }
  }
}