117 lines
3.2 KiB
Go
117 lines
3.2 KiB
Go
package friend
|
|
|
|
import (
|
|
"errors"
|
|
"gitee.ltd/lxh/xybot/base"
|
|
"slices"
|
|
"strings"
|
|
)
|
|
|
|
// AcceptFriend
|
|
// @description: 接受好友请求
|
|
// @receiver s
|
|
// @param scene
|
|
// @param v1
|
|
// @param v2
|
|
// @return err
|
|
func (s service) AcceptFriend(scene int, v1, v2 string) (err error) {
|
|
var result base.Response[base.EmptyResponse]
|
|
_, err = s.client.R().
|
|
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
SetResult(&result).
|
|
SetBody(map[string]any{
|
|
"Wxid": s.robotInfo.GetId(),
|
|
"Scene": scene,
|
|
"V1": v1,
|
|
"V2": v2,
|
|
}).Post("/AcceptFriend")
|
|
err = result.CheckError(err)
|
|
return
|
|
}
|
|
|
|
// GetContact
|
|
// @description: 通过wxid获取联系人详情
|
|
// @receiver s
|
|
// @param wxIds
|
|
// @return contactList
|
|
// @return err
|
|
func (s service) GetContact(wxIds []string) (contactList []ContactListItem, err error) {
|
|
var result base.Response[GetContactResponse]
|
|
_, err = s.client.R().
|
|
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
SetResult(&result).
|
|
SetBody(map[string]any{
|
|
"Wxid": s.robotInfo.GetId(),
|
|
"RequestWxids": strings.Join(wxIds, ","),
|
|
}).Post("/GetContact")
|
|
if err = result.CheckError(err); err != nil {
|
|
return
|
|
}
|
|
contactList = result.Data.ContactList
|
|
return
|
|
}
|
|
|
|
// GetContractDetail
|
|
// @description: 获取联系人详情
|
|
// @receiver s
|
|
// @param wxIds
|
|
// @return contactList
|
|
// @return err
|
|
func (s service) GetContractDetail(wxIds []string) (contactList []ContactListItem, err error) {
|
|
if len(wxIds) > 20 {
|
|
err = errors.New("一次最多查询20个联系人")
|
|
return
|
|
}
|
|
|
|
var result base.Response[GetContactResponse]
|
|
_, err = s.client.R().
|
|
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
SetResult(&result).
|
|
SetBody(map[string]any{
|
|
"Wxid": s.robotInfo.GetId(),
|
|
"RequestWxids": strings.Join(wxIds, ","),
|
|
"Chatroom": "",
|
|
}).Post("/GetContractDetail")
|
|
if err = result.CheckError(err); err != nil {
|
|
return
|
|
}
|
|
contactList = result.Data.ContactList
|
|
return
|
|
}
|
|
|
|
// GetContractList
|
|
// @description: 获取联系人列表
|
|
// @receiver s
|
|
// @param clearSystemAccount 是否清除系统账号
|
|
// @return wxIds
|
|
// @return err
|
|
func (s service) GetContractList(clearSystemAccount bool) (wxIds []string, err error) {
|
|
var result base.Response[GetContractListResponse]
|
|
_, err = s.client.R().
|
|
SetHeader("WeChatId", s.robotInfo.GetId()).
|
|
SetResult(&result).
|
|
SetBody(map[string]any{
|
|
"Wxid": s.robotInfo.GetId(),
|
|
"CurrentChatroomContactSeq": 0,
|
|
"CurrentWxcontactSeq": 0,
|
|
}).Post("/GetContractList")
|
|
if err = result.CheckError(err); err != nil {
|
|
return
|
|
}
|
|
|
|
wxIds = result.Data.ContactUsernameList
|
|
|
|
// 过滤掉特殊微信Id
|
|
var specialId = []string{"filehelper", "newsapp", "fmessage", "weibo", "qqmail", "tmessage", "qmessage", "qqsync",
|
|
"floatbottle", "lbsapp", "shakeapp", "medianote", "qqfriend", "readerapp", "blogapp", "facebookapp", "masssendapp",
|
|
"meishiapp", "feedsapp", "voip", "blogappweixin", "weixin", "brandsessionholder", "weixinreminder", "officialaccounts",
|
|
"notification_messages", "wxitil", "userexperience_alarm", "notification_messages", "exmail_tool", "mphelper"}
|
|
if clearSystemAccount {
|
|
wxIds = slices.DeleteFunc(wxIds, func(id string) bool {
|
|
return slices.Contains(specialId, id) || strings.HasPrefix(id, "gh_") || strings.TrimSpace(id) == ""
|
|
})
|
|
}
|
|
|
|
return
|
|
}
|