Commit eef4f8261b2127e61b8b48dcc8a9dbcd6a7ed0f5

Authored by 陆恒
1 parent bf38495c
Exists in master

提交接口

src/HttpServer/logic/datadef.go
@@ -9,15 +9,13 @@ package logic @@ -9,15 +9,13 @@ package logic
9 //"107":"签到罐" 9 //"107":"签到罐"
10 10
11 type UserLoginReq struct { 11 type UserLoginReq struct {
12 -  
13 } 12 }
14 13
15 type UserLoginData struct { 14 type UserLoginData struct {
16 - Isnew int `json:"isnew"`  
17 - Walletgold int `json:"walletgold"`  
18 - Guangold int `json:"guangold"`  
19 - PlayerData string `json:"playerData"`  
20 - 15 + Isnew int `json:"isnew"`
  16 + Walletgold int `json:"walletgold"`
  17 + Guangold int `json:"guangold"`
  18 + PlayerData string `json:"playerData"`
21 } 19 }
22 20
23 type UserLoginResp struct { 21 type UserLoginResp struct {
@@ -26,6 +24,50 @@ type UserLoginResp struct { @@ -26,6 +24,50 @@ type UserLoginResp struct {
26 Data UserLoginData `json:"data"` 24 Data UserLoginData `json:"data"`
27 } 25 }
28 26
  27 +type UploaduserbasicinfoReq struct {
  28 + Nickname string `json:"nickname"`
  29 + Headurl string `json:"headurl"`
  30 +}
  31 +
  32 +type UploaduserbasicinfoData struct {
  33 + Isnew int `json:"isnew"`
  34 + Walletgold int `json:"walletgold"`
  35 + Guangold int `json:"guangold"`
  36 + PlayerData string `json:"playerData"`
  37 +}
  38 +
  39 +type UploaduserbasicinfoResp struct {
  40 + Code int `json:"code"`
  41 + Message string `json:"message"`
  42 + Data UploaduserbasicinfoData `json:"data"`
  43 +}
  44 +
  45 +type UpdatedataReq struct {
  46 + PlayerData string `json:"playerData"`
  47 +}
  48 +
  49 +type UpdatedataData struct {
  50 +}
  51 +
  52 +type UpdatedataResp struct {
  53 + Code int `json:"code"`
  54 + Message string `json:"message"`
  55 + Data UpdatedataData `json:"data"`
  56 +}
  57 +
  58 +type SyncuserdataData struct {
  59 + Walletgold int `json:"walletgold"`
  60 + Guangold int `json:"guangold"`
  61 + Sumloginday int `json:"sumloginday"`
  62 + Nowtime int `json:"nowtime"`
  63 +}
  64 +
  65 +type SyncuserdataResp struct {
  66 + Code int `json:"code"`
  67 + Message string `json:"message"`
  68 + Data SyncuserdataData `json:"data"`
  69 +}
  70 +
29 type GetuserdataReq struct { 71 type GetuserdataReq struct {
30 Gameid string `json:"gameid"` 72 Gameid string `json:"gameid"`
31 Channel string `json:"channel"` 73 Channel string `json:"channel"`
@@ -334,10 +376,13 @@ type WithDrawDesc struct { @@ -334,10 +376,13 @@ type WithDrawDesc struct {
334 376
335 //玩家数据 377 //玩家数据
336 type UserData struct { 378 type UserData struct {
337 - Userid string //玩家w唯一id 379 + Userid string //玩家w唯一id
338 Lv int //玩家当前等级 380 Lv int //玩家当前等级
339 LvRewardGet int //当前等级奖励是否已经领取 1未领取 2普通领取 3双倍领取 381 LvRewardGet int //当前等级奖励是否已经领取 1未领取 2普通领取 3双倍领取
340 Exp int //玩家当前经验值 382 Exp int //玩家当前经验值
  383 + NickName string //昵称
  384 + HeadUrl string //头像
  385 + RegTime int //注册时间
341 GuanGold int //玩家存钱罐中金币数量 386 GuanGold int //玩家存钱罐中金币数量
342 RealGold int //玩家实际金币数量(可用于提现的) 387 RealGold int //玩家实际金币数量(可用于提现的)
343 WatchAddsTime int //当天剩余红包次数 初始化50次 388 WatchAddsTime int //当天剩余红包次数 初始化50次
src/HttpServer/logic/function.go
@@ -307,6 +307,9 @@ func InitUserInfo(resp *UserLoginResp, uniqueuid ,gameid ,channel string,uuid in @@ -307,6 +307,9 @@ func InitUserInfo(resp *UserLoginResp, uniqueuid ,gameid ,channel string,uuid in
307 initdata.LeftFreeRB = FREE_REDBAG_NUM 307 initdata.LeftFreeRB = FREE_REDBAG_NUM
308 initdata.UpLvCostTime = 0 308 initdata.UpLvCostTime = 0
309 initdata.UpLvCostTimeSec = int(time.Now().Unix()) 309 initdata.UpLvCostTimeSec = int(time.Now().Unix())
  310 + initdata.NickName = "著名沙雕"
  311 + initdata.HeadUrl = "1"
  312 + initdata.RegTime = int(time.Now().Unix())
310 313
311 for _, val := range jsonconf.GetJsonConf().RmbConfig { 314 for _, val := range jsonconf.GetJsonConf().RmbConfig {
312 var tmp WithDrawDesc 315 var tmp WithDrawDesc
src/HttpServer/logic/httpserver.go
@@ -45,7 +45,12 @@ func startServerHttpServe() { @@ -45,7 +45,12 @@ func startServerHttpServe() {
45 http.HandleFunc("/eliminatestar/addcoin", Addcoin) //测试接口 45 http.HandleFunc("/eliminatestar/addcoin", Addcoin) //测试接口
46 http.HandleFunc("/eliminatestar/clear", ClearData) //清除账号 46 http.HandleFunc("/eliminatestar/clear", ClearData) //清除账号
47 //---------------------------------------------------------------------------------------- 47 //----------------------------------------------------------------------------------------
48 - http.HandleFunc("/eliminatestar/login", UserLogin) //登录 48 + http.HandleFunc("/russiaxiaoxiao/login", UserLogin) //登录
  49 + http.HandleFunc("/russiaxiaoxiao/uploaduserbasicinfo", Uploaduserbasicinfo) //上传基本信息
  50 + http.HandleFunc("/russiaxiaoxiao/updatedata", Updatedata) //update数据
  51 + http.HandleFunc("/russiaxiaoxiao/syncuserdata", Syncuserdata) //同步玩家数据
  52 +
  53 + //..........................................
49 http.HandleFunc("/eliminatestar/getuserdata", Getuserdata) //获取玩家数据 54 http.HandleFunc("/eliminatestar/getuserdata", Getuserdata) //获取玩家数据
50 http.HandleFunc("/eliminatestar/watchads", Watchads) //观看激励视频 55 http.HandleFunc("/eliminatestar/watchads", Watchads) //观看激励视频
51 http.HandleFunc("/eliminatestar/queryguaninfo", Queryguaninfo) //获取存钱罐数据 56 http.HandleFunc("/eliminatestar/queryguaninfo", Queryguaninfo) //获取存钱罐数据
@@ -407,7 +412,7 @@ func Onlinentf(w http.ResponseWriter, r *http.Request) { @@ -407,7 +412,7 @@ func Onlinentf(w http.ResponseWriter, r *http.Request) {
407 s := string(result) 412 s := string(result)
408 logger.Info("Onlinentf , body:%v,uuid=%v", s, Uuid) 413 logger.Info("Onlinentf , body:%v,uuid=%v", s, Uuid)
409 414
410 -// HandlerOnlinentf(w, s, Uuid) 415 + // HandlerOnlinentf(w, s, Uuid)
411 } 416 }
412 417
413 func Getcashrecord(w http.ResponseWriter, r *http.Request) { 418 func Getcashrecord(w http.ResponseWriter, r *http.Request) {
@@ -512,7 +517,7 @@ func Getguangold(w http.ResponseWriter, r *http.Request) { @@ -512,7 +517,7 @@ func Getguangold(w http.ResponseWriter, r *http.Request) {
512 s := string(result) 517 s := string(result)
513 logger.Info("Getguangold , body:%v,uuid=%v", s, Uuid) 518 logger.Info("Getguangold , body:%v,uuid=%v", s, Uuid)
514 519
515 -// HandlerGetguangold(w, s, Uuid) 520 + // HandlerGetguangold(w, s, Uuid)
516 } 521 }
517 522
518 func Queryguaninfo(w http.ResponseWriter, r *http.Request) { 523 func Queryguaninfo(w http.ResponseWriter, r *http.Request) {
@@ -562,6 +567,87 @@ func Watchads(w http.ResponseWriter, r *http.Request) { @@ -562,6 +567,87 @@ func Watchads(w http.ResponseWriter, r *http.Request) {
562 //HandlerWatchads(w, s, Uuid) 567 //HandlerWatchads(w, s, Uuid)
563 } 568 }
564 569
  570 +func Syncuserdata(w http.ResponseWriter, r *http.Request) {
  571 +
  572 + //gameid := ""
  573 + //channel := ""
  574 + uniqueid := ""
  575 + Uuid := 0
  576 + if len(r.Header) > 0 {
  577 + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid"))
  578 + // gameid = r.Header.Get("Gameid")
  579 + //channel = r.Header.Get("Channel")
  580 + uniqueid = r.Header.Get("Uuid") + r.Header.Get("Channel")
  581 + }
  582 +
  583 + if Uuid == 0 {
  584 + SetHeader(w)
  585 + logger.Error("Uuid is nil!")
  586 + return
  587 + }
  588 + result, _ := ioutil.ReadAll(r.Body)
  589 + r.Body.Close()
  590 +
  591 + s := string(result)
  592 + logger.Info("Syncuserdata , body:%v,uuid=%v", s, uniqueid)
  593 +
  594 + HandlerSyncuserdata(w, s, uniqueid)
  595 +}
  596 +
  597 +func Updatedata(w http.ResponseWriter, r *http.Request) {
  598 +
  599 + //gameid := ""
  600 + //channel := ""
  601 + uniqueid := ""
  602 + Uuid := 0
  603 + if len(r.Header) > 0 {
  604 + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid"))
  605 + // gameid = r.Header.Get("Gameid")
  606 + //channel = r.Header.Get("Channel")
  607 + uniqueid = r.Header.Get("Uuid") + r.Header.Get("Channel")
  608 + }
  609 +
  610 + if Uuid == 0 {
  611 + SetHeader(w)
  612 + logger.Error("Uuid is nil!")
  613 + return
  614 + }
  615 + result, _ := ioutil.ReadAll(r.Body)
  616 + r.Body.Close()
  617 +
  618 + s := string(result)
  619 + logger.Info("Updatedata , body:%v,uuid=%v", s, uniqueid)
  620 +
  621 + HandlerUpdatedata(w, s, uniqueid)
  622 +}
  623 +
  624 +func Uploaduserbasicinfo(w http.ResponseWriter, r *http.Request) {
  625 +
  626 + //gameid := ""
  627 + //channel := ""
  628 + uniqueid := ""
  629 + Uuid := 0
  630 + if len(r.Header) > 0 {
  631 + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid"))
  632 + // gameid = r.Header.Get("Gameid")
  633 + //channel = r.Header.Get("Channel")
  634 + uniqueid = r.Header.Get("Uuid") + r.Header.Get("Channel")
  635 + }
  636 +
  637 + if Uuid == 0 {
  638 + SetHeader(w)
  639 + logger.Error("Uuid is nil!")
  640 + return
  641 + }
  642 + result, _ := ioutil.ReadAll(r.Body)
  643 + r.Body.Close()
  644 +
  645 + s := string(result)
  646 + logger.Info("Uploaduserbasicinfo , body:%v,uuid=%v", s, uniqueid)
  647 +
  648 + HandlerUploaduserbasicinfo(w, s, uniqueid)
  649 +}
  650 +
565 func UserLogin(w http.ResponseWriter, r *http.Request) { 651 func UserLogin(w http.ResponseWriter, r *http.Request) {
566 652
567 gameid := "" 653 gameid := ""
@@ -586,7 +672,7 @@ func UserLogin(w http.ResponseWriter, r *http.Request) { @@ -586,7 +672,7 @@ func UserLogin(w http.ResponseWriter, r *http.Request) {
586 s := string(result) 672 s := string(result)
587 logger.Info("UserLogin , body:%v,uuid=%v", s, uniqueid) 673 logger.Info("UserLogin , body:%v,uuid=%v", s, uniqueid)
588 674
589 - HandlerLogin(w, s, uniqueid,gameid,channel,Uuid) 675 + HandlerLogin(w, s, uniqueid, gameid, channel, Uuid)
590 } 676 }
591 677
592 func Getuserdata(w http.ResponseWriter, r *http.Request) { 678 func Getuserdata(w http.ResponseWriter, r *http.Request) {
src/HttpServer/logic/logic.go
@@ -7,9 +7,111 @@ import ( @@ -7,9 +7,111 @@ import (
7 "encoding/json" 7 "encoding/json"
8 "fmt" 8 "fmt"
9 "net/http" 9 "net/http"
  10 + "time"
10 ) 11 )
11 12
12 -func HandlerLogin(w http.ResponseWriter, data string, uniqueuuid ,gameid,channel string,uuid int) { 13 +func HandlerSyncuserdata(w http.ResponseWriter, data string, uniqueuuid string) {
  14 + SetHeader(w)
  15 +
  16 + var resp SyncuserdataResp
  17 + resp.Code = 0
  18 + resp.Message = "success"
  19 +
  20 + for {
  21 +
  22 + uinfo, err := GetUserInfo(uniqueuuid)
  23 +
  24 + if err != nil {
  25 + logger.Info("GetUserInfo HandlerSyncuserdata data failed:%v,for:%v", err, data)
  26 + resp.Message = "GetUserInfo failed"
  27 + resp.Code = 1
  28 + break
  29 + }
  30 +
  31 + resp.Data.Walletgold = uinfo.RealGold
  32 + resp.Data.Guangold = uinfo.GuanGold
  33 + resp.Data.Sumloginday = uinfo.SumLoginDay
  34 + resp.Data.Nowtime = int(time.Now().Unix())
  35 + break
  36 + }
  37 +
  38 + //回包
  39 + respstr, _ := json.Marshal(&resp)
  40 + fmt.Fprint(w, string(respstr))
  41 +}
  42 +
  43 +func HandlerUpdatedata(w http.ResponseWriter, data string, uniqueuuid string) {
  44 + SetHeader(w)
  45 +
  46 + var resp UpdatedataResp
  47 + resp.Code = 0
  48 + resp.Message = "success"
  49 + var rdata UpdatedataReq
  50 + err := json.Unmarshal([]byte(data), &rdata)
  51 + for {
  52 +
  53 + if err != nil {
  54 + logger.Info("json decode HandlerUpdatedata data failed:%v,for:%v", err, data)
  55 + resp.Message = "json解析错误"
  56 + resp.Code = ERROR_JSONUNMASH_ERROR
  57 + break
  58 + }
  59 +
  60 + //直接保存
  61 + err := SaveUserSelfData(uniqueuuid, rdata.PlayerData)
  62 + if err != nil {
  63 + logger.Info("SaveUserSelfData HandlerUpdatedata data failed:%v,for:%v", err, data)
  64 + resp.Message = "保存失败"
  65 + resp.Code = ERROR_JSONUNMASH_ERROR
  66 + break
  67 + }
  68 +
  69 + break
  70 + }
  71 +
  72 + //回包
  73 + respstr, _ := json.Marshal(&resp)
  74 + fmt.Fprint(w, string(respstr))
  75 +}
  76 +
  77 +func HandlerUploaduserbasicinfo(w http.ResponseWriter, data string, uniqueuuid string) {
  78 + SetHeader(w)
  79 +
  80 + var resp UploaduserbasicinfoResp
  81 + resp.Code = 0
  82 + resp.Message = "success"
  83 + var rdata UploaduserbasicinfoReq
  84 + err := json.Unmarshal([]byte(data), &rdata)
  85 + for {
  86 +
  87 + if err != nil {
  88 + logger.Info("json decode HandlerUploaduserbasicinfo data failed:%v,for:%v", err, data)
  89 + resp.Message = "json解析错误"
  90 + resp.Code = ERROR_JSONUNMASH_ERROR
  91 + break
  92 + }
  93 + uinfo, err := GetUserInfo(uniqueuuid)
  94 +
  95 + if err != nil {
  96 + logger.Info("GetUserInfo HandlerUploaduserbasicinfo data failed:%v,for:%v", err, data)
  97 + resp.Message = "GetUserInfo failed"
  98 + resp.Code = 1
  99 + break
  100 + }
  101 +
  102 + uinfo.HeadUrl = rdata.Headurl
  103 + uinfo.NickName = rdata.Nickname
  104 +
  105 + SaveUserInfo(uinfo, uniqueuuid)
  106 + break
  107 + }
  108 +
  109 + //回包
  110 + respstr, _ := json.Marshal(&resp)
  111 + fmt.Fprint(w, string(respstr))
  112 +}
  113 +
  114 +func HandlerLogin(w http.ResponseWriter, data string, uniqueuuid, gameid, channel string, uuid int) {
13 SetHeader(w) 115 SetHeader(w)
14 116
15 var resp UserLoginResp 117 var resp UserLoginResp
@@ -29,9 +131,8 @@ func HandlerLogin(w http.ResponseWriter, data string, uniqueuuid ,gameid,channel @@ -29,9 +131,8 @@ func HandlerLogin(w http.ResponseWriter, data string, uniqueuuid ,gameid,channel
29 if !isexist { 131 if !isexist {
30 //不存在 132 //不存在
31 133
32 - //不存在老的数据 之间走新号流程  
33 - err = InitUserInfo(&resp, uniqueuuid,gameid,channel,uuid)  
34 - 134 + //不存在老的数据 之间走新号流程
  135 + err = InitUserInfo(&resp, uniqueuuid, gameid, channel, uuid)
35 136
36 } else { 137 } else {
37 uinfo, err := GetUserInfo(uniqueuuid) 138 uinfo, err := GetUserInfo(uniqueuuid)
@@ -43,15 +144,13 @@ func HandlerLogin(w http.ResponseWriter, data string, uniqueuuid ,gameid,channel @@ -43,15 +144,13 @@ func HandlerLogin(w http.ResponseWriter, data string, uniqueuuid ,gameid,channel
43 break 144 break
44 } 145 }
45 146
46 -  
47 -  
48 resp.Data.Guangold = uinfo.GuanGold 147 resp.Data.Guangold = uinfo.GuanGold
49 resp.Data.Walletgold = uinfo.RealGold 148 resp.Data.Walletgold = uinfo.RealGold
50 149
51 - resp.Data.Isnew= 0 150 + resp.Data.Isnew = 0
52 } 151 }
53 152
54 - pdata,err := GetUserSelfData(uniqueuuid) 153 + pdata, err := GetUserSelfData(uniqueuuid)
55 154
56 if err != nil { 155 if err != nil {
57 logger.Info("GetUserSelfData HandlerLogin data failed:%v,for:%v", err, data) 156 logger.Info("GetUserSelfData HandlerLogin data failed:%v,for:%v", err, data)
@@ -61,7 +160,6 @@ func HandlerLogin(w http.ResponseWriter, data string, uniqueuuid ,gameid,channel @@ -61,7 +160,6 @@ func HandlerLogin(w http.ResponseWriter, data string, uniqueuuid ,gameid,channel
61 } 160 }
62 resp.Data.PlayerData = pdata 161 resp.Data.PlayerData = pdata
63 162
64 -  
65 resp.Code = ERROR_OK 163 resp.Code = ERROR_OK
66 break 164 break
67 } 165 }
@@ -71,4 +169,4 @@ func HandlerLogin(w http.ResponseWriter, data string, uniqueuuid ,gameid,channel @@ -71,4 +169,4 @@ func HandlerLogin(w http.ResponseWriter, data string, uniqueuuid ,gameid,channel
71 fmt.Fprint(w, string(respstr)) 169 fmt.Fprint(w, string(respstr))
72 170
73 logger.Info("###HandlerLogin###rdata:%v", string(respstr)) 171 logger.Info("###HandlerLogin###rdata:%v", string(respstr))
74 -}  
75 \ No newline at end of file 172 \ No newline at end of file
  173 +}