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