Merge branch 'jdshop' of https://e.coding.net/rosydev/jx-callback into jdshop
This commit is contained in:
@@ -280,7 +280,9 @@ func AddVendorOrgCode(ctx *jxcontext.Context, vendorOrgCode *model.VendorOrgCode
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(list) > 0 {
|
if len(list) > 0 {
|
||||||
return fmt.Errorf("库里有这个账号了,[%v]", vendorOrgCode.VendorOrgCode)
|
vendorOrgCode.ID = list[0].ID
|
||||||
|
_, err = dao.UpdateEntity(db, vendorOrgCode, "token", "updated_at", "app_key", "app_secret", "comment", "vendor_org_code")
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var userName string
|
var userName string
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/aes"
|
||||||
|
"crypto/cipher"
|
||||||
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"git.rosy.net.cn/baseapi/platformapi/tiktok_shop/tiktok_api"
|
"git.rosy.net.cn/baseapi/platformapi/tiktok_shop/tiktok_api"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxstore/common"
|
"git.rosy.net.cn/jx-callback/business/jxstore/common"
|
||||||
@@ -11,47 +15,101 @@ import (
|
|||||||
"github.com/astaxie/beego/server/web"
|
"github.com/astaxie/beego/server/web"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TiktokShopController struct {
|
type TiktokShopController struct {
|
||||||
web.Controller
|
web.Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AesDecrypt(msgSecret, appSecret string) (string, error) {
|
||||||
|
var appSecretArr = []byte(strings.ReplaceAll(appSecret, "-", ""))
|
||||||
|
bytesPass, err := base64.StdEncoding.DecodeString(msgSecret)
|
||||||
|
if err != nil {
|
||||||
|
return "", errors.New("解密失败!!!")
|
||||||
|
}
|
||||||
|
sourceMsg, err := DoAesDecrypt(bytesPass, appSecretArr)
|
||||||
|
if err != nil {
|
||||||
|
return "", errors.New("解密失败!!!")
|
||||||
|
}
|
||||||
|
return string(sourceMsg), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DoAesDecrypt(encryptedMsg, key []byte) ([]byte, error) {
|
||||||
|
block, err := aes.NewCipher(key)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
//AES分组长度为128位,所以blockSize=16,单位字节
|
||||||
|
blockSize := block.BlockSize()
|
||||||
|
blockMode := cipher.NewCBCDecrypter(block, key[:blockSize]) //初始向量的长度必须等于块block的长度16字节
|
||||||
|
origData := make([]byte, len(encryptedMsg))
|
||||||
|
blockMode.CryptBlocks(origData, encryptedMsg)
|
||||||
|
origData = PKCS5UnPadding(origData)
|
||||||
|
return origData, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func PKCS5UnPadding(origData []byte) []byte {
|
||||||
|
length := len(origData)
|
||||||
|
unfilledNum := int(origData[length-1])
|
||||||
|
return origData[:(length - unfilledNum)]
|
||||||
|
}
|
||||||
|
|
||||||
|
type Code struct {
|
||||||
|
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() {
|
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)
|
||||||
if err != nil {
|
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.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackFailCode, Msg: tiktok_api.CallbackFail}
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
globals.SugarLogger.Debugf("data=====err%s", string(data))
|
codeToken, err := AesDecrypt(string(data), globals.TiktokShopAppSecret)
|
||||||
if err := json.Unmarshal(data, &code); err != nil {
|
if 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()
|
||||||
|
}
|
||||||
|
|
||||||
|
var codeMsg Code
|
||||||
|
if err := json.Unmarshal([]byte(codeToken), &codeMsg); 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()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var msg MsgDetail
|
||||||
|
if err := json.Unmarshal([]byte(codeMsg.Msg), &msg); err != nil {
|
||||||
|
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()
|
||||||
globals.SugarLogger.Debugf("codeValues=====%s", utils.Format4Output(codeValues, false))
|
|
||||||
codeList := codeValues.Get("code")
|
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 {
|
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.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackFailCode, Msg: tiktok_api.CallbackFail}
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
globals.SugarLogger.Debugf("code ==================%s", utils.Format4Output(code, false))
|
|
||||||
|
|
||||||
if len(code) == 0 {
|
if len(code) == 0 {
|
||||||
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}
|
||||||
@@ -59,41 +117,37 @@ 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()
|
return
|
||||||
return
|
}
|
||||||
}
|
|
||||||
globals.SugarLogger.Debugf("result=====%s", utils.Format4Output(result, false))
|
|
||||||
|
|
||||||
result.ExpiresIn += time.Now().Unix()
|
data, err := json.Marshal(result)
|
||||||
data, err := json.Marshal(result)
|
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()
|
return
|
||||||
return
|
}
|
||||||
}
|
|
||||||
|
|
||||||
param := &model.VendorOrgCode{
|
param := &model.VendorOrgCode{
|
||||||
VendorID: model.VendorIDDD,
|
VendorID: model.VendorIDDD,
|
||||||
VendorOrgCode: utils.Int64ToStr(result.ShopId),
|
VendorOrgCode: utils.Int64ToStr(result.ShopId),
|
||||||
Comment: "抖音授权",
|
Comment: result.ShopName,
|
||||||
VendorType: "platform",
|
VendorType: "platform",
|
||||||
IsJxCat: 1,
|
IsJxCat: 1,
|
||||||
IsOpen: 1,
|
IsOpen: 1,
|
||||||
EmpowerURL: "https://fuwu.jinritemai.com/detail?from=open_partner_svcList&service_id=24070",
|
EmpowerURL: "https://fuwu.jinritemai.com/detail?from=open_partner_svcList&service_id=24070",
|
||||||
StoreBrandName: result.ShopName,
|
StoreBrandName: result.ShopName,
|
||||||
Token: string(data),
|
Token: string(data),
|
||||||
AppKey: "", // web.AppConfig.DefaultString("tiktokShopAppId", "7136048270014416392"),
|
AppKey: "", // web.AppConfig.DefaultString("tiktokShopAppId", "7136048270014416392"),
|
||||||
AppSecret: "", // web.AppConfig.DefaultString("tiktokShopAppSecret", "c397aa9f-3927-47c4-8cfe-4d84e02602e0")
|
AppSecret: "", // web.AppConfig.DefaultString("tiktokShopAppSecret", "c397aa9f-3927-47c4-8cfe-4d84e02602e0")
|
||||||
}
|
}
|
||||||
if err := common.AddVendorOrgCode(nil, param); err != nil {
|
if err := common.AddVendorOrgCode(nil, param); 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()
|
||||||
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()
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ var (
|
|||||||
IsAddEvent bool
|
IsAddEvent bool
|
||||||
|
|
||||||
OutputDebugMsgLevel int
|
OutputDebugMsgLevel int
|
||||||
|
TiktokShopAppSecret string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -164,6 +165,7 @@ func Init() {
|
|||||||
JdLoginName = web.AppConfig.DefaultString("jdLoginName", "")
|
JdLoginName = web.AppConfig.DefaultString("jdLoginName", "")
|
||||||
IsAddEvent = web.AppConfig.DefaultBool("addEvent", false)
|
IsAddEvent = web.AppConfig.DefaultBool("addEvent", false)
|
||||||
TictokpayNotifyURL = web.AppConfig.DefaultString("tiktokNotifyUrl", "")
|
TictokpayNotifyURL = web.AppConfig.DefaultString("tiktokNotifyUrl", "")
|
||||||
|
TiktokShopAppSecret = web.AppConfig.DefaultString("tiktokShopAppSecret", "")
|
||||||
|
|
||||||
IsStoreSkuAct = !IsProductEnv()
|
IsStoreSkuAct = !IsProductEnv()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user