101 lines
3.6 KiB
Go
101 lines
3.6 KiB
Go
package controllers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"git.rosy.net.cn/baseapi/platformapi/tiktok_shop/tiktok_api"
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
"git.rosy.net.cn/jx-callback/business/jxstore/common"
|
|
"git.rosy.net.cn/jx-callback/business/model"
|
|
"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"
|
|
)
|
|
|
|
type TiktokShopController struct {
|
|
web.Controller
|
|
}
|
|
|
|
func (c *TiktokShopController) TokenMsg() {
|
|
req := c.Ctx.Request
|
|
var code []string
|
|
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
|
|
}
|
|
|
|
globals.SugarLogger.Debugf("data=====err%s", string(data))
|
|
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}
|
|
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))
|
|
|
|
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: "https://fuwu.jinritemai.com/detail?from=open_partner_svcList&service_id=24070",
|
|
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
|
|
}
|
|
}
|
|
c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackSuccessCode, Msg: tiktok_api.CallbackSuccess}
|
|
c.ServeJSON()
|
|
}
|