44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package tao_vegetable
|
|
|
|
import (
|
|
"encoding/json"
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
"git.rosy.net.cn/jx-callback/globals"
|
|
"git.rosy.net.cn/topsdk/ability304"
|
|
"git.rosy.net.cn/topsdk/ability304/request"
|
|
"topsdk"
|
|
)
|
|
|
|
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
|
|
token string
|
|
refreshToken string
|
|
}
|
|
|
|
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
|
|
}
|