diff --git a/platformapi/tiktok_shop/tiktok_api/api.go b/platformapi/tiktok_shop/tiktok_api/api.go index e336448e..3bc368c1 100644 --- a/platformapi/tiktok_shop/tiktok_api/api.go +++ b/platformapi/tiktok_shop/tiktok_api/api.go @@ -35,7 +35,8 @@ func New(appKey, appSecret, accessToken string) *API { globals.SugarLogger.Debug("accessToken init err :", err) return nil } - return &API{ + + api := &API{ appKey: appKey, appSecret: appSecret, accessToken: access.AccessToken, @@ -43,6 +44,10 @@ func New(appKey, appSecret, accessToken string) *API { expiresIn: access.ExpiresIn, accessTokenObj: access, } + if access.ExpiresIn < time.Now().Unix() { + api.RefreshToken() + } + return api } return &API{ appKey: appKey, @@ -145,11 +150,12 @@ func (a *API) SetAccessToken(token string) { return } + a.accessToken = access.AccessToken + a.refreshToken = access.RefreshToken + a.expiresIn = access.ExpiresIn if access.ExpiresIn > time.Now().Unix() { a.accessTokenObj = access } else { - a.accessToken = access.AccessToken - a.refreshToken = access.RefreshToken a.RefreshToken() } diff --git a/platformapi/tiktok_shop/tiktok_api/api_test.go b/platformapi/tiktok_shop/tiktok_api/api_test.go new file mode 100644 index 00000000..b73980e3 --- /dev/null +++ b/platformapi/tiktok_shop/tiktok_api/api_test.go @@ -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)) +} diff --git a/platformapi/tiktok_shop/tiktok_api/sku.go b/platformapi/tiktok_shop/tiktok_api/sku.go index 7d6fe303..929d9bdb 100644 --- a/platformapi/tiktok_shop/tiktok_api/sku.go +++ b/platformapi/tiktok_shop/tiktok_api/sku.go @@ -14,6 +14,7 @@ import ( 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" 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_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) { request := product_detail_request.New() param := request.GetParams() - param.ProductId = productId - param.OutProductId = outProductId + if productId != "" { + param.ProductId = productId + } + if outProductId != "" { + param.OutProductId = outProductId + } result, err := request.Execute(a.accessTokenObj) if err != nil { return nil, err } if result.Code != RequestSuccessCode { - return nil, err + return nil, errors.New(result.SubMsg) } return result.Data, nil } @@ -207,3 +212,18 @@ func (a *API) GetSkuDetailList(param *product_listV2_request.ProductListV2Param) 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 +} diff --git a/platformapi/tiktok_shop/tiktok_api/sku_test.go b/platformapi/tiktok_shop/tiktok_api/sku_test.go index edcc54f6..c484f12a 100644 --- a/platformapi/tiktok_shop/tiktok_api/sku_test.go +++ b/platformapi/tiktok_shop/tiktok_api/sku_test.go @@ -6,6 +6,7 @@ import ( "git.rosy.net.cn/baseapi" 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/jx-callback/globals" "go.uber.org/zap" "strings" "testing" @@ -214,3 +215,12 @@ func TestCreateStoreCommodity(t *testing.T) { func TestInt16(t *testing.T) { 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)) +} diff --git a/platformapi/tiktok_shop/tiktok_api/sku_warehouse_test.go b/platformapi/tiktok_shop/tiktok_api/sku_warehouse_test.go index 7e2b9913..e035a6e6 100644 --- a/platformapi/tiktok_shop/tiktok_api/sku_warehouse_test.go +++ b/platformapi/tiktok_shop/tiktok_api/sku_warehouse_test.go @@ -47,7 +47,7 @@ func TestUploadImg(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.RefreshToken() diff --git a/platformapi/tiktok_shop/tiktok_api/store.go b/platformapi/tiktok_shop/tiktok_api/store.go index a76326b5..80eb85aa 100644 --- a/platformapi/tiktok_shop/tiktok_api/store.go +++ b/platformapi/tiktok_shop/tiktok_api/store.go @@ -216,7 +216,9 @@ func (a *API) GetStoreBindTemp(storeId int64) (freightId int64, err error) { if err != nil { return 0, err } - + if result.Data == nil || len(result.Data.StoreFreights) == 0 { + return 0, nil + } for _, v := range result.Data.StoreFreights { if v.StoreId == storeId { return v.FreightId, nil diff --git a/platformapi/tiktok_shop/tiktok_api/store_test.go b/platformapi/tiktok_shop/tiktok_api/store_test.go index d7ee17ed..03dcf494 100644 --- a/platformapi/tiktok_shop/tiktok_api/store_test.go +++ b/platformapi/tiktok_shop/tiktok_api/store_test.go @@ -2,7 +2,12 @@ package tiktok_api import ( "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" + 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" ) @@ -35,3 +40,65 @@ func TestCreateStore(t *testing.T) { func TestSysnc(t *testing.T) { 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) +}