1
This commit is contained in:
@@ -56,19 +56,21 @@ func PKCS5UnPadding(origData []byte) []byte {
|
||||
}
|
||||
|
||||
type Code struct {
|
||||
MsgType int64 `json:"msg_type"`
|
||||
msg struct {
|
||||
ActionType int64 `json:"action_type"`
|
||||
AppId int64 `json:"app_id"`
|
||||
ShopId int64 `json:"shop_id"`
|
||||
Code string `json:"code"`
|
||||
CodeGenerateTime string `json:"code_generate_time"`
|
||||
}
|
||||
MsgType int64 `json:"msg_type"`
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
type MsgDetail struct {
|
||||
ActionType int `json:"action_type"`
|
||||
AppId int64 `json:"app_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,42 +121,40 @@ func (c *TiktokShopController) TokenMsg() {
|
||||
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
|
||||
}
|
||||
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()
|
||||
return
|
||||
}
|
||||
|
||||
globals.SugarLogger.Debugf("result=====%s", utils.Format4Output(result, false))
|
||||
globals.SugarLogger.Debugf("result=====%s", utils.Format4Output(result, false))
|
||||
|
||||
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
|
||||
}
|
||||
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: "hhhh", // web.AppConfig.DefaultString("tiktokShopAppId", "7136048270014416392"),
|
||||
AppSecret: "heihei", // web.AppConfig.DefaultString("tiktokShopAppSecret", "c397aa9f-3927-47c4-8cfe-4d84e02602e0")
|
||||
}
|
||||
if err := common.AddVendorOrgCode(nil, param); err != nil {
|
||||
globals.SugarLogger.Debugf("AddVendorOrgCode=====err%s", err)
|
||||
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: "hhhh", // web.AppConfig.DefaultString("tiktokShopAppId", "7136048270014416392"),
|
||||
AppSecret: "heihei", // web.AppConfig.DefaultString("tiktokShopAppSecret", "c397aa9f-3927-47c4-8cfe-4d84e02602e0")
|
||||
}
|
||||
if err := common.AddVendorOrgCode(nil, param); err != nil {
|
||||
globals.SugarLogger.Debugf("AddVendorOrgCode=====err%s", err)
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user