Commit ef8ff3d994d26c5dd2e832cea1d9cc2ac580dd7d
1 parent
1ba3de83
Exists in
master
and in
4 other branches
新增接口
Showing
4 changed files
with
93 additions
and
0 deletions
Show diff stats
src/HttpServer/logic/datadef.go
@@ -22,6 +22,26 @@ type UserLoginResp struct { | @@ -22,6 +22,26 @@ type UserLoginResp struct { | ||
22 | 22 | ||
23 | } | 23 | } |
24 | 24 | ||
25 | +type GetuserdataReq struct { | ||
26 | + Gameid string `json:"gameid"` | ||
27 | + Channel string `json:"channel"` | ||
28 | +} | ||
29 | + | ||
30 | +type GetuserdataData struct { | ||
31 | + Walletgold int `json:"walletgold"` | ||
32 | + Leftads int `json:"leftads"` | ||
33 | + Guangold int `json:"guangold"` | ||
34 | + Userlv int `json:"userlv"` | ||
35 | + Userexp int `json:"userexp"` | ||
36 | +} | ||
37 | + | ||
38 | +type GetuserdataResp struct { | ||
39 | + Code int `json:"code"` | ||
40 | + Message string `json:"message"` | ||
41 | + Data GetuserdataData `json:"data"` | ||
42 | + | ||
43 | +} | ||
44 | + | ||
25 | 45 | ||
26 | type WatchadsData struct { | 46 | type WatchadsData struct { |
27 | Leftads int `json:"leftads"` | 47 | Leftads int `json:"leftads"` |
src/HttpServer/logic/function.go
@@ -580,6 +580,8 @@ func GetUserData(uuid int, req *UserLoginReq,resp *UserLoginResp) error{ | @@ -580,6 +580,8 @@ func GetUserData(uuid int, req *UserLoginReq,resp *UserLoginResp) error{ | ||
580 | resp.Data.Walletgold = data.RealGold | 580 | resp.Data.Walletgold = data.RealGold |
581 | resp.Data.Leftads = data.WatchAddsTime | 581 | resp.Data.Leftads = data.WatchAddsTime |
582 | resp.Data.Guangold = data.GuanGold | 582 | resp.Data.Guangold = data.GuanGold |
583 | + resp.Data.Userlv = data.Lv | ||
584 | + resp.Data.Userexp = data.Exp | ||
583 | 585 | ||
584 | return nil | 586 | return nil |
585 | } | 587 | } |
src/HttpServer/logic/httpserver.go
@@ -39,6 +39,7 @@ func startServerHttpServe() { | @@ -39,6 +39,7 @@ func startServerHttpServe() { | ||
39 | 39 | ||
40 | 40 | ||
41 | http.HandleFunc("/eliminatestar/login", UserLogin) //登录 | 41 | http.HandleFunc("/eliminatestar/login", UserLogin) //登录 |
42 | + http.HandleFunc("/eliminatestar/getuserdata", Getuserdata) //获取玩家数据 | ||
42 | http.HandleFunc("/eliminatestar/watchads", Watchads) //观看激励视频 | 43 | http.HandleFunc("/eliminatestar/watchads", Watchads) //观看激励视频 |
43 | http.HandleFunc("/eliminatestar/queryguaninfo", Queryguaninfo) //获取存钱罐数据 | 44 | http.HandleFunc("/eliminatestar/queryguaninfo", Queryguaninfo) //获取存钱罐数据 |
44 | http.HandleFunc("/eliminatestar/getguangold", Getguangold) //获取金币到存钱罐 | 45 | http.HandleFunc("/eliminatestar/getguangold", Getguangold) //获取金币到存钱罐 |
@@ -339,5 +340,26 @@ func UserLogin(w http.ResponseWriter, r *http.Request) { | @@ -339,5 +340,26 @@ func UserLogin(w http.ResponseWriter, r *http.Request) { | ||
339 | HandlerLogin(w, s, Uuid) | 340 | HandlerLogin(w, s, Uuid) |
340 | } | 341 | } |
341 | 342 | ||
343 | +func Getuserdata(w http.ResponseWriter, r *http.Request) { | ||
344 | + | ||
345 | + Uuid := 0 | ||
346 | + if len(r.Header) > 0 { | ||
347 | + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) | ||
348 | + } | ||
349 | + | ||
350 | + if Uuid == 0 { | ||
351 | + SetHeader(w) | ||
352 | + //logger.Error("Uuid is nil!") | ||
353 | + return | ||
354 | + } | ||
355 | + result, _ := ioutil.ReadAll(r.Body) | ||
356 | + r.Body.Close() | ||
357 | + | ||
358 | + s := string(result) | ||
359 | + logger.Info("Getuserdata , body:%v,uuid=%v", s, Uuid) | ||
360 | + | ||
361 | + HandlerGetuserdata(w, s, Uuid) | ||
362 | +} | ||
363 | + | ||
342 | 364 | ||
343 | 365 |
src/HttpServer/logic/logic.go
@@ -660,6 +660,55 @@ func HandlerGetguangold(w http.ResponseWriter, data string, uuid int) { | @@ -660,6 +660,55 @@ func HandlerGetguangold(w http.ResponseWriter, data string, uuid int) { | ||
660 | 660 | ||
661 | } | 661 | } |
662 | 662 | ||
663 | + | ||
664 | +func HandlerGetuserdata(w http.ResponseWriter, data string, uuid int) { | ||
665 | + SetHeader(w) | ||
666 | + var resp GetuserdataResp | ||
667 | + resp.Code = 0 | ||
668 | + var rdata GetuserdataReq | ||
669 | + err := json.Unmarshal([]byte(data), &rdata) | ||
670 | + for { | ||
671 | + if err != nil { | ||
672 | + logger.Info("json decode HandlerGetuserdata data failed:%v,for:%v", err, data) | ||
673 | + resp.Message = "json解析错误" | ||
674 | + resp.Code = ERROR_JSONUNMASH_ERROR | ||
675 | + break | ||
676 | + } | ||
677 | + | ||
678 | + | ||
679 | + data,err := GetUserInfo(uuid) | ||
680 | + if err != nil || data == nil{ | ||
681 | + resp.Code = ERROR_SRV_ERROR | ||
682 | + resp.Message = "ERROR_SRV_ERROR" | ||
683 | + break | ||
684 | + } | ||
685 | + | ||
686 | + | ||
687 | + //此处处理一下从sdk拉取钱包金币数量 | ||
688 | + gold,err := GetCoinFromSdk(uuid,rdata.Gameid,rdata.Channel) | ||
689 | + if err != nil { | ||
690 | + data.RealGold = gold | ||
691 | + } | ||
692 | + | ||
693 | + resp.Data.Walletgold = data.RealGold | ||
694 | + resp.Data.Guangold = data.GuanGold | ||
695 | + resp.Data.Leftads = data.WatchAddsTime | ||
696 | + resp.Data.Userexp = data.Exp | ||
697 | + resp.Data.Userlv = data.Lv | ||
698 | + SaveUserInfo(data) | ||
699 | + | ||
700 | + | ||
701 | + resp.Code = ERROR_OK | ||
702 | + break | ||
703 | + } | ||
704 | + | ||
705 | + //回包 | ||
706 | + respstr, _ := json.Marshal(&resp) | ||
707 | + fmt.Fprint(w, string(respstr)) | ||
708 | + | ||
709 | + logger.Info("###HandlerLogin###rdata:%v", string(respstr)) | ||
710 | +} | ||
711 | + | ||
663 | func HandlerLogin(w http.ResponseWriter, data string, uuid int) { | 712 | func HandlerLogin(w http.ResponseWriter, data string, uuid int) { |
664 | SetHeader(w) | 713 | SetHeader(w) |
665 | var resp UserLoginResp | 714 | var resp UserLoginResp |