|
@@ -0,0 +1,77 @@
|
|
|
+package utility
|
|
|
+
|
|
|
+import (
|
|
|
+ "app.yhyue.com/moapp/jybase/date"
|
|
|
+ "context"
|
|
|
+ "encoding/json"
|
|
|
+ "fmt"
|
|
|
+ "github.com/gogf/gf/v2/frame/g"
|
|
|
+ "io/ioutil"
|
|
|
+ "net/http"
|
|
|
+ "net/url"
|
|
|
+)
|
|
|
+
|
|
|
+type StationMessage struct {
|
|
|
+ Action string
|
|
|
+ Addr string
|
|
|
+ CallPlatform string
|
|
|
+}
|
|
|
+type MessageParam struct {
|
|
|
+ UserIds string // 用户mongo库id 用户userId用英文逗号拼接
|
|
|
+ SendTime string // 发送时间 暂时无用 (2022-03-31 09:08:08 仅发送模式为定时时有效)
|
|
|
+ Title string // 通知消息 消息标题
|
|
|
+ Content string // 消息内容
|
|
|
+ Link string // pc消息链接
|
|
|
+ AndroidUrl string // 安卓消息链接
|
|
|
+ IosUrl string // IOS消息链接
|
|
|
+ WeChatUrl string // 微信消息链接
|
|
|
+ SendMode int // 发送模式 1- 定时 2-实时 (所调接口未支持定时)
|
|
|
+ PositionIds string // 职位id 与userIds 对应
|
|
|
+ MsgType int // message_class 里的消息分类
|
|
|
+}
|
|
|
+type MessageRet struct {
|
|
|
+ Status string `json:"status"`
|
|
|
+ Info string `json:"info"`
|
|
|
+ Data struct {
|
|
|
+ Status int `json:"status"`
|
|
|
+ } `json:"data"`
|
|
|
+}
|
|
|
+
|
|
|
+func NewStationMessage(addr string, action string, callPlatform string) *StationMessage {
|
|
|
+ return &StationMessage{
|
|
|
+ Addr: addr,
|
|
|
+ Action: action,
|
|
|
+ CallPlatform: callPlatform,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func (s *StationMessage) SendStationMessages(ctx context.Context, p MessageParam) {
|
|
|
+ var (
|
|
|
+ ret MessageRet
|
|
|
+ cont []byte
|
|
|
+ )
|
|
|
+ parms := fmt.Sprintf("_action=%s&userIds=%s&msgType=%v&title=%s&content=%s&link=%s&sendMode=2&sendTime=%s&androidUrl=%s&iosUrl=%s&weChatUrl=%s&_token=12311&reqSource=1&callPlatform=%s&positionIds=%s&menuname=message",
|
|
|
+ s.Action, p.UserIds, p.MsgType, p.Title, p.Content, p.Link, date.NowFormat(date.Date_Short_Layout), p.AndroidUrl, p.IosUrl, p.WeChatUrl, s.CallPlatform, p.PositionIds)
|
|
|
+ paramsEncode := url.PathEscape(parms)
|
|
|
+ url := fmt.Sprintf("%s?%s", s.Addr, paramsEncode)
|
|
|
+ resp, err := http.Get(url)
|
|
|
+ if err != nil {
|
|
|
+ g.Log().Error(ctx, "发送消息失败:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer resp.Body.Close()
|
|
|
+ cont, err = ioutil.ReadAll(resp.Body)
|
|
|
+ if err != nil {
|
|
|
+ g.Log().Error(ctx, "发送消息错误信息:", string(cont), err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = json.Unmarshal(cont, &ret)
|
|
|
+ if err != nil {
|
|
|
+ g.Log().Error(ctx, "发送消息反序列化错误信息:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if ret.Data.Status != 1 {
|
|
|
+ g.Log().Error(ctx, "发送消息失败:Status != 1", ret)
|
|
|
+ }
|
|
|
+
|
|
|
+}
|