增加推送通知

pull/23/head
陶士涵 4 years ago
parent ac60d6b38c
commit 15b12d3856

@ -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,15 +58,22 @@ 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")
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"
@ -74,6 +81,8 @@ func SendAppGetuiPush(msg string) {
res, err := tools.PostHeader(url, []byte(req), headers)
log.Println(url, req, err, res)
}
}
func getGetuiToken() string {
appid := models.FindConfig("GetuiAppID")
appkey := models.FindConfig("GetuiAppKey")

@ -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,

@ -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
}

Loading…
Cancel
Save