From b1bfc4e3850e53e90235b48ba183882e629b4bef Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Wed, 10 May 2023 16:01:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BF=AE=E6=94=B9=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=9C=8D=E5=8A=A1=E5=99=A8=E6=97=B6=E9=97=B4=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/timestamp.text | 1 + bin/梦工厂后台AIP文档.md | 23 ++++++++++++ modules/web/api_createnotify.go | 4 +- modules/web/api_modifytime.go | 48 ++++++++++++++++++++++++ modules/web/api_opentime.go | 65 --------------------------------- 5 files changed, 75 insertions(+), 66 deletions(-) create mode 100644 bin/timestamp.text create mode 100644 modules/web/api_modifytime.go delete mode 100644 modules/web/api_opentime.go diff --git a/bin/timestamp.text b/bin/timestamp.text new file mode 100644 index 000000000..760e465c0 --- /dev/null +++ b/bin/timestamp.text @@ -0,0 +1 @@ +15.000000 \ No newline at end of file diff --git a/bin/梦工厂后台AIP文档.md b/bin/梦工厂后台AIP文档.md index 36ffcb7b5..5b87d1fc2 100644 --- a/bin/梦工厂后台AIP文档.md +++ b/bin/梦工厂后台AIP文档.md @@ -59,6 +59,7 @@ "data":"", } ``` + ### 邮件发放API - 接口名:createmail - 接口说明:web 服务器给玩家发送邮件 @@ -112,4 +113,26 @@ "msg":"成功", "data":"", } +``` + +### 修改服务器时间 +- 接口名:modifyopentime +- 接口说明:修改区服服务当前时间用于QA测试 +- 请求地址:{IP}:{port}/modifyopentime +- 请求参数:offest(请求时间戳|签名),sign(签名) +- 请求样例 +``` +{ + "offest":12, + "sign":"asjioqiowjeioqjweijqwejoi" +} +``` +- 返回参数 code(0:成功 -1 失败),msg(结果描述),data(返回的额外数据) +- 返回样例 +``` +{ + "code":0, + "msg":"成功", + "data":"", +} ``` \ No newline at end of file diff --git a/modules/web/api_createnotify.go b/modules/web/api_createnotify.go index c9c5359bc..e5867c8bf 100644 --- a/modules/web/api_createnotify.go +++ b/modules/web/api_createnotify.go @@ -22,7 +22,9 @@ func (this *Api_Comp) CreateNotify(c *engine.Context) { msg string data interface{} ) - defer c.JSON(http.StatusOK, &Respond{Code: code, Message: msg, Data: data}) + defer func() { + c.JSON(http.StatusOK, &Respond{Code: code, Message: msg, Data: data}) + }() if sign := gin.ParamSign(this.options.Key, map[string]interface{}{"Title": req.Title, "Ctime": req.Ctime, "Rtime": req.Rtime}); sign != req.Sign { this.module.Errorf("LoginByCaptchaReq SignError sgin:%s", sign) code = pb.ErrorCode_SignError diff --git a/modules/web/api_modifytime.go b/modules/web/api_modifytime.go new file mode 100644 index 000000000..b21403ab4 --- /dev/null +++ b/modules/web/api_modifytime.go @@ -0,0 +1,48 @@ +package web + +import ( + "context" + "go_dreamfactory/comm" + "go_dreamfactory/lego/sys/gin" + "go_dreamfactory/lego/sys/gin/engine" + "go_dreamfactory/pb" + "go_dreamfactory/sys/configure" + "net/http" + "time" +) + +type ModifyopentimeReq struct { + Offest int64 `json:"offest"` // uid + Sign string `json:"sign"` +} + +//修改开服时间 +func (this *Api_Comp) Modifyopentime(c *engine.Context) { + req := &ModifyopentimeReq{} + err := c.BindJSON(&req) + this.module.Debugf("CreateNotify:%+v err:%v", req, err) + var ( + code pb.ErrorCode + msg string + ) + defer func() { + c.JSON(http.StatusOK, &Respond{Code: code, Message: msg, Data: nil}) + }() + if sign := gin.ParamSign(this.options.Key, map[string]interface{}{"offest": req.Offest}); sign != req.Sign { + this.module.Errorf("Modifyopentime SignError sgin:%s", sign) + code = pb.ErrorCode_SignError + msg = pb.GetErrorCodeMsg(code) + return + } + configure.SetOffsettime(time.Duration(req.Offest) * time.Second) + if err := this.module.service.RpcBroadcast( + context.Background(), + comm.Service_Worker, + string(comm.Rpc_ConfigureUpDate), + &pb.EmptyReq{}, + &pb.EmptyResp{}); err != nil { + this.module.Errorln(err) + msg = err.Error() + code = pb.ErrorCode_RpcFuncExecutionError + } +} diff --git a/modules/web/api_opentime.go b/modules/web/api_opentime.go deleted file mode 100644 index 4fcca31e2..000000000 --- a/modules/web/api_opentime.go +++ /dev/null @@ -1,65 +0,0 @@ -package web - -import ( - "context" - "fmt" - "go_dreamfactory/comm" - "go_dreamfactory/lego/sys/gin/engine" - "go_dreamfactory/pb" - "go_dreamfactory/sys/configure" - "net/http" - "time" -) - -type OpenTime struct { - Optime string `json:"optime"` //开服时间 - Mytime string `json:"mytime"` //修改后的开服时间 -} - -//获取开服时间 -func (this *Api_Comp) Getopentime(c *engine.Context) { - data := &OpenTime{ - Optime: this.module.service.GetOpentime().Format("2006-01-02 15:04:05"), - Mytime: this.module.service.GetOpentime().Add(configure.GetOffsettime()).Format("2006-01-02 15:04:05"), - } - c.JSON(http.StatusOK, &Respond{ - Code: 0, - Message: "成功", - Data: data, - }) -} - -//修改开服时间 -func (this *Api_Comp) Modifyopentime(c *engine.Context) { - var ( - code pb.ErrorCode - msg string - offest time.Duration - ) - opentime := c.PostForm("opentime") - defer func() { - c.JSON(http.StatusOK, &Respond{ - Code: code, - Message: msg, - Data: opentime, - }) - }() - t, err := time.ParseInLocation("2006-01-02 15:04:05", opentime, time.Local) - if nil != err || t.IsZero() { - this.module.Errorln(err) - msg = fmt.Sprintf("opentime:%s 格式异常", opentime) - code = pb.ErrorCode_ReqParameterError - } - offest = t.Sub(this.module.service.GetOpentime()) - configure.SetOffsettime(offest) - if err := this.module.service.RpcBroadcast( - context.Background(), - comm.Service_Worker, - string(comm.Rpc_ConfigureUpDate), - &pb.EmptyReq{}, - &pb.EmptyResp{}); err != nil { - this.module.Errorln(err) - msg = err.Error() - code = pb.ErrorCode_RpcFuncExecutionError - } -}