wangshan hai 3 meses
pai
achega
d684bf7a56
Modificáronse 2 ficheiros con 7 adicións e 3 borrados
  1. 4 2
      services/filter/sessionfilter.go
  2. 3 1
      services/sse/sse.go

+ 4 - 2
services/filter/sessionfilter.go

@@ -1,8 +1,10 @@
 package filter
 
 import (
-	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
 	"net/http"
+	"strings"
+
+	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
 )
 
 // 登录限制
@@ -13,7 +15,7 @@ type sessionfilter struct {
 // 继承过滤器方法
 func (l *sessionfilter) Do(w http.ResponseWriter, req *http.Request) bool {
 	session := l.App.SessionManager.Session(req, w)
-	if req.RequestURI == "/jyActivity/getConfig/info" {
+	if req.RequestURI == "/jyActivity/getConfig/info" || strings.Contains(req.RequestURI, "/sse/") {
 		return true
 	}
 	if session.Get("userId") == nil {

+ 3 - 1
services/sse/sse.go

@@ -29,6 +29,7 @@ func (s *ServerSentRouter) Notify() {
 
 	sessVal := s.Session().GetMultiple()
 	userId := common.ObjToString(sessVal["userId"])
+	//userId = s.GetString("userId")
 	if userId != "" {
 		// 创建用户专属的消息通道
 		messageChan := make(chan string)
@@ -61,10 +62,11 @@ func (s *ServerSentRouter) Notify() {
 func (s *ServerSentRouter) Send() {
 	msg := s.GetString("msg")
 	phone := s.GetString("phone")
+	userId := s.GetString("userId")
 	if msg == "" {
 		msg = "Default notification at " + time.Now().Format(time.RFC3339)
 	} else {
-		util.SseBroadcast.SendToUsers(model.SseMessage{
+		util.SendNotification(userId, model.SseMessage{
 			Name:   msg,
 			User:   phone,
 			State:  model.WinningTarget,