tt/api/contact.go

421 lines
12 KiB
Go
Raw Permalink Normal View History

2024-05-28 08:47:31 +08:00
package api
import (
"github.com/gin-gonic/gin"
"github.com/goWxHook/goWxHook/core"
"github.com/goWxHook/goWxHook/utils"
)
// getFriendList
//
// @Summary 获取好友列表
// @Description 获取好友列表接口
// @Tags 联系人
// @Accept json
// @Produce json
// @Response 200 {object} CommonStringResponse{Data=[]core.GetFriendListResponseDateItem} "{\"code\":0, ....}
// @Router /api/v1/contact/friend/list [get]
func (w *WebApi) getFriendList(c *gin.Context) {
list, err := w.WxApi.GetFriendList()
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", list)
return
}
// getFriendInfo
//
// @Summary 获取单个好友信息
// @Description 获取单个好友信息接口
// @Tags 联系人
// @Accept json
// @Produce json
// @Param wxid path string true "微信ID"
// @Response 200 {object} CommonStringResponse{Data=core.GetFriendListResponseDateItem} "{\"code\":0, ....}
// @Router /api/v1/contact/friend/{wxid} [get]
func (w *WebApi) getFriendInfo(c *gin.Context) {
wxid := c.Param("wxid")
if len(wxid) == 0 {
utils.ResponseError(c, "wxid is required", nil)
return
}
info, err := w.WxApi.GetFriendInfo(wxid)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// getFriendBriefInfo
//
// @Summary 获取好友简要信息(协议)
// @Description 获取好友简要信息(协议)接口
// @Tags 联系人
// @Accept json
// @Produce json
// @Param wxid path string true "微信ID"
// @Response 200 {object} CommonStringResponse{Data=core.GetFriendBriefInfoByProtocolResponseData} "{\"code\":0, ....}
// @Router /api/v1/contact/friend/protocol/brief/{wxid} [get]
func (w *WebApi) getFriendBriefInfo(c *gin.Context) {
wxid := c.Param("wxid")
if len(wxid) == 0 {
utils.ResponseError(c, "wxid is required", nil)
return
}
info, err := w.WxApi.GetFriendBriefInfoByProtocol(wxid)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// getFriendDetailInfo
//
// @Summary 获取微信好友详细信息(协议)
// @Description 获取微信好友详细信息(协议)接口
// @Tags 联系人
// @Accept json
// @Produce json
// @Param wxid path string true "微信ID"
// @Response 200 {object} CommonStringResponse{Data=[]core.GetFriendDetailInfoByProtocolResponseDataContactListItem} "{\"code\":0, ....}
// @Router /api/v1/contact/friend/protocol/detail/{wxid} [get]
func (w *WebApi) getFriendDetailInfo(c *gin.Context) {
wxid := c.Param("wxid")
if len(wxid) == 0 {
utils.ResponseError(c, "wxid is required", nil)
return
}
info, err := w.WxApi.GetFriendDetailInfoByProtocol(wxid)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// batchGetFriendDetailInfo
//
// @Summary 批量获取好友详细信息(协议)
// @Description 批量获取好友详细信息(协议)接口
// @Tags 联系人
// @Accept json
// @Produce json
// @Param body body []string true "微信ID列表"
// @Response 200 {object} CommonStringResponse{Data=[]core.GetFriendDetailInfoByProtocolResponseDataContactListItem} "{\"code\":0, ....}
// @Router /api/v1/contact/friend/protocol/detail [post]
func (w *WebApi) batchGetFriendDetailInfo(c *gin.Context) {
var form []string
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
if len(form) == 0 {
utils.ResponseError(c, "wxids is required", nil)
return
}
info, err := w.WxApi.GetFriendDetailInfoListByProtocol(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// editFriendRemark
//
// @Summary 编辑好友备注
// @Description 编辑好友备注接口
// @Tags 联系人
// @Accept json
// @Produce json
// @Param body body core.EditFriendRemarkRequest true "好友备注信息"
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/contact/friend/remark [post]
func (w *WebApi) editFriendRemark(c *gin.Context) {
var form core.EditFriendRemarkRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
if len(form.Wxid) == 0 {
utils.ResponseError(c, "wxid is required", nil)
return
}
if len(form.Remark) == 0 {
utils.ResponseError(c, "remark is required", nil)
return
}
err = w.WxApi.EditFriendRemark(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// addFriend
//
// @Summary 通过群聊加好友-发送好友申请
// @Description 通过群聊加好友-发送好友申请接口
// @Tags 联系人
// @Accept json
// @Produce json
// @Param body body core.AddFriendRequest true "添加好友信息"
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/contact/friend/add [post]
func (w *WebApi) addFriend(c *gin.Context) {
var form core.AddFriendRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
if len(form.Wxid) == 0 {
utils.ResponseError(c, "wxid is required", nil)
return
}
err = w.WxApi.AddFriend(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// acceptFriend
//
// @Summary 通过好友申请
// @Description 通过好友申请接口
// @Tags 联系人
// @Accept json
// @Produce json
// @Param body body core.AcceptFriendRequest true "通过好友申请信息"
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/contact/friend/accept [post]
func (w *WebApi) acceptFriend(c *gin.Context) {
var form core.AcceptFriendRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
ret := w.WxApi.AcceptFriend(form)
if ret.Errcode != 0 {
utils.ResponseError(c, ret.Errmsg, nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// deleteFriend
//
// @Summary 删除好友
// @Description 删除好友接口
// @Tags 联系人
// @Accept json
// @Produce json
// @Param wxid path string true "微信ID"
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/contact/friend/delete/{wxid} [post]
func (w *WebApi) deleteFriend(c *gin.Context) {
wxid := c.Param("wxid")
if len(wxid) == 0 {
utils.ResponseError(c, "wxid is required", nil)
return
}
err := w.WxApi.DelFriend(wxid)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// searchWxUser
//
// @Summary 搜索微信用户
// @Description 搜索微信用户接口
// @Tags 联系人
// @Accept json
// @Produce json
// @Param keyword query string true "搜索字符串"
// @Response 200 {object} CommonStringResponse{Data=[]core.SearchWxUserResponseData} "{\"code\":0, ....}
// @Router /api/v1/contact/friend/search [get]
func (w *WebApi) searchWxUser(c *gin.Context) {
keyword := c.Query("keyword")
if len(keyword) == 0 {
utils.ResponseError(c, "keyword is required", nil)
return
}
info, err := w.WxApi.SearchWxUser(keyword)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// addSearchWxUser
//
// @Summary 添加搜索微信用户为好友
// @Description 添加搜索微信用户为好友接口
// @Tags 联系人
// @Accept json
// @Produce json
// @Param body body core.AddSearchWxUserRequest true "添加搜索微信用户为好友信息"
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/contact/friend/add/search [post]
func (w *WebApi) addSearchWxUser(c *gin.Context) {
var form core.AddSearchWxUserRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
ret := w.WxApi.AddSearchWxUser(form)
if ret.Errcode != 0 {
utils.ResponseError(c, ret.Errmsg, nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// checkFriend
//
// @Summary 检测好友状态(发送无痕清粉消息)
// @Description 检测好友状态(发送无痕清粉消息)接口
// @Tags 联系人
// @Accept json
// @Produce json
// @Param wxid path string true "微信ID"
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/contact/friend/check/{wxid} [post]
func (w *WebApi) checkFriend(c *gin.Context) {
wxid := c.Param("wxid")
if len(wxid) == 0 {
utils.ResponseError(c, "wxid is required", nil)
return
}
ret := w.WxApi.CheckFriendStatus(wxid)
if ret.Errcode != 0 {
utils.ResponseError(c, ret.Errmsg, nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// autoAcceptAddFriend
//
// @Summary 自动同意好友申请
// @Description 自动同意好友申请接口
// @Tags 联系人
// @Accept json
// @Produce json
// @Param body body core.AutoAcceptAddFriendRequest true "自动加好友"
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/contact/friend/add/auto [post]
func (w *WebApi) autoAcceptAddFriend(c *gin.Context) {
var form core.AutoAcceptAddFriendRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
err = w.WxApi.AutoAcceptAddFriend(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// autoAcceptCard
//
// @Summary 自动接收名片
// @Description 自动接收名片接口
// @Tags 联系人
// @Accept json
// @Produce json
// @Param body body core.AutoAcceptCardRequest true "自动接收名片"
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/contact/friend/card/auto [post]
func (w *WebApi) autoAcceptCard(c *gin.Context) {
var form core.AutoAcceptCardRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
err = w.WxApi.AutoAcceptCard(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// autoAcceptWCPay
//
// @Summary 自动接收好友转账
// @Description 自动接收好友转账接口
// @Tags 联系人
// @Accept json
// @Produce json
// @Param body body core.AutoAcceptWCPayRequest true "自动接收好友转账"
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/contact/accept/wc_pay/auto [post]
func (w *WebApi) autoAcceptWCPay(c *gin.Context) {
var form core.AutoAcceptWCPayRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
err = w.WxApi.AutoAcceptWCPay(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// getPublicUserList
//
// @Summary 获取公众号列表
// @Description 获取公众号列表接口
// @Tags 联系人
// @Accept json
// @Produce json
// @Response 200 {object} CommonStringResponse{Data=[]core.GetPublicUserListResponseData} "{\"code\":0, ....}
// @Router /api/v1/contact/public/list [get]
func (w *WebApi) getPublicUserList(c *gin.Context) {
list, err := w.WxApi.GetPublicUserList()
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", list)
return
}