浏览代码

seo refer

wangshan 3 天之前
父节点
当前提交
dfee6fb4d9
共有 4 个文件被更改,包括 188 次插入181 次删除
  1. 1 1
      src/go.mod
  2. 2 2
      src/go.sum
  3. 74 71
      src/jfw/filter/filter.go
  4. 111 107
      src/jfw/front/jyshare.go

+ 1 - 1
src/go.mod

@@ -6,7 +6,7 @@ require (
 	app.yhyue.com/moapp/jyMarketing v0.0.2-0.20230308011651-df591d32df88
 	app.yhyue.com/moapp/jybase v0.0.0-20250710095910-bbc834d8b6e8
 	app.yhyue.com/moapp/jylog v0.0.0-20230522075550-05d7230ca545
-	app.yhyue.com/moapp/jypkg v1.33.31
+	app.yhyue.com/moapp/jypkg v1.33.32
 	bp.jydev.jianyu360.cn/BaseService/userCenter v1.2.21
 	github.com/SKatiyar/qr v0.0.0-20151201054752-25b6bdf44e67
 	github.com/bwmarrin/snowflake v0.3.0

+ 2 - 2
src/go.sum

@@ -20,8 +20,8 @@ app.yhyue.com/moapp/jybase v0.0.0-20250710095910-bbc834d8b6e8/go.mod h1:OEtMbsn7
 app.yhyue.com/moapp/jyfs v0.0.0-20231024061508-480c270480d4/go.mod h1:61hzZ3dZHXL28BNl8BOgZsvM2S5UVY5YFzOkEUPrSu4=
 app.yhyue.com/moapp/jylog v0.0.0-20230522075550-05d7230ca545 h1:+Lak4m1zgsigQloOsvp8AJ+0XeX/+PGp9QP550xlbBQ=
 app.yhyue.com/moapp/jylog v0.0.0-20230522075550-05d7230ca545/go.mod h1:uFrsdUBFbETiJlEmr4PtJWPsZlUpPj2bHQRhryu6ggk=
-app.yhyue.com/moapp/jypkg v1.33.31 h1:DpaHMxFdLVEkGdP5V3n9/Rk6EAwY/zEKeh/B8EnUaQw=
-app.yhyue.com/moapp/jypkg v1.33.31/go.mod h1:m/OMjugcf4XK5c/2mErxnXEyAZ+WNya8HP0x8jFGw4U=
+app.yhyue.com/moapp/jypkg v1.33.32 h1:QGfOKZPgYkbuJBLzd312EyaPRR6VVXVSB1WxEhpOHsI=
+app.yhyue.com/moapp/jypkg v1.33.32/go.mod h1:m/OMjugcf4XK5c/2mErxnXEyAZ+WNya8HP0x8jFGw4U=
 app.yhyue.com/moapp/message v0.0.0-20231204024949-8c7145bfc161 h1:WGi4OEIoqw6NpNFGioUEBZnjK9aBa+xJqf/5WY+QyhM=
 app.yhyue.com/moapp/message v0.0.0-20231204024949-8c7145bfc161/go.mod h1:0Oj8SB4pVjdCLD28sy2zyM3hS0WHGpNuVcakLW43GmI=
 bp.jydev.jianyu360.cn/BP/jynsq v0.0.0-20220222052708-ebc43af90698/go.mod h1:ojo/AUH9Yr1wzarEjOaNMkj1Cet/9r8IgLyba64Z52E=

+ 74 - 71
src/jfw/filter/filter.go

@@ -1,91 +1,94 @@
 package filter
 
 import (
-	"crypto/rsa"
-	"github.com/bwmarrin/snowflake"
-	. "jy/src/jfw/config"
-	"jy/src/jfw/jyutil"
-	"net/http"
-	"regexp"
-	"time"
+    "crypto/rsa"
+    "github.com/bwmarrin/snowflake"
+    . "jy/src/jfw/config"
+    "jy/src/jfw/jyutil"
+    "log"
+    "net/http"
+    "regexp"
+    "time"
 
-	util "app.yhyue.com/moapp/jybase/common"
-	fs "app.yhyue.com/moapp/jybase/fsnotify"
-	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
-	fx "app.yhyue.com/moapp/jypkg/filter/xweb"
-	"app.yhyue.com/moapp/jypkg/identity"
-	"app.yhyue.com/moapp/jypkg/public"
+    util "app.yhyue.com/moapp/jybase/common"
+    fs "app.yhyue.com/moapp/jybase/fsnotify"
+    "app.yhyue.com/moapp/jybase/go-xweb/xweb"
+    fx "app.yhyue.com/moapp/jypkg/filter/xweb"
+    "app.yhyue.com/moapp/jypkg/identity"
+    "app.yhyue.com/moapp/jypkg/public"
 )
 
 var RouteConf struct {
-	ExcludeRoute []string
+    ExcludeRoute []string
 }
 var (
-	ExcludeUrl []*regexp.Regexp
-	PrivateKey *rsa.PrivateKey
-	PublicKey  *rsa.PublicKey
+    ExcludeUrl []*regexp.Regexp
+    PrivateKey *rsa.PrivateKey
+    PublicKey  *rsa.PublicKey
 )
 
 func init() {
-	xweb.AddFilter(&Filter{})
-	go initPrivatePublicKey()
-	go ChanMonitor()
-	Node, _ = snowflake.NewNode(util.Int64All(Seoconfig["node"]))
-	//日志过滤 路由集合
-	go fs.FSNotifyFUNC("sword->%s", "./route.json", true, func() {
-		util.ReadConfig("./route.json", &RouteConf)
-		if len(RouteConf.ExcludeRoute) > 0 {
-			ExcludeUrl = []*regexp.Regexp{}
-			for _, v := range RouteConf.ExcludeRoute {
-				ExcludeUrl = append(ExcludeUrl, regexp.MustCompile(util.ObjToString(v)))
-			}
-		}
-	})
-	time.AfterFunc(1*time.Minute, SaveLogTask)
+    xweb.AddFilter(&Filter{})
+    go initPrivatePublicKey()
+    go ChanMonitor()
+    Node, _ = snowflake.NewNode(util.Int64All(Seoconfig["node"]))
+    //日志过滤 路由集合
+    go fs.FSNotifyFUNC("sword->%s", "./route.json", true, func() {
+        util.ReadConfig("./route.json", &RouteConf)
+        if len(RouteConf.ExcludeRoute) > 0 {
+            ExcludeUrl = []*regexp.Regexp{}
+            for _, v := range RouteConf.ExcludeRoute {
+                ExcludeUrl = append(ExcludeUrl, regexp.MustCompile(util.ObjToString(v)))
+            }
+        }
+    })
+    time.AfterFunc(1*time.Minute, SaveLogTask)
 }
 
 type Filter struct {
 }
 
 func (f *Filter) Do(w http.ResponseWriter, r *http.Request) bool {
-	session := xweb.RootApp().SessionManager.Session(r, w)
-	getSession := session.GetMultiple()
-	if getSession["userId"] != nil && getSession["mgoUserId"] == nil && util.Int64All(getSession["positionType"]) == 0 {
-		session.Set("mgoUserId", getSession["userId"])
-	}
-	if getSession["base_user_id"] != nil && getSession["positionId"] == nil {
-		identity.SwitchToBest(util.Int64All(getSession["base_user_id"]), session, Middleground, &public.MQFW, false)
-	}
-	if !(&AnonymousAuth{w, r, session, getSession, make(map[string]interface{})}).Do() {
-		return false
-	}
-	(&CookieInfo{w, r, getSession["userId"] != nil, session}).Do()
-	(&fx.VisitFilter{W: w, R: r, Session: session, SessVal: getSession, MgoLog: public.MQFW, Ms: public.Mysql}).Do()
-	if !(&logFilter{w, r, session, getSession, make(map[string]interface{})}).Do() {
-		return false
-	}
-	//新版登录时间延长
-	if !(&SessionKeep{w, r, session, getSession, make(map[string]interface{})}).Do() {
-		return false
-	}
-	if !(&jyutil.SessionKeep{w, r, session, getSession, make(map[string]interface{})}).Do() {
-		return false
-	}
+    session := xweb.RootApp().SessionManager.Session(r, w)
+    getSession := session.GetMultiple()
+    if getSession["userId"] != nil && getSession["mgoUserId"] == nil && util.Int64All(getSession["positionType"]) == 0 {
+        session.Set("mgoUserId", getSession["userId"])
+    }
+    if getSession["base_user_id"] != nil && getSession["positionId"] == nil {
+        identity.SwitchToBest(util.Int64All(getSession["base_user_id"]), session, Middleground, &public.MQFW, false)
+    }
+    if !(&AnonymousAuth{w, r, session, getSession, make(map[string]interface{})}).Do() {
+        return false
+    }
+    (&CookieInfo{w, r, getSession["userId"] != nil, session}).Do()
+    seoRefer, _ := r.Cookie("SeoRefer")
+    log.Println("-----------seo--refer---------------", seoRefer.Value)
+    (&fx.VisitFilter{W: w, R: r, Session: session, SessVal: getSession, MgoLog: public.MQFW, Ms: public.Mysql}).Do()
+    if !(&logFilter{w, r, session, getSession, make(map[string]interface{})}).Do() {
+        return false
+    }
+    //新版登录时间延长
+    if !(&SessionKeep{w, r, session, getSession, make(map[string]interface{})}).Do() {
+        return false
+    }
+    if !(&jyutil.SessionKeep{w, r, session, getSession, make(map[string]interface{})}).Do() {
+        return false
+    }
 
-	if !(&mergeFilter{w, r, session, getSession}).Do() {
-		return false
-	}
-	if !(&phoneFilter{w, r, session, getSession}).Do() {
-		return false
-	}
-	if !(&pcFilter{w, r, session, getSession}).Do() {
-		return false
-	}
-	if !(&salesFilter{w, r, session, getSession}).Do() {
-		return false
-	}
-	if !(&pcSalesFilter{w, r, session, getSession}).Do() {
-		return false
-	}
-	return true
+    if !(&mergeFilter{w, r, session, getSession}).Do() {
+        return false
+    }
+    if !(&phoneFilter{w, r, session, getSession}).Do() {
+        return false
+    }
+    if !(&pcFilter{w, r, session, getSession}).Do() {
+        return false
+    }
+    if !(&salesFilter{w, r, session, getSession}).Do() {
+        return false
+    }
+    if !(&pcSalesFilter{w, r, session, getSession}).Do() {
+        return false
+    }
+    return true
 }

+ 111 - 107
src/jfw/front/jyshare.go

@@ -1,131 +1,135 @@
 package front
 
 import (
-	util "app.yhyue.com/moapp/jybase/common"
-	"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
-	fx "app.yhyue.com/moapp/jypkg/filter/xweb"
-	"fmt"
-	jutil "jy/src/jfw/jyutil"
-	"log"
-	"net/http"
-	"net/url"
-	"strconv"
-	"strings"
+    util "app.yhyue.com/moapp/jybase/common"
+    "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
+    fx "app.yhyue.com/moapp/jypkg/filter/xweb"
+    "fmt"
+    jutil "jy/src/jfw/jyutil"
+    "log"
+    "net/http"
+    "net/url"
+    "strconv"
+    "strings"
 
-	. "jy/src/jfw/public"
+    . "jy/src/jfw/public"
 
-	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
-	"app.yhyue.com/moapp/jybase/redis"
+    "app.yhyue.com/moapp/jybase/go-xweb/xweb"
+    "app.yhyue.com/moapp/jybase/redis"
 )
 
 type Jyshare struct {
-	*xweb.Action
-	wxShare xweb.Mapper `xweb:"/front/wxshare/([^.]*)"` //微信分享图片
-	share   xweb.Mapper `xweb:"/front/share/([^.]*)"`   //电脑版微信二维码
+    *xweb.Action
+    wxShare xweb.Mapper `xweb:"/front/wxshare/([^.]*)"` //微信分享图片
+    share   xweb.Mapper `xweb:"/front/share/([^.]*)"`   //电脑版微信二维码
 }
 
 func init() {
-	xweb.AddAction(&Jyshare{})
+    xweb.AddAction(&Jyshare{})
 }
 
 // 电脑版微信二维码
 func (m *Jyshare) Share(pid string) error {
-	//生成的pid中,有时候结尾会带有/,pid是接收不到的,所以pid直接从url中取
-	urlEntity, _ := url.Parse(m.Url())
-	log.Println(urlEntity)
-	pid = strings.TrimLeft(urlEntity.Path, "/front/share/")
-	var pngdata = []byte{}
-	pid = se.DecodeString(pid)
-	if pid == "" {
-		pid = "jy001"
-		log.Println(pid, "-share_referer-", m.Request.Referer())
-	}
-	if ret, _ := redis.GetBytes("sso", "p_share_"+pid); ret != nil {
-		pngdata = *ret
-	} else {
-		//id, _ := strconv.Atoi(pid)
-		GetShareQRStr(pid)
-		tmp, err := redis.GetBytes("sso", "p_share_"+pid)
-		if err == nil {
-			pngdata = *tmp
-		}
-	}
-	source := m.GetString("source") //企业信用报告新增
-	if source != "" {
-		fx.SetVisitSource(m.Session(), source)
-	}
-	//page_action  页面请求 GetLoginNum 函数,页面对应id,会有二维码不经过此函数,直接获取二维码。此时 page_action 没有值,后续可以把GetLoginNum 逻辑放在此处
-	go ErBindVisitInfo(pid, m.Session(), m.Request)
-	w := m.ResponseWriter
-	w.Header().Set("Cache-Control", "no-cache,no-store,must-revalidate")
-	w.Header().Set("Prama", "no-cache")
-	w.Header().Set("Expires", "0")
-	w.Header().Set("Content-Type", "image/png")
-	w.Write(pngdata)
-	return nil
+    //生成的pid中,有时候结尾会带有/,pid是接收不到的,所以pid直接从url中取
+    urlEntity, _ := url.Parse(m.Url())
+    log.Println(urlEntity)
+    pid = strings.TrimLeft(urlEntity.Path, "/front/share/")
+    var pngdata = []byte{}
+    pid = se.DecodeString(pid)
+    if pid == "" {
+        pid = "jy001"
+        log.Println(pid, "-share_referer-", m.Request.Referer())
+    }
+    if ret, _ := redis.GetBytes("sso", "p_share_"+pid); ret != nil {
+        pngdata = *ret
+    } else {
+        //id, _ := strconv.Atoi(pid)
+        GetShareQRStr(pid)
+        tmp, err := redis.GetBytes("sso", "p_share_"+pid)
+        if err == nil {
+            pngdata = *tmp
+        }
+    }
+    source := m.GetString("source") //企业信用报告新增
+    if source != "" {
+        fx.SetVisitSource(m.Session(), source)
+    }
+    //page_action  页面请求 GetLoginNum 函数,页面对应id,会有二维码不经过此函数,直接获取二维码。此时 page_action 没有值,后续可以把GetLoginNum 逻辑放在此处
+    go ErBindVisitInfo(pid, m.Session(), m.Request)
+    w := m.ResponseWriter
+    w.Header().Set("Cache-Control", "no-cache,no-store,must-revalidate")
+    w.Header().Set("Prama", "no-cache")
+    w.Header().Set("Expires", "0")
+    w.Header().Set("Content-Type", "image/png")
+    w.Write(pngdata)
+    return nil
 }
 
 // 取微信分享 用户的二维码 图片
 func (m *Jyshare) WxShare(openids string) error {
-	wxidCode := strings.Split(openids, "__")
-	var openid = ""
-	var jyCode = ""
-	if len(wxidCode) > 0 {
-		openid = wxidCode[0]
-		jyCode = wxidCode[1]
-	}
-	var pngData []byte
-	openid = se.DecodeString(openid)
-	pid := jutil.FindMyShareId(openid, jyCode)
-	if pid == "" {
-		pid = "jy002"
-		log.Println(pid, "-WxShare_referer-", m.Request.Referer())
-	}
-	if ret, _ := redis.GetBytes("sso", "p_share_"+pid); ret != nil {
-		pngData = *ret
-	} else {
-		GetShareQRStr(pid)
-		tmp, _ := redis.GetBytes("sso", "p_share_"+pid)
-		pngData = *tmp
-	}
-	//微信分享默认是32
-	m.Session().Set("page_action", "32")
-	go ErBindVisitInfo(pid, m.Session(), m.Request)
-	w := m.ResponseWriter
-	w.Header().Set("Cache-Control", "no-cache,no-store,must-revalidate")
-	w.Header().Set("Prama", "no-cache")
-	w.Header().Set("Expires", "0")
-	w.Header().Set("Content-Type", "image/png")
-	w.Write(pngData)
-	return nil
+    wxidCode := strings.Split(openids, "__")
+    var openid = ""
+    var jyCode = ""
+    if len(wxidCode) > 0 {
+        openid = wxidCode[0]
+        jyCode = wxidCode[1]
+    }
+    var pngData []byte
+    openid = se.DecodeString(openid)
+    pid := jutil.FindMyShareId(openid, jyCode)
+    if pid == "" {
+        pid = "jy002"
+        log.Println(pid, "-WxShare_referer-", m.Request.Referer())
+    }
+    if ret, _ := redis.GetBytes("sso", "p_share_"+pid); ret != nil {
+        pngData = *ret
+    } else {
+        GetShareQRStr(pid)
+        tmp, _ := redis.GetBytes("sso", "p_share_"+pid)
+        pngData = *tmp
+    }
+    //微信分享默认是32
+    m.Session().Set("page_action", "32")
+    //微信分享用户来源
+    if fx.GetVisitSource(m.Session()) == "" {
+        fx.SetVisitSource(m.Session(), fmt.Sprintf("微信好友分享:%s", jyCode))
+    }
+    go ErBindVisitInfo(pid, m.Session(), m.Request)
+    w := m.ResponseWriter
+    w.Header().Set("Cache-Control", "no-cache,no-store,must-revalidate")
+    w.Header().Set("Prama", "no-cache")
+    w.Header().Set("Expires", "0")
+    w.Header().Set("Content-Type", "image/png")
+    w.Write(pngData)
+    return nil
 }
 
 // 访问者信息和二维码进行绑定  用于 微信扫码 关注或者扫码登录记录信息
 func ErBindVisitInfo(erId string, sess *httpsession.Session, r *http.Request) {
-	sessVal := sess.GetMultiple()
-	data := make(map[string]interface{})
-	ua := "" //UA
-	if len(r.Header["User-Agent"]) > 0 {
-		ua = r.Header["User-Agent"][0]
-	}
-	data["Ros"] = util.GetOS(ua)                              //系统
-	data["Rip"] = util.GetIp(r)                               //ip
-	data["Rbrowse"] = util.GetBrowse(ua)                      //浏览器
-	data["RURL"] = r.Referer()                                //当前页面 请求地址
-	data["RModule"] = sessVal["RModule"]                      //模块  基本不使用
-	data["RActiveCode"] = sessVal["RActiveCode"]              //活动代码
-	data["RReferer"] = sessVal["RReferer"]                    //referer
-	data["RSource"] = fx.GetVisitSource(sess)                 //来源
-	data["Rparamarea"] = sessVal["paramarea"]                 //标签查询 地区
-	data["Rparaminfotype"] = sessVal["paraminfotype"]         //标签查询 信息类型
-	pageAction := util.InterfaceToStr(sessVal["page_action"]) //二维码 对应页面的id seo.json  根据当前页面请求地址 获取对应的配置 page_action (不够规范)
-	if _, err := strconv.Atoi(erId); err == nil {
-		pageAction = erId
-	}
-	data["action"] = pageAction
-	ckSource, err := r.Cookie("source") //原逻辑 暂不清楚什么情况下会有这个参数
-	if err == nil {
-		data["cookieSource"] = ckSource.Value
-	}
-	redis.Put("sso", fmt.Sprintf("p_shareData_%s", erId), data, 2*60*60) //仅供微信扫码关注使用
+    sessVal := sess.GetMultiple()
+    data := make(map[string]interface{})
+    ua := "" //UA
+    if len(r.Header["User-Agent"]) > 0 {
+        ua = r.Header["User-Agent"][0]
+    }
+    data["Ros"] = util.GetOS(ua)                              //系统
+    data["Rip"] = util.GetIp(r)                               //ip
+    data["Rbrowse"] = util.GetBrowse(ua)                      //浏览器
+    data["RURL"] = r.Referer()                                //当前页面 请求地址
+    data["RModule"] = sessVal["RModule"]                      //模块  基本不使用
+    data["RActiveCode"] = sessVal["RActiveCode"]              //活动代码
+    data["RReferer"] = sessVal["RReferer"]                    //referer
+    data["RSource"] = fx.GetVisitSource(sess)                 //来源
+    data["Rparamarea"] = sessVal["paramarea"]                 //标签查询 地区
+    data["Rparaminfotype"] = sessVal["paraminfotype"]         //标签查询 信息类型
+    pageAction := util.InterfaceToStr(sessVal["page_action"]) //二维码 对应页面的id seo.json  根据当前页面请求地址 获取对应的配置 page_action (不够规范)
+    if _, err := strconv.Atoi(erId); err == nil {
+        pageAction = erId
+    }
+    data["action"] = pageAction
+    ckSource, err := r.Cookie("source") //原逻辑 暂不清楚什么情况下会有这个参数
+    if err == nil {
+        data["cookieSource"] = ckSource.Value
+    }
+    redis.Put("sso", fmt.Sprintf("p_shareData_%s", erId), data, 2*60*60) //仅供微信扫码关注使用
 }