Commit dd229061a4a63f0a20eed47d4bd3a0ca03b92681
1 parent
5e6918b1
Exists in
master
and in
1 other branch
提交
Showing
1 changed file
with
51 additions
and
7 deletions
Show diff stats
src/HttpServer/logic/httpserver.go
@@ -206,11 +206,43 @@ func QueryReadGold(w http.ResponseWriter, r *http.Request) { | @@ -206,11 +206,43 @@ func QueryReadGold(w http.ResponseWriter, r *http.Request) { | ||
206 | 206 | ||
207 | func Addcoin(w http.ResponseWriter, r *http.Request) { | 207 | func Addcoin(w http.ResponseWriter, r *http.Request) { |
208 | SetHeader(w) | 208 | SetHeader(w) |
209 | - query := r.URL.Query() | ||
210 | - uuid := query.Get("uuid") //需要加上渠道号 460012 | ||
211 | - channel := query.Get("channel") | ||
212 | - uuidnum, _ := strconv.Atoi(uuid) | ||
213 | - uniqueuuid := uuid + channel | 209 | + type TesaApiData struct { |
210 | + Value int `json:"value"` | ||
211 | + Gameid string `json:"gameid"` | ||
212 | + Channel string `json:"channel"` | ||
213 | + } | ||
214 | + | ||
215 | + type AddcoinResp struct { | ||
216 | + Code int `json:"code"` | ||
217 | + Message string `json:"message"` | ||
218 | + } | ||
219 | + | ||
220 | + Uuid := 0 | ||
221 | + if len(r.Header) > 0 { | ||
222 | + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) | ||
223 | + } | ||
224 | + | ||
225 | + if Uuid == 0 { | ||
226 | + SetHeader(w) | ||
227 | + logger.Error("Uuid is nil!") | ||
228 | + return | ||
229 | + } | ||
230 | + result, _ := ioutil.ReadAll(r.Body) | ||
231 | + r.Body.Close() | ||
232 | + | ||
233 | + s := string(result) | ||
234 | + logger.Info("Addcoin , body:%v,uuid=%v", s, Uuid) | ||
235 | + | ||
236 | + var rdata TesaApiData | ||
237 | + err := json.Unmarshal([]byte(s), &rdata) | ||
238 | + | ||
239 | + if err != nil { | ||
240 | + logger.Info("json decode Addcoin data failed:%v,for:%v", err, s) | ||
241 | + fmt.Fprint(w, "failed") | ||
242 | + return | ||
243 | + } | ||
244 | + | ||
245 | + uniqueuuid := strconv.Itoa(Uuid) + rdata.Channel | ||
214 | uinfo, err := GetUserInfo(uniqueuuid) | 246 | uinfo, err := GetUserInfo(uniqueuuid) |
215 | if err != nil || uinfo == nil { | 247 | if err != nil || uinfo == nil { |
216 | logger.Error("redis failed err=%v", err) | 248 | logger.Error("redis failed err=%v", err) |
@@ -218,12 +250,24 @@ func Addcoin(w http.ResponseWriter, r *http.Request) { | @@ -218,12 +250,24 @@ func Addcoin(w http.ResponseWriter, r *http.Request) { | ||
218 | return | 250 | return |
219 | } | 251 | } |
220 | 252 | ||
253 | + addgold := rdata.Value | ||
254 | + if addgold > 10000 { | ||
255 | + addgold = 10000 | ||
256 | + } | ||
221 | //调用sdk | 257 | //调用sdk |
222 | - gold, err := AddCoinToSdk(uuidnum, 1000, "1001", "SA002", 99) | 258 | + gold, err := AddCoinToSdk(Uuid, addgold, rdata.Gameid, rdata.Channel, 108) |
223 | if err != nil { | 259 | if err != nil { |
224 | - logger.Error("test ddt! err=%v", err) | 260 | + logger.Error("Addcoin test ddt! err=%v", err) |
225 | } | 261 | } |
226 | uinfo.RealGold = gold | 262 | uinfo.RealGold = gold |
263 | + | ||
264 | + SaveUserInfo(uinfo,uniqueuuid) | ||
265 | + | ||
266 | + var resp AddcoinResp | ||
267 | + resp.Code = 0 | ||
268 | + resp.Message = "success" | ||
269 | + respstr, _ := json.Marshal(&resp) | ||
270 | + fmt.Fprint(w, string(respstr)) | ||
227 | } | 271 | } |
228 | 272 | ||
229 | func Testapi(w http.ResponseWriter, r *http.Request) { | 273 | func Testapi(w http.ResponseWriter, r *http.Request) { |