api.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package api
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
  5. notify_response "github.com/flipped-aurora/gin-vue-admin/server/plugin/notify/model/response"
  6. "github.com/flipped-aurora/gin-vue-admin/server/plugin/notify/service"
  7. "github.com/gin-gonic/gin"
  8. "go.uber.org/zap"
  9. )
  10. type Api struct {
  11. }
  12. // @Tags Notify
  13. // @Summary 发送文字消息接口
  14. // @Security ApiKeyAuth
  15. // @Produce application/json
  16. // @Param data body notify_response.TextNotify true "发送文字消息的参数"
  17. // @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}"
  18. // @Router /notify/sendTextMessage [post]
  19. func (s *Api) SendTextMessage(c *gin.Context) {
  20. var textNotify notify_response.TextNotify
  21. _ = c.ShouldBindJSON(&textNotify)
  22. if err := service.ServiceGroupApp.SendTextMessage(textNotify.Content, textNotify.AtMobiles, textNotify.IsAtAll); err != nil {
  23. global.GVA_LOG.Error("发送失败!", zap.Any("err", err))
  24. response.FailWithMessage("发送失败", c)
  25. } else {
  26. response.OkWithData("发送成功", c)
  27. }
  28. }
  29. // @Tags Notify
  30. // @Summary 发送图文链接消息接口
  31. // @Security ApiKeyAuth
  32. // @Produce application/json
  33. // @Param data body notify_response.LinkNotify true "发送图文链接消息的参数"
  34. // @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}"
  35. // @Router /notify/sendLinkMessage [post]
  36. func (s *Api) SendLinkMessage(c *gin.Context) {
  37. var linkNotify notify_response.LinkNotify
  38. _ = c.ShouldBindJSON(&linkNotify)
  39. if err := service.ServiceGroupApp.SendLinkMessage(linkNotify.Content, linkNotify.Title, linkNotify.PicUrl, linkNotify.MessageUrl); err != nil {
  40. global.GVA_LOG.Error("发送失败!", zap.Any("err", err))
  41. response.FailWithMessage("发送失败", c)
  42. } else {
  43. response.OkWithData("发送成功", c)
  44. }
  45. }
  46. // @Tags Notify
  47. // @Summary 发送markdown消息接口
  48. // @Security ApiKeyAuth
  49. // @Produce application/json
  50. // @Param data body notify_response.MarkdownNotify true "发送markdown消息的参数"
  51. // @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}"
  52. // @Router /notify/sendMarkdownMessage [post]
  53. func (s *Api) SendMarkdownMessage(c *gin.Context) {
  54. var markdownNotify notify_response.MarkdownNotify
  55. _ = c.ShouldBindJSON(&markdownNotify)
  56. if err := service.ServiceGroupApp.SendMarkdownMessage(markdownNotify.Content, markdownNotify.Title, markdownNotify.AtMobiles, markdownNotify.IsAtAll); err != nil {
  57. global.GVA_LOG.Error("发送失败!", zap.Any("err", err))
  58. response.FailWithMessage("发送失败", c)
  59. } else {
  60. response.OkWithData("发送成功", c)
  61. }
  62. }