diff --git a/src/HttpServer/logic/datadef.go b/src/HttpServer/logic/datadef.go index 0d4fdab..327d2bc 100644 --- a/src/HttpServer/logic/datadef.go +++ b/src/HttpServer/logic/datadef.go @@ -134,6 +134,16 @@ type GetcashReq struct { Ctype int `json:"ctype"` } +type GetCashWechatData struct { + Cdkey string `json:"cdkey"` +} + +type GetCashWechatResp struct { + Code string `json:"code"` + Data GetCashWechatData `json:"data"` + Msg string `json:"msg"` +} + type CommReq struct { Gameid string `json:"gameid"` Channel string `json:"channel"` @@ -148,6 +158,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"` @@ -419,9 +449,16 @@ func (v WithDrawDescs) Less(i, j int) bool { return v[i].Cid < v[j].Cid } +type CashCdKeyInfo struct { + Id int `json:"id"` + Money float32 `json:"money"` + Cdkey string `json:"cdkey"` +} + type WithDrawInfo struct { Cashdata WithDrawDescs `json:"cashdata"` SpecialCashdata WithDrawDescs `json:"specialcashdata"` + Cdkeycashdata []CashCdKeyInfo `json:"cdkeycashdata"` } type WithDrawDesc struct { @@ -465,6 +502,7 @@ type UserData struct { Sunti int //总答题数 Coti int //正确提数 WithDraw WithDrawInfo //提现记录信息 + Cdkeys []CashCdKeyInfo //记录提现的cdkeys //SpecialWithDraw WithDrawInfo //活跃提现记录信息 Task TaskInfo //玩家任务完成相关信息 Achieve AchieveMentInfo //玩家成就完成相关数据 diff --git a/src/HttpServer/logic/function.go b/src/HttpServer/logic/function.go index 81908f1..679c73e 100644 --- a/src/HttpServer/logic/function.go +++ b/src/HttpServer/logic/function.go @@ -1331,6 +1331,121 @@ 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 == "" || ver == "" { + logger.Error("GetCashFromSDK param empty") + return "error", errors.New("param empty") + } + + if openid == "" { + openid = "test" + } + 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 = 11 + 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=" + "11" //微信 + 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 "error", err + } + res, err := DoHttpPost(bys, "api/server/tixiancdkey") + 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 "error", 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 "error", err + } + + if resp.Code != "0" { + logger.Error("GetCashWechatFromSDK failed=%v", resp.Msg) + return "error", errors.New(resp.Msg) + } + + return resp.Data.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 79772ed..4c35c28 100644 --- a/src/HttpServer/logic/httpserver.go +++ b/src/HttpServer/logic/httpserver.go @@ -63,6 +63,7 @@ func startServerHttpServe() { http.HandleFunc("/guessge/drawguangold", Drawguangold) //提取存钱罐的金币到个人钱包 http.HandleFunc("/guessge/querdrawinfo", Querdrawinfo) //获取提现档位信息接口 http.HandleFunc("/guessge/getcash", Getcash) //提现 + http.HandleFunc("/guessge/getcashwechat", Getcashwechat) //提现 http.HandleFunc("/guessge/getcashrecord", Getcashrecord) //提现记录列表 http.HandleFunc("/guessge/onlinentf", Onlinentf) //在线通知 http.HandleFunc("/guessge/updatetaskandachieve", Updatetaskandachieve) //上报任务事件进度 @@ -546,6 +547,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 327b88a..42b4fe1 100644 --- a/src/HttpServer/logic/logic.go +++ b/src/HttpServer/logic/logic.go @@ -107,6 +107,160 @@ 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 + } + logger.Info("HandlerGetcashwechat cdkey=%v", cdkey) + + //保存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 + } + + //回包 + logger.Info("HandlerGetcashwechat resp=%+v", resp) + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) + +} + func HandlerGetcash(w http.ResponseWriter, data string, uuid int) { SetHeader(w) var resp GetcashResp @@ -1110,6 +1264,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