首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >3.接口文档

3.接口文档

作者头像
六月的雨
发布2018-05-14 14:24:54
9200
发布2018-05-14 14:24:54
举报
文章被收录于专栏:Android开发指南Android开发指南

接口文档

  1. HTTP部分
    • 全局规范
    • Login 登录接口
    • Register 注册接口
    • 搜素用户接口
    • 接受用户用户邀请
    • 获取朋友列表
    • 修改用户名接口
  2. Socket自定义协议
    • 全局规范
    • client 请求部分
      • Auth认证
      • 发送邀请
      • 发送文本消息
    • server 推送部分
      • 推送用户邀请
      • 推送接受用户邀请
      • 推送文本消息
      • 推送用户名变更

Http部分

(一般都是这样)

全局规范

  • URL URL的组成:基本的网络地址 + 分支节点 http://127.0.0.1:8080/chat 为 基本的网络地址 /login 为 分支节点 http://127.0.0.1:8080/chat/login 组成完整的 URL 当前统一的基本网络地址为 http://127.0.0.1:8080/ChatServer
  • 请求方式 POST GET PUT
  • 请求消息头 键值对(key value形式)
  • 请求参数 键值对(key value形式)
  • 响应的状态码 统一的返回码为: 200 (注:只要访问服务器成功,一律返回200)
  • 响应的格式 Json
  • 响应的JSON规范
    • 成功 {flag:true, data:...} 成功的标记为 flag 为 true 根据具体的请求,如果需要返回值 data节点 包含的是 返回结果 不需要需要返回值 ,则没有data节点
    • 失败 {flag:false, errorCode:1, errorString:"错误原因"} 失败的标记为 flag 为 false flag 为 false时,必然返回 errorCodeerrorString 节点 errorCode说明了错误编码 errorString说明错误原因

Login(登录接口)

  • 分支节点 : /login
  • 请求方式 : POST
  • 请求参数 : key | 类型 | 说明 ------------ | -------- | ------------ account | String | 用户的账号 password | String | 用户的密码
  • 响应结果 :
    • 成功 { "flag": true, "data": { "account": "zhangsan", "name": "张三", "sex": 1, "icon": "/a/b/zhangsan.png", "sign": "我的个性签名", "area": "深圳", "token": "5904c7ae-3e75-48c8-bbee-ad094533a422" } }
    • 失败 errorCode | errorString ---------- | -------------- 100 | 用户密码错误 101 | 用户不存在

Regisger(注册接口)

  • 分支节点 : /register
  • 请求方式 : POST
  • 请求参数 : key | 类型 | 说明 ------------ | -------- | ------------ account | String | 用户注册的账号 password | String | 用户注册的密码
  • 响应结果 :
    • 成功 { "flag": true, "data": { "account": "zhangsan", "name": "张三", "sex": 1, "icon": "/a/b/zhangsan.png", "sign": "我的个性签名", "area": "深圳", "token": "5904c7ae-3e75-48c8-bbee-ad094533a422" } }
    • 失败 errorCode | errorString ---------- | -------------- 150 | 用户已经存在

搜索用户接口

  • 分支节点 : /user/search
  • 请求方式 : POST
  • 请求消息头 : key | 类型 | 说明 ------------ | -------- | ------------ account | String | 用户的账号 token | String | 用户的唯一标识
  • 请求参数 : key | 类型 | 说明 ------------ | -------- | ------------ search | String | 搜索的账号
  • 响应结果 :
    • 成功 { "flag": true, "data": { "account": "zhangsan", "name": "张三", "icon": "/a/b/zhangsan.png", "sign": "我的个性签名", "area": "深圳" } }
    • 失败 errorCode | errorString ---------- | -------------- 200 | 用户不存在

接受用户用户邀请

  • 分支节点 : /friend/accept
  • 请求方式 : POST
  • 请求消息头 : key | 类型 | 说明 ------------ | -------- | ------------ account | String | 用户的账号 token | String | 用户的唯一标识
  • 请求参数 : key | 类型 | 说明 ------------ | -------- | ------------ invitor | String | 邀请者的账号 acceptor | String | 接受者的账号
  • 响应结果 :
    • 成功 { "flag": true }
    • 失败 { "flag": false }

获取朋友列表

  • 分支节点 : /friend/list
  • 请求方式 : POST
  • 请求消息头 : key | 类型 | 说明 ------------ | -------- | ------------ account | String | 用户的账号 token | String | 用户的唯一标识
  • 请求参数 : 无
  • 响应结果 :
    • 成功 { "flag": true }
    • 失败 { "flag": false }

用户名称修改接口

  • 分支节点 : /user/nameChange
  • 请求方式 : POST
  • 请求消息头 : key | 类型 | 说明 ------------ | -------- | ------------ account | String | 用户的账号 token | String | 用户的唯一标识
  • 请求参数 : key | 类型 | 说明 ------------ | -------- | ------------ name | String | 修改后的用户名
  • 响应结果 :
    • 成功 { "flag": true }
    • 失败 { "flag": false }

Sokect自定义协议

全局规范

  • 协议的定义
    1. 传输格式为json
    2. 协议分为 请求 和 响应
    3. 传输方向: client --> server : 发送消息 server --> client : 推送消息
    4. 发送消息 发送过程包含的两个过程: 请求 : client 发送消息到 server 响应 : server 响应 client 的这次消息请求 两个过程 都完成 才算 当前消息发送成功
    5. 推送消息 推送过程包含的两个过程: 请求 : server 发送消息到 client 响应 : client 响应 server 的这次消息请求 两个过程 都完成 才算 当前消息发送成功
    6. 消息必备格式 请求部分: { "sequence": "9f4c696e-9ab5-46cf-959c-b1e2e35200d2", "type": "request", "action": "text" } 响应部分: { "sequence": "9f4c696e-9ab5-46cf-959c-b1e2e35200d2", "type": "response", "flag": "true" } sequece : 标记 请求 和 响应,用来表明 响应 是 针对 哪次 请求type : 用来标记 是 请求 还是 响应 action : 请求发送方 的 发送类型,由具体请求 决定取值。

Client 部分

Auth认证
  • Action : auth
  • 请求的 key-Value key | 类型 | 说明 --------|-----------|------------- type | String |请求:request sequence| String |请求的序列号 action | String |请求的行为:auth sender | String |发送者账号 token | String |发送者token标志
  • 请求的json 格式: { "sequence": "9f4c696e-9ab5-46cf-959c-b1e2e35200d2", "type": "request", "action": "auth", "sender":"xxxx", "token":"xxxx" } {"sequence":"1","type":"request","action":"auth","sender":"iphone1","token":"0dce6f76ac1a29d276c0c6dabe60519c"}
  • 响应的json 格式: 成功 : { "sequence": "9f4c696e-9ab5-46cf-959c-b1e2e35200d2", "type": "response", "flag": "true", } 失败 : { "sequence": "9f4c696e-9ab5-46cf-959c-b1e2e35200d2", "type": "response", "flag": "false", "errorCode":"", "errorString":"" }
发送邀请
  • Action : invitation
  • 请求的 key-Value key | 类型 | 说明 --------|-----------|------------- type | String |请求:request sequence| String |请求的序列号 action | String |请求的行为:invitation sender | String |发送者账号 token | String |发送者token标志 receiver| String |接收者的账号 content | String |邀请的文本内容
  • 请求的json 格式: { "sequence": "9f4c696e-9ab5-46cf-959c-b1e2e35200d2", "type": "request", "action": "invitation", "token":"xxxx", "sender":"xxxx", "receiver":"xxxx", "content":"xxxxxx" }
  • 响应的json 格式: 成功 : { "sequence": "9f4c696e-9ab5-46cf-959c-b1e2e35200d2", "type": "response", "flag": "true", } 失败 : { "sequence": "9f4c696e-9ab5-46cf-959c-b1e2e35200d2", "type": "response", "flag": "false", "errorCode":"", "errorString":"" }
发送文本消息
  • Action : text
  • 请求的 key-Value key | 类型 | 说明 --------|-----------|------------- type | String |请求:request sequence| String |请求的序列号 action | String |请求的行为:invitation sender | String |发送者账号 token | String |发送者token标志 receiver| String |接收者的账号 content | String |邀请的文本内容
  • 请求的json 格式: { "sequence": "9f4c696e-9ab5-46cf-959c-b1e2e35200d2", "type": "request", "action": "text", "token":"xxxx", "sender":"xxxx", "receiver":"xxxx", "content":"xxxxxx" }
  • 响应的json 格式: 成功 : { "sequence": "9f4c696e-9ab5-46cf-959c-b1e2e35200d2", "type": "response", "flag": "true", } 失败 : { "sequence": "9f4c696e-9ab5-46cf-959c-b1e2e35200d2", "type": "response", "flag": "false", "errorCode":"", "errorString":"" }

Server 部分

推送用户邀请
  • action : invitation
  • 请求的 key-Value key | 类型 | 说明 --------|-----------|------------- type | String |请求:request sequence| String |请求的序列号 action | String |请求的行为:invitation sender | String |发送者账号 receiver| String |接收者的账号 invitorname|String |邀请者的名字 invitoricon|String |邀请者的头像 content | String |邀请的文本内容
  • 请求的json 格式: { "sequence":"3", "type":"request", "action":"invitation", "sender":"iphone1", "receiver":"iphone2", "invitor_name":"iphone2", "invitor_icon":"/icon/iphone2.png", "content":"hehe" }
  • 响应的json 格式: 成功 : { "sequence": "3", "type": "response", "flag": "true", } 失败 : { "sequence": "3", "type": "response", "flag": "false", "errorCode":"", "errorString":"" }
推送用户接受邀请
  • action : reinvitation
  • 请求的 key-Value key | 类型 | 说明 --------|-----------|------------- type | String |请求:request sequence| String |请求的序列号 action | String |请求的行为:reinvitation sender | String |发送者账号 receiver| String |接收者的账号 name | String |接受邀请者的名字 icon | String |接受邀请者的头像 content | String |邀请的文本内容
  • 请求的json 格式: { "sequence":"3", "type":"request", "action":"text", "sender":"iphone1", "receiver":"iphone2", "name":"iphone1", "icon","/icon/iphone1.png", "content":"hehe" }
  • 响应的json 格式: 成功 : { "sequence": "3", "type": "response", "flag": "true", } 失败 : { "sequence": "3", "type": "response", "flag": "false", "errorCode":"", "errorString":"" }
推送文本消息
  • action : text
  • 请求的 key-Value key | 类型 | 说明 --------|-----------|------------- type | String |请求:request sequence| String |请求的序列号 action | String |请求的行为:text sender | String |发送者账号 receiver| String |接收者的账号 content | String |邀请的文本内容
  • 请求的json 格式: { "sequence":"3", "type":"request", "action":"text", "sender":"iphone1", "receiver":"iphone2", "content":"hehe" }
  • 响应的json 格式: 成功 : { "sequence": "3", "type": "response", "flag": "true", } 失败 : { "sequence": "3", "type": "response", "flag": "false", "errorCode":"", "errorString":"" }
推送用户名变更
  • action : nameChange
  • 请求的 key-Value key | 类型 | 说明 --------|-----------|------------- type | String |请求:request sequence| String |请求的序列号 action | String |请求的行为:nameChange sender | String |发送者账号 receiver| String |接收者的账号 name | String |发送者变更后的名字
  • 请求的json 格式: { "sequence":"3", "type":"request", "action":"text", "sender":"iphone1", "receiver":"iphone2", "content":"hehe" }
  • 响应的json 格式: 成功 : { "sequence": "3", "type": "response", "flag": "true", } 失败 : { "sequence": "3", "type": "response", "flag": "false", "errorCode":"", "errorString":"" }

附件列表

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-02-13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 接口文档
    • Http部分
      • 全局规范
      • Login(登录接口)
      • Regisger(注册接口)
      • 搜索用户接口
      • 接受用户用户邀请
      • 获取朋友列表
      • 用户名称修改接口
  • (一般都是这样)
    • Sokect自定义协议
      • 全局规范
      • Client 部分
      • Server 部分
      • 附件列表
相关产品与服务
访问管理
访问管理(Cloud Access Management,CAM)可以帮助您安全、便捷地管理对腾讯云服务和资源的访问。您可以使用CAM创建子用户、用户组和角色,并通过策略控制其访问范围。CAM支持用户和角色SSO能力,您可以根据具体管理场景针对性设置企业内用户和腾讯云的互通能力。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档