contact.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package hook
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. // 获取好友和群信息
  7. func (h *Hook) GetFriendAndChatRoomList(typeStr string) (result GetFriendAndChatRoomListReap, err error) {
  8. resp, err := h.Client.R().SetBody(&GetFriendAndChatRoomListReq{
  9. Type: typeStr,
  10. }).SetSuccessResult(&result).Post("http://" + h.ServerIp + ":" + h.WxPort + "/GetFriendAndChatRoomList")
  11. if err != nil {
  12. return
  13. }
  14. if !resp.IsSuccessState() {
  15. err = fmt.Errorf("GetFriendAndChatRoomList failed with status code %d", resp.StatusCode)
  16. return
  17. }
  18. return
  19. }
  20. // 批量获取联系人简明信息(每次100个)
  21. func (h *Hook) BatchGetContactBriefInfo(wxids []string) (result BatchGetContactBriefInfoReap, err error) {
  22. wxidList := strings.Join(wxids, ",")
  23. resp, err := h.Client.R().SetBody(&BatchGetContactBriefInfoReq{
  24. WxidList: wxidList,
  25. }).SetSuccessResult(&result).Post("http://" + h.ServerIp + ":" + h.WxPort + "/BatchGetContactBriefInfo")
  26. if err != nil {
  27. return
  28. }
  29. if !resp.IsSuccessState() {
  30. err = fmt.Errorf("BatchGetChatRoomMemberWxid failed with status code %d", resp.StatusCode)
  31. return
  32. }
  33. return
  34. }
  35. // 添加新的好友
  36. func (h *Hook) AddNewFriend(v3_wxid string, v4 string, desc string, addType string, role string) (result AddNewFriendReap, err error) {
  37. resp, err := h.Client.R().SetBody(&AddNewFriendReq{
  38. V3Wxid: v3_wxid,
  39. V4: v4,
  40. Desc: desc,
  41. AddType: addType,
  42. Role: role,
  43. }).SetSuccessResult(&result).Post("http://" + h.ServerIp + ":" + h.WxPort + "/AddNewFriend")
  44. if err != nil {
  45. return
  46. }
  47. if !resp.IsSuccessState() {
  48. err = fmt.Errorf("AddNewFriend failed with status code %d", resp.StatusCode)
  49. return
  50. }
  51. return
  52. }