0
点赞
收藏
分享

微信扫一扫

Android 开发中的接口文档


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

Http部分

全局规范

  • URL

​基本的网络地址​

  •  + ​​分支节点​

​​http://127.0.0.1:8080/chat​​​ 为 基本的网络地址/login 为 分支节点​​http://127.0.0.1:8080/chat/login​​​当前统一的基本网络地址为 ​​http://127.0.0.1:8080/ChatServer​​

  • 请求方式

POSTGETPUT

  • 请求消息头

键值对(key value形式)

  • 请求参数

键值对(key value形式)

  • 响应的状态码

统一的返回码为: 200 (注:只要访问服务器成功,一律返回200)

  • 响应的格式

Json

  • 响应的JSON规范

​成功​

{flag:true, data:...}

成功的标记为 flag 为 true

根据具体的请求,如果需要返回值 ​​data节点​​ 包含的是 ​​返回结果​​不需要需要返回值 ,则​​没有data节点​​​​失败​

{flag:false, errorCode:1, errorString:"错误原因"}

​失败的标记为 flag 为 false​​flag 为 false时,必然返回 ​​errorCode​​和​​errorString​​​​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​

  1. 协议分为 

​请求​

  1.  和 

​响应​

  1. 传输方向:

client --> serverserver --> client

  1. 发送消息
    发送过程包含的两个过程:

请求响应两个过程 都完成 才算 当前消息发送成功

  1. 推送消息
    推送过程包含的两个过程:

请求响应两个过程 都完成 才算 当前消息发送成功

  1. 消息必备格式

​请求部分​

  1. :

{
"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

接收者的账号

invitor_name

String

邀请者的名字

invitor_icon

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":""
}

举报

相关推荐

0 条评论