1
This commit is contained in:
41
platformapi/tao_vegetable/api_token.go
Normal file
41
platformapi/tao_vegetable/api_token.go
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package tao_vegetable
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
|
"topsdk"
|
||||||
|
"topsdk/ability304"
|
||||||
|
"topsdk/ability304/request"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
AppKey = "34402634"
|
||||||
|
AppSecret = "fda9a7045262e3aa1f26ca508a9be242"
|
||||||
|
ServerUrl = "https://eco.taobao.com/router/rest"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewTaoVegetable(appKey, appSecret, serverUrl string) API {
|
||||||
|
return API{client: topsdk.NewDefaultTopClient(appKey, appSecret, serverUrl, 2000, 2000)}
|
||||||
|
}
|
||||||
|
|
||||||
|
type API struct {
|
||||||
|
client topsdk.TopClient
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a API) GetStoreToken(code, uuId string) (*StoreTokenInfo, error) {
|
||||||
|
param := &request.TaobaoTopAuthTokenCreateRequest{
|
||||||
|
Code: &code,
|
||||||
|
}
|
||||||
|
data, err := ability304.NewAbility304(&a.client).TaobaoTopAuthTokenCreate(param)
|
||||||
|
globals.SugarLogger.Debugf("token := %s", utils.Format4Output(data, false))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var token *StoreTokenInfo
|
||||||
|
if err := json.Unmarshal([]byte(data.TokenResult), &token); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return token, err
|
||||||
|
}
|
||||||
@@ -1,9 +1,17 @@
|
|||||||
package tao_vegetable
|
package tao_vegetable
|
||||||
|
|
||||||
// ShopCode 商户code解析
|
// StoreTokenInfo 信息解析
|
||||||
type ShopCode struct {
|
type StoreTokenInfo struct {
|
||||||
ResponseType string `json:"response_type"` // 授权类型 code
|
W2Valid int64 `json:"w2_valid"`
|
||||||
Sp string `json:"sp"` // 业务线 hema
|
R1Valid int64 `json:"r1_valid"`
|
||||||
Op string `json:"op"` // 业务线 topApp
|
Sp string `json:"sp"`
|
||||||
ClientId string `json:"client_id"` // appKey
|
R2Valid int64 `json:"r2_valid"`
|
||||||
|
W1Valid int64 `json:"w1_valid"`
|
||||||
|
Locale string `json:"locale"`
|
||||||
|
UserId string `json:"user_id"`
|
||||||
|
ExpireTime int64 `json:"expire_time"`
|
||||||
|
RefreshToken string `json:"refresh_token"`
|
||||||
|
UserNick string `json:"user_nick"`
|
||||||
|
RefreshTokenValidTime int64 `json:"refresh_token_valid_time"`
|
||||||
|
AccessToken string `json:"access_token"`
|
||||||
}
|
}
|
||||||
|
|||||||
44
platformapi/tao_vegetable/store_categary.go
Normal file
44
platformapi/tao_vegetable/store_categary.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package tao_vegetable
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"topsdk/ability587"
|
||||||
|
"topsdk/ability587/domain"
|
||||||
|
"topsdk/ability587/request"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (a API) GetStoreCategoryInfo(code string) (*CategoryInfo, error) {
|
||||||
|
a.client.ServerUrl = "https://eco.taobao.com/router/rest/alibaba.wdk.sku.category.query"
|
||||||
|
storeCategory := ability587.NewAbility587(&a.client)
|
||||||
|
resp, err := storeCategory.AlibabaWdkSkuCategoryQuery(&request.AlibabaWdkSkuCategoryQueryRequest{Param: &domain.AlibabaWdkSkuCategoryQueryCategoryDo{Code: &code}}, "")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if resp.Result.ErrMsg != nil {
|
||||||
|
return nil, fmt.Errorf("requestId:" + resp.RequestId + "msg:" + *resp.Result.ErrMsg)
|
||||||
|
}
|
||||||
|
var info *CategoryInfo
|
||||||
|
if err := json.Unmarshal([]byte(*resp.Result.Model), &info); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return info, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a API) AddStoreCategoryInfo(param *request.AlibabaWdkSkuCategoryAddRequest) (*CategoryInfo, error) {
|
||||||
|
storeCategory := ability587.NewAbility587(&a.client)
|
||||||
|
resp, err := storeCategory.AlibabaWdkSkuCategoryAdd(param, "258adasdad222aa")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if resp.Result.ErrMsg != nil {
|
||||||
|
return nil, fmt.Errorf("requestId:" + resp.RequestId + "msg:" + *resp.Result.ErrMsg)
|
||||||
|
}
|
||||||
|
var info *CategoryInfo
|
||||||
|
if err := json.Unmarshal([]byte(*resp.Result.Model), &info); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return info, nil
|
||||||
|
}
|
||||||
30
platformapi/tao_vegetable/store_info.go
Normal file
30
platformapi/tao_vegetable/store_info.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package tao_vegetable
|
||||||
|
|
||||||
|
type CategoryInfo struct {
|
||||||
|
Code string `json:"code"` // 类目编码
|
||||||
|
Name string `json:"name"` // 类目名称
|
||||||
|
Leaf string `json:"leaf"` // 是否叶子结点
|
||||||
|
SortOrder string `json:"sortOrder"` // 排序值
|
||||||
|
Desc string `json:"desc"` // 详细描述
|
||||||
|
ChildCategorys string `json:"childCategorys"` // 子节点信息
|
||||||
|
ForestId string `json:"forestId"` // 类目id
|
||||||
|
ParentForestId string `json:"parentForestId"` // 父节点id
|
||||||
|
}
|
||||||
|
|
||||||
|
//func (a API) QueryStoreDetailsList() {
|
||||||
|
// a.client.ServerUrl = "qimen.taobao.qimen.pos.store.get"
|
||||||
|
// storeCategory := ability587.NewAbility587(&a.client)
|
||||||
|
// resp, err := storeCategory.AlibabaWdkSkuCategoryQuery(&request.AlibabaWdkSkuCategoryQueryRequest{Param: &domain.AlibabaWdkSkuCategoryQueryCategoryDo{Code: &code}}, "")
|
||||||
|
// if err != nil {
|
||||||
|
// return nil, err
|
||||||
|
// }
|
||||||
|
// if resp.Result.ErrMsg != nil {
|
||||||
|
// return nil, fmt.Errorf("requestId:" + resp.RequestId + "msg:" + *resp.Result.ErrMsg)
|
||||||
|
// }
|
||||||
|
// var info *CategoryInfo
|
||||||
|
// if err := json.Unmarshal([]byte(*resp.Result.Model), &info); err != nil {
|
||||||
|
// return nil, err
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return info, nil
|
||||||
|
//}
|
||||||
42
platformapi/tao_vegetable/store_test.go
Normal file
42
platformapi/tao_vegetable/store_test.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package tao_vegetable
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.rosy.net.cn/baseapi"
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
|
"go.uber.org/zap"
|
||||||
|
"testing"
|
||||||
|
"topsdk/ability587/domain"
|
||||||
|
"topsdk/ability587/request"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
apiTao API
|
||||||
|
sugarLogger *zap.SugaredLogger
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
apiTao = NewTaoVegetable(AppKey, AppSecret, ServerUrl)
|
||||||
|
|
||||||
|
logger, _ := zap.NewDevelopment()
|
||||||
|
sugarLogger = logger.Sugar()
|
||||||
|
baseapi.Init(sugarLogger)
|
||||||
|
}
|
||||||
|
func TestGetStoreCategory(t *testing.T) {
|
||||||
|
data, err := apiTao.GetStoreCategoryInfo("11111")
|
||||||
|
globals.SugarLogger.Debugf("data := %s", utils.Format4Output(data, false))
|
||||||
|
globals.SugarLogger.Debugf("err := %s", utils.Format4Output(err, false))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAddCategory(t *testing.T) {
|
||||||
|
data, err := apiTao.AddStoreCategoryInfo(&request.AlibabaWdkSkuCategoryAddRequest{Param: &domain.AlibabaWdkSkuCategoryAddCategoryDo{
|
||||||
|
Code: utils.String2Pointer("1111"),
|
||||||
|
Name: utils.String2Pointer("1111"),
|
||||||
|
ParentCode: utils.String2Pointer("1111"),
|
||||||
|
Leaf: utils.Bool2Point(false),
|
||||||
|
Desc: utils.String2Pointer("1111"),
|
||||||
|
SortOrder: utils.Int64ToPointer(1),
|
||||||
|
}})
|
||||||
|
globals.SugarLogger.Debugf("data := %s", utils.Format4Output(data, false))
|
||||||
|
globals.SugarLogger.Debugf("err := %s", utils.Format4Output(err, false))
|
||||||
|
}
|
||||||
5
platformapi/tao_vegetable/tao_consts.go
Normal file
5
platformapi/tao_vegetable/tao_consts.go
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package tao_vegetable
|
||||||
|
|
||||||
|
const (
|
||||||
|
AddStoreCategoryApi = "alibaba.wdk.sku.category.add"
|
||||||
|
)
|
||||||
@@ -223,6 +223,10 @@ func Bool2Int(value bool) int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Bool2Point(value bool) *bool {
|
||||||
|
return &value
|
||||||
|
}
|
||||||
|
|
||||||
func Str2Int64WithDefault(str string, defValue int64) int64 {
|
func Str2Int64WithDefault(str string, defValue int64) int64 {
|
||||||
retVal, err := strconv.ParseInt(str, 10, 64)
|
retVal, err := strconv.ParseInt(str, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user