联网api略微调整,http请求处理规范化

This commit is contained in:
MrZ626
2021-01-29 00:45:35 +08:00
parent 8d3910b7a0
commit c8f4faaa95
6 changed files with 35 additions and 15 deletions

View File

@@ -10,7 +10,7 @@ local function tick_httpREQ_launch(task)
local response,request_error=client.poll(task)
if response then
local res=json.decode(response.body)
if res then
if res.message=="OK"then
if response.code==200 then
LOG.print(res.notice,360,COLOR.sky)
if VERSION_CODE>=res.version_code then
@@ -41,10 +41,12 @@ local function tick_httpREQ_autoLogin(task)
local response,request_error=client.poll(task)
if response then
if response.code==200 then
LOGIN=true
local res=json.decode(response.body)
if res then
if res.message=="OK"then
LOGIN=true
LOG.print(text.loginSuccessed)
else
LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")
end
else
LOGIN=false
@@ -213,6 +215,10 @@ function scene.update()
LOG.print("==============",COLOR.red)
LOG.print("Merry Christmas!",COLOR.white)
LOG.print("==============",COLOR.red)
elseif FESTIVAL=="sprFes"then
LOG.print("=======",COLOR.red)
LOG.print("新年快乐!",COLOR.white)
LOG.print("=======",COLOR.red)
end
end
if loadTar then

View File

@@ -4,14 +4,18 @@ local function tick_httpREQ_newLogin(task)
coroutine.yield()
local response,request_error=client.poll(task)
if response then
local res=json.decode(response.body)
LOGIN=response.code==200
if res then
if LOGIN then
LOG.print(text.loginSuccessed)
if response.code==200 then
local res=json.decode(response.body)
if res.message=="OK"then
LOGIN=true
USER.email=res.email
USER.auth_token=res.auth_token
USER.name=res.name
USER.id=res.id
USER.motto=res.motto
USER.avatar=res.avatar
FILE.save(USER,"conf/user","q")
LOG.print(text.loginSuccessed)
httpRequest(
TICK_httpREQ_getAccessToken,

View File

@@ -11,9 +11,9 @@ local function task_fetchRooms(task)
coroutine.yield()
local response,request_error=client.poll(task)
if response then
local res=json.decode(response.body)
if res then
if response.code==200 then
if response.code==200 then
local res=json.decode(response.body)
if res.message=="OK"then
rooms=res.room_list
else
LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")

View File

@@ -4,9 +4,15 @@ local function tick_httpREQ_register(task)
coroutine.yield()
local response,request_error=client.poll(task)
if response then
local res=json.decode(response.body)
if res then
if response.code==200 then
if response.code==200 then
local res=json.decode(response.body)
if res.message=="OK"then
LOGIN=true
USER.name=res.name
USER.id=res.id
USER.motto=res.motto
USER.avatar=res.avatar
FILE.save(USER,"conf/user","q")
LOG.print(text.registerSuccessed..": "..res.message)
else
LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")