package logic import ( "HttpServer/conf" "bytes" "common/logger" "encoding/json" "strconv" //"encoding/json" "fmt" "io/ioutil" //"log" "net/http" ) 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() { /*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://192.144.198.179:50064/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) } } func startServerHttpServe() { http.HandleFunc("/api/account/login", UserLogin) //登录 http.HandleFunc("/happycat/getuserdata", GetUserData) //拉取用户数据 http.HandleFunc("/happycat/exchangetwoPos", ExchangePos) //交换位置 http.HandleFunc("/happycat/clickcatbox", ClickCatBox) //请求点击猫箱子 http.HandleFunc("/happycat/upgradecatbox", UpgradeCatBox) //请求点击猫箱子 http.HandleFunc("/happycat/acclecte", AcclecteGold) //请求点击猫箱子 http.HandleFunc("/happycat/automerge", AutoMerge) //请求自动合成 http.HandleFunc("/happycat/generatebox", GenerateBox) //请求点击猫箱子 http.HandleFunc("/happycat/clickrandgift", ClickRandGift) //请求点击猫箱子 http.HandleFunc("/happycat/querybuycat", QueryBuyCat) //请求商店购买信息 http.HandleFunc("/happycat/dobuycat", DoBuyCat) //购买猫 http.HandleFunc("/happycat/querwarehouse", QueryWareHouse) //请求仓库信息 http.HandleFunc("/happycat/putcattowarehouse", PutCattoWareHouse) //将合成界面的猫放入仓库 http.HandleFunc("/happycat/takecatoutfromwarehouse", TakeCatoutfromWareHouse) //将仓库的猫取出 http.HandleFunc("/happycat/acclecteboxrate ", AcclecteBoxRate) //请求点击猫箱子 http.HandleFunc("/happycat/queryautomergeinfo ", QueryAutomergeInfo) //请求点击猫箱子 http.HandleFunc("/happycat/querycatroominfo ", QueryCatRoomInfo) //请求点击猫箱子 http.HandleFunc("/happycat/buycatroom ", BuyCatRoom) //请求点击猫箱子 http.HandleFunc("/happycat/upcattoroom ", UpCattoRoom) //请求点击猫箱子 http.HandleFunc("/happycat/querycatshopinfo ", QueryCatShopInfo) //请求点击猫箱子 http.HandleFunc("/happycat/catshoplay ", CatShoPlay) //请求点击猫箱子 http.HandleFunc("/happycat/getcatshopreward ", GetCatShopReward) //请求点击猫箱子 http.HandleFunc("/happycat/acclectecatstory ", AcclecteCatStory) //请求点击猫箱子 http.HandleFunc("/chappycatat/updateuserinfo ", UpdateUserInfo) //请求点击猫箱子 http.HandleFunc("/happycat/queryplayerrank ", QueryPlayerRank) //请求点击猫箱子 http.HandleFunc("/happycat/querycompletetask ", QueryCompleteTask) //请求点击猫箱子 http.HandleFunc("/happycat/querycompleteachievement ", QueryCompleteAchievement) //请求点击猫箱子 http.HandleFunc("/happycat/gettaskreward ", GetTaskReward) //请求点击猫箱子 http.HandleFunc("/happycat/getachievereward ", GetAchieveReward) //请求点击猫箱子 http.HandleFunc("/happycat/startonlinetask ", StartOnlineTask) //请求开始在线时长任务 http.HandleFunc("/happycat/getofflinereward ", GetOfflineReward) //请求开始在线时长任务 err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) CheckErr(err) } func GetOfflineReward(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("GetOfflineReward , body:%v,uuid=%v", s, Uuid) //HandlerGetOfflineReward(w, s, Uuid) } func StartOnlineTask(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("StartOnlineTask , body:%v,uuid=%v", s, Uuid) //HandlerStartOnlineTask(w, s, Uuid) } func QueryCompleteTask(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("QueryCompleteTask , body:%v,uuid=%v", s, Uuid) //HandlerQueryCompleteTask(w, s, Uuid) } func QueryCompleteAchievement(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("QueryCompleteAchievement , body:%v,uuid=%v", s, Uuid) //HandlerQueryCompleteAchievement(w, s, Uuid) } func GetTaskReward(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("GetTaskReward , body:%v,uuid=%v", s, Uuid) //HandlerGetTaskReward(w, s, Uuid) } func GetAchieveReward(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("GetAchieveReward , body:%v,uuid=%v", s, Uuid) //HandlerGetAchieveReward(w, s, Uuid) } func UpdateUserInfo(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("UpdateUserInfo , body:%v,uuid=%v", s, Uuid) //HandlerUpdateUserInfo(w, s, Uuid) } func QueryPlayerRank(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("QueryPlayerRank , body:%v,uuid=%v", s, Uuid) //HandlerQueryPlayerRank(w, s, Uuid) } func AcclecteCatStory(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("AcclecteCatStory , body:%v,uuid=%v", s, Uuid) //HandlerAcclecteCatStory(w, s, Uuid) } func QueryCatShopInfo(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("QueryCatShopInfo , body:%v,uuid=%v", s, Uuid) //HandlerQueryCatShopInfo(w, s, Uuid) } func CatShoPlay(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("CatShoPlay , body:%v,uuid=%v", s, Uuid) //HandlerCatShoPlay(w, s, Uuid) } func GetCatShopReward(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("GetCatShopReward , body:%v,uuid=%v", s, Uuid) //HandlerGetCatShopReward(w, s, Uuid) } func QueryCatRoomInfo(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("QueryCatRoomInfo , body:%v,uuid=%v", s, Uuid) //HandlerQueryCatRoomInfo(w, s, Uuid) } func BuyCatRoom(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("BuyCatRoom , body:%v,uuid=%v", s, Uuid) //HandlerBuyCatRoom(w, s, Uuid) } func UpCattoRoom(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("QueryCatRoomInfo , body:%v,uuid=%v", s, Uuid) //HandlerUpCattoRoom(w, s, Uuid) } func QueryAutomergeInfo(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("QueryAutomergeInfo , body:%v,uuid=%v", s, Uuid) //HandlerQueryAutomergeInfo(w, s, Uuid) } func QueryWareHouse(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("QueryWareHouse , body:%v,uuid=%v", s, Uuid) //HandlerQueryWareHouse(w, s, Uuid) } func PutCattoWareHouse(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("PutCattoWareHouse , body:%v,uuid=%v", s, Uuid) //HandlerPutCattoWareHouse(w, s, Uuid) } func TakeCatoutfromWareHouse(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("TakeCatoutfromWareHouse , body:%v,uuid=%v", s, Uuid) ///HandlerTakeCatoutfromWareHouse(w, s, Uuid) } func DoBuyCat(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("DoBuyCat , body:%v,uuid=%v", s, Uuid) //HandlerDoBuyCat(w, s, Uuid) } func QueryBuyCat(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } 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) //HandlerQueryBuyCat(w, s, Uuid) } func ClickRandGift(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("ClickRandGift , body:%v,uuid=%v", s, Uuid) //HandlerClickRandGift(w, s, Uuid) } func AutoMerge(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("AutoMerge , body:%v,uuid=%v", s, Uuid) // HandlerAutoMerge(w, s, Uuid) } func ClickCatBox(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("ClickCatBox , body:%v,uuid=%v", s, Uuid) //HandlerClickCatBox(w, s, Uuid) } func GenerateBox(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("GenerateBox , body:%v,uuid=%v", s, Uuid) // HandlerGenerateBox(w, s, Uuid) } func UpgradeCatBox(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("UpgradeCatBox , body:%v,uuid=%v", s, Uuid) // HandlerUpgradeCatBox(w, s, Uuid) } func AcclecteBoxRate(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("AcclecteBoxRate , body:%v,uuid=%v", s, Uuid) // HandlerAcclecteBoxRate(w, s, Uuid) } func AcclecteGold(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("AcclecteGold , body:%v,uuid=%v", s, Uuid) // HandlerAcclecteGold(w, s, Uuid) } func ExchangePos(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("ExchangePos , body:%v,uuid=%v", s, Uuid) //HandlerExchangePos(w, s, Uuid) } func GetUserData(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) } if Uuid == 0 { SetHeader(w) return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("GetUserData , body:%v,uuid=%v", s, Uuid) //HandlerGetUserData(w, s, Uuid) } func UserLogin(w http.ResponseWriter, r *http.Request) { /*logger.Info("%%%%%%%%%%%%%%%%path=%v", *r.URL) for k, v := range r.Header { logger.Info("*********************key=%v,value=%v", k, v) } w.Header().Add("Access-Control-Allow-Headers", "") w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Length, X-CSRF-Token, Token,session,X_Requested_With,Accept, Origin, Host, Connection, Accept-Encoding, Accept-Language,DNT, X-CustomHeader, Keep-Alive, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Pragma") */ Uuid := 0 Token := "" if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("uid")) Token = r.Header.Get("token") } /*if Uuid == 0 { SetHeader(w) /*var resp UserLoginResp resp.Code = -1 resp.Message = "uuid is nil" respstr, _ := json.Marshal(&resp) fmt.Fprint(w, string(respstr)) logger.Error("UserLogin uuid=0! failed!")*/ //return //} result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("UserLogin , body:%v,uuid=%v token=%v", s, Uuid,Token) HandlerLogin(w, s, Uuid,Token) } func ReviewAllianceHandler(w http.ResponseWriter, r *http.Request) { //defer utils.PrintPanicStack() result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) logger.Info("ReviewAllianceHandler , body:%v", s) //go HandleReviewedAlliance(s) fmt.Fprint(w, "Success!") }