Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
268 lines (220 sloc) 4.24 KB

百步梯 2017 年爱上你主播投票·前后台接口文档

后端接口全局返回模板

{
  "type": "object",
  "oneOf": [
    {
      "properties": {
        "status": { "enum": [ 0 ] },
        "data": {
          "type": "object"
        }
      },
      "required": ["status", "data"]
    },
    {
      "description" : "需要用户往redirect跳转,如在需要获取用户openid的时候",
      "properties": {
        "status": { "enum": [ -1 ] },
        "redirect": {
          "type": "string",
          "description": "需要用户跳转的地址"
        }
      },
      "required": ["status", "redirect"]
    },
    {
      "description" : "处理请求出错,错误信息会在errorMessage中给出",
      "properties": {
        "status": { "type": "", "not": { "enum": [ 0 , -1] } },
        "errorMessage": {"type": "string" }
      },
      "required": ["status", "errorMessage"]
    }
  ]
}

示例

成功:

{
	"status": 0,
	"data": {}
}

data 即为下文所示后端返回数据

异常:

{
	"status": 1,
	"errorMessage": "信息未填写完整"
}

需要用户跳转:

{
	"status": -1,
	"redirect": "https://www.baidu.com/"
}

测试接口

仅在测试服务器上可用

指定当前session的openid

POST api/staging/setOpenID/
{
  "description": "设定当前session的openid",
  "type": "object",
  "properties": {
        "openID": {
          "description": "要设定的openid",
          "type":"string",
          "pattern": "^[0-9A-Za-z]{5,10}$"
        }
      },
      "required": [ "openID" ]
}

后端返回(依据全局模板status判断是否设定成功)

{}

取当前session的openid

GET api/staging/getOpenID/

后端返回

{
  "description": "当前session的openid",
  "type": "object",
  "properties": {
        "openID": {
          "description": "openid",
          "type":"string"
        }
      },
      "required": [ "openID" ]
}

面向用户接口

当前用户今日是否已投票

GET api/user/getVoteStatus/

后端返回

{
  "description": "用于判断用户今日是否已投票且投的是谁",
  "type": "object",
  "oneOf": [
    {
      "properties": {
        "isVote": {
          "description": "今日是否已投票",
          "enum": [ false ]
        }
      },
      "required": [ "isVote" ]
    },
    {
      "properties": {
        "isVote": {
          "description": "今日是否已投票",
          "enum": [ true ]
        },
        "voicerID": {
          "description": "投的选手的ID",
          "type": "number"
        },
      },
      "required": [ "isVote", "voicerID" ]
    }
  ]
}

取选手信息列表

GET api/vote/getVoicersList/

后端返回

{
  "description": "取选手信息列表(随机顺序)",
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "voicerID": {
        "description": "该选手的ID",
        "type": "number"
      },
      "name": {
        "description": "姓名",
        "type": "string"
      },
      "voteCount": {
        "description": "当前票数",
        "type": "string"
      },
      "rank":{
        "description": "当前排名",
        "type": "number"
      }
    },
    "required": ["voicerID", "name", "voteCount","rank"]
  }
}

取某选手信息

GET api/vote/getVoicer/id/{voicerID}/

{voicerID}:要取的选手ID

后端返回

{
  "description": "取某选手信息",
  "type": "object",
  "properties": {
    "voicerID": {
      "description": "该选手的ID",
      "type": "number"
    },
    "name": {
      "description": "姓名",
      "type": "string"
    },
    "voteCount": {
      "description": "当前票数",
      "type": "string"
    },
    "rank":{
      "description": "当前排名",
      "type": "number"
    }
  },
  "required": ["voicerID", "name", "voteCount","rank"]
}

投票

POST api/vote/loveUp/

{
  "description": "投票",
  "type": "object",
  "properties": {
        "voicerID": {
          "description": "要投的选手的ID",
          "type":"number"
        }
      },
      "required": [ "voicerID" ]
}

后端返回

与 取某选手信息 一致

格式校(甩)对(锅)器:https://www.jsonschemavalidator.net/