zhangxinlei1996 3 жил өмнө
parent
commit
00315882c9

+ 6 - 2
src/config.json

@@ -8,7 +8,7 @@
     "weixinrpc": "127.0.0.1:8083",
     "cacheflag": false,
     "agreement": "http",
-    "webdomain": "https://web2-jytest.jydev.jianyu360.com",
+    "webdomain": "https://web-zxl.jydev.jianyu360.com",
     "redirect": {
         "searchinfo": "/jylab/mainSearch",
         "rssset": "/swordfish/newhistorypush",
@@ -299,5 +299,9 @@
     "pcindexCacheKey":"jypcindex2",
     "dedupUrl":  "http://127.0.0.1:8888/data/deduplication",
     "bmwxrcoll":"drainage_wxreply_log",
-    "optimalTime":"2021-08-03 12:00:00"
+    "optimalTime":"2021-08-03 12:00:00",
+    "pcFilterFlag":true,
+    "pcSessionFlag":true,
+    "sessionTimeout":168,
+    "pcSessionTimeout":168
 }

+ 3 - 1
src/jfw/active/active_future.go

@@ -10,10 +10,12 @@ import (
 	"jfw/public"
 	"jfw/wx"
 	"log"
+
 	//	"math/rand"
 	"net/url"
 	"qfw/util"
 	"sync"
+
 	//	"qfw/util/redis"
 	"time"
 )
@@ -41,7 +43,7 @@ func (a *Active) FutureIndex(share_openid string) error {
 							isSubscribe = CheckUserIsSubscribe(openid)
 						}
 						if isSubscribe {
-							FindUserAndCreateSess(openid, a.Session())
+							FindUserAndCreateSess(openid, a.Session(), "wx", false)
 						}
 					}
 				}

+ 1 - 1
src/jfw/active/active_seal.go

@@ -255,7 +255,7 @@ func (a *Active) Index() error {
 							isSubscribe = CheckUserIsSubscribe(openid)
 						}
 						if isSubscribe {
-							FindUserAndCreateSess(openid, a.Session())
+							FindUserAndCreateSess(openid, a.Session(), "wx", false)
 						}
 					}
 				}

+ 1 - 1
src/jfw/active/live.go

@@ -122,7 +122,7 @@ func (this *Active) LivePage() error {
 						checkIsSubscribeFlag = CheckUserIsSubscribe(openid)
 						if checkIsSubscribeFlag {
 							//关注用户 建session
-							go FindUserAndCreateSess(openid, this.Session())
+							go FindUserAndCreateSess(openid, this.Session(), "wx", false)
 						}
 					}
 				}

+ 3 - 0
src/jfw/filter/filter.go

@@ -31,5 +31,8 @@ func (f *Filter) Do(w http.ResponseWriter, r *http.Request) bool {
 	if !(&phoneFilter{w, r, session, getSession}).Do() {
 		return false
 	}
+	if !(&pcFilter{w, r, session, getSession}).Do() {
+		return false
+	}
 	return true
 }

+ 1 - 2
src/jfw/front/applysub.go

@@ -20,7 +20,6 @@ import (
 
 type Applysub struct {
 	*xweb.Action
-
 	index         xweb.Mapper `xweb:"/front/applysub/index"`         //申请开通订阅推送首页
 	infoPage      xweb.Mapper `xweb:"/front/applysub/infoPage"`      //申请开通订阅推送申请详情页
 	checkPhoneNum xweb.Mapper `xweb:"/front/applysub/checkPhoneNum"` //查询手机号是否已使用
@@ -214,7 +213,7 @@ func (a *Applysub) Index() error {
 						isSubscribe = CheckUserIsSubscribe(openid)
 					}
 					if isSubscribe {
-						FindUserAndCreateSess(openid, a.Session())
+						FindUserAndCreateSess(openid, a.Session(), "wx", false)
 					}
 				}
 			}

+ 3 - 2
src/jfw/front/commonPayWx.go

@@ -3,13 +3,14 @@ package front
 import (
 	"errors"
 	"fmt"
-	"github.com/go-xweb/xweb"
 	"jfw/config"
 	"jfw/jyutil"
 	"jfw/public"
 	"jfw/wx"
 	"net/url"
 	"qfw/util"
+
+	"github.com/go-xweb/xweb"
 )
 
 /*
@@ -102,7 +103,7 @@ func (w *WxPayCommon) ToMyWxOrder() error {
 						isSubscribe = CheckUserIsSubscribe(openid)
 					}
 					if isSubscribe {
-						FindUserAndCreateSess(openid, w.Session())
+						FindUserAndCreateSess(openid, w.Session(), "wx", false)
 					}
 				}
 			}

+ 3 - 3
src/jfw/front/distribution.go

@@ -43,7 +43,7 @@ func (this *Distrib) LinkShare(discored string) error {
 					checkIsSubscribeFlag = CheckUserIsSubscribe(openid)
 					if checkIsSubscribeFlag {
 						//关注用户 建session
-						FindUserAndCreateSess(openid, this.Session())
+						FindUserAndCreateSess(openid, this.Session(), "wx", false)
 					}
 				}
 			}
@@ -91,7 +91,7 @@ func (this *Distrib) LinkShareX(discored string) error {
 					checkIsSubscribeFlag = CheckUserIsSubscribe(openid)
 					if checkIsSubscribeFlag {
 						//关注用户 建session
-						FindUserAndCreateSess(openid, this.Session())
+						FindUserAndCreateSess(openid, this.Session(), "wx", false)
 					}
 				}
 			}
@@ -140,7 +140,7 @@ func (this *Distrib) LinkShareG(discored string) error {
 					checkIsSubscribeFlag = CheckUserIsSubscribe(openid)
 					if checkIsSubscribeFlag {
 						//关注用户 建session
-						FindUserAndCreateSess(openid, this.Session())
+						FindUserAndCreateSess(openid, this.Session(), "wx", false)
 					}
 				}
 			}

+ 16 - 6
src/jfw/front/front.go

@@ -604,7 +604,7 @@ func (f *Front) Login(key string) error {
 	shareid := se.DecodeString(key)
 	openid := redis.GetStr("sso", "p_usershare_"+shareid)
 	if openid != "" {
-		ok, user, userInfo := FindUserAndCreateSess(openid, f.Session())
+		ok, user, userInfo := FindUserAndCreateSess(openid, f.Session(), "pc", true)
 		if ok {
 			(*user)["shareid"] = shareid
 			f.SetSession("user", *user)
@@ -785,21 +785,21 @@ func (m *Front) Wxerr() error {
 }
 
 //查找用户并创建session
-func FindUserAndCreateSess(openid string, sess *httpsession.Session) (bool, *map[string]interface{}, map[string]interface{}) {
+func FindUserAndCreateSess(openid string, sess *httpsession.Session, typ string, flag bool) (bool, *map[string]interface{}, map[string]interface{}) {
 	return CreateSession(map[string]interface{}{
 		"s_m_openid": openid,
 		"s_unionid":  map[string]interface{}{"$ne": openid}, //处理排除未关注用户点击菜单创建的用户
 		"i_ispush":   1,
-	}, sess)
+	}, sess, typ, flag)
 }
 
 func FindUserAndCreateSessById(userId primitive.ObjectID, sess *httpsession.Session) (bool, *map[string]interface{}, map[string]interface{}) {
 	return CreateSession(map[string]interface{}{
 		"_id": userId,
-	}, sess)
+	}, sess, "pc", true)
 }
 
-func CreateSession(q map[string]interface{}, sess *httpsession.Session) (bool, *map[string]interface{}, map[string]interface{}) {
+func CreateSession(q map[string]interface{}, sess *httpsession.Session, typ string, flag bool) (bool, *map[string]interface{}, map[string]interface{}) {
 	if q == nil || len(q) == 0 {
 		return false, nil, nil
 	}
@@ -807,6 +807,16 @@ func CreateSession(q map[string]interface{}, sess *httpsession.Session) (bool, *
 	if person == nil {
 		return false, nil, nil
 	}
+	log.Println(config.Sysconfig["pcSessionFlag"].(bool), flag)
+	//
+	if pcSessionFlag, ok := config.Sysconfig["pcSessionFlag"].(bool); pcSessionFlag && ok && flag {
+		userid := util.ObjToString(sessionVal["userId"])
+		sidStr := fmt.Sprint(sess.Id())
+		jyutil.ClearPcSession(userid, sidStr)
+		log.Println("sess:", sess.Id(), q["_id"])
+		redis.Put("other", jyutil.LoginRedisKey(userid), sess.Id(), 3600*util.IntAllDef(config.Sysconfig["pcSessionTimeout"], 168))
+	}
+	sessionVal["platform"] = typ
 	sess.SetMultiple(sessionVal)
 	infoData := map[string]interface{}{
 		"result":      "ok",
@@ -836,7 +846,7 @@ func (m *Front) Sess(ostr string) error {
 	str := strings.Split(sewx.DecodeString(strs[0]), ",")
 	if len(str) == 4 {
 		openid := str[0]
-		ok, _, _ := FindUserAndCreateSess(openid, m.Session())
+		ok, _, _ := FindUserAndCreateSess(openid, m.Session(), "wx", false)
 		if ok {
 			actionurl := util.ObjToString(urlMap[str[3]])
 			if actionurl != "" {

+ 1 - 1
src/jfw/front/frontRouter.go

@@ -52,7 +52,7 @@ func (this *CommonRouter) WxCommonPage(folder, loginSign, htmlPage string) error
 	if loginSign != "free" {
 		openid, _ := this.GetSession("s_m_openid").(string)
 		if openid != "" {
-			ok, _, _ := FindUserAndCreateSess(openid, this.Session())
+			ok, _, _ := FindUserAndCreateSess(openid, this.Session(), "wx", false)
 			if !ok {
 				openid = ""
 			}

+ 62 - 62
src/jfw/front/jylog.go

@@ -1,73 +1,73 @@
 package front
 
-/**
-日志文件自动切换,默认保留15天内日志
-**/
+// /**
+// 日志文件自动切换,默认保留15天内日志
+// **/
 
-import (
-	"log"
-	"os"
-	"path/filepath"
-	"regexp"
-	"time"
+// import (
+// 	"log"
+// 	"os"
+// 	"path/filepath"
+// 	"regexp"
+// 	"time"
 
-	"github.com/go-xweb/xweb"
-	"github.com/robfig/cron"
-)
+// 	"github.com/go-xweb/xweb"
+// 	"github.com/robfig/cron"
+// )
 
-//日志格式
-var fileReg = regexp.MustCompile("^(\\d{4}_[0-9_]{14})\\.log$")
+// //日志格式
+// var fileReg = regexp.MustCompile("^(\\d{4}_[0-9_]{14})\\.log$")
 
-//当前日志文件句柄
-var LogFile *os.File
+// //当前日志文件句柄
+// var LogFile *os.File
 
-//时间格式
-var FMT = "2006_01_02_15_04_05"
+// //时间格式
+// var FMT = "2006_01_02_15_04_05"
 
-//日志目录
-var LogPath = "./jylog"
+// //日志目录
+// var LogPath = "./jylog"
 
-func init() {
-	os.Mkdir(LogPath, os.ModePerm)
-	//默认保留15天内的日志,-1为永久保留
-	initLog(15)
-}
+// func init() {
+// 	os.Mkdir(LogPath, os.ModePerm)
+// 	//默认保留15天内的日志,-1为永久保留
+// 	initLog(15)
+// }
 
-func initLog(saveDay int) {
-	go logfile()
-	task := cron.New()
-	task.Start()
-	task.AddFunc("0 0 0 * * ?", func() {
-		go logfile()
-		time.Sleep(50 * time.Second)
-		if saveDay > 0 {
-			filepath.Walk(LogPath, func(path string, info os.FileInfo, err error) error {
-				str := fileReg.FindStringSubmatch(info.Name())
-				if len(str) == 2 {
-					t, er := time.ParseInLocation(FMT, str[1], time.Local)
-					if er == nil {
-						if (time.Now().Unix()-t.Unix())/86400 > int64(saveDay) {
-							log.Println("delete log file:", path, os.Remove(path))
-						}
-					}
-				}
-				return nil
-			})
-		}
-	})
-}
+// func initLog(saveDay int) {
+// 	go logfile()
+// 	task := cron.New()
+// 	task.Start()
+// 	task.AddFunc("0 0 0 * * ?", func() {
+// 		go logfile()
+// 		time.Sleep(50 * time.Second)
+// 		if saveDay > 0 {
+// 			filepath.Walk(LogPath, func(path string, info os.FileInfo, err error) error {
+// 				str := fileReg.FindStringSubmatch(info.Name())
+// 				if len(str) == 2 {
+// 					t, er := time.ParseInLocation(FMT, str[1], time.Local)
+// 					if er == nil {
+// 						if (time.Now().Unix()-t.Unix())/86400 > int64(saveDay) {
+// 							log.Println("delete log file:", path, os.Remove(path))
+// 						}
+// 					}
+// 				}
+// 				return nil
+// 			})
+// 		}
+// 	})
+// }
 
-//创建并切换输出文件
-func logfile() {
-	now := time.Now().Format(FMT)
-	file, _ := os.Create(LogPath + "/" + now + ".log")
-	log.SetOutput(file)
-	xweb.RootApp().Logger.SetOutput(file)
-	go func(file *os.File) {
-		time.Sleep(5 * time.Second)
-		if LogFile != nil {
-			LogFile.Close()
-		}
-		LogFile = file
-	}(file)
-}
+// //创建并切换输出文件
+// func logfile() {
+// 	now := time.Now().Format(FMT)
+// 	file, _ := os.Create(LogPath + "/" + now + ".log")
+// 	log.SetOutput(file)
+// 	xweb.RootApp().Logger.SetOutput(file)
+// 	go func(file *os.File) {
+// 		time.Sleep(5 * time.Second)
+// 		if LogFile != nil {
+// 			LogFile.Close()
+// 		}
+// 		LogFile = file
+// 	}(file)
+// }

+ 2 - 2
src/jfw/front/shorturl.go

@@ -82,7 +82,7 @@ func (s *Short) Article(stype, id string) error {
 					if openid != "" {
 						isSubscribe := CheckUserIsSubscribe(openid)
 						if isSubscribe {
-							FindUserAndCreateSess(openid, s.Session())
+							FindUserAndCreateSess(openid, s.Session(), "wx", false)
 						}
 					}
 				}
@@ -199,7 +199,7 @@ func (s *Short) Article(stype, id string) error {
 			}
 			//之前sessionkeep.go中没有放userId,造成关注有问题
 			if s.GetSession("userId") == nil {
-				FindUserAndCreateSess(ssOpenid.(string), s.Session())
+				FindUserAndCreateSess(ssOpenid.(string), s.Session(), "wx", false)
 			}
 		}
 		surl := s.GetString("url")

+ 1 - 1
src/jfw/front/swordfish.go

@@ -1237,7 +1237,7 @@ func (m *Front) About() error {
 	if myopenid != "" {
 		isSubscribe = CheckUserIsSubscribe(myopenid)
 		if isSubscribe {
-			FindUserAndCreateSess(myopenid, m.Session())
+			FindUserAndCreateSess(myopenid, m.Session(), "wx", false)
 			myopenid, _ = m.Session().Get("s_m_openid").(string)
 			mynickname, _ = m.Session().Get("s_nickname").(string)
 		}

+ 1 - 1
src/jfw/front/vipsubscribe.go

@@ -180,7 +180,7 @@ func (s *Subscribepay) Introduce() error {
 				if openid != "" {
 					isSubscribe := CheckUserIsSubscribe(openid)
 					if isSubscribe {
-						FindUserAndCreateSess(openid, s.Session())
+						FindUserAndCreateSess(openid, s.Session(), "wx", false)
 						userId = util.ObjToString(s.GetSession("userId"))
 					}
 				}

+ 1 - 1
src/jfw/front/websocket.go

@@ -151,7 +151,7 @@ func LoginInfo(shareid, openid string, Sess interface{}) map[string]interface{}
 	}
 	sess, _ := Sess.(*httpsession.Session)
 	if openid != "" {
-		ok, user, infoData := FindUserAndCreateSess(openid, sess)
+		ok, user, infoData := FindUserAndCreateSess(openid, sess, "pc", true)
 		if ok {
 			(*user)["shareid"] = shareid
 			sess.Set("user", *user)

+ 3 - 3
src/jfw/front/ws_dataExport.go

@@ -57,7 +57,7 @@ func (w *WsDataExport) WxToOrderDetail() error {
 						isSubscribe = CheckUserIsSubscribe(openid)
 					}
 					if isSubscribe {
-						FindUserAndCreateSess(openid, w.Session())
+						FindUserAndCreateSess(openid, w.Session(), "wx", false)
 					}
 				}
 			}
@@ -238,7 +238,7 @@ func (w *WsDataExport) ToPreview(_id string) error {
 						isSubscribe = CheckUserIsSubscribe(openid)
 					}
 					if isSubscribe {
-						FindUserAndCreateSess(openid, w.Session())
+						FindUserAndCreateSess(openid, w.Session(), "wx", false)
 					}
 				}
 			}
@@ -276,7 +276,7 @@ func (w *WsDataExport) SubmitOrder() error {
 						isSubscribe = CheckUserIsSubscribe(openid)
 					}
 					if isSubscribe {
-						FindUserAndCreateSess(openid, w.Session())
+						FindUserAndCreateSess(openid, w.Session(), "wx", false)
 					}
 				}
 			}

+ 1 - 1
src/jfw/front/wxMyOrder.go

@@ -60,7 +60,7 @@ func (w *WxMyOrder) MyMenu() error {
 						isSubscribe = CheckUserIsSubscribe(openid)
 					}
 					if isSubscribe {
-						FindUserAndCreateSess(openid, w.Session())
+						FindUserAndCreateSess(openid, w.Session(), "wx", false)
 					}
 				}
 			}

+ 22 - 0
src/jfw/jyutil/jyutil.go

@@ -193,3 +193,25 @@ func GetSessionVal(q map[string]interface{}) (*map[string]interface{}, map[strin
 	sessionVal["phone"] = phone
 	return person, sessionVal
 }
+
+//pc限制登陆 只允许一个账号登陆 根据lgoinrediskey判断
+//ok接口是否调用成功 isGet是否有loginRedisKey
+func ClearPcSession(userid, sessid string) (bool, bool) {
+	ok, isGet := true, true
+	//pc限制登陆
+	if sid := redis.Get("other", LoginRedisKey(userid)); sid != nil {
+		ssid, _ := sid.(string)
+		sidRds := redis.Get("session", sessid)
+		if ssid != sessid && sidRds != nil {
+			ok = redis.Del("session", ssid)
+		}
+	} else {
+		isGet = false
+	}
+	return ok, isGet
+}
+
+//value 用户sessionid
+func LoginRedisKey(userid string) string {
+	return fmt.Sprintf("login_%s", userid)
+}

+ 2 - 1
src/main.go

@@ -102,7 +102,8 @@ func initXweb() {
 	xweb.RootApp().AppConfig.Mode = xweb.Product
 	xweb.RootApp().SetConfig("schecm", Sysconfig["agreement"])
 	xweb.RootApp().AppConfig.ReloadTemplates = true
-	xweb.RootApp().AppConfig.SessionTimeout = 7 * 24 * time.Hour
+	xweb.RootApp().AppConfig.SessionTimeout = time.Hour * time.Duration(util.IntAllDef(Sysconfig["sessionTimeout"], 168))
+	log.Println("~~~", time.Hour*time.Duration(util.IntAllDef(Sysconfig["sessionTimeout"], 168)))
 	xweb.RootApp().AppConfig.CacheTemplates = Sysconfig["cacheflag"].(bool)
 	xweb.RootApp().AddTmplVar("Msg", tag.Msg)
 	xweb.RootApp().AddTmplVar("Ad", tag.Ad)