wangchuanjin 2 年 前
コミット
854669eee0
6 ファイル変更22 行追加18 行削除
  1. 1 0
      go.mod
  2. 2 0
      go.sum
  3. 5 6
      jyutil/jyCms.go
  4. 2 3
      jyutil/jyutil.go
  5. 7 8
      jyutil/sessionEncryption.go
  6. 5 1
      jyutil/sessionkeep.go

+ 1 - 0
go.mod

@@ -7,6 +7,7 @@ require (
 	app.yhyue.com/moapp/message v0.0.0-20221202072401-d825fc65512c
 	github.com/nsqio/go-nsq v1.1.0
 	github.com/robfig/cron v1.2.0
+	github.com/robfig/cron/v3 v3.0.1
 	github.com/tealeg/xlsx v1.0.5
 	github.com/thinxer/go-word2vec v0.0.0-20150917053916-5c19ec7379ed
 	go.mongodb.org/mongo-driver v1.11.1

+ 2 - 0
go.sum

@@ -504,6 +504,8 @@ github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqn
 github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
 github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ=
 github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
+github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
+github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
 github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
 github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
 github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=

+ 5 - 6
jyutil/jyCms.go

@@ -5,7 +5,6 @@ import (
 	"encoding/json"
 	"fmt"
 	"html/template"
-	"jy/src/jfw/config"
 	"regexp"
 	"strconv"
 	"time"
@@ -24,7 +23,7 @@ const (
 )
 
 //GetFirstJyCms 获取首评信息
-func GetFirstJyCms(contentType string, size int) (r []map[string]interface{}) {
+func GetFirstJyCms(contentType string, size int, Seoconfig map[string]interface{}) (r []map[string]interface{}) {
 	// 默认剑鱼博客栏目
 	contentType = util.If(contentType == "", "jybk", contentType).(string)
 	redisKey := fmt.Sprintf(jyMsgFirstCache, contentType, size)
@@ -34,7 +33,7 @@ func GetFirstJyCms(contentType string, size int) (r []map[string]interface{}) {
 		rs, _ := JyCmsSearch(map[string]string{
 			"contentType": contentType,
 			"perPage":     fmt.Sprintf("%d", size),
-		})
+		}, Seoconfig)
 		if rs != nil {
 			for _, v := range *rs {
 				delete(v, "praise")
@@ -49,7 +48,7 @@ func GetFirstJyCms(contentType string, size int) (r []map[string]interface{}) {
 }
 
 // JyCmsSearch 剑鱼文章检索
-func JyCmsSearch(query map[string]string) (*[]map[string]interface{}, *[]interface{}) {
+func JyCmsSearch(query map[string]string, Seoconfig map[string]interface{}) (*[]map[string]interface{}, *[]interface{}) {
 	perPage, _ := strconv.Atoi(query["perPage"])
 	currentPage, _ := strconv.Atoi(query["currentPage"])
 	//修复
@@ -111,12 +110,12 @@ func JyCmsSearch(query map[string]string) (*[]map[string]interface{}, *[]interfa
 			m["time"] = reltime.Format(Date_Short_Layout) //首页展示
 			s_pic, _ := m["s_pic"].(string)
 			if s_pic != "" {
-				s_pic = config.Seoconfig["jyadd"].(string) + s_pic
+				s_pic = Seoconfig["jyadd"].(string) + s_pic
 			}
 			m["s_pic"] = s_pic
 			s_pic1, _ := m["s_pic1"].(string)
 			if s_pic1 != "" {
-				s_pic1 = config.Seoconfig["jyadd"].(string) + s_pic1
+				s_pic1 = Seoconfig["jyadd"].(string) + s_pic1
 			}
 			m["s_pic1"] = s_pic1
 			m["_id"] = se.EncodeString(BsonIdToSId(m["_id"]))

+ 2 - 3
jyutil/jyutil.go

@@ -4,7 +4,6 @@ import (
 	"encoding/json"
 	"fmt"
 	"io/ioutil"
-	"jy/src/jfw/config"
 	"log"
 	"net/http"
 	"reflect"
@@ -64,9 +63,9 @@ func FindMyShareId(activecode, openid string) string {
 }
 
 //获取用户openid
-func Getopenid(code string) (openid string) {
+func Getopenid(code, Wxoauthinfo string) (openid string) {
 	defer util.Catch()
-	recturl := fmt.Sprintf(config.Wxoauthinfo, code)
+	recturl := fmt.Sprintf(Wxoauthinfo, code)
 	resp, err := http.Get(recturl)
 	if err != nil {
 		log.Println(err.Error())

+ 7 - 8
jyutil/sessionEncryption.go

@@ -7,8 +7,6 @@ import (
 	"crypto/x509"
 	"encoding/json"
 	"encoding/pem"
-	"jy/src/jfw/config"
-	"jy/src/jfw/nodemgr"
 	"log"
 	"sync"
 	"time"
@@ -125,15 +123,15 @@ type EncryptionConf struct {
 }
 
 //首次启动加载秘钥
-func InitEncryptionStruct() *EncryptionStruct {
+func InitEncryptionStruct(Sysconfig map[string]interface{}) *EncryptionStruct {
 	encryStruct := EncryptionStruct{EncryptionConf: &EncryptionConf{}, Lock: &sync.Mutex{}}
 	//	log.Println("xxxxxx", redis.GetInt("other", "jynode_"+nodemgr.NodeName))
 	//	isMaster := util.If(redis.GetInt("other", "jynode_"+nodemgr.NodeName) == 1, true, false).(bool)
 	go func() {
 		cn := cron.New()
-		str := util.ObjToString(config.Sysconfig["sessionEnctryFlushCorn"])
+		str := util.ObjToString(Sysconfig["sessionEnctryFlushCorn"])
 		cn.AddFunc(str, func() {
-			encryStruct.Flush()
+			encryStruct.Flush(Sysconfig)
 		})
 		cn.Start()
 	}()
@@ -185,8 +183,9 @@ func (e *EncryptionStruct) initAllRsa() {
 }
 
 //定时更新秘钥
-func (e *EncryptionStruct) Flush() {
-	isMaster := util.If(redis.GetInt("other", "jynode_"+nodemgr.NodeName) == 1, true, false).(bool)
+func (e *EncryptionStruct) Flush(Sysconfig map[string]interface{}) {
+	NodeName := util.ObjToString(Sysconfig["nodeName"])
+	isMaster := util.If(redis.GetInt("other", "jynode_"+NodeName) == 1, true, false).(bool)
 	if !isMaster {
 		//从节点从redis中更新秘钥
 		for {
@@ -197,7 +196,7 @@ func (e *EncryptionStruct) Flush() {
 				if e.RsaStruct_Now.Sign == encryconf.Now {
 					log.Println("从节点定时更新EncryptionStruct失败,一分钟后重试", e.RsaStruct_Now.Sign)
 					time.Sleep(time.Minute)
-					if redis.GetInt("other", "jynode_"+nodemgr.NodeName) == 1 {
+					if redis.GetInt("other", "jynode_"+NodeName) == 1 {
 						break
 					} else {
 						continue

+ 5 - 1
jyutil/sessionkeep.go

@@ -20,13 +20,17 @@ const (
 )
 
 var (
-	Encryption = InitEncryptionStruct()
+	Encryption *EncryptionStruct
 	//过滤器
 	//爬虫百度、谷歌、雅虎、新浪、搜狗、搜搜、网易有道
 	//var reg = regexp.MustCompile(`(baidu|google|yahoo|iask|sogou|soso|youdao|Android|Mobile)`)
 	reg = regexp.MustCompile(`(Android|Mobile)`)
 )
 
+func InitEncryptionStructByConf(Sysconfig map[string]interface{}) {
+	Encryption = InitEncryptionStruct(Sysconfig)
+}
+
 // SessionKeep session保持
 type SessionKeep struct {
 	W          http.ResponseWriter