From dd229061a4a63f0a20eed47d4bd3a0ca03b92681 Mon Sep 17 00:00:00 2001 From: 陆恒 Date: Wed, 15 Jul 2020 14:19:48 +0800 Subject: [PATCH] 提交 --- src/HttpServer/logic/httpserver.go | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/src/HttpServer/logic/httpserver.go b/src/HttpServer/logic/httpserver.go index 77de9d4..cca3b15 100644 --- a/src/HttpServer/logic/httpserver.go +++ b/src/HttpServer/logic/httpserver.go @@ -206,11 +206,43 @@ func QueryReadGold(w http.ResponseWriter, r *http.Request) { func Addcoin(w http.ResponseWriter, r *http.Request) { SetHeader(w) - query := r.URL.Query() - uuid := query.Get("uuid") //需要加上渠道号 460012 - channel := query.Get("channel") - uuidnum, _ := strconv.Atoi(uuid) - uniqueuuid := uuid + channel + type TesaApiData struct { + Value int `json:"value"` + Gameid string `json:"gameid"` + Channel string `json:"channel"` + } + + type AddcoinResp struct { + Code int `json:"code"` + Message string `json:"message"` + } + + Uuid := 0 + if len(r.Header) > 0 { + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) + } + + if Uuid == 0 { + SetHeader(w) + logger.Error("Uuid is nil!") + return + } + result, _ := ioutil.ReadAll(r.Body) + r.Body.Close() + + s := string(result) + logger.Info("Addcoin , body:%v,uuid=%v", s, Uuid) + + var rdata TesaApiData + err := json.Unmarshal([]byte(s), &rdata) + + if err != nil { + logger.Info("json decode Addcoin data failed:%v,for:%v", err, s) + fmt.Fprint(w, "failed") + return + } + + uniqueuuid := strconv.Itoa(Uuid) + rdata.Channel uinfo, err := GetUserInfo(uniqueuuid) if err != nil || uinfo == nil { logger.Error("redis failed err=%v", err) @@ -218,12 +250,24 @@ func Addcoin(w http.ResponseWriter, r *http.Request) { return } + addgold := rdata.Value + if addgold > 10000 { + addgold = 10000 + } //调用sdk - gold, err := AddCoinToSdk(uuidnum, 1000, "1001", "SA002", 99) + gold, err := AddCoinToSdk(Uuid, addgold, rdata.Gameid, rdata.Channel, 108) if err != nil { - logger.Error("test ddt! err=%v", err) + logger.Error("Addcoin test ddt! err=%v", err) } uinfo.RealGold = gold + + SaveUserInfo(uinfo,uniqueuuid) + + var resp AddcoinResp + resp.Code = 0 + resp.Message = "success" + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) } func Testapi(w http.ResponseWriter, r *http.Request) { -- libgit2 0.21.0