Merge branch 'master' of https://e.coding.net/rosydev/baseapi
This commit is contained in:
@@ -35,7 +35,8 @@ func New(appKey, appSecret, accessToken string) *API {
|
|||||||
globals.SugarLogger.Debug("accessToken init err :", err)
|
globals.SugarLogger.Debug("accessToken init err :", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &API{
|
|
||||||
|
api := &API{
|
||||||
appKey: appKey,
|
appKey: appKey,
|
||||||
appSecret: appSecret,
|
appSecret: appSecret,
|
||||||
accessToken: access.AccessToken,
|
accessToken: access.AccessToken,
|
||||||
@@ -43,6 +44,10 @@ func New(appKey, appSecret, accessToken string) *API {
|
|||||||
expiresIn: access.ExpiresIn,
|
expiresIn: access.ExpiresIn,
|
||||||
accessTokenObj: access,
|
accessTokenObj: access,
|
||||||
}
|
}
|
||||||
|
if access.ExpiresIn < time.Now().Unix() {
|
||||||
|
api.RefreshToken()
|
||||||
|
}
|
||||||
|
return api
|
||||||
}
|
}
|
||||||
return &API{
|
return &API{
|
||||||
appKey: appKey,
|
appKey: appKey,
|
||||||
@@ -145,11 +150,12 @@ func (a *API) SetAccessToken(token string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.accessToken = access.AccessToken
|
||||||
|
a.refreshToken = access.RefreshToken
|
||||||
|
a.expiresIn = access.ExpiresIn
|
||||||
if access.ExpiresIn > time.Now().Unix() {
|
if access.ExpiresIn > time.Now().Unix() {
|
||||||
a.accessTokenObj = access
|
a.accessTokenObj = access
|
||||||
} else {
|
} else {
|
||||||
a.accessToken = access.AccessToken
|
|
||||||
a.refreshToken = access.RefreshToken
|
|
||||||
a.RefreshToken()
|
a.RefreshToken()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
18
platformapi/tiktok_shop/tiktok_api/api_test.go
Normal file
18
platformapi/tiktok_shop/tiktok_api/api_test.go
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package tiktok_api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestApi(t *testing.T) {
|
||||||
|
token := `{"access_token":"a1746210-a8a3-4497-a87b-09d1f10dbb95","expires_in":1665652230,"scope":"SCOPE","shop_id":"","shop_name":"小时达开放平台对接专用店","refresh_token":"c1cf8d88-0983-4f2a-b969-3746fae6b0cd","authority_id":""}`
|
||||||
|
|
||||||
|
a := New("7136048270014416392", "c397aa9f-3927-47c4-8cfe-4d84e02602e0", token)
|
||||||
|
a.SetAccessToken(token)
|
||||||
|
globals.SugarLogger.Debugf("%v", utils.Format4Output(a, false))
|
||||||
|
globals.SugarLogger.Debugf("%v", utils.Format4Output(a.accessTokenObj, false))
|
||||||
|
globals.SugarLogger.Debugf("%v", utils.Format4Output(a.appKey, false))
|
||||||
|
globals.SugarLogger.Debugf("%v", utils.Format4Output(a.appSecret, false))
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
product_listV2_response "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/product_listV2/response"
|
product_listV2_response "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/product_listV2/response"
|
||||||
product_setOffline_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/product_setOffline/request"
|
product_setOffline_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/product_setOffline/request"
|
||||||
shop_getShopCategory_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/shop_getShopCategory/request"
|
shop_getShopCategory_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/shop_getShopCategory/request"
|
||||||
|
sku_editPrice_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/sku_editPrice/request"
|
||||||
sku_syncStock_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/sku_syncStock/request"
|
sku_syncStock_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/sku_syncStock/request"
|
||||||
sku_syncStockBatch_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/sku_syncStockBatch/request"
|
sku_syncStockBatch_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/sku_syncStockBatch/request"
|
||||||
)
|
)
|
||||||
@@ -179,15 +180,19 @@ func (a *API) ProductSetOffline(productId int64) error {
|
|||||||
func (a *API) GetSkuDetail(productId, outProductId string) (*product_detail_response.ProductDetailData, error) {
|
func (a *API) GetSkuDetail(productId, outProductId string) (*product_detail_response.ProductDetailData, error) {
|
||||||
request := product_detail_request.New()
|
request := product_detail_request.New()
|
||||||
param := request.GetParams()
|
param := request.GetParams()
|
||||||
param.ProductId = productId
|
if productId != "" {
|
||||||
param.OutProductId = outProductId
|
param.ProductId = productId
|
||||||
|
}
|
||||||
|
if outProductId != "" {
|
||||||
|
param.OutProductId = outProductId
|
||||||
|
}
|
||||||
|
|
||||||
result, err := request.Execute(a.accessTokenObj)
|
result, err := request.Execute(a.accessTokenObj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if result.Code != RequestSuccessCode {
|
if result.Code != RequestSuccessCode {
|
||||||
return nil, err
|
return nil, errors.New(result.SubMsg)
|
||||||
}
|
}
|
||||||
return result.Data, nil
|
return result.Data, nil
|
||||||
}
|
}
|
||||||
@@ -207,3 +212,18 @@ func (a *API) GetSkuDetailList(param *product_listV2_request.ProductListV2Param)
|
|||||||
|
|
||||||
return result.Data, nil
|
return result.Data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EditPrice 编辑商品价格
|
||||||
|
func (a *API) EditPrice(skuPrice *sku_editPrice_request.SkuEditPriceParam) error {
|
||||||
|
request := sku_editPrice_request.New()
|
||||||
|
request.Param = skuPrice
|
||||||
|
|
||||||
|
result, err := request.Execute(a.accessTokenObj)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if result.Code != RequestSuccessCode {
|
||||||
|
return errors.New(result.SubMsg)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"git.rosy.net.cn/baseapi"
|
"git.rosy.net.cn/baseapi"
|
||||||
product_addV2_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/product_addV2/request"
|
product_addV2_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/product_addV2/request"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -214,3 +215,12 @@ func TestCreateStoreCommodity(t *testing.T) {
|
|||||||
func TestInt16(t *testing.T) {
|
func TestInt16(t *testing.T) {
|
||||||
fmt.Println(utils.Str2Int16(strings.ReplaceAll("08:00", ":", "")))
|
fmt.Println(utils.Str2Int16(strings.ReplaceAll("08:00", ":", "")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetSkuDetail(t *testing.T) {
|
||||||
|
token := `{"access_token":"a1746210-a8a3-4497-a87b-09d1f10dbb95","expires_in":1665652230,"scope":"SCOPE","shop_id":"","shop_name":"小时达开放平台对接专用店","refresh_token":"c1cf8d88-0983-4f2a-b969-3746fae6b0cd","authority_id":""}`
|
||||||
|
|
||||||
|
a := New("7136048270014416392", "c397aa9f-3927-47c4-8cfe-4d84e02602e0", token)
|
||||||
|
data, err := a.GetSkuDetail("3574180746237226525", "")
|
||||||
|
fmt.Println(err)
|
||||||
|
globals.SugarLogger.Debugf("====%s", utils.Format4Output(data, false))
|
||||||
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func TestUploadImg(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRefundToken(t *testing.T) {
|
func TestRefundToken(t *testing.T) {
|
||||||
token := `{"access_token":"a1746210-a8a3-4497-a87b-09d1f10dbb95","expires_in":604800,"scope":"SCOPE","shop_id":"","shop_name":"小时达开放平台对接专 用店","refresh_token":"c1cf8d88-0983-4f2a-b969-3746fae6b0cd","authority_id ":""}`
|
token := `{"access_token":"a1746210-a8a3-4497-a87b-09d1f10dbb95","expires_in":1665652252,"scope":"SCOPE","shop_id":"","shop_name":"小时达开放平台对 接专用店","refresh_token":"c1cf8d88-0983-4f2a-b969-3746fae6b0cd","authorit y_id":""}`
|
||||||
|
|
||||||
a := New("7136048270014416392", "c397aa9f-3927-47c4-8cfe-4d84e02602e0", token)
|
a := New("7136048270014416392", "c397aa9f-3927-47c4-8cfe-4d84e02602e0", token)
|
||||||
a.RefreshToken()
|
a.RefreshToken()
|
||||||
|
|||||||
@@ -216,7 +216,9 @@ func (a *API) GetStoreBindTemp(storeId int64) (freightId int64, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
if result.Data == nil || len(result.Data.StoreFreights) == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
for _, v := range result.Data.StoreFreights {
|
for _, v := range result.Data.StoreFreights {
|
||||||
if v.StoreId == storeId {
|
if v.StoreId == storeId {
|
||||||
return v.FreightId, nil
|
return v.FreightId, nil
|
||||||
|
|||||||
@@ -2,7 +2,12 @@ package tiktok_api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
freightTemplate_create_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/freightTemplate_create/request"
|
||||||
shop_batchCreateStore_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/shop_batchCreateStore/request"
|
shop_batchCreateStore_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/shop_batchCreateStore/request"
|
||||||
|
warehouse_bindStore_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/warehouse_bindStore/request"
|
||||||
|
warehouse_createBatch_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/warehouse_createBatch/request"
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -35,3 +40,65 @@ func TestCreateStore(t *testing.T) {
|
|||||||
func TestSysnc(t *testing.T) {
|
func TestSysnc(t *testing.T) {
|
||||||
fmt.Println((2 & 2) != 0) // 创建
|
fmt.Println((2 & 2) != 0) // 创建
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStoreTemp(t *testing.T) {
|
||||||
|
token := `{"access_token":"a1746210-a8a3-4497-a87b-09d1f10dbb95","expires_in":1665652230,"scope":"SCOPE","shop_id":"","shop_name":"小时达开放平台对接专用店","refresh_token":"c1cf8d88-0983-4f2a-b969-3746fae6b0cd","authority_id":""}`
|
||||||
|
|
||||||
|
a := New("7136048270014416392", "c397aa9f-3927-47c4-8cfe-4d84e02602e0", token)
|
||||||
|
a.GetStoreBindTemp(63114504)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAPI_CreateTradeLimitTemplate(t *testing.T) {
|
||||||
|
token := `{"access_token":"a1746210-a8a3-4497-a87b-09d1f10dbb95","expires_in":1665652230,"scope":"SCOPE","shop_id":"","shop_name":"小时达开放平台对接专用店","refresh_token":"c1cf8d88-0983-4f2a-b969-3746fae6b0cd","authority_id":""}`
|
||||||
|
|
||||||
|
a := New("7136048270014416392", "c397aa9f-3927-47c4-8cfe-4d84e02602e0", token)
|
||||||
|
a.FreightTemplateCreate(&freightTemplate_create_request.FreightTemplateCreateParam{
|
||||||
|
Template: &freightTemplate_create_request.Template{
|
||||||
|
TemplateName: "小时购" + "_" + utils.Int64ToStr(rand.Int63n(19930)) + "_系统模板",
|
||||||
|
ProductProvince: 51,
|
||||||
|
ProductCity: 510100,
|
||||||
|
CalculateType: 2,
|
||||||
|
TransferType: 1, // 快递
|
||||||
|
RuleType: 1,
|
||||||
|
FixedAmount: 500,
|
||||||
|
},
|
||||||
|
Columns: nil,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 批量创建区域仓
|
||||||
|
func TestCreateWarehouse(t *testing.T) {
|
||||||
|
token := `{"access_token":"a1746210-a8a3-4497-a87b-09d1f10dbb95","expires_in":1665652230,"scope":"SCOPE","shop_id":"","shop_name":"小时达开放平台对接专用店","refresh_token":"c1cf8d88-0983-4f2a-b969-3746fae6b0cd","authority_id":""}`
|
||||||
|
a := New("7136048270014416392", "c397aa9f-3927-47c4-8cfe-4d84e02602e0", token)
|
||||||
|
|
||||||
|
data, err := a.BatchCreateWarehouse(&warehouse_createBatch_request.WarehouseCreateBatchParam{
|
||||||
|
OutWarehouseList: []warehouse_createBatch_request.OutWarehouseListItem{
|
||||||
|
{
|
||||||
|
OutWarehouseId: "666667",
|
||||||
|
Name: "火车南站仓库",
|
||||||
|
Intro: "这是一个火车南站的仓库,仓库id为京西门店id",
|
||||||
|
AddressDetail: "四川省成都市新都区大丰镇南丰大道37号",
|
||||||
|
WarehouseLocation: &warehouse_createBatch_request.WarehouseLocation{
|
||||||
|
AddressId1: 51,
|
||||||
|
AddressId2: 510100,
|
||||||
|
AddressId3: 510114,
|
||||||
|
AddressId4: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}})
|
||||||
|
fmt.Println(data)
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 仓库绑定门店
|
||||||
|
func TestBindWarehouseToStore(t *testing.T) {
|
||||||
|
token := `{"access_token":"a1746210-a8a3-4497-a87b-09d1f10dbb95","expires_in":1665652230,"scope":"SCOPE","shop_id":"","shop_name":"小时达开放平台对接专用店","refresh_token":"c1cf8d88-0983-4f2a-b969-3746fae6b0cd","authority_id":""}`
|
||||||
|
a := New("7136048270014416392", "c397aa9f-3927-47c4-8cfe-4d84e02602e0", token)
|
||||||
|
|
||||||
|
data, err := a.StoreBindWarehouse(&warehouse_bindStore_request.WarehouseBindStoreParam{
|
||||||
|
StoreIds: []int64{63114504},
|
||||||
|
OutWarehouseId: "666667",
|
||||||
|
})
|
||||||
|
fmt.Println(data)
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user