This commit is contained in:
邹宗楠
2022-10-24 21:53:59 +08:00
parent 475044fd4b
commit 6bb26fed16

View File

@@ -57,18 +57,20 @@ func PKCS5UnPadding(origData []byte) []byte {
type Code struct { type Code struct {
MsgType int64 `json:"msg_type"` MsgType int64 `json:"msg_type"`
msg struct { Msg string `json:"msg"`
ActionType int64 `json:"action_type"` }
type MsgDetail struct {
ActionType int `json:"action_type"`
AppId int64 `json:"app_id"` AppId int64 `json:"app_id"`
ShopId int64 `json:"shop_id"` ShopId int `json:"shop_id"`
Code string `json:"code"` Code string `json:"code"`
CodeGenerateTime string `json:"code_generate_time"` CodeGenerateTime string `json:"code_generate_time"`
}
} }
func (c *TiktokShopController) TokenMsg() { func (c *TiktokShopController) TokenMsg() {
req := c.Ctx.Request req := c.Ctx.Request
var code []string var code string
switch req.Method { switch req.Method {
case http.MethodPost: case http.MethodPost:
data, err := ioutil.ReadAll(req.Body) data, err := ioutil.ReadAll(req.Body)
@@ -85,15 +87,22 @@ func (c *TiktokShopController) TokenMsg() {
} }
globals.SugarLogger.Debugf("codeToken============%s", utils.Format4Output(codeToken, false)) globals.SugarLogger.Debugf("codeToken============%s", utils.Format4Output(codeToken, false))
var codeResult Code var codeMsg Code
if err := json.Unmarshal([]byte(codeToken), &codeResult); err != nil { if err := json.Unmarshal([]byte(codeToken), &codeMsg); err != nil {
globals.SugarLogger.Debugf("err============%s", utils.Format4Output(codeToken, false)) globals.SugarLogger.Debugf("err============%s", utils.Format4Output(codeToken, false))
c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackFailCode, Msg: tiktok_api.CallbackFail} c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackFailCode, Msg: tiktok_api.CallbackFail}
c.ServeJSON() c.ServeJSON()
return return
} }
globals.SugarLogger.Debugf("codeResult============%s", utils.Format4Output(codeResult, false))
code = append(code, codeResult.msg.Code) var msg MsgDetail
if err := json.Unmarshal([]byte(codeMsg.Msg), &msg); err != nil {
globals.SugarLogger.Debugf("err============%s", utils.Format4Output(codeToken, false))
c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackFailCode, Msg: tiktok_api.CallbackFail}
c.ServeJSON()
return
}
code = msg.Code
case http.MethodGet: case http.MethodGet:
codeValues := req.URL.Query() codeValues := req.URL.Query()
codeList := codeValues.Get("code") codeList := codeValues.Get("code")
@@ -112,8 +121,7 @@ func (c *TiktokShopController) TokenMsg() {
return return
} }
for _, v := range code { result, err := api.TiktokStore.CreateToken(code)
result, err := api.TiktokStore.CreateToken(v)
if err != nil { if err != nil {
c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackFailCode, Msg: tiktok_api.CallbackFail} c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackFailCode, Msg: tiktok_api.CallbackFail}
c.ServeJSON() c.ServeJSON()
@@ -148,7 +156,6 @@ func (c *TiktokShopController) TokenMsg() {
c.ServeJSON() c.ServeJSON()
return return
} }
}
c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackSuccessCode, Msg: tiktok_api.CallbackSuccess} c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackSuccessCode, Msg: tiktok_api.CallbackSuccess}
c.ServeJSON() c.ServeJSON()
} }