This commit is contained in:
邹宗楠
2022-10-06 11:42:00 +08:00
parent 2eec6d7304
commit b6caab8204
2 changed files with 33 additions and 9 deletions

View File

@@ -27,21 +27,25 @@ type API struct {
func New(appKey, appSecret, accessToken string) *API {
var access *doudian_sdk.AccessToken
doudian_sdk.GlobalConfig.AppKey = appKey
doudian_sdk.GlobalConfig.AppSecret = appSecret
if accessToken != "" {
if err := json.Unmarshal([]byte(accessToken), &access); err != nil {
globals.SugarLogger.Debug("accessToken init err :", err)
return nil
}
return &API{
appKey: appKey,
appSecret: appSecret,
accessToken: access.AccessToken,
refreshToken: access.RefreshToken,
expiresIn: access.ExpiresIn,
accessTokenObj: access,
}
}
doudian_sdk.GlobalConfig.AppKey = appKey
doudian_sdk.GlobalConfig.AppSecret = appSecret
return &API{
appKey: appKey,
appSecret: appSecret,
accessToken: access.AccessToken,
refreshToken: access.RefreshToken,
expiresIn: access.ExpiresIn,
accessTokenObj: access,
appKey: appKey,
appSecret: appSecret,
}
}
@@ -135,6 +139,11 @@ func (a *API) SetAccessToken(token string) {
return
}
a.accessTokenObj = access
if access.ExpiresIn > time.Now().Unix() {
a.accessTokenObj = access
} else {
a.RefreshToken()
}
return
}