1
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
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))
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user