增加推送通知

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

@ -36,7 +36,7 @@ func SendNoticeEmail(username, msg string) {
log.Println(err) log.Println(err)
} }
} }
func SendAppGetuiPush(msg string) { func SendAppGetuiPush(kefu string, title, content string) {
token := models.FindConfig("GetuiToken") token := models.FindConfig("GetuiToken")
if token == "" { if token == "" {
token = getGetuiToken() token = getGetuiToken()
@ -58,21 +58,30 @@ func SendAppGetuiPush(msg string) {
}, },
"push_message":{ "push_message":{
"notification":{ "notification":{
"title":"请填写通知标题", "title":"%s",
"body":"请填写通知内容", "body":"%s",
"click_type":"url", "click_type":"url",
"url":"https//:xxx" "url":"https//:xxx"
} }
} }
} }
` `
req := fmt.Sprintf(format, tools.Uuid(), "0507db8a6769af494f22e17a6177c29a") clients := models.FindClients(kefu)
url := "https://restapi.getui.com/v2/" + appid + "/push/single/cid" if len(clients) == 0 {
headers := make(map[string]string) return
headers["Content-Type"] = "application/json;charset=utf-8" }
headers["token"] = token //clientIds := make([]string, 0)
res, err := tools.PostHeader(url, []byte(req), headers) for _, client := range clients {
log.Println(url, req, err, res) //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 { func getGetuiToken() string {
appid := models.FindConfig("GetuiAppID") appid := models.FindConfig("GetuiAppID")

@ -102,7 +102,7 @@ func PostVisitorLogin(c *gin.Context) {
//各种通知 //各种通知
go SendNoticeEmail(visitor.Name, "来了") go SendNoticeEmail(visitor.Name, "来了")
go SendAppGetuiPush(visitor.Name + "来了") go SendAppGetuiPush(kefuInfo.Name, visitor.Name, visitor.Name+"来了")
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"code": 200, "code": 200,

@ -18,3 +18,8 @@ func CreateUserClient(kefu, clientId string) uint {
DB.Create(u) DB.Create(u)
return u.ID return u.ID
} }
func FindClients(kefu string) []User_client {
var arr []User_client
DB.Where("kefu = ?", kefu).Find(&arr)
return arr
}

Loading…
Cancel
Save