diff --git a/src/HttpServer/logic/datadef.go b/src/HttpServer/logic/datadef.go index dfaa1fc..fcf94d9 100644 --- a/src/HttpServer/logic/datadef.go +++ b/src/HttpServer/logic/datadef.go @@ -130,6 +130,17 @@ type QueryBuyCatResp struct { Data []BuyCatDesc `json:"data"` } +type LeftRateTimesDesc struct { + LeftTimes int `json:"leftTimes"` + LimitTimes int `json:"limitTimes"` +} + +type LeftRateTimesResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data LeftRateTimesDesc `json:"data"` +} + type BuyCatDesc struct { CatId int `json:"catId"` Coin string `json:"coin"` diff --git a/src/HttpServer/logic/httpserver.go b/src/HttpServer/logic/httpserver.go index 045cd36..f53db3b 100644 --- a/src/HttpServer/logic/httpserver.go +++ b/src/HttpServer/logic/httpserver.go @@ -2,9 +2,7 @@ package logic import ( "HttpServer/conf" - "bytes" "common/logger" - "encoding/json" "strconv" //"encoding/json" @@ -18,150 +16,6 @@ func StartHttpServe() { startServerHttpServe() } -type QueryInviteReq struct { - Uuid int `json:"uuid"` -} - -type FetchReward struct { - Gameid string `json:"gameid"` - Channel string `json:"channel"` - Tasktype int `json:"tasktype"` - Taskid int `json:"taskid"` -} - -//just for test -func Testsendhttp() { - return - /*var queryinb QueryInviteReq - queryinb.Uuid = 131532 - client := &http.Client{} - - bys, err := json.Marshal(&queryinb) - if err != nil { - logger.Error("testsendhttp failed=%v", err) - return - } - body := bytes.NewBuffer(bys) - url := "https://catcafeapi.puchigame.com/catcafe/user/queryInvite" - reqest, err := http.NewRequest("POST", url, body) - if err != nil { - logger.Error("http.NewRequest failed") - } - //reqest.Header.Add("Uuid", "101") - //发送 - //res, err := http.Post(url, "application/json;charset=utf-8", body) - res, err := client.Do(reqest) - if err != nil { - logger.Error(" post failed to %v err:%v data:%v", url, err, string(bys)) - return - } - - result, _ := ioutil.ReadAll(res.Body) - res.Body.Close() - - s := string(result) - logger.Info("Testsendhttp result=%v", s)*/ - - client1 := &http.Client{} - var fr FetchReward - fr.Gameid = "1" - fr.Channel = "2" - fr.Tasktype = 2 - fr.Taskid = 1 - bys, err := json.Marshal(&fr) - if err != nil { - logger.Error("testsendhttp failed=%v", err) - return - } - body := bytes.NewBuffer(bys) - url1 := "https://test-game-3.d3games.com/api/account/login" - reqest, err := http.NewRequest("POST", url1, body) - if err != nil { - logger.Error("http.NewRequest failed") - } - reqest.Header.Add("Uuid", "13") - //发送 - //res, err := http.Post(url1, "application/json;charset=utf-8", body) - if err != nil { - logger.Error("http.Post failed err=%v", err) - } - res, err := client1.Do(reqest) - if err != nil { - logger.Error(" post failed to %v err:%v data:%v", url1, err, string(bys)) - return - } - - result, _ := ioutil.ReadAll(res.Body) - res.Body.Close() - - s := string(result) - logger.Info("Testsendhttp result=%v", s) - return - - /*var test UserLoginData - //test.Uuid = 100 - test.Fromid = 200 - test.Sharetype = 1 - - client := &http.Client{} - - bys, err := json.Marshal(&test) - if err != nil { - logger.Error("testsendhttp failed=%v", err) - return - } - body := bytes.NewBuffer(bys) - url := "http://127.0.0.1:50056/cat/login" - reqest, err := http.NewRequest("POST", url, body) - if err != nil { - logger.Error("http.NewRequest failed") - } - reqest.Header.Add("Uuid", "101") - //发送 - //res, err := http.Post(url, "application/json;charset=utf-8", body) - res, err := client.Do(reqest) - if err != nil { - logger.Error(" post failed to %v err:%v data:%v", url, err, string(bys)) - return - } - - result, _ := ioutil.ReadAll(res.Body) - res.Body.Close() - - s := string(result) - var resp GetUserDataResp - resp.Code = 0 - var rdata UserLoginResp - _ = json.Unmarshal([]byte(s), &rdata) - logger.Info("testsendhttp , body:%v", rdata) - - url = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token=32_d50mJQLwHa87YFPGn-WqGo7wAz_92Q7pN5yWsFJKGP1kB3UiEWTXvgR7Z0X_qYBID52aano4IDOU93LdDiNWbRhrrwbqOdTeeH1grKJ_gqUz0m1AzKAbytocmhRE-cf7GaGFD9aUSKLquRelFDCfAAAVTS" - type DDT struct { - Content string `json:"content"` - } - var ddt DDT - ddt.Content = "fuck you" - bys, err = json.Marshal(&ddt) - if err != nil { - logger.Error("testsendhttp2 failed=%v", err) - return - } - - body = bytes.NewBuffer(bys) - res, err = http.Post(url, "application/json;charset=utf-8", body) - if err != nil { - logger.Error(" post failed to %v err:%v data:%v", url, err, string(bys)) - return - } - - result, _ = ioutil.ReadAll(res.Body) - res.Body.Close() - - s = string(result) - - logger.Info("testsendhttp2222222222 , body:%v", s)*/ -} - func CheckErr(err error) { if err != nil { panic(err) @@ -177,6 +31,7 @@ func startServerHttpServe() { http.HandleFunc("/api/home/index", GetMainPageInfo) //主页面 http.HandleFunc("/api/home/adRate", AcclecteGold) //看广告加速 http.HandleFunc("/api/home/shop", QueryBuyCat) //商店 + http.HandleFunc("/api/home/leftRateTimes", LeftRateTimes) //剩余看广告加速次数 http.HandleFunc("/happycat/exchangetwoPos", ExchangePos) //交换位置 http.HandleFunc("/happycat/clickcatbox", ClickCatBox) //请求点击猫箱子 @@ -590,6 +445,24 @@ func DoBuyCat(w http.ResponseWriter, r *http.Request) { HandlerDoBuyCat(w, s, Uuid) } +func LeftRateTimes(w http.ResponseWriter, r *http.Request) { + Uuid := 0 + if len(r.Header) > 0 { + Uuid, _ = strconv.Atoi(r.Header.Get("uid")) + } + if Uuid == 0 { + SetHeader(w) + return + } + result, _ := ioutil.ReadAll(r.Body) + r.Body.Close() + + s := string(result) + logger.Info("QueryBuyCat , body:%v,uuid=%v", s, Uuid) + + HandlerLeftRateTimes(w, s, Uuid) +} + func QueryBuyCat(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { diff --git a/src/HttpServer/logic/logic.go b/src/HttpServer/logic/logic.go index 421d6e5..ac704b8 100644 --- a/src/HttpServer/logic/logic.go +++ b/src/HttpServer/logic/logic.go @@ -41,7 +41,7 @@ func HandlerLogin(w http.ResponseWriter, data string, uuid int, token string) { if err != nil { logger.Info("json decode HandlerLogin data failed:%v,for:%v", err, data) resp.Message = "json unmarshal failed" - resp.Code = 0 + resp.Code = 1 respstr, _ := json.Marshal(&resp) logger.Info("###HandlerLogin###rdata:%v", string(respstr)) fmt.Fprint(w, string(respstr)) @@ -455,6 +455,33 @@ func HandlerAcclecteGold(w http.ResponseWriter, data string, uuid int) { fmt.Fprint(w, string(respstr)) } +func HandlerLeftRateTimes(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp LeftRateTimesResp + resp.Code = 0 + resp.Message = "success" + + for { + + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) + if err != nil || uinfo == nil { + logger.Error("HandlerAcclecteGold getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + + resp.Data.LeftTimes = uinfo.DoubleLeftTimes + resp.Data.LimitTimes = ACCGOLDRATELIMIT + + resp.Code = 0 + break + } + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) +} + func HandlerQueryBuyCat(w http.ResponseWriter, data string, uuid int) { SetHeader(w) var resp QueryBuyCatResp diff --git a/src/HttpServer/main/main.go b/src/HttpServer/main/main.go index f83cf84..39f70fc 100644 --- a/src/HttpServer/main/main.go +++ b/src/HttpServer/main/main.go @@ -60,7 +60,7 @@ func main() { go logic.StartHttpServe() //go logic.StartHttpTicker() time.Sleep(time.Duration(2) * time.Second) - logic.Testsendhttp() + //logic.Testsendhttp() select { case _ = <-ch: -- libgit2 0.21.0