封装一层API

This commit is contained in:
tt 2024-05-28 08:47:31 +08:00
commit 60bf7feede
59 changed files with 30095 additions and 0 deletions

8
.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
/bin/
.idea
test.go
test_init.exe
Helper_3.9.10.19.dll
HPSocket4C.dll
Loader_3.9.10.19.dll
callexe.exe

85
README.md Normal file
View File

@ -0,0 +1,85 @@
# 注意
仅支持windows x64
# 安装
> 私有仓库先配置ssh秘钥,或者你应该知道怎么get私有仓库的代码
> [教程](https://geek-docs.com/git/git-questions/974_git_whats_the_proper_way_to_go_get_a_private_repository.html)
> 当然git到本地也行
```
replace github.com/goWxHook/goWxHook => your path/goWxHook
```
```azure
go install github.com/swaggo/swag/cmd/swag@v1.16.3
swag init --parseInternal --parseDependency -g main.go
```
# 功能表
## core.WxApi
- [x] 获取好友列表消息
- > GetFriendLists
- [x] 获取公众号消息
- > GetPublicUserLIst
- [x] 获取群聊列表
- > GetChatRoomList
- [x] 获取群成员
- > GetRoomMember
- [x] 发送文本消息 (私聊/群聊/@)
- > SendTextMsg
- [x] 发送图片消息
- > SendImageMsg
- [x] 发送GIF消息
- > SendGifMsg
- [x] 发送文件消息
- > SendFileMsg
- [x] 发送视频消息
- > SendVideoMsg
- [x] 发送名片消息
- > SendCardMsg
- [x] 发送链接消息
- > SendLinkMsg
- [x] 加好友
- > AddFriend
- [x] 删除好友
- > DelFriend
- [x] 修改好友备注
- > EditFriendRemark
- [x] 自动同意好友申请
- > AutoAcceptAddFriend
- [x] 自动同意好友转帐
- > AutoAccpetWCPay
- [x] 自动进群邀请
- > AutoAccpetRoom
- [x] 自动加名片
- > AutoAccpetCard
- [x] 邀请好友进群消息
- > InviteToChatRoom
- [x] 删除群成员
- > DelChatRoomMember
- [x] 退出并删除群
- > DelChatRoom
- [x] 修改群名称
- > EditChatRoomName
- [x] 修改群通知
- > EditChatRoomNotice
- [x] 创建群聊
- > CreateChatRoom
- [x] 进入直播间
- > LiveEnter
- [x] 直播间发言
- > LiveSendMsg
- [x] 解密图片
- > DecryptImg
- [x] 置顶消息
- > ChatSessionTop
- [x] 免打扰消息
- > ChatMsgNotNotify
- [x] 修改显示群昵称
- > RoomShowNameMsg
- [x] 保存到联系人
- > SaveRoomSaveToContact
- [x] 修改群内昵称
- > EditRoomMemberNickName

442
api/cdn.go Normal file
View File

@ -0,0 +1,442 @@
package api
import (
"github.com/gin-gonic/gin"
"github.com/goWxHook/goWxHook/core"
"github.com/goWxHook/goWxHook/utils"
)
// cdnInitial
//
// @Summary CDN初始化
// @Description CDN初始化接口
// @Tags CDN
// @Accept json
// @Produce json
// @Response 200 {object} CommonStringResponse{Data=core.CDNInitialResponseData} "{\"code\":0, ....}
// @Router /api/v1/cdn/initial [post]
func (w *WebApi) cdnInitial(c *gin.Context) {
ret, err := w.WxApi.InitialCDN()
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", ret)
return
}
// cdnUpload
//
// @Summary CDN上传
// @Description CDN上传接口
// @Tags CDN
// @Accept json
// @Produce json
// @Param body body core.CDNUploadRequest true "上传数据"
// @Response 200 {object} CommonStringResponse{Data=core.CDNUploadResponseData} "{\"code\":0, ....}
// @Router /api/v1/cdn/upload [post]
func (w *WebApi) cdnUpload(c *gin.Context) {
var form core.CDNUploadRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
ret, err := w.WxApi.CDNUpload(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", ret)
return
}
// cdnDownload
//
// @Summary CDN下载
// @Description CDN下载接口
// @Tags CDN
// @Accept json
// @Produce json
// @Param body body core.CDNDownloadRequest true "下载数据"
// @Response 200 {object} CommonStringResponse{Data=core.CDNDownloadResponseData} "{\"code\":0, ....}
// @Router /api/v1/cdn/download [post]
func (w *WebApi) cdnDownload(c *gin.Context) {
var form core.CDNDownloadRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
ret, err := w.WxApi.CDNDownload(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", ret)
return
}
// cdnWorkWxDownload
//
// @Summary 企业微信CDN下载
// @Description 企业微信CDN下载接口
// @Tags CDN
// @Accept json
// @Produce json
// @Param body body core.WorkWxCdnDownloadRequest true "下载数据"
// @Response 200 {object} CommonStringResponse{Data=core.WorkWxCdnDownloadResponseData} "{\"code\":0, ....}
// @Router /api/v1/cdn/workwx/download [post]
func (w *WebApi) cdnWorkWxDownload(c *gin.Context) {
var form core.WorkWxCdnDownloadRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
ret, err := w.WxApi.WorkWxCdnDownload(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", ret)
return
}
// cdnSendTextMsg
//
// @Summary 发送文本消息
// @Description 发送文本消息接口
// @Tags CDN发送消息
// @Accept json
// @Produce json
// @Param body body core.CDNSendTextMsgRequest true "消息"
// @Response 200 {object} CommonStringResponse{Data=core.CDNSendTextMsgResponseData} "{\"code\":0, ....}
// @Router /api/v1/cdn/send/text [post]
func (w *WebApi) cdnSendTextMsg(c *gin.Context) {
var form core.CDNSendTextMsgRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
ret, err := w.WxApi.CDNSendTextMsg(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", ret)
return
}
// cdnSendImageMsg
//
// @Summary 发送图片消息
// @Description 发送图片消息接口
// @Tags CDN发送消息
// @Accept json
// @Produce json
// @Param body body core.CDNSendImageMsgRequest true "消息"
// @Response 200 {object} CommonStringResponse{Data=core.CDNSendImageMsgResponseData} "{\"code\":0, ....}
// @Router /api/v1/cdn/send/image [post]
func (w *WebApi) cdnSendImageMsg(c *gin.Context) {
var form core.CDNSendImageMsgRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
ret, err := w.WxApi.CDNSendImageMsg(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", ret)
return
}
// cdnSendVideoMsg
//
// @Summary 发送视频消息
// @Description 发送视频消息接口
// @Tags CDN发送消息
// @Accept json
// @Produce json
// @Param body body core.CDNSendVideoMsgRequest true "消息"
// @Response 200 {object} CommonStringResponse{Data=core.CDNSendVideoMsgResponseData} "{\"code\":0, ....}
// @Router /api/v1/cdn/send/video [post]
func (w *WebApi) cdnSendVideoMsg(c *gin.Context) {
var form core.CDNSendVideoMsgRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
ret, err := w.WxApi.CDNSendVideoMsg(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", ret)
return
}
// cdnSendFileMsg
//
// @Summary 发送文件消息
// @Description 发送文件消息接口
// @Tags CDN发送消息
// @Accept json
// @Produce json
// @Param body body core.CDNSendFileMsgRequest true "消息"
// @Response 200 {object} CommonStringResponse{Data=core.CDNSendFileMsgResponseData} "{\"code\":0, ....}
// @Router /api/v1/cdn/send/file [post]
func (w *WebApi) cdnSendFileMsg(c *gin.Context) {
var form core.CDNSendFileMsgRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
ret, err := w.WxApi.CDNSendFileMsg(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", ret)
return
}
// cdnSendCardLinkMsg
//
// @Summary 发送卡片链接消息
// @Description 发送卡片链接消息接口
// @Tags CDN发送消息
// @Accept json
// @Produce json
// @Param body body core.CDNSendCardLinkMsgRequest true "消息"
// @Response 200 {object} CommonStringResponse{Data=core.CDNSendCardLinkMsgResponseData} "{\"code\":0, ....}
// @Router /api/v1/cdn/send/card_link [post]
func (w *WebApi) cdnSendCardLinkMsg(c *gin.Context) {
var form core.CDNSendCardLinkMsgRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
ret, err := w.WxApi.CDNSendCardLinkMsg(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", ret)
return
}
// cdnSendGifMsg
//
// @Summary 发送GIF消息
// @Description 发送GIF消息接口
// @Tags CDN发送消息
// @Accept json
// @Produce json
// @Param body body core.CDNSendGifMsgRequest true "消息"
// @Response 200 {object} CommonStringResponse{Data=core.CDNSendGifMsgResponseData} "{\"code\":0, ....}
// @Router /api/v1/cdn/send/gif [post]
func (w *WebApi) cdnSendGifMsg(c *gin.Context) {
var form core.CDNSendGifMsgRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
ret, err := w.WxApi.CDNSendGifMsg(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", ret)
return
}
// cdnSendMiniProgramMsg
//
// @Summary 发送小程序消息
// @Description 发送小程序消息接口
// @Tags CDN发送消息
// @Accept json
// @Produce json
// @Param body body core.CDNSendMiniProgramMsgRequest true "消息"
// @Response 200 {object} CommonStringResponse{Data=core.CDNSendMiniProgramMsgResponseData} "{\"code\":0, ....}
// @Router /api/v1/cdn/send/mini_program [post]
func (w *WebApi) cdnSendMiniProgramMsg(c *gin.Context) {
var form core.CDNSendMiniProgramMsgRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
ret, err := w.WxApi.CDNSendMiniProgramMsg(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", ret)
return
}
// cdnSendVideoMomentMsg
//
// @Summary 发送视频号消息
// @Description 发送视频号消息接口
// @Tags CDN发送消息
// @Accept json
// @Produce json
// @Param body body core.CDNSendVideoMomentMsgRequest true "消息"
// @Response 200 {object} CommonStringResponse{Data=core.CDNSendVideoMomentMsgResponseData} "{\"code\":0, ....}
// @Router /api/v1/cdn/send/video_number [post]
func (w *WebApi) cdnSendVideoMomentMsg(c *gin.Context) {
var form core.CDNSendVideoMomentMsgRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
ret, err := w.WxApi.CDNSendVideoMomentMsg(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", ret)
return
}
// cdnSendCardMsg
//
// @Summary 发送名片消息
// @Description 发送名片消息接口
// @Tags CDN发送消息
// @Accept json
// @Produce json
// @Param body body core.CDNSendCardMsgRequest true "消息"
// @Response 200 {object} CommonStringResponse{Data=core.CDNSendCardMsgResponseData} "{\"code\":0, ....}
// @Router /api/v1/cdn/send/card [post]
func (w *WebApi) cdnSendCardMsg(c *gin.Context) {
var form core.CDNSendCardMsgRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
ret, err := w.WxApi.CDNSendCardMsg(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", ret)
return
}
// cdnSendLocationMsg
//
// @Summary 发送位置消息
// @Description 发送位置消息接口
// @Tags CDN发送消息
// @Accept json
// @Produce json
// @Param body body core.CDNSendLocationMsgRequest true "消息"
// @Response 200 {object} CommonStringResponse{Data=core.CDNSendLocationMsgResponseData} "{\"code\":0, ....}
// @Router /api/v1/cdn/send/location [post]
func (w *WebApi) cdnSendLocationMsg(c *gin.Context) {
var form core.CDNSendLocationMsgRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
ret, err := w.WxApi.CDNSendLocationMsg(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", ret)
return
}
// cdnSendRevokeMsg
//
// @Summary 发送撤回消息
// @Description 发送撤回消息接口
// @Tags CDN发送消息
// @Accept json
// @Produce json
// @Param body body core.CDNSendRevokeMsgRequest true "消息"
// @Response 200 {object} CommonStringResponse{Data=core.CDNSendRevokeMsgResponseData} "{\"code\":0, ....}
// @Router /api/v1/cdn/send/revoke [post]
func (w *WebApi) cdnSendRevokeMsg(c *gin.Context) {
var form core.CDNSendRevokeMsgRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
ret, err := w.WxApi.CDNSendRevokeMsg(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", ret)
return
}
// cdnSendXmkMsg
//
// @Summary 发送xml消息
// @Description 发送xml消息接口
// @Tags CDN发送消息
// @Accept json
// @Produce json
// @Param body body core.CDNSendXmlMsgRequest true "消息"
// @Response 200 {object} CommonStringResponse{Data=core.CDNSendXmlMsgResponseData} "{\"code\":0, ....}
// @Router /api/v1/cdn/send/xml [post]
func (w *WebApi) cdnSendXmkMsg(c *gin.Context) {
var form core.CDNSendXmlMsgRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
ret, err := w.WxApi.CDNSendXmlMsg(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", ret)
return
}
// cdnSendGifMsgNew
//
// @Summary 发送GIF消息
// @Description 发送GIF消息接口
// @Tags CDN发送消息
// @Accept json
// @Produce json
// @Param body body core.CDNSendGifMsgNewRequest true "消息"
// @Response 200 {object} CommonStringResponse{Data=core.CDNSendGifMsgNewResponseData} "{\"code\":0, ....}
// @Router /api/v1/cdn/send/gif_new [post]
func (w *WebApi) cdnSendGifMsgNew(c *gin.Context) {
var form core.CDNSendGifMsgNewRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
ret, err := w.WxApi.CDNSendGifMsgNew(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", ret)
return
}

78
api/collect.go Normal file
View File

@ -0,0 +1,78 @@
package api
import (
"github.com/gin-gonic/gin"
"github.com/goWxHook/goWxHook/core"
"github.com/goWxHook/goWxHook/utils"
)
// getCollectList
//
// @Summary 获取收藏列表
// @Description 获取收藏列表接口
// @Tags 收藏
// @Accept json
// @Produce json
// @Response 200 {object} CommonStringResponse{Data=core.GetCollectListResponseData} "{\"code\":0, ....}
// @Router /api/v1/collect/list [get]
func (w *WebApi) getCollectList(c *gin.Context) {
list, err := w.WxApi.GetCollectList()
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", list)
return
}
// sendCollect
//
// @Summary 发送收藏(旧)
// @Description 发送收藏(旧)接口
// @Tags 收藏
// @Accept json
// @Produce json
// @Param body body core.SendCollectRequest true "收藏信息"
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/collect/send [post]
func (w *WebApi) sendCollect(c *gin.Context) {
var form core.SendCollectRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
err = w.WxApi.SendCollect(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// sendCollectMsgByMsgId
//
// @Summary 收藏指定消息(旧)
// @Description 收藏指定消息(旧)接口
// @Tags 收藏
// @Accept json
// @Produce json
// @Param body body core.SendCollectMsgByMsgIdRequest true "消息"
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/collect/send/msgid [post]
func (w *WebApi) sendCollectMsgByMsgId(c *gin.Context) {
var form core.SendCollectMsgByMsgIdRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
err = w.WxApi.SendCollectMsgByMsgId(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}

420
api/contact.go Normal file
View File

@ -0,0 +1,420 @@
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
}

7
api/doc.go Normal file
View File

@ -0,0 +1,7 @@
package api
type CommonStringResponse struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data string `json:"data"`
}

130
api/live.go Normal file
View File

@ -0,0 +1,130 @@
package api
import (
"github.com/gin-gonic/gin"
"github.com/goWxHook/goWxHook/core"
"github.com/goWxHook/goWxHook/utils"
)
// liveEnter
//
// @Summary 进入直播间
// @Description 进入直播间接口
// @Tags 直播
// @Accept json
// @Produce json
// @Param body body core.LiveEnterRequest true "直播间信息"
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/live/enter [post]
func (w *WebApi) liveEnter(c *gin.Context) {
var form core.LiveEnterRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
err = w.WxApi.LiveEnter(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// liveGetOnlineUser
//
// @Summary 获取直播间在线用户
// @Description 获取直播间在线用户接口
// @Tags 直播
// @Accept json
// @Produce json
// @Param body body core.LiveGetOnlineUserRequest true "直播间信息"
// @Response 200 {object} CommonStringResponse{Data=interface{}} "{\"code\":0, ....}
// @Router /api/v1/live/get/online/user [post]
func (w *WebApi) liveGetOnlineUser(c *gin.Context) {
var form core.LiveGetOnlineUserRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
info, err := w.WxApi.LiveGetOnlineUser(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// liveGetChangeInfo
//
// @Summary 获取直播间变动信息(人气,实时发言等))
// @Description 获取直播间变动信息(人气,实时发言等))接口
// @Tags 直播
// @Accept json
// @Produce json
// @Response 200 {object} CommonStringResponse{Data=interface{}} "{\"code\":0, ....}
// @Router /api/v1/live/get/change/info [post]
func (w *WebApi) liveGetChangeInfo(c *gin.Context) {
info, err := w.WxApi.LiveGetChangeInfo()
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// liveSendMsg
//
// @Summary 发送直播间消息
// @Description 发送直播间消息接口
// @Tags 直播
// @Accept json
// @Produce json
// @Param body body core.LiveSendMsgRequest true "直播间信息"
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/live/send/msg [post]
func (w *WebApi) liveSendMsg(c *gin.Context) {
var form core.LiveSendMsgRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
err = w.WxApi.LiveSendMsg(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// liveGetShelf
//
// @Summary 获取直播间货架
// @Description 获取直播间货架接口
// @Tags 直播
// @Accept json
// @Produce json
// @Param body body core.LiveGetShelfRequest true "直播间信息"
// @Response 200 {object} CommonStringResponse{Data=interface{}} "{\"code\":0, ....}
// @Router /api/v1/live/get/shelf [post]
func (w *WebApi) liveGetShelf(c *gin.Context) {
var form core.LiveGetShelfRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
info, err := w.WxApi.LiveGetShelf(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}

101
api/login.go Normal file
View File

@ -0,0 +1,101 @@
package api
import (
"github.com/gin-gonic/gin"
"github.com/goWxHook/goWxHook/utils"
)
// getWxVersion
//
// @Summary 获取微信版本
// @Description 获取微信版本号接口
// @Tags 登录
// @Accept json
// @Produce json
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/login/version [get]
func (w *WebApi) getWxVersion(c *gin.Context) {
version, err := w.WxApi.GetUserWeChatVersion()
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", version)
return
}
// getLoginUserInfo
//
// @Summary 获取登录用户信息
// @Description 获取登录用户信息接口
// @Tags 登录
// @Accept json
// @Produce json
// @Response 200 {object} CommonStringResponse{Data=core.GetLoginUserInfoResponseData} "{\"code\":0, ....}
// @Router /api/v1/login/userinfo [get]
func (w *WebApi) getLoginUserInfo(c *gin.Context) {
info, err := w.WxApi.GetLoginUserInfo()
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// refreshLoginQrCode
//
// @Summary 刷新登录二维码
// @Description 刷新登录二维码接口
// @Tags 登录
// @Accept json
// @Produce json
// @Response 200 {object} CommonStringResponse{Data=core.RefreshLoginQrCodeResponseData} "{\"code\":0, ....}
// @Router /api/v1/login/qrcode/refresh [post]
func (w *WebApi) refreshLoginQrCode(c *gin.Context) {
info, err := w.WxApi.RefreshLoginQrCode()
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// wxLogout
//
// @Summary 注销微信登录
// @Description 注销微信登录接口
// @Tags 登录
// @Accept json
// @Produce json
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/login/logout [post]
func (w *WebApi) wxLogout(c *gin.Context) {
err := w.WxApi.WxUserLogout()
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// wxExit
//
// @Summary 退出微信
// @Description 退出微信接口
// @Tags 登录
// @Accept json
// @Produce json
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/login/exit [post]
func (w *WebApi) wxExit(c *gin.Context) {
err := w.WxApi.WxExit()
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}

267
api/message.go Normal file
View File

@ -0,0 +1,267 @@
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
}

163
api/moment.go Normal file
View File

@ -0,0 +1,163 @@
package api
import (
"github.com/gin-gonic/gin"
"github.com/goWxHook/goWxHook/core"
"github.com/goWxHook/goWxHook/utils"
)
// getMoment
//
// @Summary 获取朋友圈
// @Description 获取朋友圈接口
// @Tags 朋友圈
// @Accept json
// @Produce json
// @Param body body core.GetMomentRequest true "朋友圈信息"
// @Response 200 {object} CommonStringResponse{Data=core.GetMomentResponseData} "{\"code\":0, ....}
// @Router /api/v1/moment/list [post]
func (w *WebApi) getMoment(c *gin.Context) {
var form core.GetMomentRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
info, err := w.WxApi.GetMoment(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// commentMoment
//
// @Summary 评论朋友圈
// @Description 评论朋友圈接口
// @Tags 朋友圈
// @Accept json
// @Produce json
// @Param body body core.CommentMomentRequest true "评论信息"
// @Response 200 {object} CommonStringResponse{Data=core.CommentMomentResponseData} "{\"code\":0, ....}
// @Router /api/v1/moment/comment [post]
func (w *WebApi) commentMoment(c *gin.Context) {
var form core.CommentMomentRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
info, err := w.WxApi.CommentMoment(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// likeMoment
//
// @Summary 点赞朋友圈
// @Description 点赞朋友圈接口
// @Tags 朋友圈
// @Accept json
// @Produce json
// @Param body body core.LikeMomentRequest true "点赞信息"
// @Response 200 {object} CommonStringResponse{Data=core.LikeMomentResponseData} "{\"code\":0, ....}
// @Router /api/v1/moment/like [post]
func (w *WebApi) likeMoment(c *gin.Context) {
var form core.LikeMomentRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
info, err := w.WxApi.LikeMoment(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// sendMoment
//
// @Summary 发送朋友圈
// @Description 发送朋友圈接口
// @Tags 朋友圈
// @Accept json
// @Produce json
// @Param body body core.SendMomentRequest true "发送信息"
// @Response 200 {object} CommonStringResponse{Data=core.SendMomentResponseData} "{\"code\":0, ....}
// @Router /api/v1/moment/send [post]
func (w *WebApi) sendMoment(c *gin.Context) {
var form core.SendMomentRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
info, err := w.WxApi.SendMoment(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// uploadMomentImage
//
// @Summary 上传朋友圈图片
// @Description 上传朋友圈图片接口
// @Tags 朋友圈
// @Accept json
// @Produce json
// @Param body body core.UploadMomentImageRequest true "上传图片信息"
// @Response 200 {object} CommonStringResponse{Data=core.UploadMomentImageResponseData} "{\"code\":0, ....}
// @Router /api/v1/moment/upload/image [post]
func (w *WebApi) uploadMomentImage(c *gin.Context) {
var form core.UploadMomentImageRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
info, err := w.WxApi.UploadMomentImage(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// getFriendMoment
//
// @Summary 获取好友朋友圈
// @Description 获取好友朋友圈接口
// @Tags 朋友圈
// @Accept json
// @Produce json
// @Param body body core.GetFriendMomentRequest true "好友朋友圈信息"
// @Response 200 {object} CommonStringResponse{Data=core.GetFriendMomentResponseData} "{\"code\":0, ....}
// @Router /api/v1/moment/friend/list [post]
func (w *WebApi) getFriendMoment(c *gin.Context) {
var form core.GetFriendMomentRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
info, err := w.WxApi.GetFriendMoment(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}

33
api/mp.go Normal file
View File

@ -0,0 +1,33 @@
package api
import (
"github.com/gin-gonic/gin"
"github.com/goWxHook/goWxHook/core"
"github.com/goWxHook/goWxHook/utils"
)
// getMiniProgramCode
//
// @Summary 获取小程序授权Code
// @Description 获取小程序授权Code接口
// @Tags 小程序
// @Accept json
// @Produce json
// @Param body body core.GetMiniProgramCodeRequest true "小程序信息"
// @Response 200 {object} CommonStringResponse{Data=core.GetMiniProgramCodeResponseData} "{\"code\":0, ....}
// @Router /api/v1/mini/program/code [post]
func (w *WebApi) getMiniProgramCode(c *gin.Context) {
var form core.GetMiniProgramCodeRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
info, err := w.WxApi.GetMiniProgramCode(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}

59
api/other.go Normal file
View File

@ -0,0 +1,59 @@
package api
import (
"github.com/gin-gonic/gin"
"github.com/goWxHook/goWxHook/core"
"github.com/goWxHook/goWxHook/utils"
)
// getA8Key
//
// @Summary 获取A8Key
// @Description 获取A8Key接口
// @Tags 其他
// @Accept json
// @Produce json
// @Param body body core.GetA8KeyRequest true "A8Key请求"
// @Response 200 {object} CommonStringResponse{Data=core.GetA8KeyResponseData} "{\"code\":0, ....}
// @Router /api/v1/other/get_a8_key [post]
func (w *WebApi) getA8Key(c *gin.Context) {
var form core.GetA8KeyRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
info, err := w.WxApi.GetA8Key(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// decryptImg
//
// @Summary 解密图片
// @Description 解密图片接口
// @Tags 其他
// @Accept json
// @Produce json
// @Param body body core.DecryptImgRequest true "解密图片请求"
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/other/decrypt_img [post]
func (w *WebApi) decryptImg(c *gin.Context) {
var form core.DecryptImgRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
err = w.WxApi.DecryptImg(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}

458
api/room.go Normal file
View File

@ -0,0 +1,458 @@
package api
import (
"github.com/gin-gonic/gin"
"github.com/goWxHook/goWxHook/core"
"github.com/goWxHook/goWxHook/utils"
)
// getRoomList
//
// @Summary 获取群列表
// @Description 获取群列表接口
// @Tags 群管理
// @Accept json
// @Produce json
// @Response 200 {object} CommonStringResponse{Data=[]core.GetChatRoomListResponseDataItem} "{\"code\":0, ....}
// @Router /api/v1/contact/room/list [get]
func (w *WebApi) getRoomList(c *gin.Context) {
list, err := w.WxApi.GetChatRoomList()
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", list)
return
}
// getRoomMemberList
//
// @Summary 获取群成员列表
// @Description 获取群成员列表接口
// @Tags 群管理
// @Accept json
// @Produce json
// @Param roomWxid path string true "微信群ID"
// @Response 200 {object} CommonStringResponse{Data=core.GetChatRoomMemberListResponseData} "{\"code\":0, ....}
// @Router /api/v1/contact/room/member/list/{roomWxid} [get]
func (w *WebApi) getRoomMemberList(c *gin.Context) {
roomWxid := c.Param("roomWxid")
if len(roomWxid) == 0 {
utils.ResponseError(c, "roomWxid is required", nil)
return
}
list, err := w.WxApi.GetChatRoomMemberList(roomWxid)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", list)
return
}
// getRoomDetailInfo
//
// @Summary 获取微信群详细信息(协议)
// @Description 获取微信群详细信息(协议)接口
// @Tags 群管理
// @Accept json
// @Produce json
// @Param roomWxid path string true "微信群ID"
// @Response 200 {object} CommonStringResponse{Data=[]core.GetFriendDetailInfoByProtocolResponseDataContactListItem} "{\"code\":0, ....}
// @Router /api/v1/contact/room/protocol/detail/{roomWxid} [get]
func (w *WebApi) getRoomDetailInfo(c *gin.Context) {
roomWxid := c.Param("roomWxid")
if len(roomWxid) == 0 {
utils.ResponseError(c, "roomWxid is required", nil)
return
}
info, err := w.WxApi.GetRoomDetailInfoByProtocol(roomWxid)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// getRoomInviteRelationList
//
// @Summary 获取群成员邀请关系(协议)
// @Description 获取群成员邀请关系(协议)接口
// @Tags 群管理
// @Accept json
// @Produce json
// @Param roomWxid path string true "微信群ID"
// @Response 200 {object} CommonStringResponse{Data=core.GetRoomMemberInviteListResponseData} "{\"code\":0, ....}
// @Router /api/v1/contact/room/protocol/invite/list/{roomWxid} [get]
func (w *WebApi) getRoomInviteRelationList(c *gin.Context) {
roomWxid := c.Param("roomWxid")
if len(roomWxid) == 0 {
utils.ResponseError(c, "roomWxid is required", nil)
return
}
info, err := w.WxApi.GetRoomMemberInviteList(roomWxid)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// createRoom
//
// @Summary 创建群聊
// @Description 创建群聊接口
// @Tags 群管理
// @Accept json
// @Produce json
// @Param body body core.CreateRoomRequest true "微信ID列表"
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/contact/room/create [post]
func (w *WebApi) createRoom(c *gin.Context) {
var form core.CreateRoomRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
if len(form.Wxids) == 0 {
utils.ResponseError(c, "wxids is required", nil)
return
}
err = w.WxApi.CreateChatRoom(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// createRoomByProtocol
//
// @Summary 创建群聊(协议)
// @Description 创建群聊(协议)接口
// @Tags 群管理
// @Accept json
// @Produce json
// @Param body body core.CreateRoomRequest true "微信ID列表"
// @Response 200 {object} CommonStringResponse{Data=core.CreateChatRoomByProtocolResponseData} "{\"code\":0, ....}
// @Router /api/v1/contact/room/protocol/create [post]
func (w *WebApi) createRoomByProtocol(c *gin.Context) {
var form core.CreateRoomRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
if len(form.Wxids) == 0 {
utils.ResponseError(c, "wxids is required", nil)
return
}
info, err := w.WxApi.CreateChatRoomByProtocol(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// inviteToRoom
//
// @Summary 邀请好友进群
// @Description 邀请好友进群接口
// @Tags 群管理
// @Accept json
// @Produce json
// @Param body body core.InviteToRoomRequest true "邀请信息"
// @Response 200 {object} CommonStringResponse{Data=core.InviteToRoomResponseData} "{\"code\":0, ....}
// @Router /api/v1/contact/room/member/invite [post]
func (w *WebApi) inviteToRoom(c *gin.Context) {
var form core.InviteToRoomRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
if len(form.MemberList) == 0 {
utils.ResponseError(c, "member_list is required", nil)
return
}
info, err := w.WxApi.InviteToRoom(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// deleteRoomMember
//
// @Summary 踢除群成员
// @Description 踢除群成员接口
// @Tags 群管理
// @Accept json
// @Produce json
// @Param body body core.DelChatRoomMemberRequest true "成员信息"
// @Response 200 {object} CommonStringResponse{} "{\"code\":0, ....}
// @Router /api/v1/contact/room/member/delete [post]
func (w *WebApi) deleteRoomMember(c *gin.Context) {
var form core.DelChatRoomMemberRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
if len(form.MemberList) == 0 {
utils.ResponseError(c, "member_list is required", nil)
return
}
err = w.WxApi.DelChatRoomMember(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// editRoomName
//
// @Summary 修改群聊名称
// @Description 修改群聊名称接口
// @Tags 群管理
// @Accept json
// @Produce json
// @Param body body core.EditChatRoomMemberRequest true "成员信息"
// @Response 200 {object} CommonStringResponse{} "{\"code\":0, ....}
// @Router /api/v1/contact/room/name/modify [post]
func (w *WebApi) editRoomName(c *gin.Context) {
var form core.EditChatRoomMemberRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
if len(form.RoomWxid) == 0 {
utils.ResponseError(c, "room_wxid is required", nil)
return
}
err = w.WxApi.EditChatRoomName(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// editRoomNotice
//
// @Summary 修改群公告
// @Description 修改群公告接口
// @Tags 群管理
// @Accept json
// @Produce json
// @Param body body core.EditChatRoomNoticeRequest true "公告信息"
// @Response 200 {object} CommonStringResponse{} "{\"code\":0, ....}
// @Router /api/v1/contact/room/notice/modify [post]
func (w *WebApi) editRoomNotice(c *gin.Context) {
var form core.EditChatRoomNoticeRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
if len(form.RoomWxid) == 0 {
utils.ResponseError(c, "room_wxid is required", nil)
return
}
err = w.WxApi.EditChatRoomNotice(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// editRoomMineNickName
//
// @Summary 修改我在本群的昵称
// @Description 修改我在本群的昵称接口
// @Tags 群管理
// @Accept json
// @Produce json
// @Param body body core.EditRoomMineNickNameRequest true "昵称信息"
// @Response 200 {object} CommonStringResponse{} "{\"code\":0, ....}
// @Router /api/v1/contact/room/mine/nickname/modify [post]
func (w *WebApi) editRoomMineNickName(c *gin.Context) {
var form core.EditRoomMineNickNameRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
if len(form.RoomWxid) == 0 {
utils.ResponseError(c, "room_wxid is required", nil)
return
}
err = w.WxApi.EditRoomMineNickName(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// showRoomNickName
//
// @Summary 是否显示群成员昵称
// @Description 是否显示群成员昵称接口
// @Tags 群管理
// @Accept json
// @Produce json
// @Param body body core.RoomShowNickNameRequest true "昵称信息"
// @Response 200 {object} CommonStringResponse{} "{\"code\":0, ....}
// @Router /api/v1/contact/room/member/nickname/show [post]
func (w *WebApi) showRoomNickName(c *gin.Context) {
var form core.RoomShowNickNameRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
if len(form.RoomWxid) == 0 {
utils.ResponseError(c, "room_wxid is required", nil)
return
}
err = w.WxApi.RoomShowNickName(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// roomSaveToContact
//
// @Summary 保存到/移出通讯录
// @Description 保存到/移出通讯录接口
// @Tags 群管理
// @Accept json
// @Produce json
// @Param body body core.SaveRoomSaveToContactRequest true "昵称信息"
// @Response 200 {object} CommonStringResponse{} "{\"code\":0, ....}
// @Router /api/v1/contact/room/to_contact/save [post]
func (w *WebApi) roomSaveToContact(c *gin.Context) {
var form core.SaveRoomSaveToContactRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
if len(form.RoomWxid) == 0 {
utils.ResponseError(c, "room_wxid is required", nil)
return
}
err = w.WxApi.SaveRoomSaveToContact(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// addRoomMemberToFriend
//
// @Summary 添加群成员为好友
// @Description 添加群成员为好友接口
// @Tags 群管理
// @Accept json
// @Produce json
// @Param body body core.AddFriendRequest true "添加好友信息"
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/contact/room/friend/add [post]
func (w *WebApi) addRoomMemberToFriend(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
}
// deleteRoom
//
// @Summary 退出群聊
// @Description 退出群聊接口
// @Tags 群管理
// @Accept json
// @Produce json
// @Param body body core.DelChatRoomRequest true "推出的群聊"
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/contact/room/delete [post]
func (w *WebApi) deleteRoom(c *gin.Context) {
var form core.DelChatRoomRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
if len(form.RoomWxid) == 0 {
utils.ResponseError(c, "room_wxid is required", nil)
return
}
err = w.WxApi.DelChatRoom(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// autoAcceptRoom
//
// @Summary 自动接受群邀请
// @Description 自动接受群邀请接口
// @Tags 群管理
// @Accept json
// @Produce json
// @Param body body core.AutoAcceptRoomRequest true "自动接受群邀请"
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/contact/room/accept/auto [post]
func (w *WebApi) autoAcceptRoom(c *gin.Context) {
var form core.AutoAcceptRoomRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
err = w.WxApi.AutoAcceptRoom(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}

169
api/router.go Normal file
View File

@ -0,0 +1,169 @@
package api
import (
"fmt"
"github.com/gin-contrib/pprof"
"github.com/gin-gonic/gin"
"github.com/goWxHook/goWxHook/core"
"github.com/goWxHook/goWxHook/docs"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
"log/slog"
)
type WebApi struct {
WxApi *core.WxApi
Port int
}
func NewWebApi(wxApi *core.WxApi, port int) *WebApi {
return &WebApi{
WxApi: wxApi,
Port: port,
}
}
func (w *WebApi) StartWebApi() error {
gin.SetMode(gin.ReleaseMode)
app := gin.New()
app.Use(gin.Recovery())
api := app.Group("/api")
v1 := api.Group("/v1")
// swagger doc
docs.SwaggerInfo.Host = fmt.Sprintf("127.0.0.1:%d", w.Port)
docs.SwaggerInfo.Schemes = []string{"http"}
url := ginSwagger.URL("/api/swagger/doc.json")
app.GET("/api/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, url))
pprof.Register(app, "/api/v1/debug/pprof")
// 登录接口
v1.GET("/login/version", w.getWxVersion)
v1.GET("/login/userinfo", w.getLoginUserInfo)
v1.POST("/login/qrcode/refresh", w.refreshLoginQrCode)
v1.POST("/login/logout", w.wxLogout)
v1.POST("/login/exit", w.wxExit)
// 联系人接口
v1.GET("/contact/friend/list", w.getFriendList)
v1.GET("/contact/friend/:wxid", w.getFriendInfo)
v1.GET("/contact/friend/protocol/brief/:wxid", w.getFriendBriefInfo)
v1.GET("/contact/friend/protocol/detail/:wxid", w.getFriendDetailInfo)
v1.POST("/contact/friend/protocol/detail", w.batchGetFriendDetailInfo)
v1.POST("/contact/friend/remark", w.editFriendRemark)
v1.POST("/contact/friend/add", w.addFriend)
v1.POST("/contact/friend/accept", w.acceptFriend)
v1.POST("/contact/friend/delete/:wxid", w.deleteFriend)
v1.GET("/contact/friend/search", w.searchWxUser)
v1.POST("/contact/friend/add/search", w.addSearchWxUser)
v1.POST("/contact/friend/check/:wxid", w.checkFriend)
v1.POST("/contact/friend/add/auto", w.autoAcceptAddFriend)
v1.POST("/contact/friend/card/auto", w.autoAcceptCard)
v1.POST("/contact/accept/wc_pay/auto", w.autoAcceptWCPay)
v1.POST("/contact/public/list", w.getPublicUserList)
v1.GET("/contact/room/list", w.getRoomList)
v1.GET("/contact/room/member/list/:roomWxid", w.getRoomMemberList)
v1.GET("/contact/room/protocol/detail/:roomWxid", w.getRoomDetailInfo)
v1.GET("/contact/room/protocol/invite/list/:roomWxid", w.getRoomInviteRelationList)
v1.POST("/contact/room/create", w.createRoom)
v1.POST("/contact/room/protocol/create", w.createRoomByProtocol)
v1.POST("/contact/room/member/invite", w.inviteToRoom)
v1.POST("/contact/room/member/delete", w.deleteRoomMember)
v1.POST("/contact/room/name/modify", w.editRoomName)
v1.POST("/contact/room/notice/modify", w.editRoomNotice)
v1.POST("/contact/room/mine/nickname/modify", w.editRoomMineNickName)
v1.POST("/contact/room/member/nickname/show", w.showRoomNickName)
v1.POST("/contact/room/to_contact/save", w.roomSaveToContact)
v1.POST("/contact/room/friend/add", w.addRoomMemberToFriend)
v1.POST("/contact/room/delete/:roomWxid", w.deleteRoom)
v1.POST("/contact/room/accept/auto", w.autoAcceptRoom)
v1.POST("/message/send/text", w.sendTextMsg)
v1.POST("/message/send/card", w.sendCardMsg)
v1.POST("/message/send/link", w.sendLinkMsg)
v1.POST("/message/send/image", w.sendImageMsg)
v1.POST("/message/send/file", w.sendFileMsg)
v1.POST("/message/send/video", w.sendVideoMsg)
v1.POST("/message/send/gif", w.sendGifMsg)
v1.POST("/message/send/xml", w.sendXmlMsg)
v1.POST("/message/send/forward", w.sendForwardMsg)
v1.POST("/message/register_msg_http_callback", w.registerMsgHttpCallBack)
v1.POST("/cdn/initial", w.cdnInitial)
v1.POST("/cdn/upload", w.cdnUpload)
v1.POST("/cdn/download", w.cdnDownload)
v1.POST("/cdn/workwx/download", w.cdnWorkWxDownload)
v1.POST("/cdn/send/text", w.cdnSendTextMsg)
v1.POST("/cdn/send/image", w.cdnSendImageMsg)
v1.POST("/cdn/send/video", w.cdnSendVideoMsg)
v1.POST("/cdn/send/file", w.cdnSendFileMsg)
v1.POST("/cdn/send/card_link", w.cdnSendCardLinkMsg)
v1.POST("/cdn/send/gif", w.cdnSendGifMsg)
v1.POST("/cdn/send/mini_program", w.cdnSendMiniProgramMsg)
v1.POST("/cdn/send/video_number", w.cdnSendVideoMomentMsg)
v1.POST("/cdn/send/card", w.cdnSendCardMsg)
v1.POST("/cdn/send/location", w.cdnSendLocationMsg)
v1.POST("/cdn/send/revoke", w.cdnSendRevokeMsg)
v1.POST("/cdn/send/xml", w.cdnSendXmkMsg)
v1.POST("/cdn/send/gif_new", w.cdnSendGifMsgNew)
v1.GET("/workwx/user/list", w.getWorkWxUserList)
v1.GET("/workwx/room/list", w.getWorkWxRoomList)
v1.POST("/workwx/room/member/list", w.getWorkWxRoomMemberList)
v1.GET("/collect/list", w.getCollectList)
v1.POST("/collect/send", w.sendCollect)
v1.POST("/collect/send/msgid", w.sendCollectMsgByMsgId)
v1.GET("/tag/list", w.getTagList)
v1.POST("/tag/add", w.addTag)
v1.POST("/tag/delete", w.deleteTag)
v1.POST("/tag/modify", w.modifyTag)
v1.POST("/tag/add/user", w.addTagToUser)
v1.POST("/tag/list/user", w.getTagListByWxid)
v1.POST("/voice/to/text", w.voiceToText)
v1.POST("/mini/program/code", w.getMiniProgramCode)
v1.POST("/ui/switch/session", w.switchSession)
v1.POST("/ui/clear/chat/record", w.clearChatRecord)
v1.POST("/ui/chat/msg/not/notify", w.chatMsgNotNotify)
v1.POST("/ui/chat/session/top", w.chatSessionTop)
v1.POST("/moment/list", w.getMoment)
v1.POST("/moment/comment", w.commentMoment)
v1.POST("/moment/like", w.likeMoment)
v1.POST("/moment/send", w.sendMoment)
v1.POST("/moment/upload/image", w.uploadMomentImage)
v1.POST("/moment/friend/list", w.getFriendMoment)
v1.POST("/video_moment/init", w.videoMomentInit)
v1.POST("/video_moment/search", w.videoMomentSearch)
v1.POST("/video_moment/user/home", w.videoMomentUserHome)
v1.POST("/video_moment/video/detail", w.videoMomentVideoDetail)
v1.POST("/video_moment/follow", w.videoMomentFollow)
v1.POST("/video_moment/like", w.videoMomentLike)
v1.POST("/video_moment/get/session_id", w.videoMomentGetSessionId)
v1.POST("/video_moment/send/msg", w.videoMomentSendMsg)
v1.POST("/video_moment/create/virtual_nickname", w.videoMomentCreateVirtualNickName)
v1.POST("/video_moment/switch/virtual_nickname", w.videoMomentSwitchVirtualNickName)
v1.POST("/video_moment/delete/virtual_nickname", w.videoMomentDeleteVirtualNickName)
v1.POST("/live/enter", w.liveEnter)
v1.POST("/live/get/online/user", w.liveGetOnlineUser)
v1.POST("/live/get/change/info", w.liveGetChangeInfo)
v1.POST("/live/send/msg", w.liveSendMsg)
v1.POST("/live/get/shelf", w.liveGetShelf)
v1.POST("/other/get_a8_key", w.getA8Key)
v1.POST("/other/decrypt_img", w.decryptImg)
// 启动一个API服务
slog.Info("启动服务WEB服务", "API监听", fmt.Sprintf("http://127.0.0.1:%d", w.Port),
"接口文档", fmt.Sprintf("http://127.0.0.1:%d%s", w.Port, "/api/swagger/index.html"))
return app.Run(fmt.Sprintf(":%d", w.Port))
}

156
api/tag.go Normal file
View File

@ -0,0 +1,156 @@
package api
import (
"github.com/gin-gonic/gin"
"github.com/goWxHook/goWxHook/core"
"github.com/goWxHook/goWxHook/utils"
)
// getTagList
//
// @Summary 获取标签列表
// @Description 获取标签列表接口
// @Tags 标签
// @Accept json
// @Produce json
// @Response 200 {object} CommonStringResponse{Data=[]core.GetTagListResponseDataItem} "{\"code\":0, ....}
// @Router /api/v1/tag/list [get]
func (w *WebApi) getTagList(c *gin.Context) {
list, err := w.WxApi.GetTagList()
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", list)
return
}
// addTag
//
// @Summary 添加标签
// @Description 添加标签接口
// @Tags 标签
// @Accept json
// @Produce json
// @Param body body core.AddTagRequest true "标签信息"
// @Response 200 {object} CommonStringResponse{Data=core.AddTagResponseData} "{\"code\":0, ....}
// @Router /api/v1/tag/add [post]
func (w *WebApi) addTag(c *gin.Context) {
var form core.AddTagRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
info, err := w.WxApi.AddTag(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// deleteTag
//
// @Summary 删除标签
// @Description 删除标签接口
// @Tags 标签
// @Accept json
// @Produce json
// @Param body body core.DeleteTagRequest true "标签信息"
// @Response 200 {object} CommonStringResponse{Data=core.DeleteTagResponseData} "{\"code\":0, ....}
// @Router /api/v1/tag/delete [post]
func (w *WebApi) deleteTag(c *gin.Context) {
var form core.DeleteTagRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
info, err := w.WxApi.DeleteTag(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// modifyTag
//
// @Summary 修改标签
// @Description 修改标签接口
// @Tags 标签
// @Accept json
// @Produce json
// @Param body body core.ModifyTagRequest true "标签信息"
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/tag/modify [post]
func (w *WebApi) modifyTag(c *gin.Context) {
var form core.ModifyTagRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
err = w.WxApi.ModifyTag(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// addTagToUser
//
// @Summary 为用户添加标签
// @Description 为用户添加标签接口
// @Tags 标签
// @Accept json
// @Produce json
// @Param body body core.AddTagToUserRequest true "标签信息"
// @Response 200 {object} CommonStringResponse{Data=core.AddTagToUserResponseData} "{\"code\":0, ....}
// @Router /api/v1/tag/add/user [post]
func (w *WebApi) addTagToUser(c *gin.Context) {
var form core.AddTagToUserRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
ret, err := w.WxApi.AddTagToUser(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", ret)
return
}
// getTagListByWxid
//
// @Summary 获取用户标签列表
// @Description 获取用户标签列表接口
// @Tags 标签
// @Accept json
// @Produce json
// @Param body body core.GetTagListByWxidRequest true "标签信息"
// @Response 200 {object} CommonStringResponse{Data=core.GetTagListByWxidResponseData} "{\"code\":0, ....}
// @Router /api/v1/tag/list/user [post]
func (w *WebApi) getTagListByWxid(c *gin.Context) {
var form core.GetTagListByWxidRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
ret, err := w.WxApi.GetTagListByWxid(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", ret)
return
}

104
api/ui.go Normal file
View File

@ -0,0 +1,104 @@
package api
import (
"github.com/gin-gonic/gin"
"github.com/goWxHook/goWxHook/core"
"github.com/goWxHook/goWxHook/utils"
)
// switchSession
//
// @Summary 切换会话
// @Description 切换会话接口
// @Tags 界面
// @Accept json
// @Produce json
// @Param body body core.SwitchSessionRequest true "会话"
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/ui/switch/session [post]
func (w *WebApi) switchSession(c *gin.Context) {
var form core.SwitchSessionRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
err = w.WxApi.SwitchSession(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// clearChatRecord
//
// @Summary 清空聊天记录
// @Description 清空聊天记录接口
// @Tags 界面
// @Accept json
// @Produce json
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/ui/clear/chat/record [post]
func (w *WebApi) clearChatRecord(c *gin.Context) {
err := w.WxApi.ClearChatRecord()
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// chatMsgNotNotify
//
// @Summary 消息免打扰
// @Description 消息免打扰接口
// @Tags 界面
// @Accept json
// @Produce json
// @Param body body core.ChatMsgNotNotifyRequest true "消息免打扰"
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/ui/chat/msg/not/notify [post]
func (w *WebApi) chatMsgNotNotify(c *gin.Context) {
var form core.ChatMsgNotNotifyRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
err = w.WxApi.ChatMsgNotNotify(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}
// chatSessionTop
//
// @Summary 置顶会话
// @Description 置顶会话接口
// @Tags 界面
// @Accept json
// @Produce json
// @Param body body core.ChatSessionTopRequest true "会话"
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/ui/chat/session/top [post]
func (w *WebApi) chatSessionTop(c *gin.Context) {
var form core.ChatSessionTopRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
err = w.WxApi.ChatSessionTop(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}

279
api/video_moment.go Normal file
View File

@ -0,0 +1,279 @@
package api
import (
"github.com/gin-gonic/gin"
"github.com/goWxHook/goWxHook/core"
"github.com/goWxHook/goWxHook/utils"
)
// videoMomentInit
//
// @Summary 视频号初始化
// @Description 视频号初始化接口
// @Tags 视频号
// @Accept json
// @Produce json
// @Response 200 {object} CommonStringResponse{Data=core.VideoMomentInitResponseData} "{\"code\":0, ....}
// @Router /api/v1/video_moment/init [post]
func (w *WebApi) videoMomentInit(c *gin.Context) {
info, err := w.WxApi.VideoMomentInit()
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// videoMomentSearch
//
// @Summary 搜索视频号
// @Description 搜索视频号接口
// @Tags 视频号
// @Accept json
// @Produce json
// @Param body body core.VideoMomentSearchRequest true "搜索信息"
// @Response 200 {object} CommonStringResponse{Data=interface{}} "{\"code\":0, ....}
// @Router /api/v1/video_moment/search [post]
func (w *WebApi) videoMomentSearch(c *gin.Context) {
var form core.VideoMomentSearchRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
info, err := w.WxApi.VideoMomentSearch(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// videoMomentUserHome
//
// @Summary 视频号用户主页
// @Description 视频号用户主页接口
// @Tags 视频号
// @Accept json
// @Produce json
// @Param body body core.VideoMomentUserHomeRequest true "用户信息"
// @Response 200 {object} CommonStringResponse{Data=interface{}} "{\"code\":0, ....}
// @Router /api/v1/video_moment/user/home [post]
func (w *WebApi) videoMomentUserHome(c *gin.Context) {
var form core.VideoMomentUserHomeRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
info, err := w.WxApi.VideoMomentUserHome(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// videoMomentVideoDetail
//
// @Summary 查看视频详细信息(包含评论)
// @Description 查看视频详细信息(包含评论)接口
// @Tags 视频号
// @Accept json
// @Produce json
// @Param body body core.VideoMomentVideoDetailRequest true "视频信息"
// @Response 200 {object} CommonStringResponse{Data=interface{}} "{\"code\":0, ....}
// @Router /api/v1/video_moment/video/detail [post]
func (w *WebApi) videoMomentVideoDetail(c *gin.Context) {
var form core.VideoMomentVideoDetailRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
info, err := w.WxApi.VideoMomentVideoDetail(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// videoMomentFollow
//
// @Summary 关注视频号
// @Description 关注视频号接口
// @Tags 视频号
// @Accept json
// @Produce json
// @Param body body core.VideoMomentFollowRequest true "关注信息"
// @Response 200 {object} CommonStringResponse{Data=core.VideoMomentFollowResponseData} "{\"code\":0, ....}
// @Router /api/v1/video_moment/follow [post]
func (w *WebApi) videoMomentFollow(c *gin.Context) {
var form core.VideoMomentFollowRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
info, err := w.WxApi.VideoMomentFollow(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// videoMomentLike
//
// @Summary 点赞视频
// @Description 点赞视频接口
// @Tags 视频号
// @Accept json
// @Produce json
// @Param body body core.VideoMomentLikeRequest true "点赞信息"
// @Response 200 {object} CommonStringResponse{Data=core.VideoMomentLikeResponseData} "{\"code\":0, ....}
// @Router /api/v1/video_moment/like [post]
func (w *WebApi) videoMomentLike(c *gin.Context) {
var form core.VideoMomentLikeRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
info, err := w.WxApi.VideoMomentLike(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// videoMomentGetSessionId
//
// @Summary 获取私信sessionId
// @Description 获取私信sessionId接口
// @Tags 视频号
// @Accept json
// @Produce json
// @Param body body core.VideoMomentGetSessionIdRequest true "sessionId信息"
// @Response 200 {object} CommonStringResponse{Data=core.VideoMomentGetSessionIdResponseData} "{\"code\":0, ....}
// @Router /api/v1/video_moment/get/session_id [post]
func (w *WebApi) videoMomentGetSessionId(c *gin.Context) {
var form core.VideoMomentGetSessionIdRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
info, err := w.WxApi.VideoMomentGetSessionId(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// videoMomentSendMsg
//
// @Summary 发送私信
// @Description 发送私信接口
// @Tags 视频号
// @Accept json
// @Produce json
// @Param body body core.VideoMomentSendMsgRequest true "发送信息"
// @Response 200 {object} CommonStringResponse{Data=core.VideoMomentSendMsgResponseData} "{\"code\":0, ....}
// @Router /api/v1/video_moment/send/msg [post]
func (w *WebApi) videoMomentSendMsg(c *gin.Context) {
var form core.VideoMomentSendMsgRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
info, err := w.WxApi.VideoMomentSendMsg(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// videoMomentCreateVirtualNickName
//
// @Summary 创建虚拟昵称
// @Description 创建虚拟昵称接口
// @Tags 视频号
// @Accept json
// @Produce json
// @Param body body core.VideoMomentCreateVirtualNickNameRequest true "昵称信息"
// @Response 200 {object} CommonStringResponse{Data=interface{}} "{\"code\":0, ....}
// @Router /api/v1/video_moment/create/virtual_nickname [post]
func (w *WebApi) videoMomentCreateVirtualNickName(c *gin.Context) {
var form core.VideoMomentCreateVirtualNickNameRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
info, err := w.WxApi.VideoMomentCreateVirtualNickName(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// videoMomentSwitchVirtualNickName
//
// @Summary 切换虚拟昵称
// @Description 切换虚拟昵称接口
// @Tags 视频号
// @Accept json
// @Produce json
// @Param body body core.VideoMomentSwitchVirtualNickNameRequest true "昵称信息"
// @Response 200 {object} CommonStringResponse{Data=interface{}} "{\"code\":0, ....}
// @Router /api/v1/video_moment/switch/virtual_nickname [post]
func (w *WebApi) videoMomentSwitchVirtualNickName(c *gin.Context) {
var form core.VideoMomentSwitchVirtualNickNameRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
info, err := w.WxApi.VideoMomentSwitchVirtualNickName(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}
// videoMomentDeleteVirtualNickName
//
// @Summary 删除虚拟昵称
// @Description 删除虚拟昵称接口
// @Tags 视频号
// @Accept json
// @Produce json
// @Response 200 {object} CommonStringResponse "{\"code\":0, ....}
// @Router /api/v1/video_moment/delete/virtual_nickname [post]
func (w *WebApi) videoMomentDeleteVirtualNickName(c *gin.Context) {
err := w.WxApi.VideoMomentDeleteVirtualNickName()
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", nil)
return
}

33
api/voice.go Normal file
View File

@ -0,0 +1,33 @@
package api
import (
"github.com/gin-gonic/gin"
"github.com/goWxHook/goWxHook/core"
"github.com/goWxHook/goWxHook/utils"
)
// voiceToText
//
// @Summary 语音转文字
// @Description 语音转文字接口
// @Tags 语音转文字
// @Accept json
// @Produce json
// @Param body body core.VoiceToTextRequest true "语音信息"
// @Response 200 {object} CommonStringResponse{Data=core.VoiceToTextResponseData} "{\"code\":0, ....}
// @Router /api/v1/voice/to/text [post]
func (w *WebApi) voiceToText(c *gin.Context) {
var form core.VoiceToTextRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
info, err := w.WxApi.VoiceToText(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", info)
return
}

71
api/workwx.go Normal file
View File

@ -0,0 +1,71 @@
package api
import (
"github.com/gin-gonic/gin"
"github.com/goWxHook/goWxHook/core"
"github.com/goWxHook/goWxHook/utils"
)
// getWorkWxUserList
//
// @Summary 获取企业微信用户列表
// @Description 获取企业微信用户列表接口
// @Tags 企业微信
// @Accept json
// @Produce json
// @Response 200 {object} CommonStringResponse{Data=[]core.GetWorkWxUserListResponseDataItem} "{\"code\":0, ....}
// @Router /api/v1/workwx/user/list [get]
func (w *WebApi) getWorkWxUserList(c *gin.Context) {
list, err := w.WxApi.GetWorkWxUserList()
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", list)
return
}
// getWorkWxRoomList
//
// @Summary 获取企业微信群列表
// @Description 获取企业微信群列表接口
// @Tags 企业微信
// @Accept json
// @Produce json
// @Response 200 {object} CommonStringResponse{Data=[]core.GetWorkWxRoomListResponseDataItem} "{\"code\":0, ....}
// @Router /api/v1/workwx/room/list [get]
func (w *WebApi) getWorkWxRoomList(c *gin.Context) {
list, err := w.WxApi.GetWorkWxRoomList()
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", list)
return
}
// getWorkWxRoomMemberList
//
// @Summary 获取企业微信群成员列表
// @Description 获取企业微信群成员列表接口
// @Tags 企业微信
// @Accept json
// @Produce json
// @Param body body core.GetWorkWxChatRoomMemberRequest true "群信息"
// @Response 200 {object} CommonStringResponse{Data=core.GetWorkWxChatRoomMemberResponseData} "{\"code\":0, ....}
// @Router /api/v1/workwx/room/member/list [post]
func (w *WebApi) getWorkWxRoomMemberList(c *gin.Context) {
var form core.GetWorkWxChatRoomMemberRequest
err := c.ShouldBindJSON(&form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
list, err := w.WxApi.GetWorkWxChatRoomMember(form)
if err != nil {
utils.ResponseError(c, err.Error(), nil)
return
}
utils.ResponseOK(c, "success", list)
return
}

168
core/ListenServer.go Normal file
View File

@ -0,0 +1,168 @@
package core
import (
"bytes"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"github.com/goWxHook/goWxHook/utils"
"github.com/goWxHook/goWxHook/utils/json"
"io"
"log/slog"
"net/http"
"strconv"
"time"
)
var (
// ReportClientConnecFunc 客户连接
ReportClientConnecFunc func(id string)
// ReportClientCloseFunc 客户关闭
ReportClientCloseFunc func(id string)
// ReportClientMsgFunc 收到消息
ReportClientMsgFunc func(id string, data string)
// wxInitiativeCallQueue 主动消息队列
// key: 消息id
wxInitiativeCallQueue = utils.NewSafeMap[int, *wxCallQueue]()
registerPid = make(map[int]bool)
)
// 每种消息类型的主动消息队列
type wxCallQueue struct {
Send chan string // 是否有消息等待投递
Resp chan string // 应答消息
}
func registerWxCallBackListen(port int) error {
gin.SetMode(gin.ReleaseMode)
callback := gin.New()
callback.Use(gin.Recovery())
callback.POST("/send/error", func(c *gin.Context) {
data, _ := io.ReadAll(c.Request.Body)
lastErrorStr = string(data)
})
// 客户端上报(被动消息)
clientGroup := callback.Group("/report/client")
{
clientGroup.GET("/connect", reportClientConnect)
clientGroup.GET("/close", reportClientClose)
clientGroup.POST("/msg", reportClientMsg)
clientGroup.POST("/log", reportTest)
}
slog.Info(fmt.Sprintf("启动微信回调接收监听 :%d", port))
return callback.Run(fmt.Sprintf(":%d", port))
}
func RegisterClientConnectFunc(f func(id string)) {
ReportClientConnecFunc = f
}
func reportTest(c *gin.Context) {
id, _ := strconv.Atoi(c.Query("id"))
data, _ := io.ReadAll(c.Request.Body)
defer c.Request.Body.Close()
slog.Debug("test log", "id", id, "data", string(data))
}
func reportClientConnect(c *gin.Context) {
id := c.Query("id")
if ReportClientConnecFunc != nil {
ReportClientConnecFunc(id)
}
}
func RegisterClientCloseFunc(f func(id string)) {
ReportClientCloseFunc = f
}
func reportClientClose(c *gin.Context) {
id := c.Query("id")
if ReportClientCloseFunc != nil {
ReportClientCloseFunc(id)
}
}
func registerClientMsgFunc(f func(id string, data string)) {
ReportClientMsgFunc = f
}
type wxRespDataSimple struct {
Type int `json:"type"`
}
func reportClientMsg(c *gin.Context) {
defer c.Request.Body.Close()
id := c.Query("id")
data, _ := io.ReadAll(c.Request.Body)
// 拦截解析主动消息
var respData wxRespDataSimple
_ = json.Unmarshal(data, &respData)
if respData.Type != 0 {
// 检查主动消息
if v, ok := wxInitiativeCallQueue.Get(respData.Type); ok {
if respData.Type == loginSuccessMsg {
sr := WxLoginInfoResp{}
_ = json.Unmarshal(data, &sr)
if _, isexits := registerPid[sr.Data.Pid]; !isexits {
select {
case message, ifSubscribe := <-v.Send:
if ifSubscribe {
v.Resp <- string(data)
_ = message
return
}
}
}
} else {
select {
case message, ifSubscribe := <-v.Send:
if ifSubscribe {
v.Resp <- string(data)
_ = message
return
}
}
}
}
}
// 无订阅, 进入用户回调
dataStr := string(data)
if ReportClientMsgFunc != nil {
ReportClientMsgFunc(id, dataStr)
}
}
type HttpCallBackRequest struct {
Url string `json:"url"`
Timeout int `json:"timeout"` // 默认5秒
}
// RegisterHttpCallback 注册http消息回调
func RegisterHttpCallback(url string, timeout int) error {
if len(url) == 0 {
return errors.New("url不能为空")
}
if timeout == 0 {
timeout = 5
}
if timeout > 60 {
timeout = 60
}
registerClientMsgFunc(func(id string, data string) {
debugOutput(data)
// 注册http post回调
client := http.Client{
Timeout: time.Duration(timeout) * time.Second,
}
_, err := client.Post(url, "application/json", io.NopCloser(bytes.NewBufferString(data)))
if err != nil {
slog.Error("RegisterHttpCallback: http post error", "url", url, "error", err)
return
}
})
return nil
}

106
core/WxModule.go Normal file
View File

@ -0,0 +1,106 @@
package core
import (
"errors"
"fmt"
"github.com/goWxHook/goWxHook/resource"
"github.com/goWxHook/goWxHook/utils"
"github.com/goWxHook/goWxHook/utils/tcp"
"log/slog"
"os"
"os/exec"
"strconv"
"time"
)
var (
GlobalCallUrl string
lastErrorStr string
GlobalDebug bool
)
func init() {
files := map[string]*[]byte{
"Helper_3.9.10.19.dll": &resource.HelperDll,
"Loader_3.9.10.19.dll": &resource.LoaderDll,
"callexe.exe": &resource.CallExe,
"HPSocket4C.dll": &resource.HPSocket4C,
}
for name, val := range files {
if !utils.FileExists(name) {
if err := utils.WriteFile(name, *val); err != nil {
panic(err)
}
}
}
}
// 获取宿主机上下一个可用的Api端口检测端口和+1的端口是否可用
func getNextAvailableApiPort(fromPort int) (int, error) {
const lowerLimit = 1000
const upperLimit = 65535
searchDown := (fromPort - lowerLimit) > (upperLimit - fromPort)
var step int
if searchDown {
step = -1
} else {
step = 1
}
var m = make(map[int]bool)
for {
fromPort += step
if fromPort < lowerLimit || fromPort > upperLimit {
return 0, errors.New("no available port")
}
portUsed := tcp.CheckPortConnection("127.0.0.1", fromPort)
m[fromPort] = portUsed
if !portUsed {
beforePort := fromPort - step
if v, ok := m[beforePort]; ok && !v {
if searchDown {
return fromPort, nil
} else {
return beforePort, nil
}
}
}
}
}
// WxModuleInit 初始化微信模块
// 除此之外系统主动检测启动端口用于dll和服务内部统信
func WxModuleInit(listenerPort int, debug bool) error {
GlobalDebug = debug
if GlobalDebug {
slog.SetLogLoggerLevel(slog.LevelDebug)
}
// 获取内部服务使用端口
port, err := getNextAvailableApiPort(listenerPort)
if err != nil {
return err
}
var lserr error
go func() {
lserr = registerWxCallBackListen(port + 1)
}()
time.Sleep(2 * time.Second)
if lserr != nil {
return lserr
}
args := []string{strconv.Itoa(os.Getpid()), strconv.Itoa(port)}
cmd := exec.Command(".\\callexe.exe", args...)
err = cmd.Start()
if err != nil {
return err
}
// 等待3秒进程启动
time.Sleep(3 * time.Second)
GlobalCallUrl = fmt.Sprintf("http://127.0.0.1:%d", port)
slog.Info(fmt.Sprintf("启动微信监听 %d\n", port))
api := WxApi{}
if err := api.Ping(); err != nil {
return err
}
return nil
}

29
core/WxStruct.go Normal file
View File

@ -0,0 +1,29 @@
package core
type WxCommonResponse struct {
Data WxCommonData `json:"data"`
Type int `json:"type"`
}
// WxCommonData 微信通用返回的结构体
type WxCommonData struct {
Errcode int `json:"errcode"` // 0代表成功其他代表失败
Errmsg string `json:"errmsg"`
Status int `json:"status"`
Wxid string `json:"wxid"`
}
type WxLoginInfoResp struct {
Data UserClientInfo `json:"data"`
Type int `json:"type"`
}
type UserClientInfo struct {
Account string `json:"account"`
Avatar string `json:"avatar"`
Nickname string `json:"nickname"`
Phone string `json:"phone"`
Pid int `json:"pid"`
UnreadMsgCount int `json:"unread_msg_count"`
WxUserDir string `json:"wx_user_dir"`
Wxid string `json:"wxid"`
}

381
core/callapi.go Normal file
View File

@ -0,0 +1,381 @@
package core
import (
"bytes"
"fmt"
"github.com/goWxHook/goWxHook/utils/json"
"io"
"log/slog"
"net/http"
"time"
)
const (
MtDebugLog = 11024 // debug消息
loginSuccessMsg = 11025 // 登录成功
MtUserLogin = 11025 // 登录消息
MtUserLogout = 11026 // 注销消息
MtSqlQuery = 11027 // 数据库查询消息
MtDataOwnerMsg = 11028 // 获取我的信息消息
MtDataWxidMsg = 11029 // 获取单个好友信息
MtDataFriendsMsg = 11030 // 获取好友列表消息
MtDataChatroomsMsg = 11031 // 获取群聊列表消息
MtDataChatroomMembersMsg = 11032 // 获取群成员消息
MtDataPublicsMsg = 11033 // 获取公众号消息
MtUpdateWxidMsg = 11034 // 从网络更新单个好友信息消息
MtUpdateRoomMemberMsg = 11035 // 从网络更新群成员信息消息
MtSendTextmsg = 11036 // 发送文本消息
MtSendChatroomAtmsg = 11037 // 发送群@消息
MtSendCardmsg = 11038 // 发送名片消息
MtSendLinkmsg = 11039 // 发送链接消息
MtSendImgmsg = 11040 // 发送图片消息
MtSendFilemsg = 11041 // 发送文件消息
MtSendVideomsg = 11042 // 发送视频消息
MtSendGifmsg = 11043 // 发送gif消息
MtRecvTextMsg = 11046 // 接收文本消息
MtRecvPictureMsg = 11047 // 接收图片消息
MtRecvVoiceMsg = 11048 // 接收视频消息
MtRecvFriendMsg = 11049 // 接收申请好友消息
MtRecvCardMsg = 11050 // 接收名片消息
MtRecvVideoMsg = 11051 // 接收视频消息
MtRecvEmojiMsg = 11052 // 接收表情消息
MtRecvLocationMsg = 11053 // 接收位置消息
MtRecvLinkMsg = 11054 // 接收链接消息
MtRecvFileMsg = 11055 // 接收文件消息
MtRecvMiniappMsg = 11056 // 接收小程序消息
MtRecvWcpayMsg = 11057 // 接收好友转账消息
MtRecvSystemMsg = 11058 // 接收系统消息
MtRecvRevokeMsg = 11059 // 接收撤回消息
MtRecvOtherMsg = 11060 // 接收其他未知消息
MtRecvOtherAppMsg = 11061 // 接收应用类型未知消息
MtAddFriendMsg = 11062 // 发送加好友消息
MtModFriendRemarkMsg = 11063 // 发送修改好友备注消息
MtDelFriendMsg = 11064 // 发送删除好友消息
MtAcceptFriendMsg = 11065 // 发送同意加好友申请消息
MtAcceptWcpayMsg = 11066 // 发送接收好友转帐消息
MtAcceptRoomMsg = 11067 // 发送同意进群邀请消息
MtCreateRoomMsg = 11068 // 发送创建群聊消息
MtInviteToRoomMsg = 11069 // 发送邀请好友进群消息40人以下
MtInviteToRoomReqMsg = 11070 // 发送邀请好友进群消息40人以上
MtDelRoomMemberMsg = 11071 // 发送删除群成员消息
MtModRoomNameMsg = 11072 // 发送修改群名称消息
MtModRoomNoticeMsg = 11073 // 发送修改群通知消息
MtModRoomMemberNameMsg = 11074 // 发送修改我在本群的昵称消息
MtModRoomShowNameMsg = 11075 // 发送修改显示群昵称消息
MtSaveRoomToContactMsg = 11076 // 发送保存到联系人消息
MtQuitDelRoomMsg = 11077 // 发送退出并删除群消息
MtModRecvNotifyMsg = 11078 // 发送消息免打扰消息
MtModChatSessionTopMsg = 11079 // 发送置顶消息
MtZombieCheckMsg = 11080 // 发送无痕清粉消息
MtAutoAcceptFriendMsg = 11081 // 发送自动同意好友申请消息
MtAutoAcceptWcpayMsg = 11082 // 发送自动同意好友转帐消息
MtAutoAcceptRoomMsg = 11083 // 发送自动进群邀请消息
MtAutoAcceptCardMsg = 11084 // 发送自动加名片消息
MtDecryptImgMsg = 11085 // 发送解密图片消息
MtOpenBrowserMsg = 11086 // 发送打开浏览器消息
MtRefreshLoginQrcode = 11087 // 刷新登录二维码
MtSwitchSessionMsg = 11090 // 发送切换当前会话消息
MtSearchWxUserMsg = 11096 // 搜索微信用户
MtAddSearchUserMsg = 11097 // 添加搜索的微信用户
MtVoiceToTextMsg = 11112 // 语音消息转文本(旧)
MtSendXmlMsg = 11113 // 发送XML原始消息
MtLogoutMsg = 11104 // 发送注销登录消息
MtExitMsg = 11105 // 发送退出微信消息
MtClearChatRecordMsg = 11108 // 清除聊天记录
MtGetCollectListMsg = 11109 // 获取收藏列表
MtSendCollectMsg = 11110 // 发送收藏(旧)
MtSendCollectMsgByMsgId = 11111 // 收藏指定消息(旧)
MtGetWorkWxChatRoomMsg = 11129 // 获取企业微信群
MtGetWorkWxChatRoomMemberMsg = 11130 //获取企业微信群成员
MtGetWorkWxUserListMsg = 11132 // 获取企业微信好友
MtGetChatRoomInviteRelationMsg = 11134 // 获取群成员邀请关系(协议)
MtGetA8KeyMsg = 11135 // A8Key接口
MtGetMiniProgramCodeMsg = 11136 // 获取小程序授权code
MtAddTagMsg = 11137 // 添加标签
MtDeleteTagMsg = 11138 // 删除标签
MtModifyTagMsg = 11139 // 修改标签
MtAddTagToUserMsg = 11140 // 批量给用户加标签
MtGetTagListByWxidMsg = 11141 // 获取指定好友的所有标签
MtGetTagListMsg = 11142 // 获取标签列表
MtGetMomentMsg = 11145 // 获取朋友圈
MtCommentMomentMsg = 11146 // 朋友圈评论
MtLikeMomentMsg = 11147 // 朋友圈点赞
MtSendMomentMsg = 11148 // 朋友圈发表
MtUploadMomentImageMsg = 11149 // 朋友圈上传图片
MtGetFriendMomentMsg = 11150 // 获取好友朋友圈
MtVideoMomentInitMsg = 11160 // 视频号初始化
MtVideoMomentSearchMsg = 11161 // 视频号搜索
MtLiveEnterMsg = 11162 //进入直播间
MtLiveGetChangeInfoMsg = 11163 // 获取直播间变动信息(人气,实时发言等)
MtLiveSendMsg = 11164 // 发送直播间消息
MtVideoMomentFollowMsg = 11167 // 关注博主
MtVideoMomentLikeMsg = 11168 // 视频号点赞
MtVideoMomentVideoDetailMsg = 11169 // 查看视频详细信息(包含评论)
MtVideoMomentUserHomeMsg = 11170 // 视频号用户主页
MtLiveGetOnlineUserMsg = 11172 // 获取直播间在线人员
MtGetFriendDetailMsg = 11174 // 获取好友详细信息(协议)
MtLiveGetShelfMsg = 11186 // 获取直播间货架
MtVideoMomentCreateVirtualNickNameMsg = 11194 // 视频号创建虚拟昵称
MtVideoMomentSwitchVirtualNickNameMsg = 11195 // 视频号切换虚拟昵称
MtVideoMomentDeleteVirtualNickNameMsg = 11197 // 视频号删除虚拟昵称
MtVideoMomentGetSessionIdMsg = 11202 // 获取视频号私信sessionId
MtVideoMomentSendMsg = 11203 // 发送视频号私信
MtCdnSendXmlMsg = 11214 // 发送XML原始消息
MtCdnInitialMsg = 11228 // CDN初始化
MtCdnUploadFileMsg = 11229 // CDN上传
MtCdnDownloadFileMsg = 11230 // CDN下载
MtCdnSendImageMsg = 11231 // 发送图片消息
MtCdnSendVideoMsg = 11233 // 发送视频消息
MtCdnSendFileMsg = 11235 // 发送文件消息
MtCdnSendCardLinkMsg = 11236 // 发送链接卡片消息
MtCdnSendTextMsg = 11237 // 发送文本消息
MtCdnSendLocationMsg = 11238 // 发送位置
MtCdnSendCardMsg = 11239 // 发送名片
MtCdnSendAtTextMsg = 11240 // 发送At消息
MtCdnSendGifMsg = 11241 // 发送动图消息
MtCdnSendMiniProgramMsg = 11242 // 发送小程序
MtCdnSendVideoMomentMsg = 11243 // 发送视频号
MtCdnSendRevokeMsg = 11244 // 撤回消息
MtForwardMsg = 11245 // 转发任意类型消息
MtCreateRoomByProtocolMsg = 11246 // 创建群聊(协议)
MtWorkWxCdnDownloadMsg = 11253 // 企业微信CDN
MtCdnSendGifMsgNew = 11254 // 发送动图消息New
)
type RespJson struct {
Error int `json:"error"`
Msg string `json:"msg"`
Data any `json:"data"`
}
type WxApi struct {
UserInfo UserClientInfo
TimeOut int // 上传大文件时记得手动拉长超时
}
func debugOutput(msg string) {
if GlobalDebug {
slog.Debug(msg)
}
}
// Ping 📡 微信与服务的健康脉动,轻触即刻,安心无边
// 骑上代码的独角兽,驰骋在微信与服务的和谐旋律中;
// 若路遇荆棘错误翩翩WxError的信使将携谜团(-1)翩然而至。
func (*WxApi) Ping() error {
// 抛出魔法飞毯,直抵全球通讯站(GlobalCallUrl)/ping
resp, err := http.Get(GlobalCallUrl + "/ping")
if err != nil {
// 魔法失效WxError的封印(-1)悄然降临,记录下不解之谜
return WxError{-1, err.Error()}
}
defer resp.Body.Close() // 隐身术,抹去所有痕迹,不留下一丝涟漪
// 倾听回响,秘密文字在耳边低语
data, err := io.ReadAll(resp.Body)
if err != nil {
// 文字破碎WxError的警告(-2)再次响起
return WxError{-2, err.Error()}
}
// 古卷解读将回响化为RespJson的智慧之光
rjson := RespJson{}
json.Unmarshal(data, &rjson)
// 密文比对10000是神秘的共鸣密码
if rjson.Error != 10000 {
// 密码失真WxError的困惑(-rjson.Error)引领着归途
return WxError{rjson.Error, rjson.Msg}
}
// 脉动稳健,旅程圆满,一切安好
return nil
}
// GetUserWeChatVersion 探索微信的奥秘维度
// 跨越星辰大海,追寻新版图的圣杯传说;
// 若遭逢风暴空荡的圣杯将裹挟WxError的失落归来。
func (*WxApi) GetUserWeChatVersion() (string, error) {
// 出发,以光年速度驶向微信版本的时空节点
resp, err := http.Get(GlobalCallUrl + "/GetUserWeChatVersion")
if err != nil {
// 时空乱流WxError的幻影(-1)携破碎梦想现身
return "", WxError{-1, err.Error()}
}
defer resp.Body.Close() // 关闭时空裂隙,以防异界侵袭
// 接纳圣杯的微光,倾听宇宙的低语
data, err := io.ReadAll(resp.Body)
if err != nil {
// 信息迷失WxError(-2)的哀歌在虚空中回荡
return "", WxError{-2, err.Error()}
}
// 古老符文解析揭示RespJson的宇宙密语
rjson := RespJson{}
_ = json.Unmarshal(data, &rjson)
// 密令确认10000是真理的指引
if rjson.Error != 10000 {
// 光芒黯淡WxError(-rjson.Error)载着谜团回归
return "", WxError{rjson.Error, rjson.Msg}
}
// 圣杯显现,微信版图的最新座标(version)闪耀而出
return rjson.Data.(map[string]any)["version"].(string), nil
}
// InjectWeChat 微信灵魂注入术,让微信与服务融为一体
// 邀请全球通讯站,完成神秘仪式;
// 若召唤失败WxError的诅咒将随之降临。
func (w *WxApi) InjectWeChat() (u *UserClientInfo, r error) {
sl := make(chan int)
wait := wxInitiativeCallQueue.GetWithSetDefault(loginSuccessMsg, &wxCallQueue{
Send: make(chan string),
Resp: make(chan string),
})
go func() {
go func() {
wait.Send <- "1"
}()
const timeout = 99999
// 等待密信,或迎接时间的审判
select {
case message := <-wait.Resp:
sr := WxLoginInfoResp{}
err := json.Unmarshal([]byte(message), &sr)
if err != nil {
r = WxError{-3, "login timeout"}
sl <- 0
break
}
w.UserInfo = sr.Data
registerPid[sr.Data.Pid] = true
sl <- 1
// return &w.UserInfo, nil
break
case <-time.After(time.Duration(timeout) * time.Second):
r = WxError{-3, "login timeout"}
sl <- 0
break
}
//if w.UserInfo.Wxid != "" || r != nil {
// break
//}
}()
// 释放灵能,向宇宙宣告召唤
resp, err := http.Get(GlobalCallUrl + "/InjectWeChat")
if err != nil {
// 灵能消散WxError的阴霾笼罩(-1)
return nil, WxError{-1, err.Error()}
}
defer resp.Body.Close() // 收敛气息,防止泄露
// 汇聚反馈,领悟回应的奥秘
data, err := io.ReadAll(resp.Body)
if err != nil {
close(wait.Send)
close(wait.Resp)
wxInitiativeCallQueue.Delete(loginSuccessMsg)
// 奥秘难解WxError的迷雾笼罩(-2)
return nil, WxError{-2, err.Error()}
}
<-sl
if r != nil {
return nil, r
}
// 解析神秘符号揭示RespJson的真谛
var rjson RespJson
_ = json.Unmarshal(data, &rjson)
// 检验仪式成功10000为灵能共鸣的证明
if rjson.Error != 10000 {
// 引力失衡WxError的警告回荡
return nil, WxError{rjson.Error, rjson.Msg}
}
// 仪式圆满,灵能注入,无误返回
return &w.UserInfo, nil
}
// sendWeChatData 📨 内部秘法,向微信投递加密情报
// 注册ID、客户端ID、JSON数据及超时时限编织跨越次元的信使
// 若信使迷失WxError的幽灵将悄然而至揭示暗影的谜团。
func (*WxApi) sendWeChatData(registerID, ClientID int, JsonData string, timeout int) (rstr string, rerr error) {
// 符文编织,信使的护甲,信息封存
jsonBytes, _ := json.Marshal(map[string]interface{}{
"ClientId": ClientID,
"JsonData": JsonData,
})
var wait *wxCallQueue
if registerID != 0 {
wait = wxInitiativeCallQueue.GetWithSetDefault(registerID, &wxCallQueue{
Send: make(chan string),
Resp: make(chan string),
})
}
go func() {
go func() {
if registerID != 0 {
wait.Send <- "1"
}
}()
// 飞翔吧,信使!目标:全球通讯站/SendWeChatData
url := GlobalCallUrl + "/SendWeChatData"
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonBytes))
if err != nil {
rerr = WxError{
ErrorCode: -1,
Message: fmt.Sprintf("Error crafting message: %v", err),
}
return
}
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
rerr = WxError{
ErrorCode: -2,
Message: fmt.Sprintf("Error delivering message: %v", err),
}
return
}
defer resp.Body.Close()
}()
if registerID != 0 {
if timeout == 0 {
timeout = 999999
}
if timeout > 0 {
select {
case message := <-wait.Resp:
return message, nil
case <-time.After(time.Duration(timeout) * time.Second):
return "", WxError{-3, "request timeout"}
}
}
}
return
}
// internalCall
func (w *WxApi) internalCall(registerID, timeout, Type int, JsonData any, trace any) (string, error) {
send := map[string]interface{}{
"type": Type,
}
if JsonData != nil {
send["data"] = JsonData
}
if trace != nil {
send["trace"] = trace
}
jsonBytes, _ := json.Marshal(send)
return w.sendWeChatData(registerID, 1, string(jsonBytes), timeout)
}

696
core/callapi_cdn.go Normal file
View File

@ -0,0 +1,696 @@
package core
import (
"github.com/goWxHook/goWxHook/utils/json"
)
type CDNInitialResponse struct {
Data CDNInitialResponseData `json:"data"`
Type int `json:"type"`
}
type CDNInitialResponseData struct {
Status int `json:"status"`
}
// InitialCDN CDN初始化
func (w *WxApi) InitialCDN() (*CDNInitialResponseData, error) {
resp, err := w.internalCall(MtCdnInitialMsg, 30, MtCdnInitialMsg, map[string]interface{}{}, nil)
if err != nil {
return nil, err
}
var rdata CDNInitialResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type CDNUploadRequest struct {
FileType int `json:"file_type"`
FilePath string `json:"file_path"`
}
type CDNUploadResponseData struct {
AesKey string `json:"aes_key"`
Crc32 int64 `json:"crc32"`
ErrorCode int `json:"error_code"`
FileId string `json:"file_id"`
FileKey string `json:"file_key"`
FileMd5 string `json:"file_md5"`
FilePath string `json:"file_path"`
FileSize int `json:"file_size"`
ThumbFileMd5 string `json:"thumb_file_md5"`
ThumbFileSize int `json:"thumb_file_size"`
}
type CDNUploadResponse struct {
Data CDNUploadResponseData `json:"data"`
Type int `json:"type"`
}
// CDNUpload CDN上传
func (w *WxApi) CDNUpload(request CDNUploadRequest) (*CDNUploadResponseData, error) {
resp, err := w.internalCall(MtCdnUploadFileMsg, 600, MtCdnUploadFileMsg, request, nil)
if err != nil {
return nil, err
}
var rdata CDNUploadResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type CDNDownloadRequest struct {
FileId string `json:"file_id"`
FileType int `json:"file_type"`
AesKey string `json:"aes_key"`
SavePath string `json:"save_path"`
}
type CDNDownloadResponseData struct {
ErrorCode int `json:"error_code"`
FileId string `json:"file_id"`
FileSize int `json:"file_size"`
SavePath string `json:"save_path"`
}
type CDNDownloadResponse struct {
Data CDNDownloadResponseData `json:"data"`
Type int `json:"type"`
}
// CDNDownload CDN下载
func (w *WxApi) CDNDownload(request CDNDownloadRequest) (*CDNDownloadResponseData, error) {
resp, err := w.internalCall(MtCdnDownloadFileMsg, 600, MtCdnDownloadFileMsg, request, nil)
if err != nil {
return nil, err
}
var rdata CDNDownloadResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type WorkWxCdnDownloadRequest struct {
Url string `json:"url"`
AuthKey string `json:"auth_key"`
AesKey string `json:"aes_key"`
SavePath string `json:"save_path"`
}
type WorkWxCdnDownloadResponseData struct {
ErrorCode int `json:"error_code"`
SavePath string `json:"save_path"`
}
type WorkWxCdnDownloadResponse struct {
Data WorkWxCdnDownloadResponseData `json:"data"`
Type int `json:"type"`
}
// WorkWxCdnDownload 企业微信CDN
func (w *WxApi) WorkWxCdnDownload(request WorkWxCdnDownloadRequest) (*WorkWxCdnDownloadResponseData, error) {
resp, err := w.internalCall(MtWorkWxCdnDownloadMsg, 600, MtWorkWxCdnDownloadMsg, request, nil)
if err != nil {
return nil, err
}
var rdata WorkWxCdnDownloadResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type CDNSendTextMsgRequest struct {
ToWxid string `json:"to_wxid"`
Content string `json:"content"`
AtList []string `json:"at_list"` // 群消息时候使用
AtAll int `json:"at_all"` // 群消息时候1是at所有人
}
type CDNSendTextMsgResponseData struct {
BaseResponse struct {
Ret int `json:"ret"`
} `json:"baseResponse"`
Count int `json:"count"`
MsgResponseList []struct {
ClientMsgId int `json:"clientMsgId"`
CreateTime int `json:"createTime"`
MsgId int `json:"msgId"`
NewMsgId string `json:"newMsgId"`
Ret int `json:"ret"`
ServerTime int `json:"serverTime"`
ToUserName struct {
String string `json:"string"`
} `json:"toUserName"`
Type int `json:"type"`
} `json:"msgResponseList"`
}
type CDNSendTextMsgResponse struct {
Data CDNSendTextMsgResponseData `json:"data"`
Type int `json:"type"`
}
// CDNSendTextMsg 发送文本消息
func (w *WxApi) CDNSendTextMsg(request CDNSendTextMsgRequest) (*CDNSendTextMsgResponseData, error) {
var (
resp string
err error
)
if len(request.AtList) > 0 || request.AtAll == 1 {
resp, err = w.internalCall(MtCdnSendAtTextMsg, 30, MtCdnSendAtTextMsg, request, nil)
if err != nil {
return nil, err
}
} else {
resp, err = w.internalCall(MtCdnSendTextMsg, 30, MtCdnSendTextMsg, request, nil)
if err != nil {
return nil, err
}
}
var rdata CDNSendTextMsgResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type CDNSendImageMsgRequest struct {
AesKey string `json:"aes_key"`
FileId string `json:"file_id"`
FileMd5 string `json:"file_md5"`
FileSize int `json:"file_size"`
ThumbFileSize int `json:"thumb_file_size"`
Crc32 int `json:"crc32"`
ToWxid string `json:"to_wxid"`
}
type CDNSendImageMsgResponseData struct {
AesKey string `json:"aes_key"`
FileId string `json:"file_id"`
FileMd5 string `json:"file_md5"`
FileSize int `json:"file_size"`
ThumbFileSize int `json:"thumb_file_size"`
Crc32 int `json:"crc32"`
ToWxid string `json:"to_wxid"`
}
type CDNSendImageMsgResponse struct {
Data CDNSendImageMsgResponseData `json:"data"`
Type int `json:"type"`
}
// CDNSendImageMsg 发送图片
func (w *WxApi) CDNSendImageMsg(request CDNSendImageMsgRequest) (*CDNSendImageMsgResponseData, error) {
resp, err := w.internalCall(MtCdnSendImageMsg, 120, MtCdnSendImageMsg, request, nil)
if err != nil {
return nil, err
}
var rdata CDNSendImageMsgResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type CDNSendVideoMsgRequest struct {
AesKey string `json:"aes_key"`
FileId string `json:"file_id"`
FileMd5 string `json:"file_md5"`
FileSize int `json:"file_size"`
ThumbFileSize int `json:"thumb_file_size"`
ToWxid string `json:"to_wxid"`
}
type CDNSendVideoMsgResponseData struct {
ActionFlag int `json:"actionFlag"`
Aeskey string `json:"aeskey"`
BaseResponse struct {
Ret int `json:"ret"`
} `json:"baseResponse"`
ClientMsgId string `json:"clientMsgId"`
MsgId int `json:"msgId"`
MsgSource string `json:"msgSource"`
NewMsgId string `json:"newMsgId"`
RawAeskey string `json:"rawAeskey"`
RawVideoNeedReupload bool `json:"rawVideoNeedReupload"`
ThumbStartPos int `json:"thumbStartPos"`
VideoNeedReupload bool `json:"videoNeedReupload"`
VideoStartPos int `json:"videoStartPos"`
}
type CDNSendVideoMsgResponse struct {
Data CDNSendVideoMsgResponseData `json:"data"`
Type int `json:"type"`
}
func (w *WxApi) CDNSendVideoMsg(request CDNSendVideoMsgRequest) (*CDNSendVideoMsgResponseData, error) {
resp, err := w.internalCall(MtCdnSendVideoMsg, 120, MtCdnSendVideoMsg, request, nil)
if err != nil {
return nil, err
}
var rdata CDNSendVideoMsgResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type CDNSendFileMsgRequest struct {
AesKey string `json:"aes_key"`
FileId string `json:"file_id"`
FileMd5 string `json:"file_md5"`
FileName string `json:"file_name"`
FileSize int `json:"file_size"`
ToWxid string `json:"to_wxid"`
}
type CDNSendFileMsgResponseData struct {
ActionFlag int `json:"actionFlag"`
Aeskey string `json:"aeskey"`
AppId string `json:"appId"`
BaseResponse struct {
Ret int `json:"ret"`
} `json:"baseResponse"`
ClientMsgId string `json:"clientMsgId"`
CreateTime int `json:"createTime"`
FromUserName string `json:"fromUserName"`
MsgId int `json:"msgId"`
MsgSource string `json:"msgSource"`
NewMsgId string `json:"newMsgId"`
ToUserName string `json:"toUserName"`
Type int `json:"type"`
}
type CDNSendFileMsgResponse struct {
Data CDNSendFileMsgResponseData `json:"data"`
Type int `json:"type"`
}
// CDNSendFileMsg 发送文件
func (w *WxApi) CDNSendFileMsg(request CDNSendFileMsgRequest) (*CDNSendFileMsgResponseData, error) {
resp, err := w.internalCall(MtCdnSendFileMsg, 120, MtCdnSendFileMsg, request, nil)
if err != nil {
return nil, err
}
var rdata CDNSendFileMsgResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type CDNSendCardLinkMsgRequest struct {
ToWxid string `json:"to_wxid"`
Title string `json:"title"`
Desc string `json:"desc"`
Url string `json:"url"`
ImageUrl string `json:"image_url"`
}
type CDNSendCardLinkMsgResponseData struct {
ActionFlag int `json:"actionFlag"`
Aeskey string `json:"aeskey"`
AppId string `json:"appId"`
BaseResponse struct {
ErrMsg struct {
} `json:"errMsg"`
Ret int `json:"ret"`
} `json:"baseResponse"`
ClientMsgId string `json:"clientMsgId"`
CreateTime int `json:"createTime"`
FromUserName string `json:"fromUserName"`
MsgId int `json:"msgId"`
MsgSource string `json:"msgSource"`
NewMsgId string `json:"newMsgId"`
ToUserName string `json:"toUserName"`
Type int `json:"type"`
}
type CDNSendCardLinkMsgResponse struct {
Data CDNSendCardLinkMsgResponseData `json:"data"`
Type int `json:"type"`
}
// CDNSendCardLinkMsg 发送链接卡片
func (w *WxApi) CDNSendCardLinkMsg(request CDNSendCardLinkMsgRequest) (*CDNSendCardLinkMsgResponseData, error) {
resp, err := w.internalCall(MtCdnSendCardLinkMsg, 120, MtCdnSendCardLinkMsg, request, nil)
if err != nil {
return nil, err
}
var rdata CDNSendCardLinkMsgResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type CDNSendGifMsgRequest struct {
AesKey string `json:"aes_key"`
FileId string `json:"file_id"`
FileMd5 string `json:"file_md5"`
FileSize int `json:"file_size"`
ToWxid string `json:"to_wxid"`
}
type CDNSendGifMsgResponseData struct {
ActionFlag int `json:"actionFlag"`
Aeskey string `json:"aeskey"`
AppId string `json:"appId"`
BaseResponse struct {
Ret int `json:"ret"`
} `json:"baseResponse"`
ClientMsgId string `json:"clientMsgId"`
CreateTime int `json:"createTime"`
FromUserName string `json:"fromUserName"`
MsgId int `json:"msgId"`
MsgSource string `json:"msgSource"`
NewMsgId string `json:"newMsgId"`
ToUserName string `json:"toUserName"`
Type int `json:"type"`
}
type CDNSendGifMsgResponse struct {
Data CDNSendGifMsgResponseData `json:"data"`
Type int `json:"type"`
}
// CDNSendGifMsg 发送动图
func (w *WxApi) CDNSendGifMsg(request CDNSendGifMsgRequest) (*CDNSendGifMsgResponseData, error) {
resp, err := w.internalCall(MtCdnSendGifMsg, 120, MtCdnSendGifMsg, request, nil)
if err != nil {
return nil, err
}
var rdata CDNSendGifMsgResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type CDNSendMiniProgramMsgRequest struct {
ToWxid string `json:"to_wxid"`
Username string `json:"username"`
Appid string `json:"appid"`
Appname string `json:"appname"`
Appicon string `json:"appicon"`
Title string `json:"title"`
PagePath string `json:"page_path"`
FileId string `json:"file_id"`
AesKey string `json:"aes_key"`
FileMd5 string `json:"file_md5"`
FileSize int `json:"file_size"`
}
type CDNSendMiniProgramMsgResponseData struct {
ActionFlag int `json:"actionFlag"`
Aeskey string `json:"aeskey"`
AppId string `json:"appId"`
BaseResponse struct {
Ret int `json:"ret"`
} `json:"baseResponse"`
ClientMsgId string `json:"clientMsgId"`
CreateTime int `json:"createTime"`
FromUserName string `json:"fromUserName"`
MsgId int `json:"msgId"`
MsgSource string `json:"msgSource"`
NewMsgId string `json:"newMsgId"`
ToUserName string `json:"toUserName"`
Type int `json:"type"`
}
type CDNSendMiniProgramMsgResponse struct {
Data CDNSendMiniProgramMsgResponseData `json:"data"`
Type int `json:"type"`
}
// CDNSendMiniProgramMsg 发送小程序
func (w *WxApi) CDNSendMiniProgramMsg(request CDNSendMiniProgramMsgRequest) (*CDNSendMiniProgramMsgResponseData, error) {
resp, err := w.internalCall(MtCdnSendMiniProgramMsg, 120, MtCdnSendMiniProgramMsg, request, nil)
if err != nil {
return nil, err
}
var rdata CDNSendMiniProgramMsgResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type CDNSendVideoMomentMsgRequest struct {
ToWxid string `json:"to_wxid"`
ObjectId string `json:"object_id"`
ObjectNonceId string `json:"object_nonce_id"`
Nickname string `json:"nickname"`
Username string `json:"username"`
Avatar string `json:"avatar"`
Desc string `json:"desc"`
ThumbUrl string `json:"thumb_url"`
Url string `json:"url"`
}
type CDNSendVideoMomentMsgResponseData struct {
ActionFlag int `json:"actionFlag"`
Aeskey string `json:"aeskey"`
AppId string `json:"appId"`
BaseResponse struct {
Ret int `json:"ret"`
} `json:"baseResponse"`
ClientMsgId string `json:"clientMsgId"`
CreateTime int `json:"createTime"`
FromUserName string `json:"fromUserName"`
MsgId int `json:"msgId"`
MsgSource string `json:"msgSource"`
NewMsgId string `json:"newMsgId"`
ToUserName string `json:"toUserName"`
Type int `json:"type"`
}
type CDNSendVideoMomentMsgResponse struct {
Data CDNSendVideoMomentMsgResponseData `json:"data"`
Type int `json:"type"`
}
// CDNSendVideoMomentMsg 发送视频号
func (w *WxApi) CDNSendVideoMomentMsg(request CDNSendVideoMomentMsgRequest) (*CDNSendVideoMomentMsgResponseData, error) {
resp, err := w.internalCall(MtCdnSendVideoMomentMsg, 120, MtCdnSendVideoMomentMsg, request, nil)
if err != nil {
return nil, err
}
var rdata CDNSendVideoMomentMsgResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type CDNSendCardMsgRequest struct {
ToWxid string `json:"to_wxid"`
Username string `json:"username"`
Nickname string `json:"nickname"`
Avatar string `json:"avatar"`
}
type CDNSendCardMsgResponseData struct {
BaseResponse struct {
Ret int `json:"ret"`
} `json:"baseResponse"`
Count int `json:"count"`
MsgResponseList []struct {
ClientMsgId int `json:"clientMsgId"`
CreateTime int `json:"createTime"`
MsgId int `json:"msgId"`
NewMsgId string `json:"newMsgId"`
Ret int `json:"ret"`
ServerTime int `json:"serverTime"`
ToUserName struct {
String string `json:"string"`
} `json:"toUserName"`
Type int `json:"type"`
} `json:"msgResponseList"`
}
type CDNSendCardMsgResponse struct {
Data CDNSendCardMsgResponseData `json:"data"`
Type int `json:"type"`
}
// CDNSendCardMsg 发送名片
func (w *WxApi) CDNSendCardMsg(request CDNSendCardMsgRequest) (*CDNSendCardMsgResponseData, error) {
resp, err := w.internalCall(MtCdnSendCardMsg, 120, MtCdnSendCardMsg, request, nil)
if err != nil {
return nil, err
}
var rdata CDNSendCardMsgResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type CDNSendLocationMsgRequest struct {
ToWxid string `json:"to_wxid"`
Address string `json:"address"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Title string `json:"title"`
}
type CDNSendLocationMsgResponseData struct {
BaseResponse struct {
Ret int `json:"ret"`
} `json:"baseResponse"`
Count int `json:"count"`
MsgResponseList []struct {
ClientMsgId int `json:"clientMsgId"`
CreateTime int `json:"createTime"`
MsgId int `json:"msgId"`
NewMsgId string `json:"newMsgId"`
Ret int `json:"ret"`
ServerTime int `json:"serverTime"`
ToUserName struct {
String string `json:"string"`
} `json:"toUserName"`
Type int `json:"type"`
} `json:"msgResponseList"`
}
type CDNSendLocationMsgResponse struct {
Data CDNSendLocationMsgResponseData `json:"data"`
Type int `json:"type"`
}
// CDNSendLocationMsg 发送位置
func (w *WxApi) CDNSendLocationMsg(request CDNSendLocationMsgRequest) (*CDNSendLocationMsgResponseData, error) {
resp, err := w.internalCall(MtCdnSendLocationMsg, 120, MtCdnSendLocationMsg, request, nil)
if err != nil {
return nil, err
}
var rdata CDNSendLocationMsgResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type CDNSendRevokeMsgRequest struct {
ClientMsgid interface{} `json:"client_msgid"`
CreateTime int `json:"create_time"`
ToWxid string `json:"to_wxid"`
NewMsgid string `json:"new_msgid"`
}
type CDNSendRevokeMsgResponseData struct {
BaseResponse struct {
Ret int `json:"ret"`
} `json:"baseResponse"`
Introduction string `json:"introduction"`
SysWording string `json:"sysWording"`
}
type CDNSendRevokeMsgResponse struct {
Data CDNSendRevokeMsgResponseData `json:"data"`
Type int `json:"type"`
}
// CDNSendRevokeMsg 撤回消息
func (w *WxApi) CDNSendRevokeMsg(request CDNSendRevokeMsgRequest) (*CDNSendRevokeMsgResponseData, error) {
resp, err := w.internalCall(MtCdnSendRevokeMsg, 120, MtCdnSendRevokeMsg, request, nil)
if err != nil {
return nil, err
}
var rdata CDNSendRevokeMsgResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type CDNSendXmlMsgRequest struct {
// "<appmsg appid=\"wx6618f1cfc6c132f8\" sdkver=\"0\"><title>1658934822522.gif<... ...</weappinfo><websearch /></appmsg>",
Content string `json:"content"`
ToWxid string `json:"to_wxid"`
}
type CDNSendXmlMsgResponseData struct {
ActionFlag int `json:"actionFlag"`
Aeskey string `json:"aeskey"`
AppId string `json:"appId"`
BaseResponse struct {
Ret int `json:"ret"`
} `json:"baseResponse"`
ClientMsgId string `json:"clientMsgId"`
CreateTime int `json:"createTime"`
FromUserName string `json:"fromUserName"`
MsgId int `json:"msgId"`
MsgSource string `json:"msgSource"`
NewMsgId string `json:"newMsgId"`
ToUserName string `json:"toUserName"`
Type int `json:"type"`
}
type CDNSendXmlMsgResponse struct {
Data CDNSendXmlMsgResponseData `json:"data"`
Type int `json:"type"`
}
// CDNSendXmlMsg 发送xml消息
func (w *WxApi) CDNSendXmlMsg(request CDNSendXmlMsgRequest) (*CDNSendXmlMsgResponseData, error) {
resp, err := w.internalCall(MtCdnSendXmlMsg, 120, MtCdnSendXmlMsg, request, nil)
if err != nil {
return nil, err
}
var rdata CDNSendXmlMsgResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type CDNSendGifMsgNewRequest struct {
Path string `json:"path"`
ToWxid string `json:"to_wxid"`
}
type CDNSendGifMsgNewResponseData struct {
Md5 string `json:"md5"`
Size int `json:"size"`
ToWxid string `json:"to_wxid"`
}
type CDNSendGifMsgNewResponse struct {
Data CDNSendGifMsgNewResponseData `json:"data"`
Type int `json:"type"`
}
// CDNSendGifMsgNew 发送动图
func (w *WxApi) CDNSendGifMsgNew(request CDNSendGifMsgNewRequest) (*CDNSendGifMsgNewResponseData, error) {
resp, err := w.internalCall(MtCdnSendGifMsgNew, 120, MtCdnSendGifMsgNew, request, nil)
if err != nil {
return nil, err
}
var rdata CDNSendGifMsgNewResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}

56
core/callapi_collect.go Normal file
View File

@ -0,0 +1,56 @@
package core
import "github.com/goWxHook/goWxHook/utils/json"
type GetCollectListResponseData struct {
Items []struct {
FromUser string `json:"from_user"`
LocalId int `json:"local_id"`
RoomMember string `json:"room_member"`
Title string `json:"title"`
Type int `json:"type"`
UpdateTime int `json:"update_time"`
Xml string `json:"xml"`
} `json:"items"`
Status int `json:"status"`
}
type GetCollectListResponse struct {
Data GetCollectListResponseData `json:"data"`
Type int `json:"type"`
}
// GetCollectList 获取收藏列表
func (w *WxApi) GetCollectList() (*GetCollectListResponseData, error) {
resp, err := w.internalCall(MtGetCollectListMsg, 20, MtGetCollectListMsg, map[string]interface{}{}, nil)
if err != nil {
return nil, err
}
var rdata GetCollectListResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type SendCollectRequest struct {
ToWxid string `json:"to_wxid"`
LocalId int `json:"local_id"`
}
// SendCollect 发送收藏(旧)
func (w *WxApi) SendCollect(request SendCollectRequest) error {
_, err := w.internalCall(MtSendCollectMsg, 20, MtSendCollectMsg, request, nil)
return err
}
type SendCollectMsgByMsgIdRequest struct {
Msgid string `json:"msgid"`
}
// SendCollectMsgByMsgId 收藏指定消息(旧)
func (w *WxApi) SendCollectMsgByMsgId(request SendCollectMsgByMsgIdRequest) error {
_, err := w.internalCall(MtSendCollectMsgByMsgId, 20, MtSendCollectMsgByMsgId, request, nil)
return err
}

432
core/callapi_contact.go Normal file
View File

@ -0,0 +1,432 @@
package core
import (
"github.com/goWxHook/goWxHook/utils/json"
)
type GetFriendListResponse struct {
Data []GetFriendListResponseDateItem `json:"data"`
Type int `json:"type"`
}
type GetFriendListResponseDateItem struct {
Account string `json:"account"` // 微信账号,友情的直接连线
Avatar string `json:"avatar"` // 头像的风景画,好友的形象代言
City string `json:"city"` // 都市的温馨角落,好友的日常坐标
Country string `json:"country"` // 国界的另一端,好友的远方故事
LabelidList string `json:"labelid_list"` // 标签的彩虹桥,连接不同朋友圈的密码
Nickname string `json:"nickname"` // 昵称的诗篇,好友的个性签名
Province string `json:"province"` // 省份的风土人情,好友的地域色彩
Remark string `json:"remark"` // 备注的小秘密,只有你知道的代号
Sex int `json:"sex"` // 性别的罗盘1为蓝海2为红颜
Wxid string `json:"wxid"` // 微信ID好友的唯一坐标
}
// GetFriendList 获取好友列表
func (w *WxApi) GetFriendList() ([]GetFriendListResponseDateItem, error) {
resp, err := w.internalCall(MtDataFriendsMsg, 10, MtDataFriendsMsg, map[string]interface{}{}, nil)
if err != nil {
return nil, err
}
var rdata GetFriendListResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return rdata.Data, nil
}
type GetFriendInfoResponse struct {
Data GetFriendListResponseDateItem `json:"data"`
Type int `json:"type"`
}
// GetFriendInfo 获取单个好友信息
func (w *WxApi) GetFriendInfo(wxid string) (*GetFriendListResponseDateItem, error) {
resp, err := w.internalCall(MtDataWxidMsg, 10, MtDataWxidMsg, map[string]interface{}{"wxid": wxid}, nil)
if err != nil {
return nil, err
}
var rdata GetFriendInfoResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type GetFriendBriefInfoByProtocolResponseData struct {
Account string `json:"account"`
Avatar string `json:"avatar"`
City string `json:"city"`
Country string `json:"country"`
Nickname string `json:"nickname"`
Province string `json:"province"`
Remark string `json:"remark"`
Sex int `json:"sex"`
Signature string `json:"signature"`
SmallAvatar string `json:"small_avatar"`
SnsPic string `json:"sns_pic"`
SourceType int `json:"source_type"`
Status int `json:"status"`
V1 string `json:"v1"`
V2 string `json:"v2"`
Wxid string `json:"wxid"`
}
type GetFriendBriefInfoByProtocolResponse struct {
Data GetFriendBriefInfoByProtocolResponseData `json:"data"`
Type int `json:"type"`
}
// GetFriendBriefInfoByProtocol 获取好友简要信息(协议)
func (w *WxApi) GetFriendBriefInfoByProtocol(wxid string) (*GetFriendBriefInfoByProtocolResponseData, error) {
resp, err := w.internalCall(MtUpdateWxidMsg, 20, MtUpdateWxidMsg, map[string]interface{}{"wxid": wxid}, nil)
if err != nil {
return nil, err
}
var rdata GetFriendBriefInfoByProtocolResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type GetFriendDetailInfoByProtocolResponseData struct {
BaseResponse struct {
ErrMsg struct {
} `json:"errMsg"`
Ret int `json:"ret"`
} `json:"baseResponse"`
ContactCount int `json:"contactCount"`
ContactList []GetFriendDetailInfoByProtocolResponseDataContactListItem `json:"contactList"`
RetList []struct {
RetList int `json:"retList"`
} `json:"retList"`
VerifyUserValidTicketList []interface{} `json:"verifyUserValidTicketList"`
}
type GetFriendDetailInfoByProtocolResponseDataContactListItem struct {
AddContactScene int `json:"addContactScene"`
AdditionalContactList struct {
LinkedinContactItem struct {
} `json:"linkedinContactItem"`
} `json:"additionalContactList"`
AlbumBgImgId string `json:"albumBgImgId"`
AlbumFlag int `json:"albumFlag"`
AlbumStyle int `json:"albumStyle"`
Alias string `json:"alias"`
BigHeadImgUrl string `json:"bigHeadImgUrl"`
BitMask int64 `json:"bitMask"`
BitVal int `json:"bitVal"`
CardImgUrl string `json:"cardImgUrl"`
ChatRoomData string `json:"chatRoomData"`
ChatRoomNotify int `json:"chatRoomNotify"`
ChatRoomOwner string `json:"chatRoomOwner"`
ChatroomInfoVersion int `json:"chatroomInfoVersion"`
ChatroomMaxCount int `json:"chatroomMaxCount"`
ChatroomType int `json:"chatroomType"`
ChatroomVersion int `json:"chatroomVersion"`
City string `json:"city"`
ContactType int `json:"contactType"`
Country string `json:"country"`
CustomizedInfo struct {
BrandFlag int `json:"brandFlag"`
BrandIconURL string `json:"brandIconURL"`
BrandInfo string `json:"brandInfo"`
ExternalInfo string `json:"externalInfo"`
} `json:"customizedInfo"`
DeleteFlag int `json:"deleteFlag"`
Description string `json:"description"`
DomainList struct {
} `json:"domainList"`
EncryptUserName string `json:"encryptUserName"`
ExtInfo string `json:"extInfo"`
HasWeiXinHdHeadImg int `json:"hasWeiXinHdHeadImg"`
HeadImgMd5 string `json:"headImgMd5"`
IdcardNum string `json:"idcardNum"`
ImgBuf struct {
Buffer string `json:"buffer"`
ILen int `json:"iLen"`
} `json:"imgBuf"`
ImgFlag int `json:"imgFlag"`
LabelIdList string `json:"labelIdList"`
Level int `json:"level"`
MobileFullHash string `json:"mobileFullHash"`
MobileHash string `json:"mobileHash"`
MyBrandList string `json:"myBrandList"`
NewChatroomData struct {
ChatRoomMemberList []interface{} `json:"chatRoomMemberList"`
InfoMask int `json:"infoMask"`
MemberCount int `json:"memberCount"`
} `json:"newChatroomData"`
NickName struct {
String string `json:"string"`
} `json:"nickName"`
PersonalCard int `json:"personalCard"`
PhoneNumListInfo struct {
Count int `json:"count"`
PhoneNumList []interface{} `json:"phoneNumList"`
} `json:"phoneNumListInfo"`
Province string `json:"province"`
PyInitial struct {
String string `json:"string"`
} `json:"pyInitial"`
QuanPin struct {
String string `json:"string"`
} `json:"quanPin"`
RealName string `json:"realName"`
Remark struct {
} `json:"remark"`
RemarkPYInitial struct {
} `json:"remarkPYInitial"`
RemarkQuanPin struct {
} `json:"remarkQuanPin"`
RoomInfoCount int `json:"roomInfoCount"`
RoomInfoList []interface{} `json:"roomInfoList"`
Sex int `json:"sex"`
Signature string `json:"signature"`
SmallHeadImgUrl string `json:"smallHeadImgUrl"`
SnsUserInfo struct {
SnsBgImgId string `json:"snsBgImgId"`
SnsBgObjectId string `json:"snsBgObjectId"`
SnsFlag int `json:"snsFlag"`
SnsFlagEx int `json:"snsFlagEx"`
} `json:"snsUserInfo"`
Source int `json:"source"`
UserName struct {
String string `json:"string"`
} `json:"userName"`
VerifyContent string `json:"verifyContent"`
VerifyFlag int `json:"verifyFlag"`
VerifyInfo string `json:"verifyInfo"`
WeiDianInfo string `json:"weiDianInfo"`
Weibo string `json:"weibo"`
WeiboFlag int `json:"weiboFlag"`
WeiboNickname string `json:"weiboNickname"`
}
type GetFriendDetailInfoByProtocolResponse struct {
Data GetFriendDetailInfoByProtocolResponseData `json:"data"`
Type int `json:"type"`
}
// GetFriendDetailInfoByProtocol 获取好友详细信息(协议)
func (w *WxApi) GetFriendDetailInfoByProtocol(wxid string) ([]GetFriendDetailInfoByProtocolResponseDataContactListItem, error) {
resp, err := w.internalCall(MtGetFriendDetailMsg, 20, MtGetFriendDetailMsg, map[string]interface{}{"wxid": wxid}, nil)
if err != nil {
return nil, err
}
var rdata GetFriendDetailInfoByProtocolResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return rdata.Data.ContactList, nil
}
// GetFriendDetailInfoListByProtocol 批量获取好友详细信息(协议)
func (w *WxApi) GetFriendDetailInfoListByProtocol(wxids []string) ([]GetFriendDetailInfoByProtocolResponseDataContactListItem, error) {
resp, err := w.internalCall(MtGetFriendDetailMsg, 20, MtGetFriendDetailMsg, map[string]interface{}{"username_list": wxids}, nil)
if err != nil {
return nil, err
}
var rdata GetFriendDetailInfoByProtocolResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return rdata.Data.ContactList, nil
}
type EditFriendRemarkRequest struct {
Wxid string `json:"wxid"`
Remark string `json:"remark"`
}
// EditFriendRemark 编辑好友备注
func (w *WxApi) EditFriendRemark(request EditFriendRemarkRequest) (err error) {
_, err = w.internalCall(0, -1, MtModFriendRemarkMsg, request, nil)
return err
}
type AddFriendRequest struct {
Wxid string `json:"wxid"`
Remark string `json:"remark"`
RoomWxid string `json:"room_wxid"`
SourceType int `json:"source_type"`
}
// AddFriend 发送好友申请
// 参数:
// clientId: 客户端ID用于标识发起请求的客户端
// wxid: 待添加好友的微信ID
// remark: 对好友的备注信息
// roomWxid: 若是在某个群聊中发起的好友申请此参数为群聊的微信ID
// sourceType: 好友申请的来源类型群聊14
func (w *WxApi) AddFriend(request AddFriendRequest) (err error) {
_, err = w.internalCall(0, -1, MtAddFriendMsg, request, nil)
return err
}
type AcceptFriendRequest struct {
Encryptusername string `json:"encryptusername"`
Ticket string `json:"ticket"`
Scene int `json:"scene"`
}
type AcceptFriendResponse struct {
Data WxCommonData `json:"data"`
Type int `json:"type"`
}
// AcceptFriend 同意加好友申请
func (w *WxApi) AcceptFriend(request AcceptFriendRequest) *WxCommonData {
resp, err := w.internalCall(MtAcceptFriendMsg, 30, MtAcceptFriendMsg, request, nil)
if err != nil {
return &WxCommonData{Errcode: -1, Errmsg: err.Error()}
}
var rdata AcceptFriendResponse
err = json.Unmarshal([]byte(resp), rdata)
if err != nil {
return &WxCommonData{Errcode: -1, Errmsg: err.Error()}
}
return &rdata.Data
}
// DelFriend 删除好友
func (w *WxApi) DelFriend(wxid string) (err error) {
_, err = w.internalCall(0, -1, MtDelFriendMsg, map[string]interface{}{
"wxid": wxid,
}, nil)
return err
}
type SearchWxUserResponseData struct {
Account string `json:"account"`
Avatar string `json:"avatar"`
City string `json:"city"`
Country string `json:"country"`
Keyword string `json:"keyword"`
Nickname string `json:"nickname"`
Provice string `json:"provice"`
Search string `json:"search"`
Sex int `json:"sex"`
Signature string `json:"signature"`
SmallAvatar string `json:"small_avatar"`
Status int `json:"status"`
V1 string `json:"v1"`
V2 string `json:"v2"`
Wxid string `json:"wxid"`
}
type SearchWxUserResponse struct {
Data SearchWxUserResponseData `json:"data"`
Type int `json:"type"`
}
// SearchWxUser 搜索微信用户
func (w *WxApi) SearchWxUser(keyword string) (*SearchWxUserResponseData, error) {
resp, err := w.internalCall(MtSearchWxUserMsg, 20, MtSearchWxUserMsg, map[string]interface{}{"search": keyword}, nil)
if err != nil {
return nil, err
}
var rdata SearchWxUserResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type AddSearchWxUserRequest struct {
V1 string `json:"v1"`
V2 string `json:"v2"`
Remark string `json:"remark"`
}
type AddSearchWxUserResponse struct {
Data WxCommonData `json:"data"`
Type int `json:"type"`
}
// AddSearchWxUser 添加搜索用户
func (w *WxApi) AddSearchWxUser(request AddSearchWxUserRequest) *WxCommonData {
resp, err := w.internalCall(MtAddSearchUserMsg, 30, MtAddSearchUserMsg, request, nil)
if err != nil {
return &WxCommonData{Errcode: -1, Errmsg: err.Error()}
}
var rdata AddSearchWxUserResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return &WxCommonData{Errcode: -1, Errmsg: err.Error()}
}
return &rdata.Data
}
// CheckFriendStatus 检测好友状态(发送无痕清粉消息)
func (w *WxApi) CheckFriendStatus(wxid string) *WxCommonData {
resp, err := w.internalCall(MtZombieCheckMsg, 10, MtZombieCheckMsg, map[string]interface{}{"wxid": wxid}, nil)
if err != nil {
return &WxCommonData{Errcode: -1, Errmsg: err.Error()}
}
var rdata WxCommonResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return &WxCommonData{Errcode: -1, Errmsg: err.Error()}
}
return &rdata.Data
}
type AutoAcceptAddFriendRequest struct {
Auto int `json:"auto"` // 1自动同意 0取消自动同意
}
// AutoAcceptAddFriend 自动同意好友申请
func (w *WxApi) AutoAcceptAddFriend(request AutoAcceptAddFriendRequest) (err error) {
_, err = w.internalCall(0, -1, MtAutoAcceptFriendMsg, request, nil)
return err
}
type AutoAcceptCardRequest struct {
Auto int `json:"auto"` // 1自动接收 0取消自动接收
}
// AutoAcceptCard 自动接收名片
func (w *WxApi) AutoAcceptCard(request AutoAcceptCardRequest) error {
_, err := w.internalCall(0, -1, MtAutoAcceptCardMsg, request, nil)
return err
}
type AutoAcceptWCPayRequest struct {
Auto int `json:"auto"` // 1自动接收 0取消自动接收
}
// AutoAcceptWCPay 自动接收好友转账
func (w *WxApi) AutoAcceptWCPay(request AutoAcceptWCPayRequest) error {
_, err := w.internalCall(0, -1, MtAutoAcceptWcpayMsg, request, nil)
return err
}
type GetPublicUserListResponse struct {
Data []GetPublicUserListResponseData `json:"data"`
Type int `json:"type"`
}
type GetPublicUserListResponseData struct {
Avatar string `json:"avatar"`
Nickname string `json:"nickname"`
Wxid string `json:"wxid"`
}
func (w *WxApi) GetPublicUserList() ([]GetPublicUserListResponseData, error) {
resp, err := w.internalCall(MtDataPublicsMsg, 30, MtDataPublicsMsg, nil, map[string]interface{}{})
if err != nil {
return nil, err
}
var rdata GetPublicUserListResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return rdata.Data, nil
}

94
core/callapi_live.go Normal file
View File

@ -0,0 +1,94 @@
package core
import "github.com/goWxHook/goWxHook/utils/json"
type LiveEnterRequest struct {
ObjectId string `json:"object_id"`
LiveId string `json:"live_id"`
ObjectNonceId string `json:"object_nonce_id"`
}
// LiveEnter 进入直播间
func (w *WxApi) LiveEnter(request LiveEnterRequest) error {
_, err := w.internalCall(0, -1, MtLiveEnterMsg, request, nil)
return err
}
type LiveGetOnlineUserRequest struct {
ObjectId string `json:"object_id"`
LiveId string `json:"live_id"`
ObjectNonceId string `json:"object_nonce_id"`
LastBuff string `json:"last_buff"`
}
type LiveGetOnlineUserResponse struct {
Data interface{} `json:"data"`
Type int `json:"type"`
}
// LiveGetOnlineUser 获取直播间在线用户
func (w *WxApi) LiveGetOnlineUser(request LiveGetOnlineUserRequest) (interface{}, error) {
resp, err := w.internalCall(MtLiveGetOnlineUserMsg, 60, MtLiveGetOnlineUserMsg, request, nil)
if err != nil {
return nil, err
}
var rdata LiveGetOnlineUserResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return rdata.Data, nil
}
type LiveGetChangeInfoResponse struct {
Data interface{} `json:"data"`
Type int `json:"type"`
}
// LiveGetChangeInfo 获取直播间变动信息(人气,实时发言等))
func (w *WxApi) LiveGetChangeInfo() (interface{}, error) {
resp, err := w.internalCall(MtLiveGetChangeInfoMsg, 60, MtLiveGetChangeInfoMsg, map[string]interface{}{}, nil)
if err != nil {
return nil, err
}
var rdata LiveGetChangeInfoResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return rdata.Data, nil
}
type LiveSendMsgRequest struct {
Content string `json:"content"`
}
// LiveSendMsg 发送直播间消息
func (w *WxApi) LiveSendMsg(request LiveSendMsgRequest) error {
_, err := w.internalCall(0, -1, MtLiveSendMsg, request, nil)
return err
}
type LiveGetShelfRequest struct {
LiveUsername string `json:"live_username"`
RequestId string `json:"request_id"`
}
type LiveGetShelfResponse struct {
Data interface{} `json:"data"`
Type int `json:"type"`
}
// LiveGetShelf 获取直播间货架
func (w *WxApi) LiveGetShelf(request LiveGetShelfRequest) (interface{}, error) {
resp, err := w.internalCall(MtLiveGetShelfMsg, 60, MtLiveGetShelfMsg, request, nil)
if err != nil {
return nil, err
}
var rdata LiveGetShelfResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return rdata.Data, nil
}

71
core/callapi_login.go Normal file
View File

@ -0,0 +1,71 @@
package core
import "github.com/goWxHook/goWxHook/utils/json"
type GetLoginUserInfoResponseData struct {
Account string `json:"account"`
Avatar string `json:"avatar"`
Nickname string `json:"nickname"`
Wxid string `json:"wxid"`
Phone string `json:"phone"`
Pid int `json:"pid"`
UnreadMsgCount int `json:"unread_msg_count"`
WxUserDir string `json:"wx_user_dir"`
}
type GetLoginUserInfoResponse struct {
Data GetLoginUserInfoResponseData `json:"data"`
Type int `json:"type"`
}
// GetLoginUserInfo 获取登录用户信息
func (w *WxApi) GetLoginUserInfo() (*GetLoginUserInfoResponseData, error) {
resp, err := w.internalCall(MtDataOwnerMsg, 10, MtDataOwnerMsg, nil, map[string]interface{}{})
if err != nil {
return nil, err
}
var rdata GetLoginUserInfoResponse
debugOutput(resp)
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type RefreshLoginQrcodeResponse struct {
Data RefreshLoginQrCodeResponseData `json:"data"`
Type int `json:"type"`
}
type RefreshLoginQrCodeResponseData struct {
File string `json:"file"`
Qrcode string `json:"qrcode"`
Pid int `json:"pid"`
}
// RefreshLoginQrCode 刷新登录二维码
func (w *WxApi) RefreshLoginQrCode() (*RefreshLoginQrCodeResponseData, error) {
resp, err := w.internalCall(MtRefreshLoginQrcode, 10, MtRefreshLoginQrcode, map[string]interface{}{}, nil)
if err != nil {
return nil, err
}
var rdata RefreshLoginQrcodeResponse
debugOutput(resp)
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
// WxUserLogout 注销登录
func (w *WxApi) WxUserLogout() error {
_, err := w.internalCall(0, 10, MtLogoutMsg, nil, map[string]interface{}{})
return err
}
// WxExit 退出微信
func (w *WxApi) WxExit() error {
_, err := w.internalCall(0, 10, MtExitMsg, nil, map[string]interface{}{})
return err
}

114
core/callapi_message.go Normal file
View File

@ -0,0 +1,114 @@
package core
type SendTextMsgRequest struct {
ToWxid string `json:"to_wxid"`
Content string `json:"content"`
AtList []string `json:"at_list"` // 群消息时候使用 "notify@all" @所有人
}
// SendTextMsg 发送文本消息
func (w *WxApi) SendTextMsg(request SendTextMsgRequest) (err error) {
if len(request.AtList) > 0 {
_, err = w.internalCall(0, -1, MtSendChatroomAtmsg, request, nil)
if err != nil {
return err
}
} else {
_, err = w.internalCall(0, -1, MtSendTextmsg, request, nil)
if err != nil {
return err
}
}
return nil
}
type SendCardMsgRequest struct {
ToWxid string `json:"to_wxid"`
CardWxid string `json:"card_wxid"`
}
// SendCardMsg 发送名片消息
func (w *WxApi) SendCardMsg(request SendCardMsgRequest) (err error) {
_, err = w.internalCall(0, -1, MtSendCardmsg, request, nil)
return err
}
type SendLinkMsgRequest struct {
ToWxid string `json:"to_wxid"`
Title string `json:"title"`
Desc string `json:"desc"`
Url string `json:"url"`
ImageUrl string `json:"image_url"`
}
// SendLinkMsg 发送链接消息
func (w *WxApi) SendLinkMsg(request SendLinkMsgRequest) (err error) {
_, err = w.internalCall(0, -1, MtSendLinkmsg, request, nil)
return err
}
type SendImageMsgRequest struct {
ToWxid string `json:"to_wxid"`
File string `json:"file"` // 例如 "C:\\a.jpg"
}
// SendImageMsg 发送图片消息
func (w *WxApi) SendImageMsg(request SendImageMsgRequest) (err error) {
_, err = w.internalCall(0, 60, MtSendImgmsg, request, nil)
return err
}
type SendFileMsgRequest struct {
ToWxid string `json:"to_wxid"`
File string `json:"file"`
}
// SendFileMsg 发送文件消息
func (w *WxApi) SendFileMsg(request SendFileMsgRequest) (err error) {
_, err = w.internalCall(0, -1, MtSendFilemsg, request, nil)
return err
}
type SendVideoMsgRequest struct {
ToWxid string `json:"to_wxid"`
File string `json:"file"`
}
// SendVideoMsg 发送视频消息
func (w *WxApi) SendVideoMsg(request SendVideoMsgRequest) (err error) {
_, err = w.internalCall(0, -1, MtSendVideomsg, request, nil)
return err
}
type SendGifMsgRequest struct {
ToWxid string `json:"to_wxid"`
File string `json:"file"`
}
// SendGifMsg 发送GIF消息
func (w *WxApi) SendGifMsg(request SendGifMsgRequest) (err error) {
_, err = w.internalCall(0, -1, MtSendGifmsg, request, nil)
return err
}
type SendXmlMsgRequest struct {
ToWxid string `json:"to_wxid"`
Xml string `json:"xml"`
}
// SendXmlMsg 发送XML原始消息
func (w *WxApi) SendXmlMsg(request SendXmlMsgRequest) (err error) {
_, err = w.internalCall(0, -1, MtSendXmlMsg, request, nil)
return err
}
type ForwardMsgRequest struct {
ToWxid string `json:"to_wxid"`
Msgid string `json:"msgid"`
}
// ForwardMsg 转发任意类型消息
func (w *WxApi) ForwardMsg(request ForwardMsgRequest) (err error) {
_, err = w.internalCall(0, -1, MtForwardMsg, request, nil)
return err
}

446
core/callapi_moment.go Normal file
View File

@ -0,0 +1,446 @@
package core
import "github.com/goWxHook/goWxHook/utils/json"
type GetMomentRequest struct {
MaxId string `json:"max_id"`
}
type GetMomentResponseData interface{}
type GetMomentResponse struct {
Data GetMomentResponseData `json:"data"`
Type int `json:"type"`
}
// GetMoment 获取朋友圈
func (w *WxApi) GetMoment(request GetMomentRequest) (GetMomentResponseData, error) {
resp, err := w.internalCall(MtGetMomentMsg, 60, MtGetMomentMsg, request, nil)
if err != nil {
return nil, err
}
var rdata GetMomentResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type CommentMomentRequest struct {
ObjectId string `json:"object_id"`
Content string `json:"content"`
}
type CommentMomentResponseData struct {
BaseResponse struct {
ErrMsg struct {
} `json:"errMsg"`
Ret int `json:"ret"`
} `json:"baseResponse"`
SnsObject struct {
BlackList []interface{} `json:"blackList"`
BlackListCount int `json:"blackListCount"`
CommentCount int `json:"commentCount"`
CommentUserList []struct {
CommentFlag int `json:"commentFlag"`
CommentId int `json:"commentId"`
CommentId2 string `json:"commentId2"`
Content string `json:"content"`
CreateTime int `json:"createTime"`
DeleteFlag int `json:"deleteFlag"`
IsNotRichText int `json:"isNotRichText"`
Nickname string `json:"nickname"`
ReplyCommentId int `json:"replyCommentId"`
ReplyCommentId2 string `json:"replyCommentId2"`
ReplyUsername string `json:"replyUsername"`
Source int `json:"source"`
Type int `json:"type"`
Username string `json:"username"`
} `json:"commentUserList"`
CommentUserListCount int `json:"commentUserListCount"`
CreateTime int `json:"createTime"`
DeleteFlag int `json:"deleteFlag"`
ExtFlag int `json:"extFlag"`
GroupCount int `json:"groupCount"`
GroupList []interface{} `json:"groupList"`
GroupUser []interface{} `json:"groupUser"`
GroupUserCount int `json:"groupUserCount"`
Id string `json:"id"`
IsNotRichText int `json:"isNotRichText"`
LikeCount int `json:"likeCount"`
LikeFlag int `json:"likeFlag"`
LikeUserList []struct {
CommentFlag int `json:"commentFlag"`
CommentId int `json:"commentId"`
CommentId2 string `json:"commentId2"`
Content string `json:"content"`
CreateTime int `json:"createTime"`
DeleteFlag int `json:"deleteFlag"`
IsNotRichText int `json:"isNotRichText"`
Nickname string `json:"nickname"`
ReplyCommentId int `json:"replyCommentId"`
ReplyCommentId2 string `json:"replyCommentId2"`
ReplyUsername string `json:"replyUsername"`
Source int `json:"source"`
Type int `json:"type"`
Username string `json:"username"`
} `json:"likeUserList"`
LikeUserListCount int `json:"likeUserListCount"`
Nickname string `json:"nickname"`
NoChange int `json:"noChange"`
ObjectDesc struct {
Buffer string `json:"buffer"`
ILen int `json:"iLen"`
} `json:"objectDesc"`
ObjectOperations struct {
Buffer string `json:"buffer"`
ILen int `json:"iLen"`
} `json:"objectOperations"`
PreDownloadInfo struct {
NoPreDownloadRange string `json:"noPreDownloadRange"`
PreDownloadNetType int `json:"preDownloadNetType"`
PreDownloadPercent int `json:"preDownloadPercent"`
} `json:"preDownloadInfo"`
ReferId string `json:"referId"`
ReferUsername string `json:"referUsername"`
SnsRedEnvelops struct {
ReportId int `json:"reportId"`
ReportKey int `json:"reportKey"`
ResourceId int `json:"resourceId"`
RewardCount int `json:"rewardCount"`
RewardUserList []interface{} `json:"rewardUserList"`
} `json:"snsRedEnvelops"`
Username string `json:"username"`
WeAppInfo struct {
AppId int `json:"appId"`
MapPoiId string `json:"mapPoiId"`
RedirectUrl string `json:"redirectUrl"`
Score int `json:"score"`
ShowType int `json:"showType"`
UserName string `json:"userName"`
} `json:"weAppInfo"`
WithUserCount int `json:"withUserCount"`
WithUserList []interface{} `json:"withUserList"`
WithUserListCount int `json:"withUserListCount"`
} `json:"snsObject"`
}
type CommentMomentResponse struct {
Data CommentMomentResponseData `json:"data"`
Type int `json:"type"`
}
// CommentMoment 评论朋友圈
func (w *WxApi) CommentMoment(request CommentMomentRequest) (*CommentMomentResponseData, error) {
resp, err := w.internalCall(MtCommentMomentMsg, 60, MtCommentMomentMsg, request, nil)
if err != nil {
return nil, err
}
var rdata CommentMomentResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type LikeMomentRequest struct {
ObjectId string `json:"object_id"`
}
type LikeMomentResponseData struct {
BaseResponse struct {
ErrMsg struct {
} `json:"errMsg"`
Ret int `json:"ret"`
} `json:"baseResponse"`
SnsObject struct {
BlackList []interface{} `json:"blackList"`
BlackListCount int `json:"blackListCount"`
CommentCount int `json:"commentCount"`
CommentUserList []struct {
CommentFlag int `json:"commentFlag"`
CommentId int `json:"commentId"`
CommentId2 string `json:"commentId2"`
Content string `json:"content"`
CreateTime int `json:"createTime"`
DeleteFlag int `json:"deleteFlag"`
IsNotRichText int `json:"isNotRichText"`
Nickname string `json:"nickname"`
ReplyCommentId int `json:"replyCommentId"`
ReplyCommentId2 string `json:"replyCommentId2"`
ReplyUsername string `json:"replyUsername"`
Source int `json:"source"`
Type int `json:"type"`
Username string `json:"username"`
} `json:"commentUserList"`
CommentUserListCount int `json:"commentUserListCount"`
CreateTime int `json:"createTime"`
DeleteFlag int `json:"deleteFlag"`
ExtFlag int `json:"extFlag"`
GroupCount int `json:"groupCount"`
GroupList []interface{} `json:"groupList"`
GroupUser []interface{} `json:"groupUser"`
GroupUserCount int `json:"groupUserCount"`
Id string `json:"id"`
IsNotRichText int `json:"isNotRichText"`
LikeCount int `json:"likeCount"`
LikeFlag int `json:"likeFlag"`
LikeUserList []struct {
CommentFlag int `json:"commentFlag"`
CommentId int `json:"commentId"`
CommentId2 string `json:"commentId2"`
Content string `json:"content"`
CreateTime int `json:"createTime"`
DeleteFlag int `json:"deleteFlag"`
IsNotRichText int `json:"isNotRichText"`
Nickname string `json:"nickname"`
ReplyCommentId int `json:"replyCommentId"`
ReplyCommentId2 string `json:"replyCommentId2"`
ReplyUsername string `json:"replyUsername"`
Source int `json:"source"`
Type int `json:"type"`
Username string `json:"username"`
} `json:"likeUserList"`
LikeUserListCount int `json:"likeUserListCount"`
Nickname string `json:"nickname"`
NoChange int `json:"noChange"`
ObjectDesc struct {
Buffer string `json:"buffer"`
ILen int `json:"iLen"`
} `json:"objectDesc"`
ObjectOperations struct {
Buffer string `json:"buffer"`
ILen int `json:"iLen"`
} `json:"objectOperations"`
PreDownloadInfo struct {
NoPreDownloadRange string `json:"noPreDownloadRange"`
PreDownloadNetType int `json:"preDownloadNetType"`
PreDownloadPercent int `json:"preDownloadPercent"`
} `json:"preDownloadInfo"`
ReferId string `json:"referId"`
ReferUsername string `json:"referUsername"`
SnsRedEnvelops struct {
ReportId int `json:"reportId"`
ReportKey int `json:"reportKey"`
ResourceId int `json:"resourceId"`
RewardCount int `json:"rewardCount"`
RewardUserList []interface{} `json:"rewardUserList"`
} `json:"snsRedEnvelops"`
Username string `json:"username"`
WeAppInfo struct {
AppId int `json:"appId"`
MapPoiId string `json:"mapPoiId"`
RedirectUrl string `json:"redirectUrl"`
Score int `json:"score"`
ShowType int `json:"showType"`
UserName string `json:"userName"`
} `json:"weAppInfo"`
WithUserCount int `json:"withUserCount"`
WithUserList []interface{} `json:"withUserList"`
WithUserListCount int `json:"withUserListCount"`
} `json:"snsObject"`
}
type LikeMomentResponse struct {
Data LikeMomentResponseData `json:"data"`
Type int `json:"type"`
}
// LikeMoment 点赞朋友圈
func (w *WxApi) LikeMoment(request LikeMomentRequest) (*LikeMomentResponseData, error) {
resp, err := w.internalCall(MtLikeMomentMsg, 60, MtLikeMomentMsg, request, nil)
if err != nil {
return nil, err
}
var rdata LikeMomentResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type SendMomentRequest struct {
ObjectDesc string `json:"object_desc"`
}
type SendMomentResponseData struct {
BaseResponse struct {
ErrMsg struct {
} `json:"errMsg"`
Ret int `json:"ret"`
} `json:"baseResponse"`
SnsObject struct {
BlackList []interface{} `json:"blackList"`
BlackListCount int `json:"blackListCount"`
CommentCount int `json:"commentCount"`
CommentUserList []interface{} `json:"commentUserList"`
CommentUserListCount int `json:"commentUserListCount"`
CreateTime int `json:"createTime"`
DeleteFlag int `json:"deleteFlag"`
ExtFlag int `json:"extFlag"`
GroupCount int `json:"groupCount"`
GroupList []interface{} `json:"groupList"`
GroupUser []interface{} `json:"groupUser"`
GroupUserCount int `json:"groupUserCount"`
Id string `json:"id"`
IsNotRichText int `json:"isNotRichText"`
LikeCount int `json:"likeCount"`
LikeFlag int `json:"likeFlag"`
LikeUserList []interface{} `json:"likeUserList"`
LikeUserListCount int `json:"likeUserListCount"`
Nickname string `json:"nickname"`
NoChange int `json:"noChange"`
ObjectDesc struct {
Buffer string `json:"buffer"`
ILen int `json:"iLen"`
} `json:"objectDesc"`
ObjectOperations struct {
Buffer string `json:"buffer"`
ILen int `json:"iLen"`
} `json:"objectOperations"`
PreDownloadInfo struct {
NoPreDownloadRange string `json:"noPreDownloadRange"`
PreDownloadNetType int `json:"preDownloadNetType"`
PreDownloadPercent int `json:"preDownloadPercent"`
} `json:"preDownloadInfo"`
ReferId string `json:"referId"`
ReferUsername string `json:"referUsername"`
SnsRedEnvelops struct {
ReportId int `json:"reportId"`
ReportKey int `json:"reportKey"`
ResourceId int `json:"resourceId"`
RewardCount int `json:"rewardCount"`
RewardUserList []interface{} `json:"rewardUserList"`
} `json:"snsRedEnvelops"`
Username string `json:"username"`
WeAppInfo struct {
AppId int `json:"appId"`
MapPoiId string `json:"mapPoiId"`
RedirectUrl string `json:"redirectUrl"`
Score int `json:"score"`
ShowType int `json:"showType"`
UserName string `json:"userName"`
} `json:"weAppInfo"`
WithUserCount int `json:"withUserCount"`
WithUserList []interface{} `json:"withUserList"`
WithUserListCount int `json:"withUserListCount"`
} `json:"snsObject"`
SpamTips string `json:"spamTips"`
}
type SendMomentResponse struct {
Data SendMomentResponseData `json:"data"`
Type int `json:"type"`
}
// SendMoment 发送朋友圈
func (w *WxApi) SendMoment(request SendMomentRequest) (*SendMomentResponseData, error) {
resp, err := w.internalCall(MtSendMomentMsg, 60, MtSendMomentMsg, request, nil)
if err != nil {
return nil, err
}
var rdata SendMomentResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type UploadMomentImageRequest struct {
Path string `json:"path"`
}
type UploadMomentImageResponseData struct {
BaseResponse struct {
Ret int `json:"ret"`
} `json:"baseResponse"`
BufferUrl struct {
Type int `json:"type"`
Url string `json:"url"`
} `json:"bufferUrl"`
ClientId string `json:"clientId"`
Id int `json:"id"`
StartPos int `json:"startPos"`
ThumbUrlCount int `json:"thumbUrlCount"`
ThumbUrls []struct {
Type int `json:"type"`
Url string `json:"url"`
} `json:"thumbUrls"`
TotalLen int `json:"totalLen"`
Type int `json:"type"`
}
type UploadMomentImageResponse struct {
Data UploadMomentImageResponseData `json:"data"`
Type int `json:"type"`
}
// UploadMomentImage 上传朋友圈图片
func (w *WxApi) UploadMomentImage(request UploadMomentImageRequest) (*UploadMomentImageResponseData, error) {
resp, err := w.internalCall(MtUploadMomentImageMsg, 60, MtUploadMomentImageMsg, request, nil)
if err != nil {
return nil, err
}
var rdata UploadMomentImageResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type GetFriendMomentRequest struct {
Username string `json:"username"`
FirstPageMd5 string `json:"first_page_md5"`
MaxId string `json:"max_id"`
}
type GetFriendMomentResponseData struct {
BaseResponse struct {
ErrMsg struct {
} `json:"errMsg"`
Ret int `json:"ret"`
} `json:"baseResponse"`
ContinueId string `json:"continueId"`
FirstPageMd5 string `json:"firstPageMd5"`
LimitedId string `json:"limitedId"`
NewRequestTime int `json:"newRequestTime"`
ObjectCount int `json:"objectCount"`
ObjectCountForSameMd5 int `json:"objectCountForSameMd5"`
ObjectList []interface{} `json:"objectList"`
ObjectTotalCount int `json:"objectTotalCount"`
RetTips string `json:"retTips"`
ServerConfig struct {
CopyAndPasteWordLimit int `json:"copyAndPasteWordLimit"`
PostMentionLimit int `json:"postMentionLimit"`
} `json:"serverConfig"`
SnsUserInfo struct {
SnsBgImgId string `json:"snsBgImgId"`
SnsBgObjectId string `json:"snsBgObjectId"`
SnsFlag int `json:"snsFlag"`
SnsFlagEx int `json:"snsFlagEx"`
} `json:"snsUserInfo"`
}
type GetFriendMomentResponse struct {
Data GetFriendMomentResponseData `json:"data"`
Type int `json:"type"`
}
// GetFriendMoment 获取好友朋友圈
func (w *WxApi) GetFriendMoment(request GetFriendMomentRequest) (*GetFriendMomentResponseData, error) {
resp, err := w.internalCall(MtGetFriendMomentMsg, 60, MtGetFriendMomentMsg, request, nil)
if err != nil {
return nil, err
}
var rdata GetFriendMomentResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}

49
core/callapi_mp.go Normal file
View File

@ -0,0 +1,49 @@
package core
import "github.com/goWxHook/goWxHook/utils/json"
type GetMiniProgramCodeRequest struct {
Appid string `json:"appid"`
}
type GetMiniProgramCodeResponseData struct {
AppIconUrl string `json:"appIconUrl"`
AppName string `json:"appName"`
BaseResponse struct {
ErrMsg struct {
String string `json:"string"`
} `json:"errMsg"`
Ret int `json:"ret"`
} `json:"baseResponse"`
Code string `json:"code"`
JsApiBaseResponse struct {
Errcode int `json:"errcode"`
Errmsg string `json:"errmsg"`
} `json:"jsApiBaseResponse"`
LiftSpan int `json:"liftSpan"`
OpenId string `json:"openId"`
ScopeList []interface{} `json:"scopeList"`
SessionKey string `json:"sessionKey"`
SessionTicket string `json:"sessionTicket"`
Signature string `json:"signature"`
State string `json:"state"`
}
type GetMiniProgramCodeResponse struct {
Data GetMiniProgramCodeResponseData `json:"data"`
Type int `json:"type"`
}
// GetMiniProgramCode 获取小程序授权Code
func (w *WxApi) GetMiniProgramCode(request GetMiniProgramCodeRequest) (*GetMiniProgramCodeResponseData, error) {
resp, err := w.internalCall(MtGetMiniProgramCodeMsg, 60, MtGetMiniProgramCodeMsg, request, nil)
if err != nil {
return nil, err
}
var rdata GetMiniProgramCodeResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}

86
core/callapi_other.go Normal file
View File

@ -0,0 +1,86 @@
package core
import "github.com/goWxHook/goWxHook/utils/json"
type GetA8KeyRequest struct {
Url string `json:"url"`
Scene int `json:"scene"`
}
type GetA8KeyResponseData struct {
A8Key string `json:"a8Key"`
ActionCode int `json:"actionCode"`
AntispamTicket string `json:"antispamTicket"`
BaseResponse struct {
ErrMsg struct {
} `json:"errMsg"`
Ret int `json:"ret"`
} `json:"baseResponse"`
Content string `json:"content"`
Cookie struct {
Buffer string `json:"buffer"`
ILen int `json:"iLen"`
} `json:"cookie"`
DeepLinkBitSet struct {
BitValue string `json:"bitValue"`
} `json:"deepLinkBitSet"`
FullUrl string `json:"fullUrl"`
GeneralControlBitSet struct {
BitValue int `json:"bitValue"`
} `json:"generalControlBitSet"`
HeadImg string `json:"headImg"`
HttpHeaderCount int `json:"httpHeaderCount"`
HttpHeaderList []struct {
Key string `json:"key"`
Value string `json:"value"`
} `json:"httpHeaderList"`
JsapicontrolBytes struct {
Buffer string `json:"buffer"`
ILen int `json:"iLen"`
} `json:"jsapicontrolBytes"`
Jsapipermission struct {
BitValue int `json:"bitValue"`
BitValue2 int `json:"bitValue2"`
BitValue3 int `json:"bitValue3"`
BitValue4 int `json:"bitValue4"`
} `json:"jsapipermission"`
MenuWording string `json:"menuWording"`
Mid string `json:"mid"`
ScopeCount int `json:"scopeCount"`
ScopeList []interface{} `json:"scopeList"`
ShareUrl string `json:"shareUrl"`
Ssid string `json:"ssid"`
Title string `json:"title"`
UserName string `json:"userName"`
Wording string `json:"wording"`
}
type GetA8KeyResponse struct {
Data GetA8KeyResponseData `json:"data"`
Type int `json:"type"`
}
// GetA8Key 获取A8Key
func (w *WxApi) GetA8Key(request GetA8KeyRequest) (*GetA8KeyResponseData, error) {
resp, err := w.internalCall(MtGetA8KeyMsg, 60, MtGetA8KeyMsg, request, nil)
if err != nil {
return nil, err
}
var rdata GetA8KeyResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type DecryptImgRequest struct {
SrcFile string `json:"src_file"`
DestFile string `json:"dest_file"`
}
// DecryptImg 解密图片
func (w *WxApi) DecryptImg(request DecryptImgRequest) error {
_, err := w.internalCall(0, -1, MtDecryptImgMsg, request, nil)
return err
}

352
core/callapi_room.go Normal file
View File

@ -0,0 +1,352 @@
package core
import (
"github.com/goWxHook/goWxHook/utils"
"github.com/goWxHook/goWxHook/utils/json"
)
type GetChatRoomListResponse struct {
Data []GetChatRoomListResponseDataItem `json:"data"`
Type int `json:"type"`
}
type GetChatRoomListResponseDataItem struct {
Avatar string `json:"avatar"`
IsManager int `json:"is_manager"`
ManagerWxid string `json:"manager_wxid"`
MemberList []string `json:"member_list"`
Nickname string `json:"nickname"`
Remark string `json:"remark"`
TotalMember int `json:"total_member"`
Wxid string `json:"wxid"`
}
// GetChatRoomList 群聊列表
func (w *WxApi) GetChatRoomList() ([]GetChatRoomListResponseDataItem, error) {
resp, err := w.internalCall(MtDataChatroomsMsg, 10, MtDataChatroomsMsg, map[string]interface{}{"detail": 1}, nil)
if err != nil {
return nil, err
}
var rdata GetChatRoomListResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return rdata.Data, nil
}
type GetChatRoomMemberListResponse struct {
Data GetChatRoomMemberListResponseData `json:"data"`
Type int `json:"type"`
}
type GetChatRoomMemberListResponseData struct {
Extend string `json:"extend"`
GroupWxid string `json:"group_wxid"`
MemberList []struct {
Account string `json:"account"`
Avatar string `json:"avatar"`
City string `json:"city"`
Country string `json:"country"`
DisplayName string `json:"display_name"`
Nickname string `json:"nickname"`
Province string `json:"province"`
Remark string `json:"remark"`
Sex int `json:"sex"`
Wxid string `json:"wxid"`
} `json:"member_list"`
Total int `json:"total"`
}
// GetChatRoomMemberList 获取群成员列表
func (w *WxApi) GetChatRoomMemberList(roomWxid string) (*GetChatRoomMemberListResponseData, error) {
resp, err := w.internalCall(MtDataChatroomMembersMsg, 20, MtDataChatroomMembersMsg, map[string]interface{}{"room_wxid": roomWxid}, nil)
if err != nil {
return nil, err
}
var rdata GetChatRoomMemberListResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
// GetRoomDetailInfoByProtocol 获取群详细信息(协议)
func (w *WxApi) GetRoomDetailInfoByProtocol(roomWxid string) ([]GetFriendDetailInfoByProtocolResponseDataContactListItem, error) {
resp, err := w.internalCall(MtGetFriendDetailMsg, 20, MtGetFriendDetailMsg, map[string]interface{}{"wxid": roomWxid}, nil)
if err != nil {
return nil, err
}
var rdata GetFriendDetailInfoByProtocolResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return rdata.Data.ContactList, nil
}
type GetRoomMemberInviteListResponseData struct {
MemberList []struct {
Avatar string `json:"avatar"`
Flag int `json:"flag"`
InviteBy string `json:"invite_by"`
Nickname string `json:"nickname"`
Wxid string `json:"wxid"`
} `json:"member_list"`
RoomWxid string `json:"room_wxid"`
}
type GetRoomMemberInviteListResponse struct {
Data GetRoomMemberInviteListResponseData `json:"data"`
Type int `json:"type"`
}
// GetRoomMemberInviteList 获取群成员邀请关系(协议)
func (w *WxApi) GetRoomMemberInviteList(roomWxid string) (*GetRoomMemberInviteListResponseData, error) {
resp, err := w.internalCall(MtGetChatRoomInviteRelationMsg, 20, MtGetChatRoomInviteRelationMsg, map[string]interface{}{"room_wxid": roomWxid}, nil)
if err != nil {
return nil, err
}
var rdata GetRoomMemberInviteListResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type CreateRoomRequest struct {
Wxids []string `json:"wxids"`
}
// CreateChatRoom 创建群聊
func (w *WxApi) CreateChatRoom(request CreateRoomRequest) error {
_, err := w.internalCall(0, -1, MtCreateRoomMsg, request.Wxids, nil)
return err
}
type CreateChatRoomByProtocolResponseData struct {
BaseResponse struct {
ErrMsg struct {
String string `json:"string"`
} `json:"errMsg"`
Ret int `json:"ret"`
} `json:"baseResponse"`
BigHeadImgUrl string `json:"bigHeadImgUrl"`
ChatRoomName struct {
String string `json:"string"`
} `json:"chatRoomName"`
ImgBuf struct {
Buffer string `json:"buffer"`
ILen int `json:"iLen"`
} `json:"imgBuf"`
MemberCount int `json:"memberCount"`
MemberList []struct {
City string `json:"city"`
ContactType int `json:"contactType"`
Country string `json:"country"`
MemberName struct {
String string `json:"string"`
} `json:"memberName"`
MemberStatus int `json:"memberStatus"`
NickName struct {
String string `json:"string"`
} `json:"nickName"`
PersonalCard int `json:"personalCard"`
Province string `json:"province"`
PyInitial struct {
String string `json:"string"`
} `json:"pyInitial"`
QuanPin struct {
String string `json:"string"`
} `json:"quanPin"`
Remark struct {
} `json:"remark"`
RemarkPYInitial struct {
} `json:"remarkPYInitial"`
RemarkQuanPin struct {
} `json:"remarkQuanPin"`
Sex int `json:"sex"`
Signature string `json:"signature"`
VerifyFlag int `json:"verifyFlag"`
VerifyInfo string `json:"verifyInfo"`
} `json:"memberList"`
PyInitial struct {
} `json:"pyInitial"`
QuanPin struct {
} `json:"quanPin"`
SmallHeadImgUrl string `json:"smallHeadImgUrl"`
Topic struct {
} `json:"topic"`
}
type CreateChatRoomByProtocolResponse struct {
Data CreateChatRoomByProtocolResponseData `json:"data"`
Type int `json:"type"`
}
// CreateChatRoomByProtocol 创建群聊(协议)
func (w *WxApi) CreateChatRoomByProtocol(request CreateRoomRequest) (*CreateChatRoomByProtocolResponseData, error) {
resp, err := w.internalCall(MtCreateRoomByProtocolMsg, 20, MtCreateRoomByProtocolMsg, request.Wxids, nil)
if err != nil {
return nil, err
}
var rdata CreateChatRoomByProtocolResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type InviteToRoomRequest struct {
RoomWxid string `json:"room_wxid"`
MemberList []string `json:"member_list"`
}
type InviteToRoomResponseData struct {
BaseResponse struct {
ErrMsg struct {
String string `json:"string"`
} `json:"errMsg"`
Ret int `json:"ret"`
} `json:"baseResponse"`
MemberCount int `json:"memberCount"`
MemberList []struct {
City string `json:"city"`
ContactType int `json:"contactType"`
Country string `json:"country"`
MemberName struct {
String string `json:"string"`
} `json:"memberName"`
MemberStatus int `json:"memberStatus"`
NickName struct {
String string `json:"string"`
} `json:"nickName"`
PersonalCard int `json:"personalCard"`
Province string `json:"province"`
PyInitial struct {
String string `json:"string"`
} `json:"pyInitial"`
QuanPin struct {
String string `json:"string"`
} `json:"quanPin"`
Remark struct {
} `json:"remark"`
RemarkPYInitial struct {
} `json:"remarkPYInitial"`
RemarkQuanPin struct {
} `json:"remarkQuanPin"`
Sex int `json:"sex"`
Signature string `json:"signature"`
VerifyFlag int `json:"verifyFlag"`
VerifyInfo string `json:"verifyInfo"`
} `json:"memberList"`
}
type InviteToRoomResponse struct {
Data InviteToRoomResponseData `json:"data"`
Type int `json:"type"`
}
// InviteToRoom 批量拉人进入群聊
func (w *WxApi) InviteToRoom(request InviteToRoomRequest) (*InviteToRoomResponseData, error) {
rr := utils.Ifs(len(request.MemberList) > 40, MtInviteToRoomReqMsg, MtInviteToRoomMsg)
resp, err := w.internalCall(rr, 30, rr, request, nil)
if err != nil {
return nil, err
}
var rdata InviteToRoomResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type DelChatRoomMemberRequest struct {
RoomWxid string `json:"room_wxid"`
MemberList []string `json:"member_list"`
}
// DelChatRoomMember 删除群成员
func (w *WxApi) DelChatRoomMember(request DelChatRoomMemberRequest) error {
_, err := w.internalCall(MtDelRoomMemberMsg, 30, MtDelRoomMemberMsg, request, nil)
return err
}
type EditChatRoomMemberRequest struct {
RoomWxid string `json:"room_wxid"`
Name string `json:"name"`
}
// EditChatRoomName 修改群聊名称
func (w *WxApi) EditChatRoomName(request EditChatRoomMemberRequest) error {
_, err := w.internalCall(0, -1, MtModRoomNameMsg, request, nil)
return err
}
type EditChatRoomNoticeRequest struct {
RoomWxid string `json:"room_wxid"`
Notice string `json:"notice"`
}
// EditChatRoomNotice 修改群公告
func (w *WxApi) EditChatRoomNotice(request EditChatRoomNoticeRequest) error {
_, err := w.internalCall(0, -1, MtModRoomNoticeMsg, request, nil)
return err
}
type EditRoomMineNickNameRequest struct {
RoomWxid string `json:"room_wxid"`
Nickname string `json:"nickname"`
}
// EditRoomMineNickName 修改我在本群的昵称
func (w *WxApi) EditRoomMineNickName(request EditRoomMineNickNameRequest) error {
_, err := w.internalCall(0, -1, MtModRoomMemberNameMsg, request, nil)
return err
}
type RoomShowNickNameRequest struct {
RoomWxid string `json:"room_wxid"`
Status int `json:"status"` // 1显示 0隐藏
}
// RoomShowNickName 群聊是否显示昵称
func (w *WxApi) RoomShowNickName(request RoomShowNickNameRequest) error {
_, err := w.internalCall(0, -1, MtModRoomShowNameMsg, request, nil)
return err
}
type SaveRoomSaveToContactRequest struct {
RoomWxid string `json:"room_wxid"`
Status int `json:"status"` // 1保存 2移出
}
// SaveRoomSaveToContact 保存到/移出通讯录
func (w *WxApi) SaveRoomSaveToContact(request SaveRoomSaveToContactRequest) error {
_, err := w.internalCall(0, -1, MtSaveRoomToContactMsg, request, nil)
return err
}
type DelChatRoomRequest struct {
RoomWxid string `json:"room_wxid"`
}
// DelChatRoom 退出并删除群聊
func (w *WxApi) DelChatRoom(request DelChatRoomRequest) error {
_, err := w.internalCall(0, -1, MtQuitDelRoomMsg, request, nil)
return err
}
type AutoAcceptRoomRequest struct {
Auto int `json:"auto"` // 0不自动 1自动
}
// AutoAcceptRoom 自动接收群邀请
func (w *WxApi) AutoAcceptRoom(request AutoAcceptRoomRequest) error {
_, err := w.internalCall(0, -1, MtAutoAcceptRoomMsg, request, nil)
return err
}

158
core/callapi_tag.go Normal file
View File

@ -0,0 +1,158 @@
package core
import "github.com/goWxHook/goWxHook/utils/json"
type AddTagRequest struct {
LabelName string `json:"label_name"`
}
type AddTagResponseData struct {
LabelId int `json:"label_id"`
LabelName string `json:"label_name"`
}
type AddTagResponse struct {
Data AddTagResponseData `json:"data"`
Type int `json:"type"`
}
// AddTag 添加标签
func (w *WxApi) AddTag(request AddTagRequest) (*AddTagResponseData, error) {
resp, err := w.internalCall(MtAddTagMsg, 20, MtAddTagMsg, request, nil)
if err != nil {
return nil, err
}
var rdata AddTagResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type DeleteTagRequest struct {
LabelId int `json:"label_id"`
}
type DeleteTagResponseData struct {
BaseResponse struct {
ErrMsg struct {
} `json:"errMsg"`
Ret int `json:"ret"`
} `json:"baseResponse"`
}
type DeleteTagResponse struct {
Data DeleteTagResponseData `json:"data"`
Type int `json:"type"`
}
// DeleteTag 删除标签
func (w *WxApi) DeleteTag(request DeleteTagRequest) (*DeleteTagResponseData, error) {
resp, err := w.internalCall(MtDeleteTagMsg, 20, MtDeleteTagMsg, request, nil)
if err != nil {
return nil, err
}
var rdata DeleteTagResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type ModifyTagRequest struct {
LabelId int `json:"label_id"`
LabelName string `json:"label_name"`
}
// ModifyTag 修改标签
func (w *WxApi) ModifyTag(request ModifyTagRequest) error {
_, err := w.internalCall(MtModifyTagMsg, 20, MtModifyTagMsg, request, nil)
return err
}
type AddTagToUserRequest struct {
Wxid string `json:"wxid"`
LabelidList string `json:"labelid_list"`
}
type AddTagToUserResponseData struct {
BaseResponse struct {
ErrMsg struct {
String string `json:"string"`
} `json:"errMsg"`
Ret int `json:"ret"`
} `json:"baseResponse"`
}
type AddTagToUserResponse struct {
Data AddTagToUserResponseData `json:"data"`
Type int `json:"type"`
}
// AddTagToUser 为用户添加标签
func (w *WxApi) AddTagToUser(request AddTagToUserRequest) (*AddTagToUserResponseData, error) {
resp, err := w.internalCall(MtAddTagToUserMsg, 20, MtAddTagToUserMsg, request, nil)
if err != nil {
return nil, err
}
var rdata AddTagToUserResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type GetTagListByWxidRequest struct {
Wxid string `json:"wxid"`
}
type GetTagListByWxidResponseData struct {
LabelidList string `json:"labelid_list"`
Wxid string `json:"wxid"`
}
type GetTagListByWxidResponse struct {
Data GetTagListByWxidResponseData `json:"data"`
Type int `json:"type"`
}
// GetTagListByWxid 获取用户标签列表
func (w *WxApi) GetTagListByWxid(request GetTagListByWxidRequest) (*GetTagListByWxidResponseData, error) {
resp, err := w.internalCall(MtGetTagListByWxidMsg, 20, MtGetTagListByWxidMsg, request, nil)
if err != nil {
return nil, err
}
var rdata GetTagListByWxidResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type GetTagListResponseDataItem struct {
LabelId string `json:"label_id"`
LabelName string `json:"label_name"`
}
type GetTagListResponse struct {
Data []GetTagListResponseDataItem `json:"data"`
Type int `json:"type"`
}
// GetTagList 获取标签列表
func (w *WxApi) GetTagList() ([]GetTagListResponseDataItem, error) {
resp, err := w.internalCall(MtGetTagListMsg, 20, MtGetTagListMsg, nil, nil)
if err != nil {
return nil, err
}
var rdata GetTagListResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return rdata.Data, nil
}

39
core/callapi_ui.go Normal file
View File

@ -0,0 +1,39 @@
package core
type SwitchSessionRequest struct {
ToWxid string `json:"to_wxid"`
}
// SwitchSession 切换会话
func (w *WxApi) SwitchSession(request SwitchSessionRequest) error {
_, err := w.internalCall(0, -1, MtSwitchSessionMsg, request, nil)
return err
}
// ClearChatRecord 清空聊天记录
func (w *WxApi) ClearChatRecord() error {
_, err := w.internalCall(0, -1, MtClearChatRecordMsg, map[string]interface{}{}, nil)
return err
}
type ChatMsgNotNotifyRequest struct {
Wxid string `json:"wxid"`
Status int `json:"status"` // 1开启 0关闭
}
// ChatMsgNotNotify 消息免打扰
func (w *WxApi) ChatMsgNotNotify(request ChatMsgNotNotifyRequest) error {
_, err := w.internalCall(0, -1, MtModRecvNotifyMsg, request, nil)
return err
}
type ChatSessionTopRequest struct {
Wxid string `json:"wxid"`
Status int `json:"status"`
}
// ChatSessionTop 置顶会话
func (w *WxApi) ChatSessionTop(request ChatSessionTopRequest) error {
_, err := w.internalCall(0, -1, MtModChatSessionTopMsg, request, nil)
return err
}

View File

@ -0,0 +1,485 @@
package core
import "github.com/goWxHook/goWxHook/utils/json"
type VideoMomentInitResponseData struct {
AliasInfo []struct {
AliasMsgName string `json:"aliasMsgName"`
AliasVersion int `json:"aliasVersion"`
HeadImgUrl string `json:"headImgUrl"`
Nickname string `json:"nickname"`
RoleType int `json:"roleType"`
} `json:"aliasInfo"`
BaseResponse struct {
ErrMsg struct {
String string `json:"string"`
} `json:"errMsg"`
Ret int `json:"ret"`
} `json:"baseResponse"`
Cmdlist []interface{} `json:"cmdlist"`
ContinueFlag int `json:"continueFlag"`
CurrentAliasRoleType int `json:"currentAliasRoleType"`
FinderUsernameList []struct {
FinderUsernameList string `json:"finderUsernameList"`
} `json:"finderUsernameList"`
Keybuf struct {
Buffer string `json:"buffer"`
ILen int `json:"iLen"`
} `json:"keybuf"`
Myacct []struct {
ArchievementInfo struct {
} `json:"archievementInfo"`
AuthInfo struct {
} `json:"authInfo"`
BindInfo []interface{} `json:"bindInfo"`
CoverEntranceFlag int `json:"coverEntranceFlag"`
CoverImgUrl string `json:"coverImgUrl"`
CoverUrl string `json:"coverUrl"`
ExtFlag int `json:"extFlag"`
ExtInfo struct {
BirthDay int `json:"birthDay"`
BirthMonth int `json:"birthMonth"`
BirthYear int `json:"birthYear"`
City string `json:"city"`
Country string `json:"country"`
Province string `json:"province"`
Sex int `json:"sex"`
} `json:"extInfo"`
FansCount int `json:"fansCount"`
FeedCount int `json:"feedCount"`
FollowFlag int `json:"followFlag"`
FollowTime int `json:"followTime"`
ForeignUserFlag int `json:"foreignUserFlag"`
FriendFollowCount int `json:"friendFollowCount"`
GuestInfo struct {
} `json:"guestInfo"`
HeadUrl string `json:"headUrl"`
LiveCoverImgUrl string `json:"liveCoverImgUrl"`
LiveInfo struct {
AnchorStatusFlag string `json:"anchorStatusFlag"`
LotterySetting struct {
} `json:"lotterySetting"`
MicSetting struct {
SettingFlag string `json:"settingFlag"`
SettingSwitchFlag string `json:"settingSwitchFlag"`
} `json:"micSetting"`
SwitchFlag int `json:"switchFlag"`
} `json:"liveInfo"`
LiveNoticeInfo struct {
} `json:"liveNoticeInfo"`
LiveStatus int `json:"liveStatus"`
LoggingoutWording string `json:"loggingoutWording"`
Menu []interface{} `json:"menu"`
MsgInfo struct {
} `json:"msgInfo"`
Nickname string `json:"nickname"`
OneTimeFlag int `json:"oneTimeFlag"`
OriginalEntranceFlag int `json:"originalEntranceFlag"`
OriginalFlag int `json:"originalFlag"`
OriginalInfo struct {
PostNeedCheckFlag int `json:"postNeedCheckFlag"`
PunishYearFlag int `json:"punishYearFlag"`
RestApplyOriginalCount int `json:"restApplyOriginalCount"`
RestPunishDay int `json:"restPunishDay"`
RestRepostCount int `json:"restRepostCount"`
} `json:"originalInfo"`
Seq string `json:"seq"`
Signature string `json:"signature"`
SpamStatus int `json:"spamStatus"`
UserFlag int `json:"userFlag"`
UserMode int `json:"userMode"`
Username string `json:"username"`
VestNickname string `json:"vestNickname"`
WxUsernameV5 string `json:"wxUsernameV5"`
} `json:"myacct"`
NextAliasModAvailableTime string `json:"nextAliasModAvailableTime"`
RetryDelaySecond int `json:"retryDelaySecond"`
RingtoneConfig struct {
} `json:"ringtoneConfig"`
SlideUpGuideConfig []interface{} `json:"slideUpGuideConfig"`
TabInfos []struct {
DisplayTabType int `json:"displayTabType"`
TabName string `json:"tabName"`
} `json:"tabInfos"`
TeenmodeSetting struct {
} `json:"teenmodeSetting"`
TeenmodeTipsConfig struct {
} `json:"teenmodeTipsConfig"`
UserNotCreatedFlag int `json:"userNotCreatedFlag"`
Userver int `json:"userver"`
UserverForH5 int `json:"userverForH5"`
WxPersonalizedSetting struct {
} `json:"wxPersonalizedSetting"`
WxUserAttr struct {
NotAvailableFlag int `json:"notAvailableFlag"`
Wording string `json:"wording"`
} `json:"wxUserAttr"`
WxUsernameForH5 string `json:"wxUsernameForH5"`
}
type VideoMomentInitResponse struct {
Data VideoMomentInitResponseData `json:"data"`
Type int `json:"type"`
}
// VideoMomentInit 视频号初始化
func (w *WxApi) VideoMomentInit() (*VideoMomentInitResponseData, error) {
resp, err := w.internalCall(MtVideoMomentInitMsg, 120, MtVideoMomentInitMsg, nil, nil)
if err != nil {
return nil, err
}
var rdata VideoMomentInitResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type VideoMomentSearchRequest struct {
Query string `json:"query"`
LastBuff string `json:"last_buff"`
Scene int `json:"scene"`
}
type VideoMomentSearchResponse struct {
Data interface{} `json:"data"`
Type int `json:"type"`
}
// VideoMomentSearch 视频号搜索
func (w *WxApi) VideoMomentSearch(request VideoMomentSearchRequest) (interface{}, error) {
resp, err := w.internalCall(MtVideoMomentSearchMsg, 120, MtVideoMomentSearchMsg, request, nil)
if err != nil {
return nil, err
}
var rdata VideoMomentSearchResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return rdata.Data, nil
}
type VideoMomentUserHomeRequest struct {
Username string `json:"username"`
LastBuff string `json:"last_buff"`
}
type VideoMomentUserHomeResponse struct {
Data interface{} `json:"data"`
Type int `json:"type"`
}
// VideoMomentUserHome 视频号用户主页
func (w *WxApi) VideoMomentUserHome(request VideoMomentUserHomeRequest) (interface{}, error) {
resp, err := w.internalCall(MtVideoMomentUserHomeMsg, 120, MtVideoMomentUserHomeMsg, request, nil)
if err != nil {
return nil, err
}
var rdata VideoMomentUserHomeResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return rdata.Data, nil
}
type VideoMomentVideoDetailRequest struct {
ObjectId string `json:"object_id"`
ObjectNonceId string `json:"object_nonce_id"`
LastBuff string `json:"last_buff"`
}
type VideoMomentVideoDetailResponse struct {
Data interface{} `json:"data"`
Type int `json:"type"`
}
// VideoMomentVideoDetail 查看视频详细信息(包含评论)
func (w *WxApi) VideoMomentVideoDetail(request VideoMomentVideoDetailRequest) (interface{}, error) {
resp, err := w.internalCall(MtVideoMomentVideoDetailMsg, 120, MtVideoMomentVideoDetailMsg, request, nil)
if err != nil {
return nil, err
}
var rdata VideoMomentVideoDetailResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return rdata.Data, nil
}
type VideoMomentFollowRequest struct {
Username string `json:"username"`
}
type VideoMomentFollowResponseData struct {
BaseResponse struct {
ErrMsg struct {
String string `json:"string"`
} `json:"errMsg"`
Ret int `json:"ret"`
} `json:"baseResponse"`
Contact struct {
ArchievementInfo struct {
} `json:"archievementInfo"`
AuthInfo struct {
AppName string `json:"appName"`
AuthGuarantor struct {
} `json:"authGuarantor"`
AuthIconType int `json:"authIconType"`
AuthIconUrl string `json:"authIconUrl"`
AuthProfession string `json:"authProfession"`
AuthVerifyIdentity int `json:"authVerifyIdentity"`
CustomerType int `json:"customerType"`
DetailLink string `json:"detailLink"`
RealName string `json:"realName"`
VerifyStatus int `json:"verifyStatus"`
} `json:"authInfo"`
BindInfo []interface{} `json:"bindInfo"`
CoverEntranceFlag int `json:"coverEntranceFlag"`
CoverImgUrl string `json:"coverImgUrl"`
CoverUrl string `json:"coverUrl"`
ExtFlag int `json:"extFlag"`
ExtInfo struct {
BirthDay int `json:"birthDay"`
BirthMonth int `json:"birthMonth"`
BirthYear int `json:"birthYear"`
City string `json:"city"`
Country string `json:"country"`
Province string `json:"province"`
Sex int `json:"sex"`
} `json:"extInfo"`
FansCount int `json:"fansCount"`
FeedCount int `json:"feedCount"`
FollowFlag int `json:"followFlag"`
FollowTime int `json:"followTime"`
ForeignUserFlag int `json:"foreignUserFlag"`
FriendFollowCount int `json:"friendFollowCount"`
GuestInfo struct {
} `json:"guestInfo"`
HeadUrl string `json:"headUrl"`
LiveCoverImgUrl string `json:"liveCoverImgUrl"`
LiveInfo struct {
AnchorStatusFlag string `json:"anchorStatusFlag"`
LotterySetting struct {
AttendType int `json:"attendType"`
SettingFlag string `json:"settingFlag"`
} `json:"lotterySetting"`
MicSetting struct {
SettingFlag string `json:"settingFlag"`
SettingSwitchFlag string `json:"settingSwitchFlag"`
} `json:"micSetting"`
SwitchFlag int `json:"switchFlag"`
} `json:"liveInfo"`
LiveNoticeInfo struct {
} `json:"liveNoticeInfo"`
LiveStatus int `json:"liveStatus"`
LoggingoutWording string `json:"loggingoutWording"`
Menu []interface{} `json:"menu"`
MsgInfo struct {
} `json:"msgInfo"`
Nickname string `json:"nickname"`
OneTimeFlag int `json:"oneTimeFlag"`
OriginalEntranceFlag int `json:"originalEntranceFlag"`
OriginalFlag int `json:"originalFlag"`
OriginalInfo struct {
} `json:"originalInfo"`
Seq int `json:"seq"`
Signature string `json:"signature"`
SpamStatus int `json:"spamStatus"`
UserFlag int `json:"userFlag"`
UserMode int `json:"userMode"`
Username string `json:"username"`
VestNickname string `json:"vestNickname"`
WxUsernameV5 string `json:"wxUsernameV5"`
} `json:"contact"`
LiveStatusFlag int `json:"liveStatusFlag"`
}
type VideoMomentFollowResponse struct {
Data VideoMomentFollowResponseData `json:"data"`
Type int `json:"type"`
}
// VideoMomentFollow 关注视频号
func (w *WxApi) VideoMomentFollow(request VideoMomentFollowRequest) (*VideoMomentFollowResponseData, error) {
resp, err := w.internalCall(MtVideoMomentFollowMsg, 120, MtVideoMomentFollowMsg, request, nil)
if err != nil {
return nil, err
}
var rdata VideoMomentFollowResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type VideoMomentLikeRequest struct {
ObjectId string `json:"object_id"`
ObjectNonceId string `json:"object_nonce_id"`
}
type VideoMomentLikeResponseData struct {
BaseResponse struct {
ErrMsg struct {
String string `json:"string"`
} `json:"errMsg"`
Ret int `json:"ret"`
} `json:"baseResponse"`
Likeid int `json:"likeid"`
}
type VideoMomentLikeResponse struct {
Data VideoMomentLikeResponseData `json:"data"`
Type int `json:"type"`
}
// VideoMomentLike 视频号点赞
func (w *WxApi) VideoMomentLike(request VideoMomentLikeRequest) (*VideoMomentLikeResponseData, error) {
resp, err := w.internalCall(MtVideoMomentLikeMsg, 120, MtVideoMomentLikeMsg, request, nil)
if err != nil {
return nil, err
}
var rdata VideoMomentLikeResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type VideoMomentGetSessionIdRequest struct {
ToUsername string `json:"to_username"`
RoleType int `json:"roleType"`
}
type VideoMomentGetSessionIdResponseData struct {
BaseResponse struct {
ErrMsg struct {
} `json:"errMsg"`
Ret int `json:"ret"`
} `json:"baseResponse"`
EnableAction int `json:"enableAction"`
SessionId string `json:"sessionId"`
SessionInfo struct {
EnableAction int `json:"enableAction"`
MsgExtInfo string `json:"msgExtInfo"`
RejectMsg int `json:"rejectMsg"`
SessionId string `json:"sessionId"`
ToUsername string `json:"toUsername"`
} `json:"sessionInfo"`
ToUsername string `json:"toUsername"`
}
type VideoMomentGetSessionIdResponse struct {
Data VideoMomentGetSessionIdResponseData `json:"data"`
Type int `json:"type"`
}
// VideoMomentGetSessionId 获取私信sessionId
func (w *WxApi) VideoMomentGetSessionId(request VideoMomentGetSessionIdRequest) (*VideoMomentGetSessionIdResponseData, error) {
resp, err := w.internalCall(MtVideoMomentGetSessionIdMsg, 120, MtVideoMomentGetSessionIdMsg, request, nil)
if err != nil {
return nil, err
}
var rdata VideoMomentGetSessionIdResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type VideoMomentSendMsgRequest struct {
ToUsername string `json:"to_username"`
SessionId string `json:"session_id"`
Content string `json:"content"`
}
type VideoMomentSendMsgResponseData struct {
BaseResponse struct {
ErrMsg struct {
String string `json:"string"`
} `json:"errMsg"`
Ret int `json:"ret"`
} `json:"baseResponse"`
Newmsgid int `json:"newmsgid"`
}
type VideoMomentSendMsgResponse struct {
Data VideoMomentSendMsgResponseData `json:"data"`
Type int `json:"type"`
}
// VideoMomentSendMsg 发送私信消息
func (w *WxApi) VideoMomentSendMsg(request VideoMomentSendMsgRequest) (*VideoMomentSendMsgResponseData, error) {
resp, err := w.internalCall(MtVideoMomentSendMsg, 120, MtVideoMomentSendMsg, request, nil)
if err != nil {
return nil, err
}
var rdata VideoMomentSendMsgResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}
type VideoMomentCreateVirtualNickNameRequest struct {
Nickname string `json:"nickname"`
HeadimgUrl string `json:"headimg_url"`
}
type VideoMomentCreateVirtualNickNameResponse struct {
Data interface{} `json:"data"`
Type int `json:"type"`
}
// VideoMomentCreateVirtualNickName 创建虚拟昵称
func (w *WxApi) VideoMomentCreateVirtualNickName(request VideoMomentCreateVirtualNickNameRequest) (interface{}, error) {
resp, err := w.internalCall(MtVideoMomentCreateVirtualNickNameMsg, 120, MtVideoMomentCreateVirtualNickNameMsg, request, nil)
if err != nil {
return nil, err
}
var rdata VideoMomentCreateVirtualNickNameResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return rdata.Data, nil
}
type VideoMomentSwitchVirtualNickNameRequest struct {
RoleType int `json:"role_type"`
}
type VideoMomentSwitchVirtualNickNameResponse struct {
Data interface{} `json:"data"`
Type int `json:"type"`
}
// VideoMomentSwitchVirtualNickName 切换虚拟昵称
func (w *WxApi) VideoMomentSwitchVirtualNickName(request VideoMomentSwitchVirtualNickNameRequest) (interface{}, error) {
resp, err := w.internalCall(MtVideoMomentSwitchVirtualNickNameMsg, 120, MtVideoMomentSwitchVirtualNickNameMsg, request, nil)
if err != nil {
return nil, err
}
var rdata VideoMomentSwitchVirtualNickNameResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return rdata.Data, nil
}
// VideoMomentDeleteVirtualNickName 删除虚拟昵称
func (w *WxApi) VideoMomentDeleteVirtualNickName() error {
_, err := w.internalCall(0, -1, MtVideoMomentDeleteVirtualNickNameMsg, map[string]interface{}{}, nil)
if err != nil {
return err
}
return nil
}

36
core/callapi_voice.go Normal file
View File

@ -0,0 +1,36 @@
package core
import "github.com/goWxHook/goWxHook/utils/json"
type VoiceToTextRequest struct {
Msgid string `json:"msgid"`
}
type VoiceToTextResponseData struct {
FromWxid string `json:"from_wxid"`
Msgid string `json:"msgid"`
RoomWxid string `json:"room_wxid"`
Status int `json:"status"`
Text string `json:"text"`
ToWxid string `json:"to_wxid"`
WxType int `json:"wx_type"`
}
type VoiceToTextResponse struct {
Data VoiceToTextResponseData `json:"data"`
Type int `json:"type"`
}
// VoiceToText 语音转文字
func (w *WxApi) VoiceToText(request VoiceToTextRequest) (*VoiceToTextResponseData, error) {
resp, err := w.internalCall(MtVoiceToTextMsg, 120, MtVoiceToTextMsg, request, nil)
if err != nil {
return nil, err
}
var rdata VoiceToTextResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}

89
core/callapi_workwx.go Normal file
View File

@ -0,0 +1,89 @@
package core
import "github.com/goWxHook/goWxHook/utils/json"
type GetWorkWxUserListResponseDataItem struct {
Avatar string `json:"avatar"`
Nickname string `json:"nickname"`
Sex int `json:"sex"`
Wxid string `json:"wxid"`
}
type GetWorkWxUserListResponse struct {
Data []GetWorkWxUserListResponseDataItem `json:"data"`
Type int `json:"type"`
}
// GetWorkWxUserList 获取企业微信用户列表
func (w *WxApi) GetWorkWxUserList() ([]GetWorkWxUserListResponseDataItem, error) {
resp, err := w.internalCall(MtGetWorkWxUserListMsg, 20, MtGetWorkWxUserListMsg, nil, nil)
if err != nil {
return nil, err
}
var rdata GetWorkWxUserListResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return rdata.Data, nil
}
type GetWorkWxRoomListResponseDataItem struct {
Avatar string `json:"avatar"`
ManagerWxid string `json:"manager_wxid"`
Nickname string `json:"nickname"`
RoomWxid string `json:"room_wxid"`
TotalMember int `json:"total_member"`
}
type GetWorkWxRoomListResponse struct {
Data []GetWorkWxRoomListResponseDataItem `json:"data"`
Type int `json:"type"`
}
// GetWorkWxRoomList 获取企业微信群列表
func (w *WxApi) GetWorkWxRoomList() ([]GetWorkWxRoomListResponseDataItem, error) {
resp, err := w.internalCall(MtGetWorkWxChatRoomMsg, 20, MtGetWorkWxChatRoomMsg, nil, nil)
if err != nil {
return nil, err
}
var rdata GetWorkWxRoomListResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return rdata.Data, nil
}
type GetWorkWxChatRoomMemberRequest struct {
RoomWxid string `json:"room_wxid"`
}
type GetWorkWxChatRoomMemberResponseData struct {
MemberList []struct {
Avatar string `json:"avatar"`
Nickname string `json:"nickname"`
Sex int `json:"sex"`
Wxid string `json:"wxid"`
} `json:"member_list"`
RoomWxid string `json:"room_wxid"`
}
type GetWorkWxChatRoomMemberResponse struct {
Data GetWorkWxChatRoomMemberResponseData `json:"data"`
Type int `json:"type"`
}
// GetWorkWxChatRoomMember 获取企业微信群成员列表
func (w *WxApi) GetWorkWxChatRoomMember(request GetWorkWxChatRoomMemberRequest) (*GetWorkWxChatRoomMemberResponseData, error) {
resp, err := w.internalCall(MtGetWorkWxChatRoomMemberMsg, 20, MtGetWorkWxChatRoomMemberMsg, request, nil)
if err != nil {
return nil, err
}
var rdata GetWorkWxChatRoomMemberResponse
err = json.Unmarshal([]byte(resp), &rdata)
if err != nil {
return nil, WxError{-1, err.Error()}
}
return &rdata.Data, nil
}

22
core/error.go Normal file
View File

@ -0,0 +1,22 @@
package core
import "fmt"
type WxError struct {
ErrorCode int // 错误码
Message string // 错误信息
}
func (e WxError) Error() string {
return fmt.Sprintf("Error Code: %d, Message: %s", e.ErrorCode, e.Message)
}
// Code Error 错误码
func (e WxError) Code() int {
return e.ErrorCode
}
// ErrorMsg Error 错误信息
func (e WxError) ErrorMsg() int {
return e.ErrorMsg()
}

8583
docs/docs.go Normal file

File diff suppressed because it is too large Load Diff

8557
docs/swagger.json Normal file

File diff suppressed because it is too large Load Diff

5390
docs/swagger.yaml Normal file

File diff suppressed because it is too large Load Diff

BIN
ecode/HP_Socket.ec Normal file

Binary file not shown.

BIN
ecode/callexe.bak Normal file

Binary file not shown.

BIN
ecode/callexe.e Normal file

Binary file not shown.

BIN
ecode/zyJson2.6.ec Normal file

Binary file not shown.

Binary file not shown.

48
go.mod Normal file
View File

@ -0,0 +1,48 @@
module github.com/goWxHook/goWxHook
go 1.22.2
require (
github.com/gin-contrib/pprof v1.5.0
github.com/gin-gonic/gin v1.10.0
github.com/json-iterator/go v1.1.12
github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.0
github.com/swaggo/swag v1.16.3
)
require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/bytedance/sonic v1.11.6 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/spec v0.20.9 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.8.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

168
go.sum Normal file
View File

@ -0,0 +1,168 @@
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0=
github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4=
github.com/gin-contrib/gzip v0.0.6/go.mod h1:QOJlmV2xmayAjkNS2Y8NQsMneuRShOU/kjovCXNuzzk=
github.com/gin-contrib/pprof v1.5.0 h1:E/Oy7g+kNw94KfdCy3bZxQFtyDnAX2V7axRS7sNYVrU=
github.com/gin-contrib/pprof v1.5.0/go.mod h1:GqFL6LerKoCQ/RSWnkYczkTJ+tOAUVN/8sbnEtaqOKs=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE=
github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs=
github.com/go-openapi/jsonreference v0.20.0/go.mod h1:Ag74Ico3lPc+zR+qjn4XBUmXymS4zJbYVCZmcgkasdo=
github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE=
github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k=
github.com/go-openapi/spec v0.20.9 h1:xnlYNQAwKd2VQRRfwTEI0DcK+2cbuvI/0c7jx3gA8/8=
github.com/go-openapi/spec v0.20.9/go.mod h1:2OpW+JddWPrpXSCIX8eOx7lZ5iyuWj3RYR6VaaBKcWA=
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g=
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8=
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/swaggo/files v1.0.1 h1:J1bVJ4XHZNq0I46UU90611i9/YzdrF7x92oX1ig5IdE=
github.com/swaggo/files v1.0.1/go.mod h1:0qXmMNH6sXNf+73t65aKeB+ApmgxdnkQzVTAj2uaMUg=
github.com/swaggo/gin-swagger v1.6.0 h1:y8sxvQ3E20/RCyrXeFfg60r6H0Z+SwpTjMYsMm+zy8M=
github.com/swaggo/gin-swagger v1.6.0/go.mod h1:BG00cCEy294xtVpyIAHG6+e2Qzj/xKlRdOqDkvq0uzo=
github.com/swaggo/swag v1.16.3 h1:PnCYjPCah8FK4I26l2F/KQ4yz3sILcVUN3cTlBFA9Pg=
github.com/swaggo/swag v1.16.3/go.mod h1:DImHIuOFXKpMFAQjcC7FG4m3Dg4+QuUgUzJmKjI/gRk=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk=
golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.8.0 h1:vSDcovVPld282ceKgDimkRSC8kpaH1dgyc9UMzlt84Y=
golang.org/x/tools v0.8.0/go.mod h1:JxBZ99ISMI5ViVkT1tr6tdNmXeTrcpVSD3vZ1RsRdN4=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=

51
main.go Normal file
View File

@ -0,0 +1,51 @@
package main
import (
"flag"
"github.com/goWxHook/goWxHook/api"
WXHook "github.com/goWxHook/goWxHook/core"
"log/slog"
"time"
)
var (
webPort int
debug bool
)
func init() {
flag.IntVar(&webPort, "port", 19088, "web端口")
flag.BoolVar(&debug, "debug", false, "debug模式")
flag.Parse()
}
// @title WxHelper API
// @version 3.9.10.19
// @description 微信hook接口文档
func main() {
err := WXHook.WxModuleInit(webPort, debug)
if err != nil {
panic(err)
}
wxApi := WXHook.WxApi{
// 消息10秒无应答就超时
TimeOut: 10, // 上传大文件时记得手动拉长超时
}
// 启动web服务
go func() {
_ = api.NewWebApi(&wxApi, webPort).StartWebApi()
}()
// 注入微信
uinfo, err := wxApi.InjectWeChat()
if err != nil {
panic(err)
}
// 登录完成
slog.Info("登录完成", "微信号", uinfo.Wxid, "昵称", uinfo.Nickname, "用户目录", uinfo.WxUserDir)
// 保活检测
for wxApi.Ping() == nil {
time.Sleep(5 * time.Second)
}
}

19
resource/res.go Normal file
View File

@ -0,0 +1,19 @@
package resource
import (
_ "embed"
)
var (
//go:embed Helper_3.9.10.19.dll
HelperDll []byte
//go:embed Loader_3.9.10.19.dll
LoaderDll []byte
//go:embed callexe.exe
CallExe []byte
//go:embed HPSocket4C.dll
HPSocket4C []byte
)

44
test/test_init.go Normal file
View File

@ -0,0 +1,44 @@
package main
import (
"fmt"
WXHook "github.com/goWxHook/goWxHook/core"
"time"
)
func main() {
err := WXHook.WxModuleInit(21100, true)
if err != nil {
panic(err)
}
wxApi := WXHook.WxApi{
// 消息10秒无应答就超时
TimeOut: 10, // 上传大文件时记得手动拉长超时
}
fmt.Println(wxApi.GetUserWeChatVersion())
// 注入微信
uinfo, err := wxApi.InjectWeChat()
if err != nil {
panic(err)
}
// 登录完成
fmt.Println(uinfo)
//wxid_80buxyrw347m12
//rlist, err := wxApi.GetRoomMember(1, "17736246691@chatroom")
//fmt.Println(rlist, err)
lists, err := wxApi.GetFriendList()
if err != nil {
fmt.Println(err)
return
}
fmt.Println(lists)
// 保活检测
for wxApi.Ping() == nil {
time.Sleep(5 * time.Second)
}
fmt.Println("exit")
}

21
utils/file.go Normal file
View File

@ -0,0 +1,21 @@
package utils
import "os"
func FileExists(path string) bool {
_, err := os.Lstat(path)
if os.IsNotExist(err) {
return false
}
return err == nil
}
func WriteFile(path string, data []byte) error {
file, err := os.Create(path)
if err != nil {
return err
}
defer file.Close()
_, err = file.Write(data)
return err
}

1
utils/http.go Normal file
View File

@ -0,0 +1 @@
package utils

72
utils/json/json.go Normal file
View File

@ -0,0 +1,72 @@
package json
import (
jsoniter "github.com/json-iterator/go"
"reflect"
)
// var json = jsoniter.ConfigFastest
var json = jsoniter.Config{
EscapeHTML: false,
SortMapKeys: true,
MarshalFloatWith6Digits: true, // will lose precession
ObjectFieldMustBeSimpleString: true, // do not unescape object field
}.Froze()
//goland:noinspection GoUnusedGlobalVariable
var (
Get = json.Get
Marshal = json.Marshal
Unmarshal = json.Unmarshal
UnmarshalFromString = json.UnmarshalFromString
MarshalIndent = json.MarshalIndent
NewDecoder = json.NewDecoder
NewEncoder = json.NewEncoder
)
// MarshalToString JSON编码为字符串
//
func MarshalToString(v interface{}) string {
s, err := jsoniter.MarshalToString(v)
if err != nil {
return ""
}
return s
}
func Struct2MapByKeepFieldName(obj interface{}) map[string]interface{} {
t := reflect.TypeOf(obj)
v := reflect.ValueOf(obj)
var data = make(map[string]interface{})
for i := 0; i < t.NumField(); i++ {
data[t.Field(i).Name] = v.Field(i).Interface()
}
return data
}
func Struct2MapByJsonName(obj interface{}) (map[string]interface{}, error) {
marshal, err := json.Marshal(obj)
if err != nil {
return nil, err
}
var data map[string]interface{}
err = json.Unmarshal(marshal, &data)
if err != nil {
return nil, err
}
return data, nil
}
func MapToStruct(m map[string]interface{}, o interface{}) error {
marshal, err := json.Marshal(m)
if err != nil {
return err
}
err = json.Unmarshal(marshal, o)
if err != nil {
return err
}
return nil
}

107
utils/map.go Normal file
View File

@ -0,0 +1,107 @@
package utils
import "sync"
type Key interface {
int | int32 | int64 | string
}
type SafeMap[K Key, V any] struct {
m map[K]V
lock sync.RWMutex
}
func NewSafeMap[K Key, V any]() *SafeMap[K, V] {
return &SafeMap[K, V]{
m: make(map[K]V),
}
}
func (sm *SafeMap[K, V]) Set(key K, value V) {
sm.lock.Lock()
defer sm.lock.Unlock()
sm.m[key] = value
}
func (sm *SafeMap[K, V]) Get(key K) (V, bool) {
sm.lock.RLock()
defer sm.lock.RUnlock()
value, ok := sm.m[key]
return value, ok
}
func (sm *SafeMap[K, V]) GetWithSetDefault(key K, defaultValue V) V {
sm.lock.Lock()
defer sm.lock.Unlock()
if value, ok := sm.m[key]; ok {
return value
}
sm.m[key] = defaultValue
return defaultValue
}
func (sm *SafeMap[K, V]) Delete(key K) {
sm.lock.Lock()
defer sm.lock.Unlock()
delete(sm.m, key)
}
func (sm *SafeMap[K, V]) Range(f func(key K, value V) bool) {
sm.lock.RLock()
defer sm.lock.RUnlock()
for k, v := range sm.m {
if !f(k, v) {
break
}
}
}
func (sm *SafeMap[K, V]) Len() int {
sm.lock.RLock()
defer sm.lock.RUnlock()
return len(sm.m)
}
func (sm *SafeMap[K, V]) Keys() []K {
sm.lock.RLock()
defer sm.lock.RUnlock()
keys := make([]K, 0, len(sm.m))
for k := range sm.m {
keys = append(keys, k)
}
return keys
}
func (sm *SafeMap[K, V]) Values() []V {
sm.lock.RLock()
defer sm.lock.RUnlock()
values := make([]V, 0, len(sm.m))
for _, v := range sm.m {
values = append(values, v)
}
return values
}
func (sm *SafeMap[K, V]) Clear() {
sm.lock.Lock()
defer sm.lock.Unlock()
sm.m = make(map[K]V)
}
func (sm *SafeMap[K, V]) Copy() map[K]V {
sm.lock.RLock()
defer sm.lock.RUnlock()
m := make(map[K]V, len(sm.m))
for k, v := range sm.m {
m[k] = v
}
return m
}
func (sm *SafeMap[K, V]) Merge(m map[K]V) {
sm.lock.Lock()
defer sm.lock.Unlock()
for k, v := range m {
sm.m[k] = v
}
}

30
utils/response.go Normal file
View File

@ -0,0 +1,30 @@
package utils
import (
"github.com/gin-gonic/gin"
"net/http"
)
type Response struct {
Code int `json:"code"` // if request is success
Msg string `json:"msg"`
Data interface{} `json:"data"` // response data
}
func ResponseOK(c *gin.Context, errMsg string, data interface{}) {
c.JSON(http.StatusOK, Response{
Code: 0,
Msg: errMsg,
Data: data,
})
return
}
func ResponseError(c *gin.Context, errMsg string, data interface{}) {
c.JSON(http.StatusOK, Response{
Code: 400,
Msg: errMsg,
Data: data,
})
return
}

24
utils/tcp/port.go Normal file
View File

@ -0,0 +1,24 @@
package tcp
import (
"fmt"
"net"
"time"
)
// CheckPortConnection 检测端口是否监听
func CheckPortConnection(ip string, port int) bool {
conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", ip, port), 3*time.Second)
if err != nil {
return false
} else {
if conn != nil {
defer func(conn net.Conn) {
_ = conn.Close()
}(conn)
return true
} else {
return false
}
}
}

8
utils/u.go Normal file
View File

@ -0,0 +1,8 @@
package utils
func Ifs[T any](a bool, b, c T) T {
if a {
return b
}
return c
}