Sfoglia il codice sorgente

cache access token to redis

ls 3 anni fa
parent
commit
e1fcbd6700
2 ha cambiato i file con 6 aggiunte e 0 eliminazioni
  1. 1 0
      go.sum
  2. 5 0
      wechat/client.go

+ 1 - 0
go.sum

@@ -11,6 +11,7 @@ github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+
 github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
 github.com/go-redis/redis/v7 v7.2.0 h1:CrCexy/jYWZjW0AyVoHlcJUeZN19VWlbepTh1Vq6dJs=
 github.com/go-redis/redis/v7 v7.2.0/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg=
+github.com/go-redis/redis/v7 v7.4.0 h1:7obg6wUoj05T0EpY0o8B59S9w5yeMWql7sw2kwNW1x4=
 github.com/go-redis/redis/v7 v7.4.0/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg=
 github.com/go-sql-driver/mysql v1.4.0 h1:7LxgVwFb2hIQtMm87NdgAVfXjnt4OePseqT1tKx+opk=
 github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=

+ 5 - 0
wechat/client.go

@@ -7,6 +7,8 @@ import (
 	"net/url"
 	"time"
 
+	"git.chuangxin1.com/cx/myth/cache"
+
 	"git.chuangxin1.com/cx/myth"
 )
 
@@ -58,6 +60,9 @@ func (wc *Client) getToken() (token string, err error) {
 		key := key(wc.AppID)
 		memcache.Store(key, wc)
 		key = keyToken(wc.AppID)
+		ct := ClientToken{AppID: wc.AppID, AccessToken: wc.AccessToken, LastTokenTime: now}
+		bs, _ := json.Marshal(ct)
+		cache.Set(key, string(bs), 0)
 		//cache.Store(key, accessToken)
 	}
 	return