|
@@ -3,6 +3,7 @@ package front
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
+ . "jfw/config"
|
|
|
"jfw/public"
|
|
|
"log"
|
|
|
qutil "qfw/util"
|
|
@@ -317,3 +318,47 @@ func QrToShareTimeline(conn *websocket.Conn) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+//pc弹框 最新一条消息
|
|
|
+func GetBuoyMsg(conn *websocket.Conn) {
|
|
|
+ defer qutil.Catch()
|
|
|
+ sess := xweb.RootApp().SessionManager.Session(conn.R, conn.W)
|
|
|
+ userid, _ := sess.Get("userId").(string)
|
|
|
+ if userid == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ messageCenter, _ := Sysconfig["messageCenter"].(map[string]interface{})
|
|
|
+ appid, _ := messageCenter["appid"].(string)
|
|
|
+ dbName, _ := messageCenter["dbName"].(string)
|
|
|
+ interval := qutil.IntAllDef(messageCenter["interval"], 300)
|
|
|
+ go func() {
|
|
|
+ defer qutil.Catch()
|
|
|
+ for {
|
|
|
+ var receive string
|
|
|
+ err := websocket.Message.Receive(conn, &receive)
|
|
|
+ if err != nil {
|
|
|
+ //log.Println("websocket接收失败!", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if receive == "close" { //关闭
|
|
|
+ return
|
|
|
+ } else if receive == "HeartBeat" { //心跳监测
|
|
|
+ websocket.Message.Send(conn, "HeartBeat")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ //发送消息
|
|
|
+ for {
|
|
|
+ reply := `{}`
|
|
|
+ list := public.BaseMysql.SelectBySql(`select id,title,link,content,show_content from `+dbName+`.message where receive_userid=? and isdel=1 and appid=? and isRead=0 and show_buoy=1 order by createtime desc limit 1`, userid, appid)
|
|
|
+ if list != nil && len(*list) == 1 {
|
|
|
+ reply = fmt.Sprintf(`{"id":%d,"title":"%s","content":"%s","show_content":"%s","link":"%s"}`, qutil.Int64All((*list)[0]["id"]), qutil.ObjToString((*list)[0]["title"]), qutil.ObjToString((*list)[0]["content"]), qutil.ObjToString((*list)[0]["show_content"]), strings.Split(qutil.ObjToString((*list)[0]["link"]), ",")[0])
|
|
|
+ }
|
|
|
+ if err := websocket.Message.Send(conn, reply); err != nil {
|
|
|
+ //log.Println("websocket发送失败!", err)
|
|
|
+ conn.Close()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ time.Sleep(time.Duration(interval) * time.Second)
|
|
|
+ }
|
|
|
+}
|