package wxhelper import ( "errors" "slices" robotModel "wechat-robot/model/robot" ) type wxHelper struct { host string // hook接口地址 version WeChatVersion // 微信版本 } // Api // @description: 微信助手接口 type Api interface { CheckLogin() bool // 检查是否登录 UserInfo() (robotModel.UserInfo, error) // 获取机器人信息 SendTextMsg(toUserId, atUserId, msg string) error // 发送文字消息 SendFileMsg(toUserId, filePath string) error // 发送文件消息 SendImagesMsg(toUserId, imagePath string) error // 发送图片消息 SendCustomEmotionMsg(toUserId string, emotionPath string) error // 发送自定义表情消息 GetContactList() []robotModel.FriendItem // 获取联系人列表 GetChatRoomDetailInfo(chatRoomId string) robotModel.ChatRoomDetailInfo // 获取群聊详情 AddMemberToChatRoom(chatRoomId string, memberWxIds []string) error // 添加群成员 DelMemberFromChatRoom(chatRoomId string, memberWxIds []string) error // 删除群成员 GetMemberFromChatRoom(chatRoomId string) robotModel.GroupUser // 获取群成员 GetContactProfile(wxId string) robotModel.ContactProfile // 获取好友资料 InviteMemberToChatRoom(chatRoomId string, memberWxIds []string) error // 邀请入群 ModifyChatRoomNickname(wxId, nickname string) error // 修改群内昵称 StartHook(tcpIp string, tcpPort int) error // 开启消息监听 - 暂时只支持tcp,因为http有点儿不太好使 StopHook() error // 关闭消息监听 DownloadAttach(msgId int) error // 下载附件 DecodeImage(filePath, storeDir string) error // 解码图片 } // New // @description: 创建微信助手 // @param host // @return Api func New(host string, version WeChatVersion) (Api, error) { // 判断微信版本是否支持 keys := make([]WeChatVersion, 0, len(apiMap)) for k := range apiMap { keys = append(keys, k) } if !slices.Contains(keys, version) { return nil, errors.New("不支持的微信版本") } return &wxHelper{host: host, version: version}, nil }