Browse Source

feat:一键登录token缓存调整

fuwencai 2 years ago
parent
commit
406da24576

+ 14 - 9
src/jfw/modules/publicapply/src/oneclick/entity/entity.go

@@ -186,12 +186,15 @@ func GetAuthTokenWithOptions(host string) (_err error, token *authToken) {
 		log.Println("未匹配到host:", host)
 		return errors.New("host未匹配到"), token
 	}
-	redisKey := fmt.Sprintf("oneclick_token_%s", host)
-	// 查缓存
-	if reidsCatche, redisErr := redis.GetBytes("other", redisKey); redisErr == nil && reidsCatche != nil {
-		errs := json.Unmarshal(*reidsCatche, &token)
-		if errs == nil && token != nil {
-			return nil, token
+	// 是否走缓存
+	redisKey := fmt.Sprintf(initjson.OneClick.TokenCache.Key, host)
+	if initjson.OneClick.TokenCache.Open {
+		// 查缓存
+		if reidsCatche, redisErr := redis.GetBytes("other", redisKey); redisErr == nil && reidsCatche != nil {
+			errs := json.Unmarshal(*reidsCatche, &token)
+			if errs == nil && token != nil {
+				return nil, token
+			}
 		}
 	}
 	var (
@@ -236,9 +239,11 @@ func GetAuthTokenWithOptions(host string) (_err error, token *authToken) {
 			return
 		}
 	}
-	// 存缓存
-	if bytes, err := json.Marshal(token); err == nil && bytes != nil {
-		_ = redis.PutBytes("other", redisKey, &bytes, 60*9)
+	if initjson.OneClick.TokenCache.Open {
+		// 存缓存
+		if bytes, err := json.Marshal(token); err == nil && bytes != nil {
+			_ = redis.PutBytes("other", redisKey, &bytes, initjson.OneClick.TokenCache.Timeout)
+		}
 	}
 	return
 }

+ 5 - 0
src/jfw/modules/publicapply/src/oneclick/initjson/oc.go

@@ -15,6 +15,11 @@ type oneClick struct {
 		Origin string `json:"origin"`
 		Url    string `json:"url"`
 	} `json:"wx"`
+	TokenCache struct {
+		Open    bool   `json:"open"`
+		Key     string `json:"key"`
+		Timeout int    `json:"timeout"`
+	} `json:"tokenCache"`
 }
 
 var (

+ 5 - 0
src/jfw/modules/publicapply/src/oneclick/oneClick.json

@@ -8,5 +8,10 @@
   "wx": {
     "origin": "https://jybx-webtest.jydev.jianyu360.com",
     "url": "https://jybx-webtest.jydev.jianyu360.com/"
+  },
+  "tokenCache": {
+    "open": false,
+    "key": "",
+    "timeout": 10
   }
 }