You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
518 B
23 lines
518 B
3 years ago
|
package wechatoffice
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
3 years ago
|
"time"
|
||
3 years ago
|
)
|
||
|
|
||
2 years ago
|
func (app *App) GetAccessToken() string {
|
||
2 years ago
|
if app.redis.Db == nil {
|
||
|
return app.accessToken
|
||
3 years ago
|
}
|
||
2 years ago
|
newCache := app.redis.NewSimpleStringCache(app.redis.NewStringOperation(), time.Second*7000)
|
||
3 years ago
|
newCache.DBGetter = func() string {
|
||
2 years ago
|
token := app.CgiBinToken()
|
||
3 years ago
|
return token.Result.AccessToken
|
||
3 years ago
|
}
|
||
2 years ago
|
return newCache.GetCache(app.getAccessTokenCacheKeyName())
|
||
|
}
|
||
|
|
||
|
func (app *App) getAccessTokenCacheKeyName() string {
|
||
2 years ago
|
return fmt.Sprintf("wechat_access_token:%v", app.appId)
|
||
3 years ago
|
}
|