api.go 2.6 KB
Newer Older
Espoir__'s avatar
Espoir__ 已提交
1 2 3 4 5
package api

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
6
	notify_response "github.com/flipped-aurora/gin-vue-admin/server/plugin/notify/model/response"
Espoir__'s avatar
Espoir__ 已提交
7 8 9 10 11 12 13 14
	"github.com/flipped-aurora/gin-vue-admin/server/plugin/notify/service"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type Api struct {
}

Mr.奇淼('s avatar
Mr.奇淼( 已提交
15 16 17 18 19 20 21
// @Tags Notify
// @Summary 发送文字消息接口
// @Security ApiKeyAuth
// @Produce  application/json
// @Param data body notify_response.TextNotify true "发送文字消息的参数"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}"
// @Router /notify/sendTextMessage [post]
Mr.奇淼('s avatar
Mr.奇淼( 已提交
22
func (s *Api) SendTextMessage(c *gin.Context) {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
	var textNotify notify_response.TextNotify
	_ = c.ShouldBindJSON(&textNotify)
	if err := service.ServiceGroupApp.SendTextMessage(textNotify.Content, textNotify.AtMobiles, textNotify.IsAtAll); err != nil {
		global.GVA_LOG.Error("发送失败!", zap.Any("err", err))
		response.FailWithMessage("发送失败", c)
	} else {
		response.OkWithData("发送成功", c)
	}
}

// @Tags Notify
// @Summary 发送图文链接消息接口
// @Security ApiKeyAuth
// @Produce  application/json
// @Param data body notify_response.LinkNotify true "发送图文链接消息的参数"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}"
// @Router /notify/sendLinkMessage [post]
func (s *Api) SendLinkMessage(c *gin.Context) {
	var linkNotify notify_response.LinkNotify
	_ = c.ShouldBindJSON(&linkNotify)
	if err := service.ServiceGroupApp.SendLinkMessage(linkNotify.Content, linkNotify.Title, linkNotify.PicUrl, linkNotify.MessageUrl); err != nil {
		global.GVA_LOG.Error("发送失败!", zap.Any("err", err))
		response.FailWithMessage("发送失败", c)
	} else {
		response.OkWithData("发送成功", c)
	}
}

// @Tags Notify
// @Summary 发送markdown消息接口
// @Security ApiKeyAuth
// @Produce  application/json
// @Param data body notify_response.MarkdownNotify true "发送markdown消息的参数"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}"
// @Router /notify/sendMarkdownMessage [post]
func (s *Api) SendMarkdownMessage(c *gin.Context) {
	var markdownNotify notify_response.MarkdownNotify
	_ = c.ShouldBindJSON(&markdownNotify)
	if err := service.ServiceGroupApp.SendMarkdownMessage(markdownNotify.Content, markdownNotify.Title, markdownNotify.AtMobiles, markdownNotify.IsAtAll); err != nil {
Espoir__'s avatar
Espoir__ 已提交
62 63 64 65 66 67
		global.GVA_LOG.Error("发送失败!", zap.Any("err", err))
		response.FailWithMessage("发送失败", c)
	} else {
		response.OkWithData("发送成功", c)
	}
}