From 8ac563c031bd59df7c1e3fb9c4bfa548d767011a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 24 Oct 2022 19:20:36 +0800 Subject: [PATCH] 1 --- controllers/tiktok_store.go | 44 +++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/controllers/tiktok_store.go b/controllers/tiktok_store.go index abdab6d9c..d9ae3ddeb 100644 --- a/controllers/tiktok_store.go +++ b/controllers/tiktok_store.go @@ -9,6 +9,8 @@ import ( "git.rosy.net.cn/jx-callback/globals" "git.rosy.net.cn/jx-callback/globals/api" "github.com/astaxie/beego/server/web" + "io/ioutil" + "net/http" "time" ) @@ -17,20 +19,38 @@ type TiktokShopController struct { } func (c *TiktokShopController) TokenMsg() { - codeValues := c.Ctx.Request.URL.Query() - globals.SugarLogger.Debugf("codeValues=====%s", utils.Format4Output(codeValues, false)) - - codeList := codeValues.Get("code") - globals.SugarLogger.Debugf("codeList=====%s", utils.Format4Output(codeList, false)) - globals.SugarLogger.Debugf("codeValues.Get(\"code\")%s", utils.Format4Output(codeValues.Get("Code"), false)) - + req := c.Ctx.Request var code []string - if err := json.Unmarshal([]byte(string(codeList)), &code); err != nil { - globals.SugarLogger.Debugf("codeList=====err%s", utils.Format4Output(err, false)) - c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackFailCode, Msg: tiktok_api.CallbackFail} - c.ServeJSON() - return + switch req.Method { + case http.MethodPost: + data, err := ioutil.ReadAll(req.Body) + if err != nil { + globals.SugarLogger.Debugf("MethodPost=====err%s", utils.Format4Output(err, false)) + c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackFailCode, Msg: tiktok_api.CallbackFail} + c.ServeJSON() + return + } + + if err := json.Unmarshal(data, &code); err != nil { + globals.SugarLogger.Debugf("Unmarshal=====err%s", utils.Format4Output(err, false)) + c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackFailCode, Msg: tiktok_api.CallbackFail} + c.ServeJSON() + return + } + case http.MethodGet: + codeValues := req.URL.Query() + globals.SugarLogger.Debugf("codeValues=====%s", utils.Format4Output(codeValues, false)) + codeList := codeValues.Get("code") + globals.SugarLogger.Debugf("codeList=====%s", utils.Format4Output(codeList, false)) + globals.SugarLogger.Debugf("codeValues.Get(code)===%s", utils.Format4Output(codeValues.Get("Code"), false)) + if err := json.Unmarshal([]byte(string(codeList)), &code); err != nil { + globals.SugarLogger.Debugf("codeList=====err%s", utils.Format4Output(err, false)) + c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackFailCode, Msg: tiktok_api.CallbackFail} + c.ServeJSON() + return + } } + globals.SugarLogger.Debugf("code ==================%s", utils.Format4Output(code, false)) if len(code) == 0 { c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackFailCode, Msg: tiktok_api.CallbackFail}