#协议说明
采用json格式从客户端到服务端交换数据
采用Http post 方法 根据不同的url区分,为了保证可移植到非http协议,在字段里加一个request。 类似微博的方法,如用户相关的
user/login.json
user/info.json
user/changeinfo.json
游戏相关的采用以下的格式
{
"request" : "/helloword/game.json",
"sessionID" : "",
"gameID" : "", //房间号之类的
"moreInfo" : {
...
}
}
该json记录放在一个post字段里提交
返回一个json数据
请求错误
{
"request" : "/statuses/home_timeline.json",
"result" : "failed",
"details" : {
"errorCode" : "20502",
"error" : "Need you follow uid."
}
}
请求成功
{
"request" : "/statuses/home_timeline.json",
"result" : "success",
"details" : {
// more details info
}
}
登录模块可以一直采用http Post的方法,而且是用的一次性链接
客户端提交
{
"request" : "/user/login.json",
"loginInfo" : {
"userName" : "userName",
"password" : "password"
}
}
服务器返回
{
"request" : "/user/login.json",
"result" : "success",
"details" : {
"userInfo":{
"userID" : "userID",
"userName" : "userName",
"userNickname" : "userNickname",
"userEmail" : "userEmail",
"userAvatarType" : "id",
"userAvatar" : "1"
},
"sessionID" : ""
}
}
客户端提交
{
"request" : "/user/logout.json",
"sessionID" : "sessionID",
"logoutInfo" : {
"userName" : "username"//还没想好这里还需要什么数据
}
}
服务器返回
{
"request" : "/user/logout.json",
"result" : "success",
"details" : {
//
}
}
客户端提交
{
"request" : "/user/register.json",
"userInfo" : {
"userName" : "userName",
"userNickname" : "userNickname",
"password" : "password",
"userAvatarType" : "id",
"userAvatar" : "1"
}
}
服务器返回
{
"request" : "/user/register.json",
"result" : "success",
"details" : {
"userInfo":{
"userID" : "userID",
"userName" : "userName",
"userNickname" : "userNickname",
"userEmail" : "userEmail"
"userAvatarType" : "id",
"userAvatar" : "1"
},
"sessionID" : ""
}
}
客户端提交
{
"request" : "/user/change_userinfo.json",
"sessionID" : "sessionID"
"userInfo" : {
"userName" : "userName",
"userNickname" : "userNickname",
"oldPassword" : "oldPassword"
"newPassword" : "newPassword",
"userAvatarType" : "id",
"userAvatar" : "1"
}
}
服务器返回
{
"request" : "/user/change_userinfo.json",
"result" : "success",
"details" : {
"userInfo":{
"userID" : "userID",
"userName" : "userName",
"userNickname" : "userNickname",
"userEmail" : "userEmail"
}
}
}
客户端提交
{
"request" : "/user/update_token.json",
"sessionID" : "sessionID"
}
服务器返回
{
"request" : "/user/update_token.json",
"result" : "success",
"details" : {
"sessionID" : ""
}
}
客户端提交
{
"request" : "/helloword/request_game.json",
"sessionID" : "",
"gameType" : ""
}
服务器返回
{
"request" : "/helloword/request_game.json",
"result" : "success",
"details" : {
"num" : "10",
"gameID" : "",
"games" : [
{
"description":"",
"ans1" : "",
"ans2" : "",
"ans3" : "",
"ans4" : "",
"point" : "", //分值
"time" : ""
},
{
//
}
]
}
}
客户端提交
{
"request" : "/helloword/upload_result.json",
"sessionID" : "",
"gameID" : "",
"userAnswer":[
{
"chosen" : "a",
"time" : "5",
},
{
//
}
]
}
服务器返回
{
"request" : "/helloword/upload_result.json",
"result" : "success",
"details" : {
"correct" : "2",
"incorrect" : "3",
"thisScore" : "2",
"totalScore" : "22",
"userRank" : "23"
}
}
客户端提交
{
"request" : "/helloword/request_rank.json",
"sessionID" : ""
}
服务器返回
{
"request" : "/helloword/request_rank.json",
"result" : "success",
"details" : {
topRank :[
{
"userNickname ": "",
"totalScore" : "22",
"userRank" : "23"
}
,{}
],
myRank:[
{
"userNickname ": "",
"totalScore" : "22",
"userRank" : "23"
}
]
}
}
客户端提交
{
"request" : "/helloword/user_logout.json",
"sessionID" : "",
"gameID" : "",
"logout" : "true"
}
服务器返回
{
"request" : "/helloword/user_logout.json",
"result" : "success"
}
客户端提交
{
"request" : "/helloword/get_message.json",
"sessionID" : "",
}
服务器返回
{
"request" : "/helloword/get_message.json",
"result" : "success",
"details" : {
"title" : "",
"content" : ""
}
}
客户端提交
{
"request" : "/helloword/new_message.json",
"toSessionID" : "",
"messageType" : "",
"title" : ",
"content" : ""
}
服务器返回
{
"request" : "/helloword/new_message.json",
"result" : "success"
}
客户端提交
{
"request" : "/helloword/request_pk_game.json",
"sessionID" : "",
"gameType" : ""
}
服务器返回
{
"request" : "/helloword/request_pk_game.json",
"result" : "success",
"details" : {
"num" : "10",
"gameID" : "",
"games" : [
{
"description":"",
"ans1" : "",
"ans2" : "",
"ans3" : "",
"ans4" : "",
"point" : "", //分值
"ans" :"",
"time" : "",
"enemyTime" : "",
"enemyAns" : ""
},
{
//
}
]
}
}
客户端提交
{
"request" : "/helloword/upload_pk_result.json",
"sessionID" : "",
"gameID" : "",
"userAnswer":[
{
"ans" : "a",
"time" : "5"
},
{
//
}
]
}
服务器返回
{
"request" : "/helloword/upload_pk_result.json",
"result" : "success",
"details" : {
"correct" : "2",
"incorrect" : "3",
"userExp" :"",
"userScore" : ""
}
}