This commit is contained in:
邹宗楠
2022-10-24 17:39:06 +08:00
parent 9c66cc7c15
commit d963fa8bf6

View File

@@ -18,54 +18,58 @@ type TiktokShopController struct {
// TokenMsg 抖音用户授权
func (c *TiktokShopController) TokenMsg() {
code := utils.Interface2StringList(c.Ctx.Request.URL.Query().Get("code"))[0]
if code == "" {
codeList := c.Ctx.Request.URL.Query().Get("code")
var code []string
if err := json.Unmarshal([]byte(codeList), &code); err != nil {
c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackFailCode, Msg: tiktok_api.CallbackFail}
c.ServeJSON()
return
}
globals.SugarLogger.Debugf("==========%s", code)
result, err := api.TiktokStore.CreateToken(code)
globals.SugarLogger.Debugf("=result=========%s", utils.Format4Output(result, false))
globals.SugarLogger.Debugf("=err1=========%s", err)
if err != nil {
globals.SugarLogger.Debugf("codeList=====%s", utils.Format4Output(codeList, false))
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}
c.ServeJSON()
return
}
result.ExpiresIn += time.Now().Unix()
data, err := json.Marshal(result)
globals.SugarLogger.Debugf("=err12=========%s", utils.Format4Output(data, false))
globals.SugarLogger.Debugf("=data=========%s", err)
if err != nil {
c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackFailCode, Msg: tiktok_api.CallbackFail}
c.ServeJSON()
return
}
for _, v := range code {
result, err := api.TiktokStore.CreateToken(v)
if err != nil {
c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackFailCode, Msg: tiktok_api.CallbackFail}
c.ServeJSON()
return
}
globals.SugarLogger.Debugf("result=====%s", utils.Format4Output(result, false))
param := &model.VendorOrgCode{
VendorID: model.VendorIDDD,
VendorOrgCode: utils.Int64ToStr(result.ShopId),
Comment: "抖音授权",
VendorType: "platform",
IsJxCat: 1,
IsOpen: 1,
EmpowerURL: "",
StoreBrandName: result.ShopName,
Token: string(data),
AppKey: "", // web.AppConfig.DefaultString("tiktokShopAppId", "7136048270014416392"),
AppSecret: "", // web.AppConfig.DefaultString("tiktokShopAppSecret", "c397aa9f-3927-47c4-8cfe-4d84e02602e0")
result.ExpiresIn += time.Now().Unix()
data, err := json.Marshal(result)
if err != nil {
c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackFailCode, Msg: tiktok_api.CallbackFail}
c.ServeJSON()
return
}
param := &model.VendorOrgCode{
VendorID: model.VendorIDDD,
VendorOrgCode: utils.Int64ToStr(result.ShopId),
Comment: "抖音授权",
VendorType: "platform",
IsJxCat: 1,
IsOpen: 1,
EmpowerURL: "",
StoreBrandName: result.ShopName,
Token: string(data),
AppKey: "", // web.AppConfig.DefaultString("tiktokShopAppId", "7136048270014416392"),
AppSecret: "", // web.AppConfig.DefaultString("tiktokShopAppSecret", "c397aa9f-3927-47c4-8cfe-4d84e02602e0")
}
if err := common.AddVendorOrgCode(nil, param); err != nil {
c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackFailCode, Msg: tiktok_api.CallbackFail}
c.ServeJSON()
return
}
}
if err := common.AddVendorOrgCode(nil, param); err != nil {
globals.SugarLogger.Debugf("=err123=========%s", err)
c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackFailCode, Msg: tiktok_api.CallbackFail}
c.ServeJSON()
return
}
globals.SugarLogger.Debugf("=4=========%s", err)
c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackSuccessCode, Msg: tiktok_api.CallbackSuccess}
c.ServeJSON()
}