268 lines
6.7 KiB
Go
268 lines
6.7 KiB
Go
package api
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/goWxHook/goWxHook/core"
|
|
"github.com/goWxHook/goWxHook/utils"
|
|
)
|
|
|
|
// sendTextMsg
|
|
//
|
|
// @Summary 发送文本消息
|
|
// @Description 发送文本消息接口
|
|
// @Tags 发送消息
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param body body core.SendTextMsgRequest true "消息"
|
|
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
|
|
// @Router /api/v1/message/send/text [post]
|
|
func (w *WebApi) sendTextMsg(c *gin.Context) {
|
|
var form core.SendTextMsgRequest
|
|
err := c.ShouldBindJSON(&form)
|
|
if err != nil {
|
|
utils.ResponseError(c, err.Error(), nil)
|
|
return
|
|
}
|
|
err = w.WxApi.SendTextMsg(form)
|
|
if err != nil {
|
|
utils.ResponseError(c, err.Error(), nil)
|
|
return
|
|
}
|
|
utils.ResponseOK(c, "success", nil)
|
|
return
|
|
}
|
|
|
|
// sendCardMsg
|
|
//
|
|
// @Summary 发送名片消息
|
|
// @Description 发送名片消息接口
|
|
// @Tags 发送消息
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param body body core.SendCardMsgRequest true "消息"
|
|
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
|
|
// @Router /api/v1/message/send/card [post]
|
|
func (w *WebApi) sendCardMsg(c *gin.Context) {
|
|
var form core.SendCardMsgRequest
|
|
err := c.ShouldBindJSON(&form)
|
|
if err != nil {
|
|
utils.ResponseError(c, err.Error(), nil)
|
|
return
|
|
}
|
|
err = w.WxApi.SendCardMsg(form)
|
|
if err != nil {
|
|
utils.ResponseError(c, err.Error(), nil)
|
|
return
|
|
}
|
|
utils.ResponseOK(c, "success", nil)
|
|
return
|
|
}
|
|
|
|
// sendLinkMsg
|
|
//
|
|
// @Summary 发送链接消息
|
|
// @Description 发送链接消息接口
|
|
// @Tags 发送消息
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param body body core.SendLinkMsgRequest true "消息"
|
|
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
|
|
// @Router /api/v1/message/send/link [post]
|
|
func (w *WebApi) sendLinkMsg(c *gin.Context) {
|
|
var form core.SendLinkMsgRequest
|
|
err := c.ShouldBindJSON(&form)
|
|
if err != nil {
|
|
utils.ResponseError(c, err.Error(), nil)
|
|
return
|
|
}
|
|
err = w.WxApi.SendLinkMsg(form)
|
|
if err != nil {
|
|
utils.ResponseError(c, err.Error(), nil)
|
|
return
|
|
}
|
|
utils.ResponseOK(c, "success", nil)
|
|
return
|
|
}
|
|
|
|
// sendImageMsg
|
|
//
|
|
// @Summary 发送图片消息
|
|
// @Description 发送图片消息接口
|
|
// @Tags 发送消息
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param body body core.SendImageMsgRequest true "消息"
|
|
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
|
|
// @Router /api/v1/message/send/image [post]
|
|
func (w *WebApi) sendImageMsg(c *gin.Context) {
|
|
var form core.SendImageMsgRequest
|
|
err := c.ShouldBindJSON(&form)
|
|
if err != nil {
|
|
utils.ResponseError(c, err.Error(), nil)
|
|
return
|
|
}
|
|
err = w.WxApi.SendImageMsg(form)
|
|
if err != nil {
|
|
utils.ResponseError(c, err.Error(), nil)
|
|
return
|
|
}
|
|
utils.ResponseOK(c, "success", nil)
|
|
return
|
|
}
|
|
|
|
// sendFileMsg
|
|
//
|
|
// @Summary 发送文件消息
|
|
// @Description 发送文件消息接口
|
|
// @Tags 发送消息
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param body body core.SendFileMsgRequest true "消息"
|
|
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
|
|
// @Router /api/v1/message/send/file [post]
|
|
func (w *WebApi) sendFileMsg(c *gin.Context) {
|
|
var form core.SendFileMsgRequest
|
|
err := c.ShouldBindJSON(&form)
|
|
if err != nil {
|
|
utils.ResponseError(c, err.Error(), nil)
|
|
return
|
|
}
|
|
err = w.WxApi.SendFileMsg(form)
|
|
if err != nil {
|
|
utils.ResponseError(c, err.Error(), nil)
|
|
return
|
|
}
|
|
utils.ResponseOK(c, "success", nil)
|
|
return
|
|
}
|
|
|
|
// sendVideoMsg
|
|
//
|
|
// @Summary 发送视频文件消息
|
|
// @Description 发送视频文件消息接口
|
|
// @Tags 发送消息
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param body body core.SendVideoMsgRequest true "消息"
|
|
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
|
|
// @Router /api/v1/message/send/video [post]
|
|
func (w *WebApi) sendVideoMsg(c *gin.Context) {
|
|
var form core.SendVideoMsgRequest
|
|
err := c.ShouldBindJSON(&form)
|
|
if err != nil {
|
|
utils.ResponseError(c, err.Error(), nil)
|
|
return
|
|
}
|
|
err = w.WxApi.SendVideoMsg(form)
|
|
if err != nil {
|
|
utils.ResponseError(c, err.Error(), nil)
|
|
return
|
|
}
|
|
utils.ResponseOK(c, "success", nil)
|
|
return
|
|
}
|
|
|
|
// sendGifMsg
|
|
//
|
|
// @Summary 发送gif消息
|
|
// @Description 发送gif消息接口
|
|
// @Tags 发送消息
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param body body core.SendGifMsgRequest true "消息"
|
|
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
|
|
// @Router /api/v1/message/send/git [post]
|
|
func (w *WebApi) sendGifMsg(c *gin.Context) {
|
|
var form core.SendGifMsgRequest
|
|
err := c.ShouldBindJSON(&form)
|
|
if err != nil {
|
|
utils.ResponseError(c, err.Error(), nil)
|
|
return
|
|
}
|
|
err = w.WxApi.SendGifMsg(form)
|
|
if err != nil {
|
|
utils.ResponseError(c, err.Error(), nil)
|
|
return
|
|
}
|
|
utils.ResponseOK(c, "success", nil)
|
|
return
|
|
}
|
|
|
|
// sendXmlMsg
|
|
//
|
|
// @Summary 发送XML消息
|
|
// @Description 发送XML消息接口
|
|
// @Tags 发送消息
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param body body core.SendXmlMsgRequest true "消息"
|
|
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
|
|
// @Router /api/v1/message/send/xml [post]
|
|
func (w *WebApi) sendXmlMsg(c *gin.Context) {
|
|
var form core.SendXmlMsgRequest
|
|
err := c.ShouldBindJSON(&form)
|
|
if err != nil {
|
|
utils.ResponseError(c, err.Error(), nil)
|
|
return
|
|
}
|
|
err = w.WxApi.SendXmlMsg(form)
|
|
if err != nil {
|
|
utils.ResponseError(c, err.Error(), nil)
|
|
return
|
|
}
|
|
utils.ResponseOK(c, "success", nil)
|
|
return
|
|
}
|
|
|
|
// sendForwardMsg
|
|
//
|
|
// @Summary 转发任意类型消息
|
|
// @Description 转发任意类型消息接口
|
|
// @Tags 发送消息
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param body body core.ForwardMsgRequest true "消息"
|
|
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
|
|
// @Router /api/v1/message/send/forward [post]
|
|
func (w *WebApi) sendForwardMsg(c *gin.Context) {
|
|
var form core.ForwardMsgRequest
|
|
err := c.ShouldBindJSON(&form)
|
|
if err != nil {
|
|
utils.ResponseError(c, err.Error(), nil)
|
|
return
|
|
}
|
|
err = w.WxApi.ForwardMsg(form)
|
|
if err != nil {
|
|
utils.ResponseError(c, err.Error(), nil)
|
|
return
|
|
}
|
|
utils.ResponseOK(c, "success", nil)
|
|
return
|
|
}
|
|
|
|
// registerMsgHttpCallBack
|
|
//
|
|
// @Summary 注册消息回调
|
|
// @Description 注册消息回调接口
|
|
// @Tags 发送消息
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param body body core.HttpCallBackRequest true "回调"
|
|
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
|
|
// @Router /api/v1/message/register_msg_http_callback [post]
|
|
func (w *WebApi) registerMsgHttpCallBack(c *gin.Context) {
|
|
var form core.HttpCallBackRequest
|
|
err := c.ShouldBindJSON(&form)
|
|
if err != nil {
|
|
utils.ResponseError(c, err.Error(), nil)
|
|
return
|
|
}
|
|
err = core.RegisterHttpCallback(form.Url, form.Timeout)
|
|
if err != nil {
|
|
utils.ResponseError(c, err.Error(), nil)
|
|
return
|
|
}
|
|
utils.ResponseOK(c, "success", nil)
|
|
return
|
|
}
|