diff --git a/controller/shout.go b/controller/shout.go index 3c8d9b1..d95c638 100644 --- a/controller/shout.go +++ b/controller/shout.go @@ -36,7 +36,7 @@ func SendNoticeEmail(username, msg string) { log.Println(err) } } -func SendAppGetuiPush(msg string) { +func SendAppGetuiPush(kefu string, title, content string) { token := models.FindConfig("GetuiToken") if token == "" { token = getGetuiToken() @@ -58,21 +58,30 @@ func SendAppGetuiPush(msg string) { }, "push_message":{ "notification":{ - "title":"请填写通知标题", - "body":"请填写通知内容", + "title":"%s", + "body":"%s", "click_type":"url", "url":"https//:xxx" } } } ` - req := fmt.Sprintf(format, tools.Uuid(), "0507db8a6769af494f22e17a6177c29a") - url := "https://restapi.getui.com/v2/" + appid + "/push/single/cid" - headers := make(map[string]string) - headers["Content-Type"] = "application/json;charset=utf-8" - headers["token"] = token - res, err := tools.PostHeader(url, []byte(req), headers) - log.Println(url, req, err, res) + clients := models.FindClients(kefu) + if len(clients) == 0 { + return + } + //clientIds := make([]string, 0) + for _, client := range clients { + //clientIds = append(clientIds, client.Client_id) + req := fmt.Sprintf(format, tools.Md5(tools.Uuid()), client.Client_id, title, content) + url := "https://restapi.getui.com/v2/" + appid + "/push/single/cid" + headers := make(map[string]string) + headers["Content-Type"] = "application/json;charset=utf-8" + headers["token"] = token + res, err := tools.PostHeader(url, []byte(req), headers) + log.Println(url, req, err, res) + } + } func getGetuiToken() string { appid := models.FindConfig("GetuiAppID") diff --git a/controller/visitor.go b/controller/visitor.go index d70a940..784b95e 100644 --- a/controller/visitor.go +++ b/controller/visitor.go @@ -102,7 +102,7 @@ func PostVisitorLogin(c *gin.Context) { //各种通知 go SendNoticeEmail(visitor.Name, "来了") - go SendAppGetuiPush(visitor.Name + "来了") + go SendAppGetuiPush(kefuInfo.Name, visitor.Name, visitor.Name+"来了") c.JSON(200, gin.H{ "code": 200, diff --git a/models/user_client.go b/models/user_client.go index d02b320..40f8d15 100644 --- a/models/user_client.go +++ b/models/user_client.go @@ -18,3 +18,8 @@ func CreateUserClient(kefu, clientId string) uint { DB.Create(u) return u.ID } +func FindClients(kefu string) []User_client { + var arr []User_client + DB.Where("kefu = ?", kefu).Find(&arr) + return arr +}