Browse Source

fix update wechat token to cache

ls 3 months ago
parent
commit
5bf0fc752c
1 changed files with 10 additions and 1 deletions
  1. 10 1
      wechat/client.go

+ 10 - 1
wechat/client.go

@@ -89,13 +89,14 @@ func (wc *Client) upToken(key string, now int64) (token string, err error) {
 		bs, _ := json.Marshal(ct)
 		cache.Set(key, string(bs), 0)
 		//cache.Store(key, accessToken)
+		//log.Println("upToken", key, string(bs))
 	}
 	return
 }
 
 // 更新公众号 access_token
 func (wc *Client) UpdateToken() (token string, err error) {
-	key := keyC(wc.AppID)
+	key := keyToken(wc.AppID)
 	token, err = wc.upToken(key, time.Now().Unix())
 	return
 }
@@ -140,6 +141,13 @@ func (wc *Client) getTicket(now int64) (ticket string, err error) {
 
 		key := keyC(wc.AppID)
 		memcache.Store(key, wc)
+
+		var ct ClientTicket
+		ct.AppID = wc.AppID
+		ct.Ticket = ticket
+		ct.LastTicketTime = now
+		bs, _ := json.Marshal(ct)
+		cache.Set(key, string(bs), 0)
 	}
 
 	return
@@ -165,6 +173,7 @@ func (wc *Client) upTicket(now int64) (ticket string, err error) {
 		ct.Ticket = ticket
 		bs, _ := json.Marshal(ct)
 		cache.Set(key, string(bs), 0)
+		//log.Println("upTicket", key, string(bs))
 	}
 	return
 }