通讯协议
Andoroid与Web
登陆协议
-
登陆协议的设计包括与服务器通信协议和得到服务器相应数据格式定义
-
与服务器通信协议主要是请求URL“/login”,协议数据格式为json对象,三个键值对
-
响应数据分为成功,失败两种
-
reslut字段,recode字段,sessionid,orderid,status
-
失败时,result字段,reason字段
=== =给服务端的协议====
https://ip:port/login [json_data]
{
username: “gailun”,
password: “123123”,
driver: “yes”
}=== =得到服务器响应数据====
//成功
{
result: “ok”,
recode: “0”,
sessionid: “online-driver-xxxx-xxx-xxx-xxxx”,
orderid:“NONE”,
status:“idle”
}
//失败
{
result: “error”,
reason: “why…”
}
-
-
由于刚登陆是没有订单的,所以会直接先置空,刚登陆为idle状态,所以要先置为IDLE,orderid,sessionid,status,这些都会存在前端的一个单例类中
-
注意,登陆的通信协议是司机和乘客公用的协议,服务器根据前端数据的driver身份字段,在后端返回不同角色应该添加的数据(如sessionid不同,不同的状态机)
-
登陆成功会生成生成sessionid并缓存到redis(online-driver(passenger)-xxxx-xxx-xxx-xxxx),再重置生命周期
注册协议
- 通信协议请求路径为/reg,数据json对象都是一些角色信息的键值对,注意driver字段
==== 给服务端的协议 ====
https://ip:port/reg [json_data]
{
username: "gailun",
password: "123123",
driver: "yes/no",
tel: "13331333333",
email: "danbing_at@163.cn",
id_card: "2104041222121211122"
}
====得到服务器响应数据 ====
注册成功就默认为登陆状态
//成功
{
result: "ok",
recode: "0",
sessionid: "online-drive