Commit 82bb3859abbcdc4d9e144571158ad0d03195da3b
1 parent
ca5c19e1
Exists in
master
提交新的接口
Showing
4 changed files
with
59 additions
and
148 deletions
Show diff stats
src/HttpServer/logic/datadef.go
@@ -130,6 +130,17 @@ type QueryBuyCatResp struct { | @@ -130,6 +130,17 @@ type QueryBuyCatResp struct { | ||
130 | Data []BuyCatDesc `json:"data"` | 130 | Data []BuyCatDesc `json:"data"` |
131 | } | 131 | } |
132 | 132 | ||
133 | +type LeftRateTimesDesc struct { | ||
134 | + LeftTimes int `json:"leftTimes"` | ||
135 | + LimitTimes int `json:"limitTimes"` | ||
136 | +} | ||
137 | + | ||
138 | +type LeftRateTimesResp struct { | ||
139 | + Code int `json:"code"` | ||
140 | + Message string `json:"message"` | ||
141 | + Data LeftRateTimesDesc `json:"data"` | ||
142 | +} | ||
143 | + | ||
133 | type BuyCatDesc struct { | 144 | type BuyCatDesc struct { |
134 | CatId int `json:"catId"` | 145 | CatId int `json:"catId"` |
135 | Coin string `json:"coin"` | 146 | Coin string `json:"coin"` |
src/HttpServer/logic/httpserver.go
@@ -2,9 +2,7 @@ package logic | @@ -2,9 +2,7 @@ package logic | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "HttpServer/conf" | 4 | "HttpServer/conf" |
5 | - "bytes" | ||
6 | "common/logger" | 5 | "common/logger" |
7 | - "encoding/json" | ||
8 | "strconv" | 6 | "strconv" |
9 | 7 | ||
10 | //"encoding/json" | 8 | //"encoding/json" |
@@ -18,150 +16,6 @@ func StartHttpServe() { | @@ -18,150 +16,6 @@ func StartHttpServe() { | ||
18 | startServerHttpServe() | 16 | startServerHttpServe() |
19 | } | 17 | } |
20 | 18 | ||
21 | -type QueryInviteReq struct { | ||
22 | - Uuid int `json:"uuid"` | ||
23 | -} | ||
24 | - | ||
25 | -type FetchReward struct { | ||
26 | - Gameid string `json:"gameid"` | ||
27 | - Channel string `json:"channel"` | ||
28 | - Tasktype int `json:"tasktype"` | ||
29 | - Taskid int `json:"taskid"` | ||
30 | -} | ||
31 | - | ||
32 | -//just for test | ||
33 | -func Testsendhttp() { | ||
34 | - return | ||
35 | - /*var queryinb QueryInviteReq | ||
36 | - queryinb.Uuid = 131532 | ||
37 | - client := &http.Client{} | ||
38 | - | ||
39 | - bys, err := json.Marshal(&queryinb) | ||
40 | - if err != nil { | ||
41 | - logger.Error("testsendhttp failed=%v", err) | ||
42 | - return | ||
43 | - } | ||
44 | - body := bytes.NewBuffer(bys) | ||
45 | - url := "https://catcafeapi.puchigame.com/catcafe/user/queryInvite" | ||
46 | - reqest, err := http.NewRequest("POST", url, body) | ||
47 | - if err != nil { | ||
48 | - logger.Error("http.NewRequest failed") | ||
49 | - } | ||
50 | - //reqest.Header.Add("Uuid", "101") | ||
51 | - //发送 | ||
52 | - //res, err := http.Post(url, "application/json;charset=utf-8", body) | ||
53 | - res, err := client.Do(reqest) | ||
54 | - if err != nil { | ||
55 | - logger.Error(" post failed to %v err:%v data:%v", url, err, string(bys)) | ||
56 | - return | ||
57 | - } | ||
58 | - | ||
59 | - result, _ := ioutil.ReadAll(res.Body) | ||
60 | - res.Body.Close() | ||
61 | - | ||
62 | - s := string(result) | ||
63 | - logger.Info("Testsendhttp result=%v", s)*/ | ||
64 | - | ||
65 | - client1 := &http.Client{} | ||
66 | - var fr FetchReward | ||
67 | - fr.Gameid = "1" | ||
68 | - fr.Channel = "2" | ||
69 | - fr.Tasktype = 2 | ||
70 | - fr.Taskid = 1 | ||
71 | - bys, err := json.Marshal(&fr) | ||
72 | - if err != nil { | ||
73 | - logger.Error("testsendhttp failed=%v", err) | ||
74 | - return | ||
75 | - } | ||
76 | - body := bytes.NewBuffer(bys) | ||
77 | - url1 := "https://test-game-3.d3games.com/api/account/login" | ||
78 | - reqest, err := http.NewRequest("POST", url1, body) | ||
79 | - if err != nil { | ||
80 | - logger.Error("http.NewRequest failed") | ||
81 | - } | ||
82 | - reqest.Header.Add("Uuid", "13") | ||
83 | - //发送 | ||
84 | - //res, err := http.Post(url1, "application/json;charset=utf-8", body) | ||
85 | - if err != nil { | ||
86 | - logger.Error("http.Post failed err=%v", err) | ||
87 | - } | ||
88 | - res, err := client1.Do(reqest) | ||
89 | - if err != nil { | ||
90 | - logger.Error(" post failed to %v err:%v data:%v", url1, err, string(bys)) | ||
91 | - return | ||
92 | - } | ||
93 | - | ||
94 | - result, _ := ioutil.ReadAll(res.Body) | ||
95 | - res.Body.Close() | ||
96 | - | ||
97 | - s := string(result) | ||
98 | - logger.Info("Testsendhttp result=%v", s) | ||
99 | - return | ||
100 | - | ||
101 | - /*var test UserLoginData | ||
102 | - //test.Uuid = 100 | ||
103 | - test.Fromid = 200 | ||
104 | - test.Sharetype = 1 | ||
105 | - | ||
106 | - client := &http.Client{} | ||
107 | - | ||
108 | - bys, err := json.Marshal(&test) | ||
109 | - if err != nil { | ||
110 | - logger.Error("testsendhttp failed=%v", err) | ||
111 | - return | ||
112 | - } | ||
113 | - body := bytes.NewBuffer(bys) | ||
114 | - url := "http://127.0.0.1:50056/cat/login" | ||
115 | - reqest, err := http.NewRequest("POST", url, body) | ||
116 | - if err != nil { | ||
117 | - logger.Error("http.NewRequest failed") | ||
118 | - } | ||
119 | - reqest.Header.Add("Uuid", "101") | ||
120 | - //发送 | ||
121 | - //res, err := http.Post(url, "application/json;charset=utf-8", body) | ||
122 | - res, err := client.Do(reqest) | ||
123 | - if err != nil { | ||
124 | - logger.Error(" post failed to %v err:%v data:%v", url, err, string(bys)) | ||
125 | - return | ||
126 | - } | ||
127 | - | ||
128 | - result, _ := ioutil.ReadAll(res.Body) | ||
129 | - res.Body.Close() | ||
130 | - | ||
131 | - s := string(result) | ||
132 | - var resp GetUserDataResp | ||
133 | - resp.Code = 0 | ||
134 | - var rdata UserLoginResp | ||
135 | - _ = json.Unmarshal([]byte(s), &rdata) | ||
136 | - logger.Info("testsendhttp , body:%v", rdata) | ||
137 | - | ||
138 | - url = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token=32_d50mJQLwHa87YFPGn-WqGo7wAz_92Q7pN5yWsFJKGP1kB3UiEWTXvgR7Z0X_qYBID52aano4IDOU93LdDiNWbRhrrwbqOdTeeH1grKJ_gqUz0m1AzKAbytocmhRE-cf7GaGFD9aUSKLquRelFDCfAAAVTS" | ||
139 | - type DDT struct { | ||
140 | - Content string `json:"content"` | ||
141 | - } | ||
142 | - var ddt DDT | ||
143 | - ddt.Content = "fuck you" | ||
144 | - bys, err = json.Marshal(&ddt) | ||
145 | - if err != nil { | ||
146 | - logger.Error("testsendhttp2 failed=%v", err) | ||
147 | - return | ||
148 | - } | ||
149 | - | ||
150 | - body = bytes.NewBuffer(bys) | ||
151 | - res, err = http.Post(url, "application/json;charset=utf-8", body) | ||
152 | - if err != nil { | ||
153 | - logger.Error(" post failed to %v err:%v data:%v", url, err, string(bys)) | ||
154 | - return | ||
155 | - } | ||
156 | - | ||
157 | - result, _ = ioutil.ReadAll(res.Body) | ||
158 | - res.Body.Close() | ||
159 | - | ||
160 | - s = string(result) | ||
161 | - | ||
162 | - logger.Info("testsendhttp2222222222 , body:%v", s)*/ | ||
163 | -} | ||
164 | - | ||
165 | func CheckErr(err error) { | 19 | func CheckErr(err error) { |
166 | if err != nil { | 20 | if err != nil { |
167 | panic(err) | 21 | panic(err) |
@@ -177,6 +31,7 @@ func startServerHttpServe() { | @@ -177,6 +31,7 @@ func startServerHttpServe() { | ||
177 | http.HandleFunc("/api/home/index", GetMainPageInfo) //主页面 | 31 | http.HandleFunc("/api/home/index", GetMainPageInfo) //主页面 |
178 | http.HandleFunc("/api/home/adRate", AcclecteGold) //看广告加速 | 32 | http.HandleFunc("/api/home/adRate", AcclecteGold) //看广告加速 |
179 | http.HandleFunc("/api/home/shop", QueryBuyCat) //商店 | 33 | http.HandleFunc("/api/home/shop", QueryBuyCat) //商店 |
34 | + http.HandleFunc("/api/home/leftRateTimes", LeftRateTimes) //剩余看广告加速次数 | ||
180 | 35 | ||
181 | http.HandleFunc("/happycat/exchangetwoPos", ExchangePos) //交换位置 | 36 | http.HandleFunc("/happycat/exchangetwoPos", ExchangePos) //交换位置 |
182 | http.HandleFunc("/happycat/clickcatbox", ClickCatBox) //请求点击猫箱子 | 37 | http.HandleFunc("/happycat/clickcatbox", ClickCatBox) //请求点击猫箱子 |
@@ -590,6 +445,24 @@ func DoBuyCat(w http.ResponseWriter, r *http.Request) { | @@ -590,6 +445,24 @@ func DoBuyCat(w http.ResponseWriter, r *http.Request) { | ||
590 | HandlerDoBuyCat(w, s, Uuid) | 445 | HandlerDoBuyCat(w, s, Uuid) |
591 | } | 446 | } |
592 | 447 | ||
448 | +func LeftRateTimes(w http.ResponseWriter, r *http.Request) { | ||
449 | + Uuid := 0 | ||
450 | + if len(r.Header) > 0 { | ||
451 | + Uuid, _ = strconv.Atoi(r.Header.Get("uid")) | ||
452 | + } | ||
453 | + if Uuid == 0 { | ||
454 | + SetHeader(w) | ||
455 | + return | ||
456 | + } | ||
457 | + result, _ := ioutil.ReadAll(r.Body) | ||
458 | + r.Body.Close() | ||
459 | + | ||
460 | + s := string(result) | ||
461 | + logger.Info("QueryBuyCat , body:%v,uuid=%v", s, Uuid) | ||
462 | + | ||
463 | + HandlerLeftRateTimes(w, s, Uuid) | ||
464 | +} | ||
465 | + | ||
593 | func QueryBuyCat(w http.ResponseWriter, r *http.Request) { | 466 | func QueryBuyCat(w http.ResponseWriter, r *http.Request) { |
594 | Uuid := 0 | 467 | Uuid := 0 |
595 | if len(r.Header) > 0 { | 468 | if len(r.Header) > 0 { |
src/HttpServer/logic/logic.go
@@ -41,7 +41,7 @@ func HandlerLogin(w http.ResponseWriter, data string, uuid int, token string) { | @@ -41,7 +41,7 @@ func HandlerLogin(w http.ResponseWriter, data string, uuid int, token string) { | ||
41 | if err != nil { | 41 | if err != nil { |
42 | logger.Info("json decode HandlerLogin data failed:%v,for:%v", err, data) | 42 | logger.Info("json decode HandlerLogin data failed:%v,for:%v", err, data) |
43 | resp.Message = "json unmarshal failed" | 43 | resp.Message = "json unmarshal failed" |
44 | - resp.Code = 0 | 44 | + resp.Code = 1 |
45 | respstr, _ := json.Marshal(&resp) | 45 | respstr, _ := json.Marshal(&resp) |
46 | logger.Info("###HandlerLogin###rdata:%v", string(respstr)) | 46 | logger.Info("###HandlerLogin###rdata:%v", string(respstr)) |
47 | fmt.Fprint(w, string(respstr)) | 47 | fmt.Fprint(w, string(respstr)) |
@@ -455,6 +455,33 @@ func HandlerAcclecteGold(w http.ResponseWriter, data string, uuid int) { | @@ -455,6 +455,33 @@ func HandlerAcclecteGold(w http.ResponseWriter, data string, uuid int) { | ||
455 | fmt.Fprint(w, string(respstr)) | 455 | fmt.Fprint(w, string(respstr)) |
456 | } | 456 | } |
457 | 457 | ||
458 | +func HandlerLeftRateTimes(w http.ResponseWriter, data string, uuid int) { | ||
459 | + SetHeader(w) | ||
460 | + var resp LeftRateTimesResp | ||
461 | + resp.Code = 0 | ||
462 | + resp.Message = "success" | ||
463 | + | ||
464 | + for { | ||
465 | + | ||
466 | + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) | ||
467 | + if err != nil || uinfo == nil { | ||
468 | + logger.Error("HandlerAcclecteGold getuserinfo failed=%v", err) | ||
469 | + resp.Code = 1 | ||
470 | + resp.Message = "get userinfo failed" | ||
471 | + break | ||
472 | + } | ||
473 | + | ||
474 | + resp.Data.LeftTimes = uinfo.DoubleLeftTimes | ||
475 | + resp.Data.LimitTimes = ACCGOLDRATELIMIT | ||
476 | + | ||
477 | + resp.Code = 0 | ||
478 | + break | ||
479 | + } | ||
480 | + //回包 | ||
481 | + respstr, _ := json.Marshal(&resp) | ||
482 | + fmt.Fprint(w, string(respstr)) | ||
483 | +} | ||
484 | + | ||
458 | func HandlerQueryBuyCat(w http.ResponseWriter, data string, uuid int) { | 485 | func HandlerQueryBuyCat(w http.ResponseWriter, data string, uuid int) { |
459 | SetHeader(w) | 486 | SetHeader(w) |
460 | var resp QueryBuyCatResp | 487 | var resp QueryBuyCatResp |
src/HttpServer/main/main.go
@@ -60,7 +60,7 @@ func main() { | @@ -60,7 +60,7 @@ func main() { | ||
60 | go logic.StartHttpServe() | 60 | go logic.StartHttpServe() |
61 | //go logic.StartHttpTicker() | 61 | //go logic.StartHttpTicker() |
62 | time.Sleep(time.Duration(2) * time.Second) | 62 | time.Sleep(time.Duration(2) * time.Second) |
63 | - logic.Testsendhttp() | 63 | + //logic.Testsendhttp() |
64 | 64 | ||
65 | select { | 65 | select { |
66 | case _ = <-ch: | 66 | case _ = <-ch: |