|
|
@@ -102,6 +102,9 @@ const (
|
|
|
requestQRScene = `{"expire_seconds":%d,"action_name":"QR_SCENE","action_info":{"scene":{"scene_id":%d}}}`
|
|
|
requestQRLimitScene = `{"action_name":"QR_LIMIT_SCENE","action_info":{"scene":{"scene_id":%d}}}`
|
|
|
requestQRLimitSceneStr = `{"action_name":"QR_LIMIT_SCENE","action_info":{"scene":{"scene_str":%s}}}`
|
|
|
+
|
|
|
+ //
|
|
|
+ RedisCode = "wxtoken"
|
|
|
)
|
|
|
|
|
|
// Common message header
|
|
|
@@ -305,13 +308,13 @@ func New(token string, appid string, secret string) *Weixin {
|
|
|
select {
|
|
|
case t := <-wx.refreshTokenChan:
|
|
|
log.Println("重新获取 access token")
|
|
|
- c := redis.RedisPool["sso"].Get()
|
|
|
- c.Do("PUBLISH", "WxRefreshSub", fmt.Sprintf("token_%s %s", wx.appId, t))
|
|
|
+ c := redis.RedisPool[RedisCode].Get()
|
|
|
+ c.Do("PUBLISH", "WxRefreshSub_"+wx.appId, fmt.Sprintf("token_%s", t))
|
|
|
c.Close()
|
|
|
case <-wx.refreshTicketChan:
|
|
|
log.Println("重新获取 jsApi ticket")
|
|
|
- c := redis.RedisPool["sso"].Get()
|
|
|
- c.Do("PUBLISH", "WxRefreshSub", fmt.Sprintf("ticket_%s", wx.appId))
|
|
|
+ c := redis.RedisPool[RedisCode].Get()
|
|
|
+ c.Do("PUBLISH", "WxRefreshSub_"+wx.appId, "ticket")
|
|
|
c.Close()
|
|
|
}
|
|
|
}
|
|
|
@@ -848,7 +851,7 @@ func checkSignature(t string, w http.ResponseWriter, r *http.Request) bool {
|
|
|
|
|
|
func authAccessToken(appid, t string, r chan string) (string, int64, int64) {
|
|
|
r <- t
|
|
|
- ret, err := redis.GetNewBytes("sso", fmt.Sprintf("WxToken_%s", appid))
|
|
|
+ ret, err := redis.GetNewBytes(RedisCode, fmt.Sprintf("WxToken_%s", appid))
|
|
|
if err != nil {
|
|
|
log.Println("redis中获取Token出错", err)
|
|
|
} else if ret != nil {
|
|
|
@@ -892,7 +895,7 @@ func authAccessToken(appid, t string, r chan string) (string, int64, int64) {
|
|
|
}*/
|
|
|
func getJsApiTicket(appid string, r chan bool) (*jsApiTicket, error) {
|
|
|
r <- true
|
|
|
- ret, err := redis.GetNewBytes("sso", fmt.Sprintf("WxTicket_%s", appid))
|
|
|
+ ret, err := redis.GetNewBytes(RedisCode, fmt.Sprintf("WxTicket_%s", appid))
|
|
|
if err != nil {
|
|
|
log.Println("redis中获取Token出错", err)
|
|
|
} else if ret != nil {
|
|
|
@@ -944,14 +947,16 @@ func createAccessToken(c chan accessToken, appid string, refresh *bool, r chan s
|
|
|
}
|
|
|
reTry++
|
|
|
subToken := ""
|
|
|
+ forceRefresh := false
|
|
|
if *refresh || *token.lasttime == -1 {
|
|
|
+ forceRefresh = true
|
|
|
subToken = token.token
|
|
|
}
|
|
|
*refresh = false
|
|
|
var expires int64
|
|
|
var lasttime int64
|
|
|
token.token, expires, lasttime = authAccessToken(appid, subToken, r)
|
|
|
- if (*refresh || *token.lasttime == -1) && token.expires.Unix() == expires {
|
|
|
+ if forceRefresh && token.expires.Unix() == expires {
|
|
|
continue
|
|
|
}
|
|
|
token.expires = time.Unix(expires, 0)
|