Commit 44d0666a9973d701112fff4d3e5acb531c9b25c3
1 parent
2a449103
Exists in
master
and in
4 other branches
提交
Showing
4 changed files
with
152 additions
and
2 deletions
Show diff stats
src/HttpServer/logic/constdef.go
... | ... | @@ -53,6 +53,8 @@ const ( |
53 | 53 | ) |
54 | 54 | |
55 | 55 | const ( |
56 | - WATCH_ADD_DAY_LIMIT = 50 //当天获取红包次数限制 | |
57 | - FREE_REDBAG_NUM = 3 //玩家免费红包次数 | |
56 | + WATCH_ADD_DAY_LIMIT = 50 //当天获取红包次数限制 | |
57 | + FREE_REDBAG_NUM = 3 //玩家免费红包次数 | |
58 | + READGOLDMULTI = 10 //阅读量到金币转化倍数 | |
59 | + SDKOPGOLD_TYPEWE = 302 //微转发金币类型 | |
58 | 60 | ) | ... | ... |
src/HttpServer/logic/datadef.go
... | ... | @@ -223,6 +223,26 @@ type QuerysigndataData struct { |
223 | 223 | IssignToday int `json:"issignToday"` |
224 | 224 | } |
225 | 225 | |
226 | +type QueryReadGoldData struct { | |
227 | + Goldnum int `json:"goldnum"` | |
228 | +} | |
229 | + | |
230 | +type QueryReadGoldResp struct { | |
231 | + Code int `json:"code"` | |
232 | + Message string `json:"message"` | |
233 | + Data QueryReadGoldData `json:"data"` | |
234 | +} | |
235 | + | |
236 | +type FetchreadgoldData struct { | |
237 | + Goldnum int `json:"goldnum"` | |
238 | +} | |
239 | + | |
240 | +type FetchreadgoldResp struct { | |
241 | + Code int `json:"code"` | |
242 | + Message string `json:"message"` | |
243 | + Data FetchreadgoldData `json:"data"` | |
244 | +} | |
245 | + | |
226 | 246 | type QuerysigndataResp struct { |
227 | 247 | Code int `json:"code"` |
228 | 248 | Message string `json:"message"` | ... | ... |
src/HttpServer/logic/httpserver.go
... | ... | @@ -63,6 +63,8 @@ func startServerHttpServe() { |
63 | 63 | http.HandleFunc("/eliminatestar/usersign", Usersign) //玩家签到 |
64 | 64 | // |
65 | 65 | http.HandleFunc("/eliminatestar/readNumUpload", ReadNumUpload) //阅读量上报 |
66 | + http.HandleFunc("/eliminatestar/queryreadgold", QueryReadGold) //获取微转发金币数 | |
67 | + http.HandleFunc("/eliminatestar/fetchreadgold", Fetchreadgold) //领取微转发金币数 | |
66 | 68 | |
67 | 69 | err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) |
68 | 70 | CheckErr(err) |
... | ... | @@ -160,6 +162,48 @@ func Querysigndata(w http.ResponseWriter, r *http.Request) { |
160 | 162 | HandlerQuerysigndata(w, s, Uuid) |
161 | 163 | } |
162 | 164 | |
165 | +func Fetchreadgold(w http.ResponseWriter, r *http.Request) { | |
166 | + | |
167 | + Uuid := 0 | |
168 | + if len(r.Header) > 0 { | |
169 | + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) | |
170 | + } | |
171 | + | |
172 | + if Uuid == 0 { | |
173 | + SetHeader(w) | |
174 | + //logger.Error("Uuid is nil!") | |
175 | + return | |
176 | + } | |
177 | + result, _ := ioutil.ReadAll(r.Body) | |
178 | + r.Body.Close() | |
179 | + | |
180 | + s := string(result) | |
181 | + logger.Info("Fetchreadgold , body:%v,uuid=%v", s, Uuid) | |
182 | + | |
183 | + HandlerFetchreadgold(w, s, Uuid) | |
184 | +} | |
185 | + | |
186 | +func QueryReadGold(w http.ResponseWriter, r *http.Request) { | |
187 | + | |
188 | + Uuid := 0 | |
189 | + if len(r.Header) > 0 { | |
190 | + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) | |
191 | + } | |
192 | + | |
193 | + if Uuid == 0 { | |
194 | + SetHeader(w) | |
195 | + //logger.Error("Uuid is nil!") | |
196 | + return | |
197 | + } | |
198 | + result, _ := ioutil.ReadAll(r.Body) | |
199 | + r.Body.Close() | |
200 | + | |
201 | + s := string(result) | |
202 | + logger.Info("QueryReadGold , body:%v,uuid=%v", s, Uuid) | |
203 | + | |
204 | + HandlerQueryReadGold(w, s, Uuid) | |
205 | +} | |
206 | + | |
163 | 207 | func Addcoin(w http.ResponseWriter, r *http.Request) { |
164 | 208 | SetHeader(w) |
165 | 209 | query := r.URL.Query() | ... | ... |
src/HttpServer/logic/logic.go
... | ... | @@ -228,6 +228,90 @@ func HandlerGetcash(w http.ResponseWriter, data string, uuid int) { |
228 | 228 | |
229 | 229 | } |
230 | 230 | |
231 | +func HandlerFetchreadgold(w http.ResponseWriter, data string, uuid int) { | |
232 | + SetHeader(w) | |
233 | + var resp FetchreadgoldResp | |
234 | + resp.Code = 0 | |
235 | + var rdata CommReq | |
236 | + err := json.Unmarshal([]byte(data), &rdata) | |
237 | + for { | |
238 | + | |
239 | + if err != nil { | |
240 | + logger.Info("json decode HandlerFetchreadgold data failed:%v,for:%v", err, data) | |
241 | + resp.Message = "json解析错误" | |
242 | + resp.Code = ERROR_JSONUNMASH_ERROR | |
243 | + break | |
244 | + } | |
245 | + //需要加上渠道才是唯一的玩家id,不同渠道视为不同数据 | |
246 | + uniqueuuid := strconv.Itoa(uuid) + rdata.Channel | |
247 | + uinfo, err := GetUserInfo(uniqueuuid) | |
248 | + if err != nil || uinfo == nil { | |
249 | + logger.Error("redis failed err=%v", err) | |
250 | + resp.Message = "服务器错误" | |
251 | + resp.Code = ERROR_SRV_ERROR | |
252 | + break | |
253 | + } | |
254 | + | |
255 | + //加金币到后台 | |
256 | + addgold := uinfo.ReadNum * READGOLDMULTI | |
257 | + realgiold, err := AddCoinToSdk(uuid, addgold, rdata.Gameid, rdata.Channel, SDKOPGOLD_TYPEWE) | |
258 | + if err != nil { | |
259 | + logger.Error("HandlerFetchreadgold failed err=%v", err) | |
260 | + resp.Message = "后台加金币失败" | |
261 | + resp.Code = ERROR_SRV_ERROR | |
262 | + } | |
263 | + | |
264 | + uinfo.RealGold = realgiold | |
265 | + uinfo.ReadNum = 0 | |
266 | + | |
267 | + err = SaveUserInfo(uinfo, uniqueuuid) | |
268 | + if err != nil { | |
269 | + logger.Error("HandlerFetchreadgold failed err=%v", err) | |
270 | + } | |
271 | + //resp.Data.Goldnum = uinfo.ReadNum * READGOLDMULTI | |
272 | + | |
273 | + resp.Code = ERROR_OK | |
274 | + break | |
275 | + } | |
276 | + | |
277 | + respstr, _ := json.Marshal(&resp) | |
278 | + fmt.Fprint(w, string(respstr)) | |
279 | +} | |
280 | + | |
281 | +func HandlerQueryReadGold(w http.ResponseWriter, data string, uuid int) { | |
282 | + SetHeader(w) | |
283 | + var resp QueryReadGoldResp | |
284 | + resp.Code = 0 | |
285 | + var rdata CommReq | |
286 | + err := json.Unmarshal([]byte(data), &rdata) | |
287 | + for { | |
288 | + | |
289 | + if err != nil { | |
290 | + logger.Info("json decode HandlerQueryReadGold data failed:%v,for:%v", err, data) | |
291 | + resp.Message = "json解析错误" | |
292 | + resp.Code = ERROR_JSONUNMASH_ERROR | |
293 | + break | |
294 | + } | |
295 | + //需要加上渠道才是唯一的玩家id,不同渠道视为不同数据 | |
296 | + uniqueuuid := strconv.Itoa(uuid) + rdata.Channel | |
297 | + uinfo, err := GetUserInfo(uniqueuuid) | |
298 | + if err != nil || uinfo == nil { | |
299 | + logger.Error("redis failed err=%v", err) | |
300 | + resp.Message = "服务器错误" | |
301 | + resp.Code = ERROR_SRV_ERROR | |
302 | + break | |
303 | + } | |
304 | + | |
305 | + resp.Data.Goldnum = uinfo.ReadNum * READGOLDMULTI | |
306 | + | |
307 | + resp.Code = ERROR_OK | |
308 | + break | |
309 | + } | |
310 | + | |
311 | + respstr, _ := json.Marshal(&resp) | |
312 | + fmt.Fprint(w, string(respstr)) | |
313 | +} | |
314 | + | |
231 | 315 | func HandlerQuerysigndata(w http.ResponseWriter, data string, uuid int) { |
232 | 316 | SetHeader(w) |
233 | 317 | var resp QuerysigndataResp | ... | ... |