package logic import ( "HttpServer/conf" "common/logger" "strconv" //"encoding/json" "fmt" "io/ioutil" //"log" "net/http" ) func StartHttpServe() { startServerHttpServe() } func CheckErr(err error) { if err != nil { panic(err) } } func startServerHttpServe() { http.HandleFunc("/api/account/login", UserLogin) //登录 http.HandleFunc("/api/home/buy", DoBuyCat) //购买猫 http.HandleFunc("/api/home/synResource", GetUserData) //同步资源 http.HandleFunc("/api/home/recvOfflineReward", GetOfflineReward) //领取离线奖励 http.HandleFunc("/api/ranking/list", QueryPlayerRank) //排行榜 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("/api/home/change", ExchangePos) //合成 /////---------------------------------------------------------------------old 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/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("uid")) } 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 GetMainPageInfo(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("GetMainPageInfo , body:%v,uuid=%v", s, Uuid) HandlerGetMainPageInfo(w, s, Uuid) } func QueryPlayerRank(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("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("uid")) } 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 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 { 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) 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("uid")) } 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("uid")) } 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("uid")) } 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) { //w.Header().Set("Access-Control-Allow-Origin", "*") //允许访问所有域 //w.Header().Set("Content-Type", "application/json") /*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) if s == "" { logger.Error("UserLogin bodynil") //fmt.Fprint(w, "failed") //return } 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!") }