Browse Source

中转路由,用户来源

wangshan 6 months ago
parent
commit
a3a109c993
2 changed files with 22 additions and 3 deletions
  1. 15 3
      src/jfw/active/active.go
  2. 7 0
      src/jfw/modules/app/src/app/front/shorturl.go

+ 15 - 3
src/jfw/active/active.go

@@ -1,7 +1,10 @@
 package active
 
 import (
+	"app.yhyue.com/moapp/jybase/redis"
+	"app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
 	"app.yhyue.com/moapp/jypkg/public"
+	"fmt"
 	"regexp"
 
 	util "app.yhyue.com/moapp/jybase/common"
@@ -48,9 +51,12 @@ type Active struct {
 
 }
 
-var mongodb = public.MQFW
-var se = encrypt.SimpleEncrypt{Key: "topnet2015topnet2015"}
-var mobileReg = regexp.MustCompile("(?i)(Android|Mobile|Phone)")
+var (
+	mongodb      = public.MQFW
+	se           = encrypt.SimpleEncrypt{Key: "topnet2015topnet2015"}
+	mobileReg    = regexp.MustCompile("(?i)(Android|Mobile|Phone)")
+	cacheTimeOut = 3 * 24 * 60 * 60 //三天
+)
 
 func init() {
 	//添加模块解析
@@ -95,6 +101,12 @@ func (a *Active) TransitRoute(key string) error {
 				redirectUrl = util.ObjToString(shortUrl["href"])
 			}
 		}
+		//未登录
+		if userId, _ := a.GetSession("userId").(string); userId == "" {
+			jy.SetCookieValue(a.ResponseWriter, jy.ChannelCookieName, key, cacheTimeOut)                      //三天
+			redis.Put("limitation", fmt.Sprintf("firstVisitTagByWX_%s", a.Session().Id()), key, cacheTimeOut) //登录注册 用户标识
+			return a.Redirect(redirectUrl)
+		}
 	}
 	return a.Redirect(redirectUrl)
 }

+ 7 - 0
src/jfw/modules/app/src/app/front/shorturl.go

@@ -924,6 +924,13 @@ func (s *Short) TransitRoute(key string) error {
 				redirectUrl = util.ObjToString(shortUrl["href"])
 			}
 		}
+
+		//未登录
+		if userId, _ := s.GetSession("userId").(string); userId == "" {
+			jy.SetCookieValue(s.ResponseWriter, jy.ChannelCookieName, key, cacheTimeOut)                      //三天
+			redis.Put("limitation", fmt.Sprintf("firstVisitTagByWX_%s", s.Session().Id()), key, cacheTimeOut) //登录注册 用户标识
+			return s.Redirect(redirectUrl)
+		}
 	}
 	return s.Redirect(redirectUrl)
 }