3.接口文档
接口文档
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请求方式
POSTGETPUT请求消息头
键值对(key value形式)请求参数
键值对(key value形式)响应的状态码
统一的返回码为: 200(注:只要访问服务器成功,一律返回200)响应的格式
Json响应的JSON规范
成功{flag:true, data:...}成功的标记为 flag 为 true
根据具体的请求,如果需要返回值
data节点包含的是返回结果不需要需要返回值 ,则
没有data节点失败{flag:false, errorCode:1, errorString:"错误原因"}失败的标记为 flag 为 falseflag 为 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自定义协议
全局规范
协议的定义
- 传输格式为
json - 协议分为
请求和响应 传输方向:
client --> server: 发送消息server --> client: 推送消息发送消息
发送过程包含的两个过程:
请求: client 发送消息到 server响应: server 响应 client 的这次消息请求两个过程 都完成 才算 当前消息发送成功推送消息
推送过程包含的两个过程:
请求: server 发送消息到 client响应: client 响应 server 的这次消息请求两个过程 都完成 才算 当前消息发送成功消息必备格式
请求部分:{ "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":"" }
附件列表

浙公网安备 33010602011771号