Commit e62063c8ab914fb99ec4e4b06acd8d2675459847
1 parent
4596c516
Exists in
master
提交相关接口
Showing
5 changed files
with
167 additions
and
1 deletions
Show diff stats
src/HttpServer/logic/datadef.go
| @@ -25,7 +25,8 @@ type GetAccessTokenResp struct { | @@ -25,7 +25,8 @@ type GetAccessTokenResp struct { | ||
| 25 | //-------------------------------------------------------------------------- | 25 | //-------------------------------------------------------------------------- |
| 26 | 26 | ||
| 27 | type GetcurpropertyReq struct { | 27 | type GetcurpropertyReq struct { |
| 28 | - Openid string `json:"openid"` | 28 | + Openid string `json:"openid"` |
| 29 | + Device_id int `json:"device_id"` | ||
| 29 | } | 30 | } |
| 30 | 31 | ||
| 31 | type GetcurpropertyData struct { | 32 | type GetcurpropertyData struct { |
| @@ -33,6 +34,7 @@ type GetcurpropertyData struct { | @@ -33,6 +34,7 @@ type GetcurpropertyData struct { | ||
| 33 | Speed int64 `json:"speed"` | 34 | Speed int64 `json:"speed"` |
| 34 | Curlevle int64 `json:"curlevle"` | 35 | Curlevle int64 `json:"curlevle"` |
| 35 | Leftcnt int `json:"leftcnt"` | 36 | Leftcnt int `json:"leftcnt"` |
| 37 | + Curgold int `json:"curgold"` | ||
| 36 | } | 38 | } |
| 37 | 39 | ||
| 38 | type GetcurpropertyResp struct { | 40 | type GetcurpropertyResp struct { |
| @@ -59,6 +61,37 @@ type FetchproteryboxResp struct { | @@ -59,6 +61,37 @@ type FetchproteryboxResp struct { | ||
| 59 | RetData FetchproteryboxData `json:"retData"` | 61 | RetData FetchproteryboxData `json:"retData"` |
| 60 | } | 62 | } |
| 61 | 63 | ||
| 64 | +type UploadgunlvReq struct { | ||
| 65 | + Openid string `json:"openid"` | ||
| 66 | + Maxlevel int `json:"maxlevel"` | ||
| 67 | +} | ||
| 68 | + | ||
| 69 | +type UploadgunlvData struct { | ||
| 70 | + Speed int64 `json:"speed"` | ||
| 71 | +} | ||
| 72 | + | ||
| 73 | +type UploadgunlvResp struct { | ||
| 74 | + ErrNum int `json:"errNum"` | ||
| 75 | + RetMsg string `json:"retMsg"` | ||
| 76 | + RetData UploadgunlvData `json:"retData"` | ||
| 77 | +} | ||
| 78 | + | ||
| 79 | +type AddgoldReq struct { | ||
| 80 | + Openid string `json:"openid"` | ||
| 81 | + Device_id int `json:"device_id"` | ||
| 82 | + Gold_num int `json:"gold_num"` | ||
| 83 | +} | ||
| 84 | + | ||
| 85 | +type AddgoldData struct { | ||
| 86 | + Taoalgoldnum int `json:"taoalgoldnum"` | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | +type AddgoldResp struct { | ||
| 90 | + ErrNum int `json:"errNum"` | ||
| 91 | + RetMsg string `json:"retMsg"` | ||
| 92 | + RetData AddgoldData `json:"retData"` | ||
| 93 | +} | ||
| 94 | + | ||
| 62 | //------------------------------------------------------------------------------------------------------ | 95 | //------------------------------------------------------------------------------------------------------ |
| 63 | 96 | ||
| 64 | type UserData struct { | 97 | type UserData struct { |
| @@ -72,4 +105,5 @@ type UserData struct { | @@ -72,4 +105,5 @@ type UserData struct { | ||
| 72 | SingDay int //签到天数 | 105 | SingDay int //签到天数 |
| 73 | IsSign int //当天是否已经签到 | 106 | IsSign int //当天是否已经签到 |
| 74 | TodaySec int //当天零点时间戳,用于判断跨天 | 107 | TodaySec int //当天零点时间戳,用于判断跨天 |
| 108 | + PassLvGold int //当天过关获得的金币 | ||
| 75 | } | 109 | } |
src/HttpServer/logic/errordef.go
| @@ -8,5 +8,7 @@ const ( | @@ -8,5 +8,7 @@ const ( | ||
| 8 | ERROR_READCFG_FAILED = 4 //读取配置错误 | 8 | ERROR_READCFG_FAILED = 4 //读取配置错误 |
| 9 | ERROR_PROPERTY_NOTENOUGH = 5 //当前物资不足 | 9 | ERROR_PROPERTY_NOTENOUGH = 5 //当前物资不足 |
| 10 | ERROR_TOUTIAOAPI_FAILED = 6 //头条接口失败 | 10 | ERROR_TOUTIAOAPI_FAILED = 6 //头条接口失败 |
| 11 | + ERROR_PARAM_INVALID = 7 //等级参数无效 | ||
| 12 | + ERROR_GOLD_LIMIT = 8 //当日合成获得金币已达上限 | ||
| 11 | 13 | ||
| 12 | ) | 14 | ) |
src/HttpServer/logic/function.go
| @@ -72,6 +72,7 @@ func (u *UserData) InitUserInfo(openid string) error { | @@ -72,6 +72,7 @@ func (u *UserData) InitUserInfo(openid string) error { | ||
| 72 | u.MaxLevel = 1 | 72 | u.MaxLevel = 1 |
| 73 | u.Property = 0 | 73 | u.Property = 0 |
| 74 | u.SingDay = 0 | 74 | u.SingDay = 0 |
| 75 | + u.PassLvGold = 0 | ||
| 75 | u.TodaySec = int(time.Date(nowtime.Year(), nowtime.Month(), nowtime.Day(), 0, 0, 0, 0, nowtime.Location()).Unix()) | 76 | u.TodaySec = int(time.Date(nowtime.Year(), nowtime.Month(), nowtime.Day(), 0, 0, 0, 0, nowtime.Location()).Unix()) |
| 76 | u.TotalFetchCnt = 0 //用于计算当前领取次数 | 77 | u.TotalFetchCnt = 0 //用于计算当前领取次数 |
| 77 | 78 | ||
| @@ -135,6 +136,7 @@ func (u *UserData) CalcProperty() { | @@ -135,6 +136,7 @@ func (u *UserData) CalcProperty() { | ||
| 135 | u.SingDay = 0 | 136 | u.SingDay = 0 |
| 136 | u.SignRound++ | 137 | u.SignRound++ |
| 137 | } | 138 | } |
| 139 | + u.PassLvGold = 0 | ||
| 138 | } | 140 | } |
| 139 | } | 141 | } |
| 140 | //保存 | 142 | //保存 |
src/HttpServer/logic/httpserver.go
| @@ -45,10 +45,32 @@ func startServerHttpServe() { | @@ -45,10 +45,32 @@ func startServerHttpServe() { | ||
| 45 | //---------------------------------------------------------------------------------------- | 45 | //---------------------------------------------------------------------------------------- |
| 46 | http.HandleFunc("/daycs/getcurproperty", Getcurproperty) //请求当前物资 | 46 | http.HandleFunc("/daycs/getcurproperty", Getcurproperty) //请求当前物资 |
| 47 | http.HandleFunc("/daycs/fetchproterybox", Fetchproterybox) //请求领取物资宝箱 | 47 | http.HandleFunc("/daycs/fetchproterybox", Fetchproterybox) //请求领取物资宝箱 |
| 48 | + http.HandleFunc("/daycs/uploadgunlv", Uploadgunlv) //上报当前枪支等级 | ||
| 49 | + http.HandleFunc("/daycs/addgold", Addgold) //增加金币接口(过关加金币用) | ||
| 48 | err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) | 50 | err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) |
| 49 | CheckErr(err) | 51 | CheckErr(err) |
| 50 | } | 52 | } |
| 51 | 53 | ||
| 54 | +func Addgold(w http.ResponseWriter, r *http.Request) { | ||
| 55 | + result, _ := ioutil.ReadAll(r.Body) | ||
| 56 | + r.Body.Close() | ||
| 57 | + | ||
| 58 | + s := string(result) | ||
| 59 | + logger.Info("Addgold , body:%v", s) | ||
| 60 | + | ||
| 61 | + HandlerAddgold(w, s) | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +func Uploadgunlv(w http.ResponseWriter, r *http.Request) { | ||
| 65 | + result, _ := ioutil.ReadAll(r.Body) | ||
| 66 | + r.Body.Close() | ||
| 67 | + | ||
| 68 | + s := string(result) | ||
| 69 | + logger.Info("Uploadgunlv , body:%v", s) | ||
| 70 | + | ||
| 71 | + HandlerUploadgunlv(w, s) | ||
| 72 | +} | ||
| 73 | + | ||
| 52 | func Fetchproterybox(w http.ResponseWriter, r *http.Request) { | 74 | func Fetchproterybox(w http.ResponseWriter, r *http.Request) { |
| 53 | result, _ := ioutil.ReadAll(r.Body) | 75 | result, _ := ioutil.ReadAll(r.Body) |
| 54 | r.Body.Close() | 76 | r.Body.Close() |
src/HttpServer/logic/logic.go
| @@ -8,10 +8,110 @@ import ( | @@ -8,10 +8,110 @@ import ( | ||
| 8 | "net/http" | 8 | "net/http" |
| 9 | ) | 9 | ) |
| 10 | 10 | ||
| 11 | +func HandlerAddgold(w http.ResponseWriter, data string) { | ||
| 12 | + SetHeader(w) | ||
| 13 | + var resp AddgoldResp | ||
| 14 | + resp.ErrNum = 0 | ||
| 15 | + var rdata AddgoldReq | ||
| 16 | + err := json.Unmarshal([]byte(data), &rdata) | ||
| 17 | + for { | ||
| 18 | + if err != nil { | ||
| 19 | + logger.Info("json decode HandlerAddgold data failed:%v,for:%v", err, data) | ||
| 20 | + resp.RetMsg = "json解析失败" | ||
| 21 | + resp.ErrNum = ERROR_UNMASH_JSONFAILED | ||
| 22 | + break | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + uinfo, err := GetUserInfo(rdata.Openid) | ||
| 26 | + if err != nil || uinfo == nil { | ||
| 27 | + logger.Info(" HandlerAddgold getdata failed:%v,for:%v", err, data) | ||
| 28 | + resp.RetMsg = "服务器读取数据失败" | ||
| 29 | + resp.ErrNum = ERROR_SERVER_FAILED | ||
| 30 | + break | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + if uinfo.PassLvGold >= 100 { | ||
| 34 | + logger.Info(" HandlerAddgold PassLvGold failed:%v,for:%v", err, data) | ||
| 35 | + resp.RetMsg = "当日合成获得金币已达上限" | ||
| 36 | + resp.ErrNum = ERROR_GOLD_LIMIT | ||
| 37 | + break | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + addnum, sumnum, err := AddCoinToTouTiao(rdata.Openid, rdata.Device_id, rdata.Gold_num, "闯关送金币", "other") | ||
| 41 | + if err != nil { | ||
| 42 | + logger.Info(" HandlerAddgold property failed:%v,for:%v", err, data) | ||
| 43 | + resp.RetMsg = "调用头条接口失败" | ||
| 44 | + resp.ErrNum = ERROR_TOUTIAOAPI_FAILED | ||
| 45 | + break | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + uinfo.PassLvGold += addnum | ||
| 49 | + resp.RetData.Taoalgoldnum = sumnum | ||
| 50 | + //保存 | ||
| 51 | + err = SaveUserInfo(uinfo) | ||
| 52 | + if err != nil { | ||
| 53 | + logger.Error("HandlerFetchproterybox err=%v", err) | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + break | ||
| 57 | + } | ||
| 58 | + //回包 | ||
| 59 | + respstr, _ := json.Marshal(&resp) | ||
| 60 | + fmt.Fprint(w, string(respstr)) | ||
| 61 | +} | ||
| 62 | + | ||
| 63 | +func HandlerUploadgunlv(w http.ResponseWriter, data string) { | ||
| 64 | + SetHeader(w) | ||
| 65 | + var resp UploadgunlvResp | ||
| 66 | + resp.ErrNum = 0 | ||
| 67 | + resp.RetMsg = "success" | ||
| 68 | + var rdata UploadgunlvReq | ||
| 69 | + err := json.Unmarshal([]byte(data), &rdata) | ||
| 70 | + for { | ||
| 71 | + if err != nil { | ||
| 72 | + logger.Info("json decode HandlerUploadgunlv data failed:%v,for:%v", err, data) | ||
| 73 | + resp.RetMsg = "json解析失败" | ||
| 74 | + resp.ErrNum = ERROR_UNMASH_JSONFAILED | ||
| 75 | + break | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + uinfo, err := GetUserInfo(rdata.Openid) | ||
| 79 | + if err != nil || uinfo == nil { | ||
| 80 | + logger.Info(" HandlerFetchproterybox getdata failed:%v,for:%v", err, data) | ||
| 81 | + resp.RetMsg = "服务器读取数据失败" | ||
| 82 | + resp.ErrNum = ERROR_SERVER_FAILED | ||
| 83 | + break | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + if rdata.Maxlevel < uinfo.MaxLevel { | ||
| 87 | + logger.Info(" HandlerFetchproterybox MaxLevel failed:%v,for:%v", err, data) | ||
| 88 | + resp.RetMsg = "等级参数不正确" | ||
| 89 | + resp.ErrNum = ERROR_PARAM_INVALID | ||
| 90 | + break | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + uinfo.MaxLevel = rdata.Maxlevel | ||
| 94 | + | ||
| 95 | + resp.RetData.Speed = uinfo.CalcSpeed() | ||
| 96 | + | ||
| 97 | + //保存 | ||
| 98 | + err = SaveUserInfo(uinfo) | ||
| 99 | + if err != nil { | ||
| 100 | + logger.Error("HandlerFetchproterybox err=%v", err) | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + break | ||
| 104 | + } | ||
| 105 | + //回包 | ||
| 106 | + respstr, _ := json.Marshal(&resp) | ||
| 107 | + fmt.Fprint(w, string(respstr)) | ||
| 108 | +} | ||
| 109 | + | ||
| 11 | func HandlerFetchproterybox(w http.ResponseWriter, data string) { | 110 | func HandlerFetchproterybox(w http.ResponseWriter, data string) { |
| 12 | SetHeader(w) | 111 | SetHeader(w) |
| 13 | var resp FetchproteryboxResp | 112 | var resp FetchproteryboxResp |
| 14 | resp.ErrNum = 0 | 113 | resp.ErrNum = 0 |
| 114 | + resp.RetMsg = "success" | ||
| 15 | var rdata FetchproteryboxReq | 115 | var rdata FetchproteryboxReq |
| 16 | err := json.Unmarshal([]byte(data), &rdata) | 116 | err := json.Unmarshal([]byte(data), &rdata) |
| 17 | for { | 117 | for { |
| @@ -88,6 +188,7 @@ func HandlerGetcurproperty(w http.ResponseWriter, data string) { | @@ -88,6 +188,7 @@ func HandlerGetcurproperty(w http.ResponseWriter, data string) { | ||
| 88 | SetHeader(w) | 188 | SetHeader(w) |
| 89 | var resp GetcurpropertyResp | 189 | var resp GetcurpropertyResp |
| 90 | resp.ErrNum = 0 | 190 | resp.ErrNum = 0 |
| 191 | + resp.RetMsg = "success" | ||
| 91 | var rdata GetcurpropertyReq | 192 | var rdata GetcurpropertyReq |
| 92 | err := json.Unmarshal([]byte(data), &rdata) | 193 | err := json.Unmarshal([]byte(data), &rdata) |
| 93 | for { | 194 | for { |
| @@ -114,6 +215,11 @@ func HandlerGetcurproperty(w http.ResponseWriter, data string) { | @@ -114,6 +215,11 @@ func HandlerGetcurproperty(w http.ResponseWriter, data string) { | ||
| 114 | resp.RetData.Curlevle = uinfo.CalcCurLe() | 215 | resp.RetData.Curlevle = uinfo.CalcCurLe() |
| 115 | resp.RetData.Protery = uinfo.Property | 216 | resp.RetData.Protery = uinfo.Property |
| 116 | resp.RetData.Speed = uinfo.CalcSpeed() | 217 | resp.RetData.Speed = uinfo.CalcSpeed() |
| 218 | + newgold, err := GetCoinFromToutiao(rdata.Openid, rdata.Device_id) | ||
| 219 | + if err != nil { | ||
| 220 | + logger.Error("HandlerGetcurproperty err=%v", err) | ||
| 221 | + } | ||
| 222 | + resp.RetData.Curgold = newgold | ||
| 117 | 223 | ||
| 118 | break | 224 | break |
| 119 | } | 225 | } |