|
@@ -24,7 +24,7 @@ func NewMiniClient(appID, appSecret string) *MiniClient {
|
|
|
if v, ok := memcache.Load(key); ok {
|
|
|
return v.(*MiniClient)
|
|
|
}
|
|
|
- c := &MiniClient{AppID: appID, AppSecret: appSecret}
|
|
|
+ c := &MiniClient{AppID: appID, AppSecret: appSecret, UseCacheToken: true}
|
|
|
memcache.Store(key, c)
|
|
|
return c
|
|
|
}
|
|
@@ -56,34 +56,30 @@ func (mc *MiniClient) GetMiniOpenID(frm FormCode) (s MiniSession, err error) {
|
|
|
|
|
|
// getToken get token
|
|
|
func (mc *MiniClient) getToken() (token string, err error) {
|
|
|
- /*
|
|
|
- now := time.Now().Unix()
|
|
|
- if mc.LastTokenTime > 0 {
|
|
|
- if now-mc.LastTokenTime < TokenExpires {
|
|
|
- token = mc.AccessToken
|
|
|
- return
|
|
|
- }
|
|
|
+ if mc.UseCacheToken {
|
|
|
+ key := keyMiniToken(mc.AppID)
|
|
|
+ var ct ClientToken
|
|
|
+ s := ``
|
|
|
+ //now := time.Now().Unix()
|
|
|
+ s, err = cache.Get(key)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
}
|
|
|
- // */
|
|
|
- key := keyMiniToken(mc.AppID)
|
|
|
- var ct ClientToken
|
|
|
- s := ``
|
|
|
- now := time.Now().Unix()
|
|
|
- s, err = cache.Get(key)
|
|
|
- if err == nil {
|
|
|
err = json.Unmarshal([]byte(s), &ct)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
+ token = mc.AccessToken
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- if mc.LastTokenTime > 0 {
|
|
|
- if now-mc.LastTokenTime < TokenExpires {
|
|
|
- token = mc.AccessToken
|
|
|
- return
|
|
|
- }
|
|
|
+ now := time.Now().Unix()
|
|
|
+ if mc.LastTokenTime > 0 {
|
|
|
+ if now-mc.LastTokenTime < TokenExpires {
|
|
|
+ token = mc.AccessToken
|
|
|
+ return
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
token, err = mc.UpdateToken()
|
|
|
return
|
|
|
}
|