From 7c843cc37b23c90bc3ccbfe085758b11a093ca84 Mon Sep 17 00:00:00 2001 From: 陆恒 Date: Fri, 28 Aug 2020 16:47:46 +0800 Subject: [PATCH] 提交 --- src/HttpServer/logic/datadef.go | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------- src/HttpServer/logic/function.go | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/HttpServer/logic/httpserver.go | 22 ++++++++++++++++++++++ src/HttpServer/logic/logic.go | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 345 insertions(+), 26 deletions(-) diff --git a/src/HttpServer/logic/datadef.go b/src/HttpServer/logic/datadef.go index c3435a5..532a707 100644 --- a/src/HttpServer/logic/datadef.go +++ b/src/HttpServer/logic/datadef.go @@ -146,6 +146,26 @@ type GetcashResp struct { Data GetcashData `json:"data"` } +type GetcashwechatData struct { + Cdkey string `json:"cdkey"` +} +type GetcashwechatResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data GetcashwechatData `json:"data"` +} + +type GetcashwechatReq struct { + Gameid string `json:"gameid"` + Channel string `json:"channel"` + Money float32 `json:"money"` + Openid string `json:"openid"` + Nickname string `json:"nickname"` + Headurl string `json:"headurl"` + Ver string `json:"ver"` + Ctype int `json:"ctype"` +} + type GetcashrecordReq struct { Gameid string `json:"gameid"` Channel string `json:"channel"` @@ -362,8 +382,9 @@ func (v WithDrawDescs) Less(i, j int) bool { } type WithDrawInfo struct { - Cashdata WithDrawDescs `json:"cashdata"` - SpecialCashdata WithDrawDescs `json:"specialcashdata"` + Cashdata WithDrawDescs `json:"cashdata"` + SpecialCashdata WithDrawDescs `json:"specialcashdata"` + Cdkeycashdata []CashCdKeyInfo `json:"cdkeycashdata"` } type WithDrawDesc struct { @@ -375,32 +396,39 @@ type WithDrawDesc struct { Day int `json:"day"` } +type CashCdKeyInfo struct { + Id int `json:"id"` + Money float32 `json:"money"` + Cdkey string `json:"cdkey"` +} + //玩家数据 type UserData struct { - Userid int //玩家id - Lv int //玩家当前等级 - LvRewardGet int //当前等级奖励是否已经领取 1未领取 2普通领取 3双倍领取 - Exp int //玩家当前经验值 - GuanGold int //玩家存钱罐中金币数量 - RealGold int //玩家实际金币数量(可用于提现的) - WatchAddsTime int //当天剩余红包次数 初始化50次 - LastLoginTime int //上次登陆时间 - ContinueLoginDay int //连续登录天数 - SumLoginDay int //累计登陆天数 - GetFromGuanCnt int //当天从存钱款提取金币次数 - SignRound int //签到轮数 - SignSum int //累计签到天数 - IsSignToday int //今日是否已经签到 1是 0否 - LeftFreeRB int //剩余免费红包次数 - UpLvCostTime int //上一个等级升级时间 - UpLvCostTimeSec int //上一个等级升级的时间点时刻 - ReadNum int //玩家微转发阅读量 - GetCashCnt int //当天提现次数 - ShakeTime int //摇一摇 - FetchRedCnt int //领取红包次数计数 - IsNew int //新手状态 - FetchRdBagNum int //当天已领的红包 - WithDraw WithDrawInfo //提现记录信息 + Userid int //玩家id + Lv int //玩家当前等级 + LvRewardGet int //当前等级奖励是否已经领取 1未领取 2普通领取 3双倍领取 + Exp int //玩家当前经验值 + GuanGold int //玩家存钱罐中金币数量 + RealGold int //玩家实际金币数量(可用于提现的) + WatchAddsTime int //当天剩余红包次数 初始化50次 + LastLoginTime int //上次登陆时间 + ContinueLoginDay int //连续登录天数 + SumLoginDay int //累计登陆天数 + GetFromGuanCnt int //当天从存钱款提取金币次数 + SignRound int //签到轮数 + SignSum int //累计签到天数 + IsSignToday int //今日是否已经签到 1是 0否 + LeftFreeRB int //剩余免费红包次数 + UpLvCostTime int //上一个等级升级时间 + UpLvCostTimeSec int //上一个等级升级的时间点时刻 + ReadNum int //玩家微转发阅读量 + GetCashCnt int //当天提现次数 + ShakeTime int //摇一摇 + FetchRedCnt int //领取红包次数计数 + IsNew int //新手状态 + FetchRdBagNum int //当天已领的红包 + WithDraw WithDrawInfo //提现记录信息 + Cdkeys []CashCdKeyInfo //记录提现的cdkeys //SpecialWithDraw WithDrawInfo //活跃提现记录信息 Task TaskInfo //玩家任务完成相关信息 Achieve AchieveMentInfo //玩家成就完成相关数据 @@ -460,6 +488,12 @@ type GetCashResp struct { Msg string `json:"msg"` } +type GetCashWechatResp struct { + Code string `json:"code"` + Cdkey string `json:"cdkey"` + Msg string `json:"msg"` +} + type GetCashListDesc struct { Sign string `json:"sign"` Sign_type string `json:"sign_type"` diff --git a/src/HttpServer/logic/function.go b/src/HttpServer/logic/function.go index 98a0b2f..ae8891e 100644 --- a/src/HttpServer/logic/function.go +++ b/src/HttpServer/logic/function.go @@ -1337,6 +1337,116 @@ func AddCoinToSdk(uuid int, goldnum int, gameid string, channel string, atype in return resp.Data.Mycoin, realaddgoldnum, nil } +func GetCashWechatFromSDK(uuid int, goldnum int, gameid, channel, openid, nickname, headurl, ver string, checkcoin int) (string, error) { + + SERVERKEY := XIAOXINGXING_SERVERKEYTEST + if gameid == "1015" { + SERVERKEY = XIAOXINGXING_SERVERKEYTEST_1015 + } + + if gameid == "1016" { + SERVERKEY = XIAOXINGXING_SERVERKEYTEST_1016 + } + if gameid == "1019" { + SERVERKEY = XIAOXINGXING_SERVERKEYTEST_1019 + } + if gameid == "1020" { + SERVERKEY = XIAOXINGXING_SERVERKEYTEST_1020 + } + if gameid == "1021" { + SERVERKEY = XIAOXINGXING_SERVERKEYTEST_1021 + } + if gameid == "1023" { + SERVERKEY = XIAOXINGXING_SERVERKEYTEST_1023 + } + if goldnum == 0 || uuid == 0 || gameid == "" || channel == "" || openid == "" || ver == "" { + logger.Error("GetCashFromSDK param empty") + return "", errors.New("param empty") + } + var paramlist []string + var params TixianDesc + params.Sign_type = "md5" + params.Gameid = gameid + params.Channel = channel + params.Uid = uuid + params.Time_stamp = strconv.Itoa(int(time.Now().Unix())) + params.Headurl = headurl + params.Money = goldnum + params.Openid = openid + params.Nickname = nickname + params.Typ = 6 + params.Ver = ver + params.Editcoin = 1 + params.Checkcoin = checkcoin + signtypestr := "sign_type=" + params.Sign_type + timestampstr := "time_stamp=" + strconv.Itoa(int(time.Now().Unix())) + paramgameid := "gameid=" + gameid + pchannel := "channel=" + channel + puid := "uid=" + strconv.Itoa(uuid) + phead := "headurl=" + headurl + pnickname := "nickname=" + nickname + popenid := "openid=" + openid + pmoney := "money=" + strconv.Itoa(goldnum) + ptype := "typ=" + "6" //微信 + ped := "editcoin=1" + pcheco := "checkcoin=" + strconv.Itoa(checkcoin) + //pver := "ver=" + params.Ver + paramlist = append(paramlist, signtypestr) + paramlist = append(paramlist, timestampstr) + paramlist = append(paramlist, paramgameid) + paramlist = append(paramlist, pchannel) + paramlist = append(paramlist, puid) + if headurl != "" { + paramlist = append(paramlist, phead) + } + if nickname != "" { + paramlist = append(paramlist, pnickname) + } + paramlist = append(paramlist, popenid) + paramlist = append(paramlist, pmoney) + paramlist = append(paramlist, ptype) + paramlist = append(paramlist, ped) + paramlist = append(paramlist, pcheco) + //paramlist = append(paramlist, pver) + + sumparam := GettotalParam(paramlist) + //加serverkey + signsum := sumparam + SERVERKEY + + //进行hash + sign := GetHashValue(signsum) + params.Sign = sign + + bys, err := json.Marshal(¶ms) + if err != nil { + logger.Error("GetCashWechatFromSDK failed=%v", err) + return "", err + } + res, err := DoHttpPost(bys, "api/server/tixian") + logger.Info("GetCashWechatFromSDK sumparam is:%v,sign is:%v", signsum, sign) + logger.Info("GetCashWechatFromSDK sumparam param=%v", string(bys)) + if err != nil { + logger.Error("GetCashWechatFromSDK failed=%v", err) + return "", err + } + + logger.Info("GetCashWechatFromSDK res=%v", res) + + var resp GetCashWechatResp + err = json.Unmarshal([]byte(res), &resp) + if err != nil { + logger.Error("GetCashWechatFromSDK failed=%v", err) + return "", err + } + + if resp.Code != "0" { + logger.Error("GetCashWechatFromSDK failed=%v", resp.Msg) + return "", errors.New(resp.Msg) + } + + return resp.Cdkey, nil +} + func GetCashFromSDK(uuid int, goldnum int, gameid, channel, openid, nickname, headurl, ver string, checkcoin int) (int, error) { SERVERKEY := XIAOXINGXING_SERVERKEYTEST diff --git a/src/HttpServer/logic/httpserver.go b/src/HttpServer/logic/httpserver.go index 8a293b4..d7dbff4 100644 --- a/src/HttpServer/logic/httpserver.go +++ b/src/HttpServer/logic/httpserver.go @@ -53,6 +53,7 @@ func startServerHttpServe() { http.HandleFunc("/eliminatestar/drawguangold", Drawguangold) //提取存钱罐的金币到个人钱包 http.HandleFunc("/eliminatestar/querdrawinfo", Querdrawinfo) //获取提现档位信息接口 http.HandleFunc("/eliminatestar/getcash", Getcash) //提现 + http.HandleFunc("/eliminatestar/getcashwechat", Getcashwechat) //提现 http.HandleFunc("/eliminatestar/getcashrecord", Getcashrecord) //提现记录列表 http.HandleFunc("/eliminatestar/onlinentf", Onlinentf) //在线通知 http.HandleFunc("/eliminatestar/updatetaskandachieve", Updatetaskandachieve) //上报任务事件进度 @@ -453,6 +454,27 @@ func Getcashrecord(w http.ResponseWriter, r *http.Request) { HandlerGetcashrecord(w, s, Uuid) } +func Getcashwechat(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) + //logger.Error("Uuid is nil!") + return + } + result, _ := ioutil.ReadAll(r.Body) + r.Body.Close() + + s := string(result) + logger.Info("Getcashwechat , body:%v,uuid=%v", s, Uuid) + + HandlerGetcashwechat(w, s, Uuid) +} + func Getcash(w http.ResponseWriter, r *http.Request) { Uuid := 0 diff --git a/src/HttpServer/logic/logic.go b/src/HttpServer/logic/logic.go index 33da866..0dbf02d 100644 --- a/src/HttpServer/logic/logic.go +++ b/src/HttpServer/logic/logic.go @@ -107,6 +107,158 @@ func HandlerWatchads(w http.ResponseWriter, data string, uuid int) { fmt.Fprint(w, string(respstr))*/ } +func HandlerGetcashwechat(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp GetcashwechatResp + resp.Code = 0 + var rdata GetcashwechatReq + err := json.Unmarshal([]byte(data), &rdata) + for { + if err != nil { + logger.Info("json decode HandlerDrawguangold data failed:%v,for:%v", err, data) + resp.Message = "json解析错误" + resp.Code = ERROR_JSONUNMASH_ERROR + break + } + //临时处理一下 + /*if rdata.Ver == "" { + rdata.Ver = "2.0.0" + }*/ + + //需要加上渠道才是唯一的玩家id,不同渠道视为不同数据 + uniqueuuid := strconv.Itoa(uuid) + rdata.Channel + uinfo, err := GetUserInfo(uniqueuuid) + if err != nil || uinfo == nil { + logger.Error("redis failed err=%v", err) + resp.Message = "服务器错误" + resp.Code = ERROR_SRV_ERROR + break + } + + drawnum := int(rdata.Money * 100) + //需要判断一下金币是否足够 + if drawnum*100 > uinfo.RealGold { + logger.Error("gold nor enough failed err=%v", err) + resp.Message = "提现金币不足" + resp.Code = ERROR_GETCASH_GOLDNOTENOUGH_FAILED + break + } + + //需要处理一下提现级别 + + index := 0 + var info *WithDrawDesc + if rdata.Ctype == 1 { + index, info = uinfo.GetWithDrawData(rdata.Money) + } else { + index, info = uinfo.GetSpecialWithDrawData(rdata.Money) + } + + if index == -1 || info == nil { + logger.Error("AddWithDrawList failed err=%v", err) + resp.Message = "网络错误" + resp.Code = ERROR_SRV_ERROR + break + } + + if uinfo.Lv < info.Limitlv { + logger.Error("AddWithDrawList failed err=%v", err) + resp.Message = "完成日常任务可以提升人物等级哦~" + resp.Code = ERROR_WITHDRAWLVLIMIT + break + } + + if info.Isnew == 0 { + logger.Error("AddWithDrawList failed err=%v", err) + resp.Message = "新人专享只能提取一次" + resp.Code = ERROR_WITHDRAWONLYONE + break + } + + if info.Preisfind == 0 { + logger.Error("HandlerGetcash Preisfind err=%v", err) + resp.Message = "请先完成前一档提现" + resp.Code = ERROR_PRENOTFINISH + break + } + + //普通提现需要判断前置条件 + if rdata.Ctype == 1 { + //判断一下前置条件的下一档 + if index == len(uinfo.WithDraw.Cashdata)-1 { + //最后一档了不用处理 + } else { + if index < len(uinfo.WithDraw.Cashdata)-1 { + uinfo.WithDraw.Cashdata[index+1].Preisfind = 1 + } + } + } + + //如果是2.2.7版本开启提现次数限制 + if rdata.Ver == "2.2.7" && uinfo.GetCashCnt > 0 { + logger.Error("HandlerGetcash GetCashCnt err=%v", err) + resp.Message = "当天已经提现过了,请明天再来" + resp.Code = ERROR_PRENOTFINISH + break + } + + if uinfo.SumLoginDay < info.Day { + logger.Error("HandlerGetcash GetCashCnt err=%v", err) + resp.Message = "累计登陆天数不足" + resp.Code = ERROR_PRENOTFINISH + break + } + + //2.2.5版本开启自动审核 + checkcoin := 2 + if rdata.Ver == "2.2.5" || rdata.Ver == "2.2.6" || rdata.Ver == "2.2.7" { + logger.Info("HandlerGetcash autocheckcoin") + if drawnum <= 150 { + //1.5挡位以下不需要审核 + checkcoin = 1 //临时关闭u + } + } + + cdkey, err := GetCashWechatFromSDK(uuid, drawnum, rdata.Gameid, rdata.Channel, rdata.Openid, rdata.Nickname, rdata.Headurl, rdata.Ver, checkcoin) + if err != nil { + logger.Error("GetCashFromSDK failed err=%v", err) + resp.Message = "从后台提现失败了" + resp.Code = ERROR_GETCASH_FAILED + break + } + + //保存cdkey + var tmp CashCdKeyInfo + tmp.Cdkey = cdkey + tmp.Money = rdata.Money + tmp.Id = info.Cid + uinfo.Cdkeys = append(uinfo.Cdkeys, tmp) + + uinfo.GetCashCnt++ + //如果是前六挡 + if info.Cid <= 6 && rdata.Ctype == 1 { + uinfo.WithDraw.Cashdata[index].Isnew = 0 + } + if rdata.Ctype == 2 { + uinfo.WithDraw.SpecialCashdata[index].Isnew = 0 + } + + uinfo.RealGold += drawnum * 100 + //uinfo.RealGold -= drawnum * 100 + + resp.Data.Cdkey = cdkey + SaveUserInfo(uinfo, uniqueuuid) + + resp.Code = ERROR_OK + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) + +} + func HandlerGetcash(w http.ResponseWriter, data string, uuid int) { SetHeader(w) var resp GetcashResp @@ -956,6 +1108,7 @@ func HandlerQuerdrawinfo(w http.ResponseWriter, data string, uuid int) { //返回 resp.Data.Cashdata = append(resp.Data.Cashdata, uinfo.WithDraw.Cashdata...) resp.Data.SpecialCashdata = append(resp.Data.SpecialCashdata, uinfo.WithDraw.SpecialCashdata...) + resp.Data.Cdkeycashdata = append(resp.Data.Cdkeycashdata, uinfo.Cdkeys...) resp.Code = ERROR_OK break -- libgit2 0.21.0